Class: M2X::Client::Key

Inherits:
Resource show all
Defined in:
lib/m2x/key.rb

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

#attributes

Class Method Summary collapse

Instance Method Summary collapse

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.

m2x.att.com/developer/documentation/v2/keys#Create-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.

m2x.att.com/developer/documentation/v2/keys#List-Keys



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

#pathObject



32
33
34
# File 'lib/m2x/key.rb', line 32

def path
  @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("key")) }"
end

#regenerateObject

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.

m2x.att.com/developer/documentation/v2/keys#Regenerate-Key



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