Class: Supai::Authorization
- Defined in:
- lib/supai/authorization.rb
Constant Summary collapse
- ENDPOINT =
"/api/authorization/v7/authorization"
Instance Attribute Summary collapse
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#token ⇒ Object
Returns the value of attribute token.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_user(user_name:, password:, chain_id:, api: API.new) ⇒ Object
-
#initialize(hash) ⇒ Authorization
constructor
A new instance of Authorization.
Methods inherited from Resource
#as_json, attr_accessor, attr_collections, attr_objects, attr_timestamp_accessor, attributes, #inspect, #parse_collection, #parse_object, #parse_timestamp, #set_attribute, #set_attributes, #underscore
Constructor Details
#initialize(hash) ⇒ Authorization
Returns a new instance of Authorization.
15 16 17 |
# File 'lib/supai/authorization.rb', line 15 def initialize(hash) set_attributes(hash) end |
Instance Attribute Details
#secret ⇒ Object
Returns the value of attribute secret.
5 6 7 |
# File 'lib/supai/authorization.rb', line 5 def secret @secret end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/supai/authorization.rb', line 5 def token @token end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/supai/authorization.rb', line 5 def user_id @user_id end |
Class Method Details
.create(authorization, api: API.new) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/supai/authorization.rb', line 7 def self.create(, api: API.new) api = API.new response = api.request(:post, ENDPOINT, body: {}, token: ) raise response.error unless response.success? return self.new(response.json_body) end |
Instance Method Details
#authenticate_user(user_name:, password:, chain_id:, api: API.new) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/supai/authorization.rb', line 19 def authenticate_user(user_name:, password:, chain_id:, api: API.new) endpoint = "/api/workbenchentry/v7/chains/#{chain_id}/authentication" body = { "SessionToken": token, "UserName": user_name, "Password": password, } response = api.request(:post, endpoint, body: body, token: secret) raise response.error unless response.success? return User.new(response.json_body["User"]) end |