Class: Stackd::Token

Inherits:
Object
  • Object
show all
Includes:
Concerns::RequireAttr, Concerns::TattrAccessor
Defined in:
lib/stackd/token.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::RequireAttr

#require_attr!

Methods included from Concerns::TattrAccessor

#tattr?

Constructor Details

#initialize(client, attrs = {}) ⇒ Token

Returns a new instance of Token.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stackd/token.rb', line 23

def initialize client, attrs = {}
  self.client = client

  attrs.each do |key, val|
    public_send :"#{key}=", val if tattr? key
  end

  begin
    require_attr! :client, :access_token, :token_type
  rescue Concerns::RequireAttr::AttrNotSetError => e
    raise ArgumentError.new e.message
  end
end

Class Method Details

.on_grant(&block) ⇒ Object



19
20
21
# File 'lib/stackd/token.rb', line 19

def self.on_grant &block
  @_on_grant_callbacks.push block
end

Instance Method Details

#delete(*args) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/stackd/token.rb', line 65

def delete *args
  url_args = reject_body_arg *args
  body_arg = get_body_arg *args
  content_type = content_type_for body_arg

  Util::HTTP.delete self, get_url(*url_args), body_arg, content_type
end

#get(*args) ⇒ Object



37
38
39
# File 'lib/stackd/token.rb', line 37

def get *args
  Util::HTTP.get self, get_url(*args)
end

#patch(*args) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/stackd/token.rb', line 57

def patch *args
  url_args = reject_body_arg *args
  body_arg = get_body_arg *args
  content_type = content_type_for body_arg

  Util::HTTP.patch self, get_url(*url_args), body_arg, content_type
end

#post(*args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/stackd/token.rb', line 41

def post *args
  url_args = reject_body_arg *args
  body_arg = get_body_arg *args
  content_type = content_type_for body_arg

  Util::HTTP.post self, get_url(*url_args), body_arg, content_type
end

#put(*args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/stackd/token.rb', line 49

def put *args
  url_args = reject_body_arg *args
  body_arg = get_body_arg *args
  content_type = content_type_for body_arg

  Util::HTTP.put self, get_url(*url_args), body_arg, content_type
end