Class: Maventa::OAuth2

Inherits:
Resource show all
Defined in:
lib/maventa/oauth2.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, client_id:, client_secret:, vendor_api_key:) ⇒ OAuth2

Returns a new instance of OAuth2.



3
4
5
6
7
8
# File 'lib/maventa/oauth2.rb', line 3

def initialize(connection, client_id:, client_secret:, vendor_api_key:)
  super(connection, nil)
  @client_id = client_id
  @client_secret = client_secret
  @vendor_api_key = vendor_api_key
end

Instance Method Details

#currentObject



27
28
29
# File 'lib/maventa/oauth2.rb', line 27

def current
  raise "Not implemented"
end

#token(grant_type: "client_credentials", scope: "invoice:send") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/maventa/oauth2.rb', line 10

def token(grant_type: "client_credentials", scope: "invoice:send")
  payload = {
    grant_type:,
    scope:,
    vendor_api_key: @vendor_api_key
  }
  
  request(:post, "/oauth2/token", payload:) do |received_data|
    AccessToken.new(
      token: received_data["access_token"],
      expires_in: received_data["expires_in"],
      token_type: received_data["token_type"],
      scope: received_data["scope"]
    )
  end
end