Class: M2X::Client::Key
Overview
Wrapper for M2X Keys API
Constant Summary collapse
- PATH =
"/keys"
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.create!(client, params = {}) ⇒ Key
Method for Create Key endpoint.
-
.list(client, params = {}) ⇒ Array
Method for List Keys endpoint.
Instance Method Summary collapse
- #path ⇒ Object
-
#regenerate ⇒ Key
Method for Regenerate Key endpoint.
Methods inherited from Resource
#delete!, #initialize, #inspect, #refresh, #update!, #view
Constructor Details
This class inherits a constructor from M2X::Client::Resource
Class Method Details
.create!(client, params = {}) ⇒ Key
Method for Create Key endpoint. Note that, according to the parameters sent, you can create a Master API Key or a Device/Stream API Key.
31 32 33 34 35 |
# File 'lib/m2x/key.rb', line 31 def create!(client, params={}) res = client.post(PATH, nil, params, "Content-Type" => "application/json") new(client, res.json) if res.success? end |
Instance Method Details
#path ⇒ Object
38 39 40 |
# File 'lib/m2x/key.rb', line 38 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("key")) }" end |
#regenerate ⇒ Key
Method for Regenerate Key endpoint. Note that if you regenerate the key that you’re using for authentication then you would need to change your scripts to start using the new key token for all subsequent requests.
50 51 52 53 54 55 56 57 |
# File 'lib/m2x/key.rb', line 50 def regenerate res = @client.post("#{path}/regenerate", nil, {}) if res.success? @path = nil @attributes = res.json end end |