class Skroutz::Client
Attributes
client_id[RW]
client_secret[RW]
config[RW]
token[W]
user_token[RW]
Public Class Methods
new(client_id, client_secret, config = {})
click to toggle source
# 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
Public Instance Methods
application_token()
click to toggle source
# 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| ... }
click to toggle source
# 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
client()
click to toggle source
# File lib/skroutz/client.rb, line 44 def client self end
conn()
click to toggle source
# File lib/skroutz/client.rb, line 19 def conn @conn ||= Faraday.new(config[:api_endpoint]) { |client| configure_client(client) } end
search(q, options = {}) { |response| ... }
click to toggle source
# 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
token()
click to toggle source
# File lib/skroutz/client.rb, line 15 def token @token ||= user_token || application_token end
Private Instance Methods
configure_client(client)
click to toggle source
# File lib/skroutz/client.rb, line 69 def configure_client(client) client.use ::FaradayMiddleware::FollowRedirects, limit: 5 client.use ::Skroutz::ErrorHandler client.use Skroutz::TimeoutHandler client.use Faraday::Response::Logger, @config[:logger] if @config[:logger] client.adapter @config[:adapter] || Faraday.default_adapter client.headers = default_headers client.options.timeout = @config[:timeout] end
default_headers()
click to toggle source
# File lib/skroutz/client.rb, line 80 def default_headers { user_agent: config[:user_agent], accept: config[:media_type] }.merge authorization_header end
oauth_client()
click to toggle source
# File lib/skroutz/client.rb, line 58 def oauth_client @oauth_client ||= begin ::OAuth2::Client.new(client_id, client_secret, site: config[:oauth_endpoint], authorize_url: config[:authorization_code_endpoint], token_url: config[:token_endpoint], user_agent: config[:user_agent]) end end