Class: Api::Billing
- Inherits:
-
Object
show all
- Defined in:
- lib/api/billing.rb
Constant Summary
collapse
- API_HOST =
"api.securevpn.xyz"
- KEY_PATH =
"/etc/openvpn/auth_key"
Instance Method Summary
collapse
Instance Method Details
#api_call_result ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/api/billing.rb', line 34
def api_call_result
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = signed_data
@api_result ||= http.request(request)
end
|
#auth_key ⇒ Object
18
19
20
|
# File 'lib/api/billing.rb', line 18
def auth_key
File.read(KEY_PATH)
end
|
#host_with_port ⇒ Object
14
15
16
|
# File 'lib/api/billing.rb', line 14
def host_with_port
"https://#{API_HOST}"
end
|
#hostname ⇒ Object
22
23
24
|
# File 'lib/api/billing.rb', line 22
def hostname
Socket.gethostname
end
|
#response ⇒ Object
30
31
32
|
# File 'lib/api/billing.rb', line 30
def response
JSON.parse(api_call_result.body)
end
|
#signed_data ⇒ Object
50
51
52
53
|
# File 'lib/api/billing.rb', line 50
def signed_data
data
end
|
#success_api_call? ⇒ Boolean
26
27
28
|
# File 'lib/api/billing.rb', line 26
def success_api_call?
api_call_result.code == '200'
end
|
#uri ⇒ Object
46
47
48
|
# File 'lib/api/billing.rb', line 46
def uri
URI("#{host_with_port}/api/#{action}")
end
|