Class: M2X::Client::Key
Overview
Wrapper for AT&T M2X Keys API m2x.att.com/developer/documentation/v2/keys
Constant Summary collapse
- PATH =
"/keys"
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.create!(client, params = {}) ⇒ Object
Create a new API Key.
-
.list(client, params = {}) ⇒ Object
Retrieve list of keys associated with the user account.
Instance Method Summary collapse
- #path ⇒ Object
-
#regenerate ⇒ Object
Regenerate an API Key token.
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 = {}) ⇒ Object
Create a new API Key
Note that, according to the parameters sent, you can create a Master API Key or a Device/Stream API Key.
25 26 27 28 29 |
# File 'lib/m2x/key.rb', line 25 def create!(client, params={}) res = client.post(PATH, nil, params, "Content-Type" => "application/json") new(client, res.json) if res.success? end |
.list(client, params = {}) ⇒ Object
Retrieve list of keys associated with the user account.
13 14 15 16 17 |
# File 'lib/m2x/key.rb', line 13 def list(client, params={}) res = client.get(PATH, params) res.json["keys"].map{ |atts| new(client, atts) } if res.success? end |
Instance Method Details
#path ⇒ Object
32 33 34 |
# File 'lib/m2x/key.rb', line 32 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("key")) }" end |
#regenerate ⇒ Object
Regenerate an API Key token
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.
43 44 45 46 47 48 49 50 |
# File 'lib/m2x/key.rb', line 43 def regenerate res = @client.post("#{path}/regenerate", nil, {}) if res.success? @path = nil @attributes = res.json end end |