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.
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(parent) ⇒ Base
constructor
Initiate a Spotify SDK Base component.
-
#inspect ⇒ Object
rubocop:enable CyclomaticComplexity, PerceivedComplexity, AbcSize.
-
#send_http_request(method, endpoint, override_opts = {}) ⇒ Hash, ...
Handle HTTParty responses.
Constructor Details
#initialize(parent) ⇒ 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(parent) @parent = parent @options = { headers: { Authorization: "Bearer %s" % @parent.session.access_token } } end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
74 75 76 |
# File 'lib/spotify/sdk/base.rb', line 74 def parent @parent end |
Instance Method Details
#inspect ⇒ Object
rubocop:enable CyclomaticComplexity, PerceivedComplexity, AbcSize
70 71 72 |
# File 'lib/spotify/sdk/base.rb', line 70 def inspect # :nodoc: "#<%s:0x00%x>" % [self.class.name, (object_id << 1)] end |
#send_http_request(method, endpoint, override_opts = {}) ⇒ Hash, ...
Handle HTTParty responses.
TODO: Address and fix cyclomatic & code complexity issues by Rubocop. rubocop:disable CyclomaticComplexity, PerceivedComplexity, AbcSize
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/spotify/sdk/base.rb', line 53 def send_http_request(method, endpoint, override_opts={}) opts = { raw: false, expect_nil: false }.merge(override_opts[:http_options].presence || {}) httparty = self.class.send(method, endpoint, @options.merge(override_opts)) response = httparty.parsed_response response = response.try(:deep_symbolize_keys) || response raise response[:error][:message] if response.is_a?(Hash) && response[:error].present? return httparty if opts[:raw] == true response = opts[:expect_nil] ? true : raise("No response returned") if response.nil? response end |