Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion lib/ruby-stackoverflow/client/response_data.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
module RubyStackoverflow
class Client
class ResponseData
attr_reader :data, :has_more, :error
attr_reader :data, :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. [108/80]

Copy link
Owner

Choose a reason for hiding this comment

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

Wondering how we get that raw_response and raw_data
I can see :quota_max, :quota_remaining, :backoff here https://api.stackexchange.com/docs/wrapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

raw_data:
I want do data to json. but couldn't.
It was possible.

JSON.generate(res.raw_data)

raw_response:
It was possible to "full response" to json.


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

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