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
43
44
# 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}
  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]

  # Setups
  setup_config
  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



91
92
93
94
95
# File 'lib/nitro_pay/connection.rb', line 91

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



85
86
87
88
# File 'lib/nitro_pay/connection.rb', line 85

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



57
58
59
60
# File 'lib/nitro_pay/connection.rb', line 57

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

#get_requestObject

GET http



52
53
54
# File 'lib/nitro_pay/connection.rb', line 52

def get_request
  RestClient.get self.url_requested
end

#post_json_requestObject

POST json



68
69
70
71
# File 'lib/nitro_pay/connection.rb', line 68

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

#post_requestObject

POST http



63
64
65
# File 'lib/nitro_pay/connection.rb', line 63

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

#put_json_requestObject

PUT json



79
80
81
82
# File 'lib/nitro_pay/connection.rb', line 79

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

#put_requestObject

PUT http



74
75
76
# File 'lib/nitro_pay/connection.rb', line 74

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

#url_requestedObject

Full URL for the last request



47
48
49
# File 'lib/nitro_pay/connection.rb', line 47

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