Class: Quaderno::Base
Direct Known Subclasses
CheckoutSession, Contact, Credit, Estimate, Evidence, Expense, Income, Invoice, Item, Receipt, Recurring, Report, ReportRequest, Tax, Webhook
Constant Summary
collapse
- PRODUCTION_URL =
'https://quadernoapp.com/api/'
- SANDBOX_URL =
'http://sandbox-quadernoapp.com/api/'
- @@auth_token =
nil
- @@rate_limit_info =
nil
- @@api_version =
nil
- @@url =
PRODUCTION_URL
- @@user_agent_suffix =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
#rate_limit_info, #rate_limit_info=
#get_authentication
included
Methods included from Exceptions
included
Class Method Details
.api_model(klass) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/quaderno-ruby/base.rb', line 21
def self.api_model(klass)
instance_eval <<-END
def api_model
#{klass}
end
END
class_eval <<-END
def api_model
#{klass}
end
END
end
|
.api_version=(api_version) ⇒ Object
38
39
40
|
# File 'lib/quaderno-ruby/base.rb', line 38
def self.api_version=(api_version)
@@api_version = api_version
end
|
.auth_token=(auth_token) ⇒ Object
42
43
44
|
# File 'lib/quaderno-ruby/base.rb', line 42
def self.auth_token=(auth_token)
@@auth_token = auth_token
end
|
.authorization(auth_token, mode = nil) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/quaderno-ruby/base.rb', line 54
def self.authorization(auth_token, mode = nil)
mode ||= :production
url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: )
if response.code == 200
data = self.new(response.parsed_response)
data.rate_limit_info = response
data
elsif response.response.is_a?(Net::HTTPServerError)
raise_exception(Quaderno::Exceptions::ServerError, 'Server error', response)
else
raise_exception(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token', response)
end
end
|
34
35
36
|
# File 'lib/quaderno-ruby/base.rb', line 34
def self.configure
yield self
end
|
.me(options = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/quaderno-ruby/base.rb', line 98
def self.me(options = {})
options[:auth_token] ||= auth_token
options[:api_url] ||= url
authentication = get_authentication(options)
party_response = get("#{authentication[:url]}me.json",
basic_auth: authentication[:basic_auth],
headers: .merge(authentication[:headers])
)
check_exception_for(party_response, { subdomain_or_token: true })
data = self.new(party_response.parsed_response)
data.rate_limit_info = party_response
data
end
|
.ping(options = {}) ⇒ Object
Also known as:
rate_limit_info
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/quaderno-ruby/base.rb', line 72
def self.ping(options = {})
begin
options[:auth_token] ||= auth_token
options[:api_url] ||= url
authentication = get_authentication(options)
party_response = get("#{authentication[:url]}ping.json",
basic_auth: authentication[:basic_auth],
headers: .merge(authentication[:headers])
)
check_exception_for(party_response, { subdomain_or_token: true })
rescue Errno::ECONNREFUSED
return Quaderno::Base.new({ status: false })
end
data = self.new({ status: true })
data.rate_limit_info = party_response
data
end
|
.url=(url) ⇒ Object
46
47
48
|
# File 'lib/quaderno-ruby/base.rb', line 46
def self.url=(url)
@@url = url
end
|
50
51
52
|
# File 'lib/quaderno-ruby/base.rb', line 50
def self.(custom_user_agent)
@@user_agent_suffix = custom_user_agent
end
|
Instance Method Details
#to_hash ⇒ Object
118
119
120
|
# File 'lib/quaderno-ruby/base.rb', line 118
def to_hash
self.marshal_dump
end
|