Class: SimpleSpotify::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/simplespotify/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/simplespotify/request.rb', line 4

def data
  @data
end

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/simplespotify/request.rb', line 4

def endpoint
  @endpoint
end

#jsonObject

Returns the value of attribute json.



4
5
6
# File 'lib/simplespotify/request.rb', line 4

def json
  @json
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/simplespotify/request.rb', line 4

def method
  @method
end

#triesObject

Returns the value of attribute tries.



4
5
6
# File 'lib/simplespotify/request.rb', line 4

def tries
  @tries
end

Instance Method Details

#full_urlObject



49
50
51
# File 'lib/simplespotify/request.rb', line 49

def full_url
  SimpleSpotify::ENDPOINT + endpoint.to_s.gsub(SimpleSpotify::ENDPOINT, '')
end

#headersObject



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

#optionsObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/simplespotify/request.rb', line 30

def options
  return {} unless data
  if method == :get
    {query: data}
  else
    opts = {body: data.to_json}
    opts[:query] = @query if @query
    opts
  end
end

#private?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/simplespotify/request.rb', line 20

def private?
  @private;
end