Class: FattureInCloud_Ruby_Sdk::OAuth2Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb

Overview

The OAuth2Manager class is used to manage the OAuth2 flow.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, base_uri = 'https://api-v2.fattureincloud.it') ⇒ OAuth2Manager

Initializes a new instance of the OAuth2Manager class.

Parameters:

  • client_id (String)

    The client id.

  • base_uri (String) (defaults to: 'https://api-v2.fattureincloud.it')

    The base uri.



12
13
14
15
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 12

def initialize(client_id, base_uri = 'https://api-v2.fattureincloud.it')
  @client_id = client_id
  @base_uri = base_uri
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



7
8
9
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 7

def base_uri
  @base_uri
end

#client_idObject

Returns the value of attribute client_id.



7
8
9
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 7

def client_id
  @client_id
end

Class Method Details

.get_scope_string(scopes) ⇒ String

Build the scopes string.

Parameters:

  • scopes (Array<Scope>)

    The scopes.

Returns:

  • (String)

    The scopes string.



32
33
34
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 32

def self.get_scope_string(scopes)
  scopes.map { |scope| scope.to_s }.join(' ')
end

Instance Method Details

#execute_post(url, body) ⇒ Object

Get the access token.

Parameters:

  • url (String)

    The url.

  • data (Object)

    The request data.

Returns:

  • (Object)

    The response body.



21
22
23
24
25
26
27
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 21

def execute_post(url, body)
  res = Typhoeus.post(url, body: body)
  if res.response_code != 200
    raise "Error fetching token: #{res.response_body}"
  end
  JSON.parse(res.body)
end