Skip to content

Commit 659ccb5

Browse files
committed
Merge pull request #23 from AlexeyDemidov/style_cleanup
Style cleanup
2 parents c41f6f5 + b746357 commit 659ccb5

26 files changed

+328
-337
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
# Specify your gem's dependencies in ruby-stackoverflow.gemspec
44
gemspec

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "bundler/gem_tasks"
2-
require 'rspec/core/rake_task'
2+
require "rspec/core/rake_task"
33

44
RSpec::Core::RakeTask.new(:spec)
55

6-
task :default => :spec
6+
task default: :spec

lib/generators/ruby_stackoverflow/ruby_stackoverflow_generator.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
require 'rails/generators'
1+
require "rails/generators"
22

33
class RubyStackoverflowGenerator < Rails::Generators::Base
44
desc "Creates the ruby-stackoverflow initializer file at config/initialize/ruby-stackoverflow.rb"
5-
class_option :client_key, :aliases => "-k", :type => :string, :desc => "Your Stackoverflow Client key"
6-
class_option :access_token, :aliases => "-k", :type => :string, :desc => "Your STackoverflow access token"
5+
class_option :client_key, aliases: "-k", type: :string, desc: "Your Stackoverflow Client key"
6+
class_option :access_token, aliases: "-k", type: :string, desc: "Your STackoverflow access token"
77

88
def self.source_root
99
@_ruby_stackoverflow_root ||= File.expand_path("../templates", __FILE__)
1010
end
1111

1212
def install
13-
template 'ruby_stackoverflow.rb', 'config/initializers/ruby_stackoverflow.rb'
13+
template "ruby_stackoverflow.rb", "config/initializers/ruby_stackoverflow.rb"
1414
end
1515

1616
private

lib/ruby-stackoverflow.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def client
1212
end
1313

