Class: NitroPay::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro_pay/connection.rb

Direct Known Subclasses

Status, Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Connection

Constructor



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nitro_pay/connection.rb', line 15

def initialize(params = {})
  # An work around added to prevent a lot of changes
  params = params.merge({test_env:true}) if NitroPay.test_env
  params = params.merge({debug:true}) if NitroPay.debug

  # Static part
  self.request_params = {transaction:params}
  setup_config
  self.domain = 'pay.nitrostart.me'

  # If using test or Debug it is not production
  if params[:debug] || params[:test]
    self.protocol = 'http'
    self.domain = 'pay.dev:4000'
  else
    self.protocol = 'https'
    self.domain = 'pay.nitrostart.me'
  end

  self.api_version = 'v1'
  self.end_point = "#{self.protocol}://#{self.domain}/api"
  self.end_point_versioned = "#{self.protocol}://#{self.domain}/api/#{self.api_version}"

  # Dynamic env
  setup_default_app if params[:test_env]
  setup_attrs(params)
  self.recurrent_tid = params[:tid] unless params[:tid].nil?
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



9
10
11
# File 'lib/nitro_pay/connection.rb', line 9

def api_version
  @api_version
end

#authObject

Attrs



4
5
6
# File 'lib/nitro_pay/connection.rb', line 4

def auth
  @auth
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/nitro_pay/connection.rb', line 6

def domain
  @domain
end

#end_pointObject

Returns the value of attribute end_point.



8
9
10
# File 'lib/nitro_pay/connection.rb', line 8

def end_point
  @end_point
end

#end_point_versionedObject

Returns the value of attribute end_point_versioned.



12
13
14
# File 'lib/nitro_pay/connection.rb', line 12

def end_point_versioned
  @end_point_versioned
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/nitro_pay/connection.rb', line 5

def path
  @path
end

#protocolObject

Returns the value of attribute protocol.



7
8
9
# File 'lib/nitro_pay/connection.rb', line 7

def protocol
  @protocol
end

#recurrent_tidObject

Returns the value of attribute recurrent_tid.



10
11
12
# File 'lib/nitro_pay/connection.rb', line 10

def recurrent_tid
  @recurrent_tid
end

#request_paramsObject

Returns the value of attribute request_params.



11
12
13
# File 'lib/nitro_pay/connection.rb', line 11

def request_params
  @request_params
end

Instance Method Details

#delete_json_requestObject

DELETE json



89
90
91
92
93
# File 'lib/nitro_pay/connection.rb', line 89

def delete_json_request
  auth = self.request_params[:auth]
  resp = RestClient.delete self.url_requested, auth_app_id:auth[:app_id], auth_secret_key:auth[:secret_key]
  to_hash_with_symbols(resp)
end

#delete_requestObject

DELETE http



83
84
85
86
# File 'lib/nitro_pay/connection.rb', line 83

def delete_request
  auth = self.request_params[:auth]
  RestClient.delete self.url_requested, app_id:auth[:app_id], secret_key:auth[:secret_key]
end

#get_json_requestObject

GET json



55
56
57
58
# File 'lib/nitro_pay/connection.rb', line 55

def get_json_request
  resp = RestClient.get(self.url_requested)
  to_hash_with_symbols(resp).it_keys_to_sym
end

#get_requestObject

GET http



50
51
52
# File 'lib/nitro_pay/connection.rb', line 50

def get_request
  RestClient.get self.url_requested
end

#post_json_requestObject

POST json



66
67
68
69
# File 'lib/nitro_pay/connection.rb', line 66

def post_json_request
  resp = RestClient.post(self.url_requested, self.request_params)
  to_hash_with_symbols(resp)
end

#post_requestObject

POST http



61
62
63
# File 'lib/nitro_pay/connection.rb', line 61

def post_request
  RestClient.post self.url_requested, self.request_params
end

#put_json_requestObject

PUT json



77
78
79
80
# File 'lib/nitro_pay/connection.rb', line 77

def put_json_request
  resp = RestClient.put(self.url_requested, self.request_params)
  to_hash_with_symbols(resp)
end

#put_requestObject

PUT http



72
73
74
# File 'lib/nitro_pay/connection.rb', line 72

def put_request
  RestClient.put self.url_requested, self.request_params
end

#url_requestedObject

Full URL for the last request



45
46
47
# File 'lib/nitro_pay/connection.rb', line 45

def url_requested
  "#{self.end_point}/#{self.api_version}/#{self.path}"
end