Class: Spotify::SDK::Base
- Inherits:
-
Object
- Object
- Spotify::SDK::Base
- Includes:
- HTTParty
- Defined in:
- lib/spotify/sdk/base.rb
Overview
For each SDK component, we have a Base class. We’re using HTTParty.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#sdk ⇒ Object
readonly
Returns the value of attribute sdk.
Instance Method Summary collapse
-
#initialize(sdk) ⇒ Base
constructor
Initiate a Spotify SDK Base component.
-
#send_http_request(method, endpoint, opts = {}, &_block) ⇒ Object
Handle HTTParty responses.
Constructor Details
#initialize(sdk) ⇒ Base
Initiate a Spotify SDK Base component.
24 25 26 27 28 29 30 31 |
# File 'lib/spotify/sdk/base.rb', line 24 def initialize(sdk) @sdk = sdk @options = { headers: { Authorization: "Bearer %s" % sdk.access_token } } end |
Instance Attribute Details
#sdk ⇒ Object (readonly)
Returns the value of attribute sdk.
55 56 57 |
# File 'lib/spotify/sdk/base.rb', line 55 def sdk @sdk end |
Instance Method Details
#send_http_request(method, endpoint, opts = {}, &_block) ⇒ Object
Handle HTTParty responses.
46 47 48 49 50 51 52 53 |
# File 'lib/spotify/sdk/base.rb', line 46 def send_http_request(method, endpoint, opts={}, &_block) sdk_opts = opts[:_sdk_opts].presence || {} opts_sdk = {raw: false, expect_nil: false}.merge(sdk_opts) response = self.class.send(method, endpoint, @options.merge(opts)) response = response.parsed_response.try(:deep_symbolize_keys) if opts_sdk[:raw] == false response = true if opts_sdk[:expect_nil] == true && response.nil? response end |