-
Notifications
You must be signed in to change notification settings - Fork 25
Refactoring for code improvement #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,25 @@ | ||
require 'json' | ||
require 'ruby-stackoverflow/client/response_data' | ||
require 'ruby-stackoverflow/client/resource/resource' | ||
require 'ruby-stackoverflow/client/resource/user' | ||
require 'ruby-stackoverflow/client/resource/question' | ||
require 'ruby-stackoverflow/client/resource/answer' | ||
require 'ruby-stackoverflow/client/resource/notification' | ||
require 'ruby-stackoverflow/client/resource/badge' | ||
require 'ruby-stackoverflow/client/resource/reputation' | ||
require 'ruby-stackoverflow/client/resource/suggested_edit' | ||
require 'ruby-stackoverflow/client/resource/comment' | ||
require 'ruby-stackoverflow/client/resource/tag' | ||
require 'ruby-stackoverflow/client/resource/post' | ||
require 'ruby-stackoverflow/client/resource/permission' | ||
require 'ruby-stackoverflow/client/resource/stackoverflow_error' | ||
require 'ruby-stackoverflow/client/user_helper' | ||
require 'ruby-stackoverflow/client/question_helper' | ||
require 'ruby-stackoverflow/client/badges_helper' | ||
require 'ruby-stackoverflow/client/comments_helper' | ||
require 'ruby-stackoverflow/client/parse_options' | ||
|
||
require_relative 'client/response_data' | ||
require_relative 'client/resources' | ||
require_relative 'client/user_helper' | ||
require_relative 'client/question_helper' | ||
require_relative 'client/badges_helper' | ||
require_relative 'client/comments_helper' | ||
require_relative 'client/parse_options' | ||
|
||
module RubyStackoverflow | ||
class Client | ||
include RubyStackoverflow::Client::ParseOptions | ||
include RubyStackoverflow::Client::UserHelper | ||
include RubyStackoverflow::Client::QuestionHelper | ||
include RubyStackoverflow::Client::BadgesHelper | ||
include RubyStackoverflow::Client::CommentsHelper | ||
include ParseOptions | ||
include UserHelper | ||
include QuestionHelper | ||
include BadgesHelper | ||
include CommentsHelper | ||
|
||
attr_accessor :configuration | ||
|
||
def getr(url,klass, options={}) | ||
request :get, url,klass ,options | ||
def getr(url, klass, options = {}) | ||
request :get, url, klass, options | ||
end | ||
|
||
def configure | ||
|
@@ -39,9 +28,9 @@ def configure | |
|
||
private | ||
|
||
def request(method, url, klass, options={}) | ||
def request(method, url, klass, options = {}) | ||
url = append_params_to_url(url, parse_options(options)) | ||
response = HTTParty.send(method,url) | ||
response = HTTParty.send(method, url) | ||
parse_response(response, klass) | ||
end | ||
|
||
|
@@ -53,16 +42,20 @@ def parse_response(data, klass) | |
def append_params_to_url(url, options) | ||
url = Configuration.api_url + url | ||
options.merge!(key_params) | ||
options = options.to_a.map{|k,v|"#{k}=#{v}"} | ||
url+'?'+options.join('&') | ||
options = options.to_a.map { |k, v| "#{k}=#{v}" } | ||
url + '?' + options.join('&') | ||
end | ||
|
||
def key_params | ||
{key: configuration.client_key, site: 'stackoverflow', access_token: configuration.access_token} | ||
{ | ||
key: configuration.client_key, | ||
site: 'stackoverflow', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
access_token: configuration.access_token, | ||
} | ||
end | ||
|
||
def configuration | ||
@configuration||= Configuration.new | ||
@configuration ||= Configuration.new | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
module RubyStackoverflow | ||
class Client | ||
module ParseOptions | ||
def parse_options(options = {}) | ||
options.each do|k,v| | ||
case k | ||
when :fromdate , :todate, :min, :max | ||
begin | ||
options[k] = Time.parse(v).to_i | ||
rescue | ||
options[k] = v | ||
end | ||
else | ||
module ParseOptions | ||
def parse_options(options = {}) | ||
options.each do|k,v| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space missing after comma. |
||
case k | ||
when :fromdate , :todate, :min, :max | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space found before comma. |
||
begin | ||
options[k] = Time.parse(v).to_i | ||
rescue | ||
options[k] = v | ||
end | ||
else | ||
options[k] = v | ||
end | ||
end | ||
end | ||
|
||
def join_ids(ids) | ||
ids.join(';') | ||
end | ||
def join_ids(ids) | ||
ids.join(';') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative 'resources/resource' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/user' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/question' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/answer' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/notification' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/badge' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/reputation' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/suggested_edit' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/comment' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/tag' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/post' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/permission' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
require_relative 'resources/stackoverflow_error' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,17 +114,17 @@ def users_top_questions_with_given_tags(id, tags, options = {}) | |
user_response(options, url) | ||
end | ||
|
||
def user_top_tags(id, options ={}) | ||
def user_top_tags(id, options = {}) | ||
url = id + '/top-tags' | ||
user_response(options, url) | ||
end | ||
|
||
def user_top_tags_by_answers(id, options ={}) | ||
def user_top_tags_by_answers(id, options = {}) | ||
url = id + '/top-answer-tags' | ||
user_response(options, url) | ||
end | ||
|
||
def user_top_tags_by_questions(id, options ={}) | ||
def user_top_tags_by_questions(id, options = {}) | ||
url = id + '/top-question-tags' | ||
user_response(options, url) | ||
end | ||
|
@@ -147,8 +147,8 @@ def user_full_reputation_history(id, options = {}) | |
|
||
private | ||
|
||
def user_response(options={}, url='') | ||
url = 'users/'+ url | ||
def user_response(options = {}, url = '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
url = 'users/' + url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary spacing detected. |
||
getr(url, 'user', options) | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
module RubyStackoverflow | ||
describe Client::UserHelper do | ||
before(:each) do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.