Module: Fakturan
- Defined in:
- lib/fakturan_nu/error.rb,
lib/fakturan_nu.rb,
lib/fakturan_nu/row.rb,
lib/fakturan_nu/base.rb,
lib/fakturan_nu/client.rb,
lib/fakturan_nu/address.rb,
lib/fakturan_nu/invoice.rb,
lib/fakturan_nu/product.rb,
lib/fakturan_nu/middleware/logger.rb,
lib/fakturan_nu/middleware/parse_json.rb,
lib/fakturan_nu/middleware/raise_error.rb
Overview
Defined Under Namespace
Modules: Response
Classes: AccessDenied, Address, Base, Client, ClientError, ConnectionFailed, Error, Invoice, Logger, ParseError, Product, ResourceInvalid, ResourceNotFound, Row, ServerError, WithResponse
Class Method Summary
collapse
Class Method Details
.api_version=(version_no) ⇒ Object
70
71
72
73
|
# File 'lib/fakturan_nu.rb', line 70
def self.api_version=(version_no)
@api_version = version_no
rebuild_url
end
|
.build_url ⇒ Object
83
84
85
|
# File 'lib/fakturan_nu.rb', line 83
def self.build_url
"https://#{@use_sandbox ? 'sandbox.' : ''}fakturan.nu/api/v#{@api_version}"
end
|
.connection ⇒ Object
48
49
50
|
# File 'lib/fakturan_nu.rb', line 48
def self.connection
@connection
end
|
.rebuild_url ⇒ Object
87
88
89
|
# File 'lib/fakturan_nu.rb', line 87
def self.rebuild_url
self.url = self.build_url
end
|
.setup(username = nil, pass = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fakturan_nu.rb', line 26
def self.setup username = nil, pass = nil
@username, @pass = username, pass
@connection = Faraday.new(url: build_url) do |connection|
connection.request :json
connection.use Faraday::Request::BasicAuthentication, @username, @pass
connection.use Fakturan::Response::ParseJSON
connection.use Fakturan::Response::RaiseError
connection.use Fakturan::Logger, ::Logger.new(STDOUT), :bodies => true
connection.adapter Faraday.default_adapter
end
end
|
.url ⇒ Object
75
76
77
|
# File 'lib/fakturan_nu.rb', line 75
def self.url
@connection.url_prefix.to_s
end
|
.url=(new_url) ⇒ Object
79
80
81
|
# File 'lib/fakturan_nu.rb', line 79
def self.url=(new_url)
@connection.url_prefix = new_url
end
|
.use_basic_auth(username = nil, pass = nil) ⇒ Object
60
61
62
63
|
# File 'lib/fakturan_nu.rb', line 60
def self.use_basic_auth(username = nil, pass = nil)
@username, @pass = username, pass if (username && pass)
@connection.basic_auth(@username, @pass)
end
|
.use_sandbox=(true_or_false) ⇒ Object
65
66
67
68
|
# File 'lib/fakturan_nu.rb', line 65
def self.use_sandbox=(true_or_false)
@use_sandbox = self.debug_log = true_or_false
rebuild_url
end
|
.use_token_auth(token) ⇒ Object
def self.parse_json_times=(true_or_false)
ActiveSupport.parse_json_times = true_or_false
end
56
57
58
|
# File 'lib/fakturan_nu.rb', line 56
def self.use_token_auth(token)
@connection.token_auth(token)
end
|