Class: Zara4::API::Communication::Grant::GrantRequest
- Inherits:
-
Object
- Object
- Zara4::API::Communication::Grant::GrantRequest
- Includes:
- HTTParty
- Defined in:
- lib/zara4/api/communication/grant/grant_request.rb
Direct Known Subclasses
ClientCredentialsGrantRequest, PasswordGrant, RefreshTokenGrant
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
Instance Method Summary collapse
-
#get_tokens ⇒ Object
Get tokens from the API.
-
#initialize(client_id, client_secret, scopes) ⇒ GrantRequest
constructor
Constructor.
-
#with_image_processing ⇒ Object
Add image processing to the request scope.
-
#with_usage ⇒ Object
Add usage to the request scope.
Constructor Details
#initialize(client_id, client_secret, scopes) ⇒ GrantRequest
Constructor
12 13 14 15 16 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 12 def initialize(client_id, client_secret, scopes) @client_id = client_id @client_secret = client_secret @scopes = scopes end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 6 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 6 def client_secret @client_secret end |
#scopes ⇒ Object
Returns the value of attribute scopes.
6 7 8 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 6 def scopes @scopes end |
Instance Method Details
#get_tokens ⇒ Object
Get tokens from the API
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 22 def get_tokens url = Zara4::API::Communication::Util::url('/oauth/access_token') parameters = { 'grant_type' => grant_type(), 'client_id' => @client_id, 'client_secret' => @client_secret, 'scope' => @scopes.join(','), } headers = { 'Content-Type' => 'application/json' } response = self.class.post(url, { body: parameters.to_json, headers: headers }) # Check for API error response if response.has_key?('error') puts 'ERROR IS ' + response.fetch('error') end return { 'access_token' => response.fetch('access_token'), 'expires_in' => response.fetch('expires_in'), } end |
#with_image_processing ⇒ Object
Add image processing to the request scope.
58 59 60 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 58 def with_image_processing @scopes.push('image-processing') end |
#with_usage ⇒ Object
Add usage to the request scope.
66 67 68 |
# File 'lib/zara4/api/communication/grant/grant_request.rb', line 66 def with_usage @scopes.push('usage') end |