Class: Codelocks::Client
- Inherits:
-
Object
- Object
- Codelocks::Client
- Defined in:
- lib/codelocks/client.rb
Instance Attribute Summary collapse
-
#access_key ⇒ String
Return the access key.
-
#api_key ⇒ String
Return the configured API key or raise an exception.
-
#base_uri ⇒ String
The base URI used for API request.
Instance Method Summary collapse
-
#connection ⇒ Faraday
Faraday connection object.
-
#initialize(attributes = {}) ⇒ Codelocks::Client
constructor
Set configuration variables on instantiation.
-
#locks ⇒ CollectionProxy
Proxy for the locks model.
-
#net_codes ⇒ CollectionProxy
Proxy for the netcodes model.
-
#requests ⇒ CollectionProxy
Proxy for the requests model.
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_key ⇒ String
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.
26 27 28 |
# File 'lib/codelocks/client.rb', line 26 def access_key @access_key || ENV['CODELOCKS_ACCESS_KEY'] end |
#api_key ⇒ String
Return the configured API key or raise an exception
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_uri ⇒ String
The base URI used for API request
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
#connection ⇒ Faraday
Faraday connection object
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 |
#locks ⇒ CollectionProxy
Proxy for the locks model
77 78 79 |
# File 'lib/codelocks/client.rb', line 77 def locks @lock_collection ||= CollectionProxy.new(model: Lock, client: self) end |
#net_codes ⇒ CollectionProxy
Proxy for the netcodes model
69 70 71 |
# File 'lib/codelocks/client.rb', line 69 def net_codes @net_code_collection ||= CollectionProxy.new(model: NetCode, client: self) end |
#requests ⇒ CollectionProxy
Proxy for the requests model
61 62 63 |
# File 'lib/codelocks/client.rb', line 61 def requests @request_collection ||= CollectionProxy.new(model: Request, client: self) end |