Class: Maventa::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/maventa/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id: nil, client_secret: nil, vendor_api_key: nil, mode: :production) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/maventa/client.rb', line 3

def initialize(client_id: nil, client_secret: nil, vendor_api_key: nil, mode: :production)
	@client_id = client_id || Maventa::config[:client_id]
	@client_secret = client_secret || Maventa::config[:client_secret]
	@vendor_api_key = vendor_api_key || Maventa::config[:vendor_api_key]
	@mode = mode
	@access_token = nil
	
	@connection = Faraday.new(
		url: Maventa::API_URL[mode],
		headers: {
			"Content-Type" => "application/x-www-form-urlencoded"
		}
	)
end

Instance Method Details

#analysisObject



30
31
32
# File 'lib/maventa/client.rb', line 30

def analysis
	@analysis ||= Analysis.new(@connection, @access_token)
end

#authorize(grant_type: "client_credentials", scope: "global company") ⇒ Object



18
19
20
21
22
23
24
# File 'lib/maventa/client.rb', line 18

def authorize(grant_type: "client_credentials", scope: "global company")
	if @access_token&.valid?
		@access_token
	else
		@access_token = oauth2.token(grant_type:, scope:)
	end
end

#companiesObject



34
35
36
# File 'lib/maventa/client.rb', line 34

def companies
	@companies ||= Companies.new(@connection, @access_token)
end

#companyObject



38
39
40
# File 'lib/maventa/client.rb', line 38

def company
	@company ||= Company.new(@connection, @access_token)
end

#definitionsObject



42
43
44
# File 'lib/maventa/client.rb', line 42

def definitions
	@definitions ||= Definitions.new(@connection, @access_token)
end

#documentsObject



46
47
48
# File 'lib/maventa/client.rb', line 46

def documents
	@documents ||= Documents.new(@connection, @access_token)
end

#fi_bank_messagesObject



50
51
52
# File 'lib/maventa/client.rb', line 50

def fi_bank_messages
	@fi_bank_messages ||= FiBankMessages.new(@connection, @access_token)
end

#filesObject



54
55
56
# File 'lib/maventa/client.rb', line 54

def files
	@files ||= Files.new(@connection, @access_token)
end

#invoicesObject



58
59
60
# File 'lib/maventa/client.rb', line 58

def invoices
	@invoices ||= Invoices.new(@connection, @access_token)
end

#jwkObject



62
63
64
# File 'lib/maventa/client.rb', line 62

def jwk
	@jwk ||= Jwk.new(@connection, @access_token)
end

#lookupObject



66
67
68
# File 'lib/maventa/client.rb', line 66

def lookup
	@lookup ||= Lookup.new(@connection, @access_token)
end

#oauth2Object



26
27
28
# File 'lib/maventa/client.rb', line 26

def oauth2
	@oauth2 ||= OAuth2.new(@connection, client_id: @client_id, client_secret: @client_secret, vendor_api_key: @vendor_api_key)
end

#odpObject



70
71
72
# File 'lib/maventa/client.rb', line 70

def odp
	@odp ||= Odp.new(@connection, @access_token)
end

#operatorObject



74
75
76
# File 'lib/maventa/client.rb', line 74

def operator
	@operator ||= Operator.new(@connection, @access_token)
end

#partnerObject



78
79
80
# File 'lib/maventa/client.rb', line 78

def partner
	@partner ||= Partner.new(@connection, @access_token)
end

#servicesObject



82
83
84
# File 'lib/maventa/client.rb', line 82

def services
	@services ||= Services.new(@connection, @access_token)
end

#statusObject



86
87
88
# File 'lib/maventa/client.rb', line 86

def status
	@status ||= Status.new(@connection, @access_token)
end

#usersObject



90
91
92
# File 'lib/maventa/client.rb', line 90

def users
	@users ||= Users.new(@connection, @access_token)
end