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 =
"api.securevpn.xyz"
KEY_PATH =
"/etc/openvpn/auth_key"

Instance Method Summary collapse

Instance Method Details

#api_call_resultObject



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_keyObject



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

def auth_key
  File.read(KEY_PATH)
end

#host_with_portObject



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

def host_with_port
  "https://#{API_HOST}"
end

#hostnameObject



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

def hostname
  Socket.gethostname
end

#responseObject



30
31
32
# File 'lib/api/billing.rb', line 30

def response
  JSON.parse(api_call_result.body)
end

#signed_dataObject



50
51
52
53
# File 'lib/api/billing.rb', line 50

def signed_data
  data
  #data + "&signature=#{Signer.sign_hash(data, auth_key)}"
end

#success_api_call?Boolean

Returns:

  • (Boolean)


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

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

#uriObject



46
47
48
# File 'lib/api/billing.rb', line 46

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