Class: Skroutz::Client

Inherits:
Object
  • Object
show all
Includes:
Parsing
Defined in:
lib/skroutz/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parsing

#collection?, #collection_resource_key, #infer_collection, #infer_model, #link_header, #parse, #parse_collection, #parse_meta, #parse_resource, #resource_key

Constructor Details

#initialize(client_id, client_secret, config = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/skroutz/client.rb', line 9

def initialize(client_id, client_secret, config = {})
  @client_id = client_id
  @client_secret = client_secret
  @config = Skroutz::Default.to_hash.merge config
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/skroutz/client.rb', line 5

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



5
6
7
# File 'lib/skroutz/client.rb', line 5

def client_secret
  @client_secret
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/skroutz/client.rb', line 5

def config
  @config
end

#tokenObject



15
16
17
# File 'lib/skroutz/client.rb', line 15

def token
  @token ||= user_token || application_token
end

#user_tokenObject

Returns the value of attribute user_token.



5
6
7
# File 'lib/skroutz/client.rb', line 5

def user_token
  @user_token
end

Instance Method Details

#application_tokenObject



23
24
25
26
27
28
# File 'lib/skroutz/client.rb', line 23

def application_token
  oauth_client.
    client_credentials.
    get_token(scope: config[:application_permissions].join(' ')).
    token
end

#autocomplete(q, options = {}) {|response| ... } ⇒ Object

Yields:

  • (response)


48
49
50
51
52
53
54
# File 'lib/skroutz/client.rb', line 48

def autocomplete(q, options = {})
  response = get 'autocomplete', { q: q }.merge(options)

  return parse(response) unless block_given?

  yield response
end

#clientObject



44
45
46
# File 'lib/skroutz/client.rb', line 44

def client
  self
end

#connObject



19
20
21
# File 'lib/skroutz/client.rb', line 19

def conn
  @conn ||= Faraday.new(config[:api_endpoint]) { |client| configure_client(client) }
end

#search(q, options = {}) {|response| ... } ⇒ Object

Yields:

  • (response)


36
37
38
39
40
41
42
# File 'lib/skroutz/client.rb', line 36

def search(q, options = {})
  response = get 'search', { q: q }.merge(options)

  return parse(response) unless block_given?

  yield response
end