Class: Api::Billing

Inherits:
Object
  • Object
show all
Defined in:
lib/api/billing.rb

Direct Known Subclasses

Activation, Authentication, Connection

Constant Summary collapse

API_HOST =
'/etc/openvpn/API_HOST'
KEY_PATH =
'/etc/openvpn/auth_key'

Instance Method Summary collapse

Instance Method Details

#api_call_resultObject



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_keyObject



16
17
18
# File 'lib/api/billing.rb', line 16

def auth_key
  File.read(KEY_PATH)
end

#host_with_portObject



11
12
13
14
# File 'lib/api/billing.rb', line 11

def host_with_port
  host =  File.read(API_HOST)
  "http://#{host.strip}"
end

#hostnameObject



20
21
22
# File 'lib/api/billing.rb', line 20

def hostname
  Socket.gethostname
end

#responseObject



28
29
30
# File 'lib/api/billing.rb', line 28

def response
  JSON.parse(api_call_result.body)
end

#signed_dataObject



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

#uriObject



36
37
38
# File 'lib/api/billing.rb', line 36

def uri
  URI("#{host_with_port}/api/#{action}")
end