Class: Freesound::Request
- Inherits:
-
Object
- Object
- Freesound::Request
- Defined in:
- lib/freesound/request.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#format ⇒ Object
Returns the value of attribute format.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#uri_compiler ⇒ Object
readonly
Returns the value of attribute uri_compiler.
Instance Method Summary collapse
- #get! ⇒ Object
-
#initialize(api_key, params = {}) ⇒ Request
constructor
A new instance of Request.
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_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/freesound/request.rb', line 6 def api_key @api_key end |
#format ⇒ Object
Returns the value of attribute format.
6 7 8 |
# File 'lib/freesound/request.rb', line 6 def format @format end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/freesound/request.rb', line 6 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/freesound/request.rb', line 6 def response @response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/freesound/request.rb', line 6 def uri @uri end |
#uri_compiler ⇒ Object (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
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 |