Skip to content
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

add fields #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/ruby-stackoverflow/client/response_data.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
module RubyStackoverflow
class Client
class ResponseData
attr_reader :data, :has_more, :error
attr_reader :has_more, :error, :raw_response, :raw_data, :quota_max, :quota_remaining, :backoff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [101/80]


def initialize(response, klass)
@raw_response = response
if response[:items].nil?
@error = StackoverflowError.new(response)
else
@data = format_data(response[:items], klass)
@klass = klass
@raw_data = response[:items]
@has_more = response[:has_more]
@quota_max = response[:quota_max]
@quota_remaining = response[:quota_remaining]
@backoff = response[:backoff]
end
end

def data
return nil if @raw_data.nil?
@data ||= format_data(@raw_data.clone, @klass)
end

def format_data(data, klass)
eval(klass.capitalize).parse_data(data)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-stackoverflow/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

module RubyStackoverflow
class Configuration
attr_accessor :client_id, :client_sceret , :client_key, :access_token, :api_url
attr_accessor :client_id, :client_secret , :client_key, :access_token, :api_url
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [84/80]
Unnecessary spacing detected.
Space found before comma.


def self.api_url
'https://api.stackexchange.com/2.2/'
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby-stackoverflow/response_data_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'
Copy link
Collaborator

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.

require 'json'
Copy link
Collaborator

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.


module RubyStackoverflow
describe Client::ResponseData do
it 'should response data fields' do
Copy link
Collaborator

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.

data = JSON.parse(fixture("users.json").read, {:symbolize_names => true})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.
Use the new Ruby 1.9 hash syntax.
Space inside { missing.
Space inside } missing.

response = Client::ResponseData.new(data, 'user')
Copy link
Collaborator

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.

expect(response.data.count).to eq(1)
expect(response.raw_data.count).to eq(1)
expect(response.quota_max).to eq(10000)
expect(response.quota_remaining).to eq(9996)
expect(response.backoff).to be_nil
end
end
end