Class: PostyClient::Resources::ApiKey

Inherits:
Base
  • Object
show all
Defined in:
lib/posty_client/resources/api_key.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #errors, #name, #new_resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create, #delete, #load, #new_resource?, #request_with_error_handling, #resource_name, resource_name, #save, #update

Constructor Details

#initialize(name = nil) ⇒ ApiKey

Returns a new instance of ApiKey.



25
26
27
28
# File 'lib/posty_client/resources/api_key.rb', line 25

def initialize(name=nil)
  @name = name
  load if name
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/posty_client/resources/api_key.rb', line 5

def access_token
  @access_token
end

Class Method Details

.allObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/posty_client/resources/api_key.rb', line 9

def self.all
  response = RestClient.get([base_uri, resource_name].join('/'))

  return nil unless response.code == 200

  data = JSON.parse(response)

  data.collect do |datum|
    model = self.new
    model.attributes = datum.flatten.last
    model.new_resource = false

    model
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/posty_client/resources/api_key.rb', line 34

def active?
  attributes['active']
end

#expired?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/posty_client/resources/api_key.rb', line 30

def expired?
  attributes['expires_at'].to_time <= DateTime.now
end

#resource_slugObject



42
43
44
# File 'lib/posty_client/resources/api_key.rb', line 42

def resource_slug
  [base_uri, 'api_keys'].join('/')
end

#slugObject



38
39
40
# File 'lib/posty_client/resources/api_key.rb', line 38

def slug
  [resource_slug, name].join('/')
end