Class: GH::TokenCheck

Inherits:
Wrapper show all
Defined in:
lib/gh/token_check.rb

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#backend, #options

Instance Method Summary collapse

Methods inherited from Wrapper

[], #[], #frontend, #frontend=, #generate_response, #initialize, #inspect, #load, #prefixed, #reset, wraps

Constructor Details

This class inherits a constructor from GH::Wrapper

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/gh/token_check.rb', line 5

def client_id
  @client_id
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/gh/token_check.rb', line 5

def token
  @token
end

Instance Method Details

#check_tokenObject



14
15
16
17
18
19
20
# File 'lib/gh/token_check.rb', line 14

def check_token
  return unless @check_token and client_id and token
  http :head, "/applications/#{client_id}/tokens/#{token}"
  @check_token = false
rescue GH::Error
  raise GH::TokenInvalid
end

#fetch_resourceObject



22
23
24
25
# File 'lib/gh/token_check.rb', line 22

def fetch_resource(*)
  check_token
  super
end

#setup(backend, options) ⇒ Object



7
8
9
10
11
12
# File 'lib/gh/token_check.rb', line 7

def setup(backend, options)
  @client_id   = options[:client_id]
  @token       = options[:token]
  @check_token = true
  super
end