Class: Talis::Authentication::Client
- Includes:
- HTTParty
- Defined in:
- lib/talis/authentication/client.rb
Overview
Represents an OAuth client
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #add_scope(scope) ⇒ Object
-
#initialize(token, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #modify_scope(action, scope) ⇒ Object
- #remove_scope(scope) ⇒ Object
Constructor Details
#initialize(token, opts = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/talis/authentication/client.rb', line 10 def initialize(token, opts = {}) @token = token acquire_host!(opts) acquire_credentials! response = authenticate! body = JSON.parse response.body @scopes = body['scope'] raise Talis::AuthenticationFailedError unless response.code == 200 end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
9 10 11 |
# File 'lib/talis/authentication/client.rb', line 9 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
9 10 11 |
# File 'lib/talis/authentication/client.rb', line 9 def client_secret @client_secret end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/talis/authentication/client.rb', line 9 def host @host end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
9 10 11 |
# File 'lib/talis/authentication/client.rb', line 9 def scopes @scopes end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/talis/authentication/client.rb', line 9 def token @token end |
Instance Method Details
#add_scope(scope) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/talis/authentication/client.rb', line 22 def add_scope(scope) if scope.is_a? String response = modify_scope(:add, scope) @scopes << scope if response.code == 204 end end |
#modify_scope(action, scope) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/talis/authentication/client.rb', line 36 def modify_scope(action, scope) action = case action when :add '$add' when :remove '$remove' else raise 'Unknown action' end patch_client_scope(action, scope) end |
#remove_scope(scope) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/talis/authentication/client.rb', line 29 def remove_scope(scope) if scope.is_a? String response = modify_scope(:remove, scope) @scopes.delete(scope) if response.code == 204 end end |