Skip to content

Commit

Permalink
fix json response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nov committed Oct 14, 2022
1 parent f871b63 commit 3b6199b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/apple_id/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def setup_required_scope(scopes)
end

def handle_success_response(response)
token_hash = JSON.parse(response.body).with_indifferent_access
token_hash = response.body.with_indifferent_access
AccessToken.new token_hash.delete(:access_token), token_hash.merge(client: self)
end

def handle_error_response(response)
error = JSON.parse(response.body).with_indifferent_access
error = response.body.with_indifferent_access

This comment has been minimized.

Copy link
@andrewroth

andrewroth Jun 20, 2023

Hi, this is throwing off my stubs, because body is a string. Can you explain why you don't have to JSON.parse any more?

raise Error.new(response.status, error)
end
end
Expand Down
8 changes: 7 additions & 1 deletion spec/support/webmock_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def request_to(endpoint, method = :get)

def response_for(response_file, options = {})
response = {}
response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_response', "#{response_file}.#{options[:format] || :json}"))
format = options[:format] || :json
if format == :json
response[:headers] = {
'Content-Type': 'application/json'
}
end
response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_response', "#{response_file}.#{format}"))
if options[:status]
response[:status] = options[:status]
end
Expand Down

0 comments on commit 3b6199b

Please sign in to comment.