Class: EchoNest::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/another_echonest_ruby_api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Response

Returns a new instance of Response.



11
12
13
14
15
16
17
# File 'lib/another_echonest_ruby_api/response.rb', line 11

def initialize(opts={})
  @request = opts[:request]
  @raw_json = opts[:raw_json]
  h = JSON.parse(@raw_json)
  @data = Hashie::Mash.new(h['response'])
  @status = data.status
end

Instance Attribute Details

#dataObject (readonly)

data attr is a Hashie::Mash you can use to get at json attributes returned ex: response.data.artist.name, response.data.artist.name etc



9
10
11
# File 'lib/another_echonest_ruby_api/response.rb', line 9

def data
  @data
end

#raw_jsonObject (readonly)

data attr is a Hashie::Mash you can use to get at json attributes returned ex: response.data.artist.name, response.data.artist.name etc



9
10
11
# File 'lib/another_echonest_ruby_api/response.rb', line 9

def raw_json
  @raw_json
end

#requestObject (readonly)

data attr is a Hashie::Mash you can use to get at json attributes returned ex: response.data.artist.name, response.data.artist.name etc



9
10
11
# File 'lib/another_echonest_ruby_api/response.rb', line 9

def request
  @request
end

#statusObject (readonly)

data attr is a Hashie::Mash you can use to get at json attributes returned ex: response.data.artist.name, response.data.artist.name etc



9
10
11
# File 'lib/another_echonest_ruby_api/response.rb', line 9

def status
  @status
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/another_echonest_ruby_api/response.rb', line 19

def error?
  status.code != 0
end

#messageObject



23
24
25
# File 'lib/another_echonest_ruby_api/response.rb', line 23

def message
  status.message
end

#versionObject



27
28
29
# File 'lib/another_echonest_ruby_api/response.rb', line 27

def version
  status.version
end