@@ -17,7 +17,7 @@ class Base
1717 # @auth = Spotify::SDK::Base.new(@sdk)
1818 #
1919 # @sdk = Spotify::SDK.new("access_token_here")
20- # @sdk.to_hash # => { access_token: ..., expires_in : ... }
20+ # @sdk.to_hash # => { access_token: ..., expires_at : ... }
2121 #
2222 # @param [Spotify::SDK] sdk An instance of Spotify::SDK as a reference point.
2323 #
@@ -34,14 +34,22 @@ def initialize(sdk)
3434 # Handle HTTParty responses.
3535 #
3636 # @example
37- # handle_response self.class.get("/v1/me/player/devices", @options)
37+ # # Return the Hash from the JSON response.
38+ # send_http_request(:get, "/v1/me/player/devices", @options)
3839 #
39- # @param [HTTParty::Response] response_obj The response object when a HTTParty request is made.
40+ # # Return the raw HTTParty::Response object.
41+ # send_http_request(:get, "/v1/me/player/devices", @options.merge(raw: true))
42+ #
43+ # @param [Hash,HTTParty::Response] response The response from the HTTP request.
4044 # @return
4145 #
42- def handle_response ( response_obj , &_block )
43- response = block_given? ? yield : response_obj
44- response . parsed_response . deep_symbolize_keys
46+ def send_http_request ( method , endpoint , opts = { } , &_block )
47+ sdk_opts = opts [ :_sdk_opts ] . presence || { }
48+ opts_sdk = { raw : false , expect_nil : false } . merge ( sdk_opts )
49+ response = self . class . send ( method , endpoint , @options . merge ( opts ) )
50+ response = response . parsed_response . try ( :deep_symbolize_keys ) if opts_sdk [ :raw ] == false
51+ response = true if opts_sdk [ :expect_nil ] == true && response . nil?
52+ response
4553 end
4654
4755 attr_reader :sdk
0 commit comments