Class: Freesound::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, params = {}) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
# File 'lib/freesound/request.rb', line 8

def initialize(api_key, params={})
  self.format = params[:format] || :json
  @api_key = api_key
  @params = params
  @response = nil
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/freesound/request.rb', line 6

def api_key
  @api_key
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/freesound/request.rb', line 6

def format
  @format
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/freesound/request.rb', line 6

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/freesound/request.rb', line 6

def response
  @response
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/freesound/request.rb', line 6

def uri
  @uri
end

#uri_compilerObject (readonly)

Returns the value of attribute uri_compiler.



6
7
8
# File 'lib/freesound/request.rb', line 6

def uri_compiler
  @uri_compiler
end

Instance Method Details

#get!Object

Raises:



28
29
30
31
32
33
34
# File 'lib/freesound/request.rb', line 28

def get!
  response_body = Net::HTTP.get_response(self.uri).body
  @response ||= Response.new(response_body, @format)

  raise(InvalidApiKeyError, "#{@api_key} is not a valid API key") if @response.errors[:error]
  @response
end