Class: Qrfy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/qrfy/client.rb

Overview

# Qrfy Client

Hides actual implementation of HTTP API calls. You can overwrite the global configuration (api key or http adapter) passing values in the initializer.

Constant Summary collapse

BASE_URL =
"https://qrfy.com/api/public"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/qrfy/client.rb', line 15

def initialize(config = {})
  @api_key = config.key?(:api_key) ? config[:api_key] : Qrfy.configuration.api_key
  @adapter = config.key?(:adapter) ? config[:adapter] : Qrfy.configuration.adapter

  @stubs = config[:stubs]
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



13
14
15
# File 'lib/qrfy/client.rb', line 13

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



13
14
15
# File 'lib/qrfy/client.rb', line 13

def api_key
  @api_key
end

Instance Method Details

#connectionObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/qrfy/client.rb', line 22

def connection
  @connection ||= Faraday.new(url: BASE_URL) do |conn|
    conn.request :json

    conn.response :parse_dates
    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#foldersObject



33
34
35
# File 'lib/qrfy/client.rb', line 33

def folders
  Resources::Folders.new(self)
end

#qrsObject



37
38
39
# File 'lib/qrfy/client.rb', line 37

def qrs
  Resources::Qrs.new(self)
end