Class: SimpleSpotify::Request
- Inherits:
-
Object
- Object
- SimpleSpotify::Request
- Defined in:
- lib/simplespotify/request.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#json ⇒ Object
Returns the value of attribute json.
-
#method ⇒ Object
Returns the value of attribute method.
-
#tries ⇒ Object
Returns the value of attribute tries.
Instance Method Summary collapse
- #full_url ⇒ Object
- #headers ⇒ Object
-
#initialize(endpoint, opts = {}) ⇒ Request
constructor
A new instance of Request.
- #options ⇒ Object
- #private? ⇒ Boolean
Constructor Details
#initialize(endpoint, opts = {}) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/simplespotify/request.rb', line 6 def initialize endpoint, opts = {} endpoint = endpoint.join('/') if endpoint.respond_to? :join @endpoint = endpoint @headers = opts[:headers] || {} @method = opts[:method] || :get @json = opts[:json] || (@method != :get) @tries = 0 @data = opts[:data] @query = opts[:query] @private = opts[:private] || true end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/simplespotify/request.rb', line 4 def data @data end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/simplespotify/request.rb', line 4 def endpoint @endpoint end |
#json ⇒ Object
Returns the value of attribute json.
4 5 6 |
# File 'lib/simplespotify/request.rb', line 4 def json @json end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/simplespotify/request.rb', line 4 def method @method end |
#tries ⇒ Object
Returns the value of attribute tries.
4 5 6 |
# File 'lib/simplespotify/request.rb', line 4 def tries @tries end |
Instance Method Details
#full_url ⇒ Object
49 50 51 |
# File 'lib/simplespotify/request.rb', line 49 def full_url SimpleSpotify::ENDPOINT + endpoint.to_s.gsub(SimpleSpotify::ENDPOINT, '') end |
#headers ⇒ Object
42 43 44 45 46 |
# File 'lib/simplespotify/request.rb', line 42 def headers h = @headers h['Content-type'] = 'application/json' if json h end |
#options ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/simplespotify/request.rb', line 30 def return {} unless data if method == :get {query: data} else opts = {body: data.to_json} opts[:query] = @query if @query opts end end |
#private? ⇒ Boolean
20 21 22 |
# File 'lib/simplespotify/request.rb', line 20 def private? @private; end |