1414
# @private
15-
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
15+
def respond_to_missing?(method_name, include_private = false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
1616
# @private
17-
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
17+
def respond_to?(method_name, include_private = false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
1818

1919
private
2020

lib/ruby-stackoverflow/client.rb

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
require 'json'
2-
require 'ruby-stackoverflow/client/response_data'
3-
require 'ruby-stackoverflow/client/resource/resource'
4-
require 'ruby-stackoverflow/client/resource/user'
5-
require 'ruby-stackoverflow/client/resource/question'
6-
require 'ruby-stackoverflow/client/resource/answer'
7-
require 'ruby-stackoverflow/client/resource/notification'
8-
require 'ruby-stackoverflow/client/resource/badge'
9-
require 'ruby-stackoverflow/client/resource/reputation'
10-
require 'ruby-stackoverflow/client/resource/suggested_edit'
11-
require 'ruby-stackoverflow/client/resource/comment'
12-
require 'ruby-stackoverflow/client/resource/tag'
13-
require 'ruby-stackoverflow/client/resource/post'
14-
require 'ruby-stackoverflow/client/resource/permission'
15-
require 'ruby-stackoverflow/client/resource/stackoverflow_error'
16-
require 'ruby-stackoverflow/client/user_helper'
17-
require 'ruby-stackoverflow/client/question_helper'
18-
require 'ruby-stackoverflow/client/badges_helper'
19-
require 'ruby-stackoverflow/client/comments_helper'
20-
require 'ruby-stackoverflow/client/parse_options'
1+
require "json"
2+
require "ruby-stackoverflow/client/response_data"
3+
require "ruby-stackoverflow/client/resource/resource"
4+
require "ruby-stackoverflow/client/resource/user"
5+
require "ruby-stackoverflow/client/resource/question"
6+
require "ruby-stackoverflow/client/resource/answer"
7+
require "ruby-stackoverflow/client/resource/notification"
8+
require "ruby-stackoverflow/client/resource/badge"
9+
require "ruby-stackoverflow/client/resource/reputation"
10+
require "ruby-stackoverflow/client/resource/suggested_edit"
11+
require "ruby-stackoverflow/client/resource/comment"
12+
require "ruby-stackoverflow/client/resource/tag"
13+
require "ruby-stackoverflow/client/resource/post"
14+
require "ruby-stackoverflow/client/resource/permission"
15+
require "ruby-stackoverflow/client/resource/stackoverflow_error"
16+
require "ruby-stackoverflow/client/user_helper"
17+
require "ruby-stackoverflow/client/question_helper"
18+
require "ruby-stackoverflow/client/badges_helper"
19+
require "ruby-stackoverflow/client/comments_helper"
20+
require "ruby-stackoverflow/client/parse_options"
2121

2222
module RubyStackoverflow
2323
class Client
@@ -29,8 +29,8 @@ class Client
2929

3030
attr_accessor :configuration
3131

32-
def getr(url,klass, options={})
33-
request :get, url,klass ,options
32+
def getr(url, klass, options = {})
33+
request :get, url, klass, options
3434
end
3535

3636
def configure
@@ -39,9 +39,9 @@ def configure
3939

4040
private
4141

42-
def request(method, url, klass, options={})
42+
def request(method, url, klass, options = {})
4343
url = append_params_to_url(url, parse_options(options))
44-
response = HTTParty.send(method,url)
44+
response = HTTParty.send(method, url)
4545
parse_response(response, klass)
4646
end
4747

@@ -53,16 +53,17 @@ def parse_response(data, klass)
5353
def append_params_to_url(url, options)
5454
url = Configuration.api_url + url
5555
options.merge!(key_params)
56-
options = options.to_a.map{|k,v|"#{k}=#{v}"}
57-
url+'?'+options.join('&')
56+
options[:site] ||= configuration.site || "stackoverflow"
57+
options = options.to_a.map { |k, v| "#{k}=#{v}" }
58+
url + "?" + options.join("&")
5859
end
5960

6061
def key_params
61-
{key: configuration.client_key, site: 'stackoverflow', access_token: configuration.access_token}
62+
{ key: configuration.client_key, access_token: configuration.access_token }
6263
end
6364

6465
def configuration
65-
@configuration||= Configuration.new
66+
@configuration ||= Configuration.new
6667
end
6768
end
6869
end

lib/ruby-stackoverflow/client/badges_helper.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ def badges_by_ids(ids, options = {})
1010
badges_response(options, url)
1111
end
1212

13-
def badges_by_ids(ids, options = {})
14-
url = join_ids(ids)
15-
badges_response(options, url)
16-
end
17-
1813
def badges_by_name(options = {})
1914
url = "/name"
2015
badges_response(options, url)
@@ -38,7 +33,7 @@ def badges_by_tags(options = {})
3833

3934
private
4035

41-
def badges_response(options = {}, url= "")
36+
def badges_response(options = {}, url = "")
4237
url = "badges/" + url
4338
getr(url, "badge", options)
4439
end

lib/ruby-stackoverflow/client/comments_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def comments_by_ids(ids, options = {})
1212

1313
private
1414

15-
def comments_response(options={}, url='')
16-
url = 'comments/' + url
17-
getr(url, 'comment', options)
15+
def comments_response(options = {}, url = "")
16+
url = "comments/" + url
17+
getr(url, "comment", options)
1818
end
1919
end
2020
end

lib/ruby-stackoverflow/client/parse_options.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module RubyStackoverflow
22
class Client
33
module ParseOptions
44
def parse_options(options = {})
5-
options.each do|k,v|
5+
options.each do |k, v|
66
case k
7-
when :fromdate , :todate, :min, :max
7+
when :fromdate, :todate, :min, :max
88
begin
99
options[k] = Time.parse(v).to_i
1010
rescue
@@ -17,7 +17,7 @@ def parse_options(options = {})
1717
end
1818

1919
def join_ids(ids)
20-
ids.join(';')
20+
ids.join(";")
2121
end
2222
end
2323
end

lib/ruby-stackoverflow/client/question_helper.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,54 @@ def questions(options = {})
55
question_response(options)
66
end
77

8-
def questions_by_ids(ids , options = {})
8+
def questions_by_ids(ids, options = {})
99
url = join_ids(ids)
1010
question_response(options, url)
1111
end
1212

13-
def answers_of_questions(ids, options={})
14-
url = join_ids(ids) + '/answers'
13+
def answers_of_questions(ids, options = {})
14+
url = join_ids(ids) + "/answers"
1515
question_response(options, url)
1616
end
1717

18-
def comments_of_questions(ids, options={})
19-
url = join_ids(ids) + '/comments'
18+
def comments_of_questions(ids, options = {})
19+
url = join_ids(ids) + "/comments"
2020
question_response(options, url)
2121
end
2222

23-
def linked_questions(ids, options={})
24-
url = join_ids(ids)+'/linked'
23+
def linked_questions(ids, options = {})
24+
url = join_ids(ids) + "/linked"
2525
question_response(options, url)
2626
end
2727

28-
def related_questions(ids, options={})
29-
url= join_ids(ids) + '/related'
28+
def related_questions(ids, options = {})
29+
url = join_ids(ids) + "/related"
3030
question_response(options, url)
3131
end
3232

33-
def timeline_of_questions(ids, options={})
34-
url = join_ids(ids) + '/timeline'
33+
def timeline_of_questions(ids, options = {})
34+
url = join_ids(ids) + "/timeline"
3535
question_response(options, url)
3636
end
3737

38-
def featured_questions(options={})
39-
url = 'featured'
38+
def featured_questions(options = {})
39+
url = "featured"
4040
question_response(options, url)
4141
end
4242

43-
def unanswered_questions(options={})
44-
question_response(options, 'unanswered')
43+
def unanswered_questions(options = {})
44+
question_response(options, "unanswered")
4545
end
4646

47-
def noanswered_questions(options={})
48-
question_response(options, 'no-answers')
47+
def noanswered_questions(options = {})
48+
question_response(options, "no-answers")
4949
end
5050

5151
private
5252

53-
def question_response(options={}, url='')
54-
url = 'questions/' + url
55-
getr(url, 'question', options)
53+
def question_response(options = {}, url = "")
54+
url = "questions/" + url
55+
getr(url, "question", options)
5656
end
5757
end
5858
end

lib/ruby-stackoverflow/client/resource/question.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module RubyStackoverflow
22
class Client
33
class Question < Resource
4-
attr_reader :answers , :comments,:user, :posts
5-
def initialize(attributes_hash={})
4+
attr_reader :answers, :comments, :user, :posts
5+
def initialize(attributes_hash = {})
66
@answers = []
77
@comments = []
88
@posts = []
@@ -12,15 +12,15 @@ def initialize(attributes_hash={})
1212
class << self
1313
def parse_data(data)
1414
questions = []
15-
data.each do|attr_hash|
15+
data.each do |attr_hash|
1616
if data_has_answer?(data)
1717
question = create_question(attr_hash, questions, :question_id)
1818
question.answers.push(Answer.new(attr_hash))
1919
elsif data_has_comment?(data)
20-
question = create_question(attr_hash, questions,:post_id)
20+
question = create_question(attr_hash, questions, :post_id)
2121
question.comments.push(Comment.new(attr_hash))
2222
elsif data_has_timeline?(data)
23-
question = create_question(attr_hash, questions,:question_id)
23+
question = create_question(attr_hash, questions, :question_id)
2424
question.posts.push(Post.new(attr_hash))
2525
else
2626
questions << new(attr_hash)
@@ -42,20 +42,19 @@ def data_has_timeline?(data)
4242
end
4343

4444
def find_or_create_question(questions, qid)
45-
question_array = questions.select{|q|q.question_id == qid}
46-
!question_array.empty? ? question_array.first : new({question_id: qid})
45+
question_array = questions.select { |q| q.question_id == qid }
46+
!question_array.empty? ? question_array.first : new(question_id: qid)
4747
end
4848

49-
5049
def create_question(attr_hash, questions, hash_key)
5150
qid = attr_hash.delete(hash_key)
5251
question = find_or_create_question(questions, qid)
53-
questions << question unless question_exists?(questions,qid)
52+
questions << question unless question_exists?(questions, qid)
5453
question
5554
end
5655

5756
def question_exists?(questions, question_id)
58-
question_array = questions.select{|q|q.question_id == question_id }
57+
question_array = questions.select { |q| q.question_id == question_id }
5958
!question_array.empty?
6059
end
6160
end

lib/ruby-stackoverflow/client/resource/reputation.rb

-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ class Reputation < Resource
44
end
55
end
66
end
7-
8-

lib/ruby-stackoverflow/client/resource/resource.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module RubyStackoverflow
22
class Client
33
class Resource
44
def initialize(attributes_hash)
5-
attributes_hash.each do|k,v|
5+
attributes_hash.each do |k, v|
66
self.class.send :attr_accessor, k
77
var = "@#{k}"
88
case k.to_sym
9-
when :creation_date, :last_activity_date, :launch_date,:last_edit_date
9+
when :creation_date, :last_activity_date, :launch_date, :last_edit_date
1010
value = Time.at(v).utc.to_s
1111
else
1212
value = v
@@ -17,7 +17,7 @@ def initialize(attributes_hash)
1717

1818
class << self
1919
def parse_data(data)
20-
datas = data.map do|attr_hash|
20+
datas = data.map do |attr_hash|
2121
new(attr_hash)
2222
end
2323
datas

lib/ruby-stackoverflow/client/resource/stackoverflow_error.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module RubyStackoverflow
22
class Client
33
class StackoverflowError
4-
attr_reader :error_code, :error_message, :error_name
4+
attr_reader :error_code, :error_message, :error_name
55

66
def initialize(params)
77
@error_name = params[:error_name]

0 commit comments

Comments
 (0)