Skip to content

Commit

Permalink
fix: entries incorrectly mapped
Browse files Browse the repository at this point in the history
This was not being mapped correctly since the `Base` object looks for
data -> attributes when the API response does not include for
collections.

Change the attributes parsed to look at data->attributes and then only
attributes.

Add test case
  • Loading branch information
troyizzle committed Feb 21, 2023
1 parent 8f8b448 commit 347186d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/prizepicks/objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module PrizePicks
class Base < OpenStruct
def initialize(resp)
@resp = resp
super to_obstruct(resp.dig('data', 'attributes'))
super to_obstruct(attributes)
end

def attributes
@resp.dig('data', 'attributes') || @resp['attributes']
end

def data
Expand Down
4 changes: 3 additions & 1 deletion test/prizepicks/api/endpoints/test_entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def test_entries
stub: stub)
resp = client.entries
assert_equal PrizePicks::Collection, resp.class
assert_equal PrizePicks::Entry, resp.data.first.class
first_entry = resp.data.first
assert_equal PrizePicks::Entry, first_entry.class
assert_equal 2000, first_entry.amount_bet_cents
end
end
end
Expand Down

0 comments on commit 347186d

Please sign in to comment.