Class: Gracenote::Client

Inherits:
Object
  • Object
show all
Includes:
Http, QueryBuilder, Request::Fetch, Request::Register, Request::Search
Defined in:
lib/gracenote/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request::Fetch

#fetch

Methods included from Request::Search

#search

Methods included from Request::Register

#register

Methods included from QueryBuilder

#build_query

Methods included from Http

#agent, #host, #log_enabled?, #path, #post

Constructor Details

#initialize(client_id:, user_id: nil, lang: nil, country: nil) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
# File 'lib/gracenote/client.rb', line 20

def initialize(client_id:, user_id: nil, lang: nil, country: nil)
  @client_id = client_id
  @user_id = user_id
  @lang = lang || "eng"
  @country = country || "usa"
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



11
12
13
# File 'lib/gracenote/client.rb', line 11

def client_id
  @client_id
end

#countryObject

Returns the value of attribute country.



12
13
14
# File 'lib/gracenote/client.rb', line 12

def country
  @country
end

#langObject

Returns the value of attribute lang.



12
13
14
# File 'lib/gracenote/client.rb', line 12

def lang
  @lang
end

#user_idObject (readonly)

Returns the value of attribute user_id.



11
12
13
# File 'lib/gracenote/client.rb', line 11

def user_id
  @user_id
end

Instance Method Details

#authObject



31
32
33
34
# File 'lib/gracenote/client.rb', line 31

def auth
  raise "user_id is empty" unless user_id
  { client: client_id, user: user_id }
end

#query(cmd, options = {}, &block) ⇒ Object



36
37
38
39
40
# File 'lib/gracenote/client.rb', line 36

def query(cmd, options = {}, &block)
  request = build_query(cmd, options, &block).to_xml
  response = post(request)
  Response.new(response)
end

#short_client_idObject



27
28
29
# File 'lib/gracenote/client.rb', line 27

def short_client_id
  client_id.split("-", 2)[0]
end