Class: NRB::Untappd::API::Credential
- Inherits:
-
Object
- Object
- NRB::Untappd::API::Credential
show all
- Defined in:
- lib/drink-socially/api/credential.rb
Defined Under Namespace
Classes: IncompleteCredentialError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Credential
Returns a new instance of Credential.
18
19
20
21
22
23
24
25
|
# File 'lib/drink-socially/api/credential.rb', line 18
def initialize(opts={})
opts.slice!(*self.class.valid_attrs)
@creds = {}
!! opts[:access_token] && @creds[:access_token] = CGI::escape(opts[:access_token])
!! opts[:client_id] && @creds[:client_id] = CGI::escape(opts[:client_id])
!! opts[:client_secret] && @creds[:client_secret] = CGI::escape(opts[:client_secret])
raise IncompleteCredentialError.new('Provide either API access token or API client id & secret') unless valid?
end
|
Class Method Details
.valid_attrs ⇒ Object
13
14
15
|
# File 'lib/drink-socially/api/credential.rb', line 13
def self.valid_attrs
[ :access_token, :client_id, :client_secret ]
end
|
Instance Method Details
#is_client? ⇒ Boolean
Also known as:
is_app?
34
35
36
|
# File 'lib/drink-socially/api/credential.rb', line 34
def is_client?
!! @creds[:client_id] && !! @creds[:client_secret]
end
|
#is_user? ⇒ Boolean
40
41
42
|
# File 'lib/drink-socially/api/credential.rb', line 40
def is_user?
!! @creds[:access_token]
end
|
#merge(hash) ⇒ Object
45
46
47
|
# File 'lib/drink-socially/api/credential.rb', line 45
def merge(hash)
@creds.merge(hash)
end
|
50
51
52
|
# File 'lib/drink-socially/api/credential.rb', line 50
def to_h
@creds
end
|
55
56
57
|
# File 'lib/drink-socially/api/credential.rb', line 55
def to_param
@creds.map { |k,v| "#{k}=#{v}" }.join("&")
end
|