Class: Api::Billing
- Inherits:
-
Object
show all
- Defined in:
- lib/api/billing.rb
Constant Summary
collapse
- KEY_PATH =
'/etc/openvpn/auth_key'
Instance Method Summary
collapse
Instance Method Details
#api_call_result ⇒ Object
31
32
33
|
# File 'lib/api/billing.rb', line 31
def api_call_result
@api_result ||= Net::HTTP.post_form(uri, signed_data)
end
|
#auth_key ⇒ Object
15
16
17
|
# File 'lib/api/billing.rb', line 15
def auth_key
File.read(KEY_PATH)
end
|
#host_with_port ⇒ Object
10
11
12
13
|
# File 'lib/api/billing.rb', line 10
def host_with_port
host = ENV['API_HOST']
"http://#{host.strip}"
end
|
#hostname ⇒ Object
19
20
21
|
# File 'lib/api/billing.rb', line 19
def hostname
ENV['HOSTNAME']
end
|
#response ⇒ Object
27
28
29
|
# File 'lib/api/billing.rb', line 27
def response
JSON.parse(api_call_result.body)
end
|
#signed_data ⇒ Object
39
40
41
|
# File 'lib/api/billing.rb', line 39
def signed_data
data.merge!({ signature: Signer.sign_hash(data, auth_key) })
end
|
#success_api_call? ⇒ Boolean
23
24
25
|
# File 'lib/api/billing.rb', line 23
def success_api_call?
api_call_result.code == '200'
end
|
#uri ⇒ Object
35
36
37
|
# File 'lib/api/billing.rb', line 35
def uri
URI("#{host_with_port}/api/#{action}")
end
|