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