Class: Skroutz::Client
- Inherits:
-
Object
- Object
- Skroutz::Client
- Includes:
- Parsing
- Defined in:
- lib/skroutz/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#config ⇒ Object
Returns the value of attribute config.
- #token ⇒ Object
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
- #application_token ⇒ Object
- #autocomplete(q, options = {}) {|response| ... } ⇒ Object
- #client ⇒ Object
- #conn ⇒ Object
-
#initialize(client_id, client_secret, config = {}) ⇒ Client
constructor
A new instance of Client.
- #search(q, options = {}) {|response| ... } ⇒ Object
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_id ⇒ Object
Returns the value of attribute client_id.
5 6 7 |
# File 'lib/skroutz/client.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
5 6 7 |
# File 'lib/skroutz/client.rb', line 5 def client_secret @client_secret end |
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/skroutz/client.rb', line 5 def config @config end |
#token ⇒ Object
15 16 17 |
# File 'lib/skroutz/client.rb', line 15 def token @token ||= user_token || application_token end |
#user_token ⇒ Object
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_token ⇒ Object
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
48 49 50 51 52 53 54 |
# File 'lib/skroutz/client.rb', line 48 def autocomplete(q, = {}) response = get 'autocomplete', { q: q }.merge() return parse(response) unless block_given? yield response end |
#client ⇒ Object
44 45 46 |
# File 'lib/skroutz/client.rb', line 44 def client self end |
#conn ⇒ Object
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
36 37 38 39 40 41 42 |
# File 'lib/skroutz/client.rb', line 36 def search(q, = {}) response = get 'search', { q: q }.merge() return parse(response) unless block_given? yield response end |