Class: Api::Billing

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

Direct Known Subclasses

Activation, Authentication, Connection

Constant Summary collapse

KEY_PATH =
'/etc/openvpn/auth_key'

Instance Method Summary collapse

Instance Method Details

#api_call_resultObject



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_keyObject



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

def auth_key
  File.read(KEY_PATH)
end

#host_with_portObject



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

def host_with_port
  host = ENV['API_HOST']
  "http://#{host.strip}"
end

#hostnameObject



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

def hostname
  ENV['HOSTNAME']
end

#responseObject



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

def response
  JSON.parse(api_call_result.body)
end

#signed_dataObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/api/billing.rb', line 23

def success_api_call?
  api_call_result.code == '200'
end

#uriObject



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

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