Class: Codelocks::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Codelocks::Client

Set configuration variables on instantiation



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/codelocks/client.rb', line 45

def initialize(attributes = {})
  attributes.each do |key, val|
    setter = :"#{key}="

    if respond_to?(setter)
      send(setter, val)
    end
  end

  self
end

Instance Attribute Details

#access_keyString

Return the access key. This is tied to the K3 Connect App. This can be nil, as for certain models of locks you will provide a 6 digit ID instead.

Returns:

  • (String)

    the access key



26
27
28
# File 'lib/codelocks/client.rb', line 26

def access_key
  @access_key || ENV['CODELOCKS_ACCESS_KEY']
end

#api_keyString

Return the configured API key or raise an exception

Returns:

  • (String)

    the API key



17
18
19
# File 'lib/codelocks/client.rb', line 17

def api_key
  @api_key || ENV['CODELOCKS_API_KEY'] || (raise CodelocksError.new("No API key specified"))
end

#base_uriString

The base URI used for API request

Returns:

  • (String)

    the base URI



9
10
11
# File 'lib/codelocks/client.rb', line 9

def base_uri
  @base_uri || ENV['CODELOCKS_BASE_URI'] || (raise CodelocksError.new("No base URI specified"))
end

Instance Method Details

#connectionFaraday

Faraday connection object

Returns:

  • (Faraday)


34
35
36
37
38
39
# File 'lib/codelocks/client.rb', line 34

def connection
  @connection ||= Faraday.new(url: base_uri) do |faraday|
    faraday.request  :url_encoded
    faraday.adapter  Faraday.default_adapter
  end
end

#locksCollectionProxy

Proxy for the locks model

Returns:



77
78
79
# File 'lib/codelocks/client.rb', line 77

def locks
  @lock_collection ||= CollectionProxy.new(model: Lock, client: self)
end

#net_codesCollectionProxy

Proxy for the netcodes model

Returns:



69
70
71
# File 'lib/codelocks/client.rb', line 69

def net_codes
  @net_code_collection ||= CollectionProxy.new(model: NetCode, client: self)
end

#requestsCollectionProxy

Proxy for the requests model

Returns:



61
62
63
# File 'lib/codelocks/client.rb', line 61

def requests
  @request_collection ||= CollectionProxy.new(model: Request, client: self)
end