Class: NitroPay::Connection
- Inherits:
-
Object
- Object
- NitroPay::Connection
- Defined in:
- lib/nitro_pay/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth ⇒ Object
Attrs.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#end_point_versioned ⇒ Object
Returns the value of attribute end_point_versioned.
-
#path ⇒ Object
Returns the value of attribute path.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#recurrent_tid ⇒ Object
Returns the value of attribute recurrent_tid.
-
#request_params ⇒ Object
Returns the value of attribute request_params.
Instance Method Summary collapse
-
#delete_json_request ⇒ Object
DELETE json.
-
#delete_request ⇒ Object
DELETE http.
-
#get_json_request ⇒ Object
GET json.
-
#get_request ⇒ Object
GET http.
-
#initialize(params = {}) ⇒ Connection
constructor
Constructor.
-
#post_json_request ⇒ Object
POST json.
-
#post_request ⇒ Object
POST http.
-
#put_json_request ⇒ Object
PUT json.
-
#put_request ⇒ Object
PUT http.
-
#url_requested ⇒ Object
Full URL for the last request.
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 |
# 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 # TODO when add SSL to Production replace http to https self.protocol = 'http' 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_version ⇒ Object
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/nitro_pay/connection.rb', line 9 def api_version @api_version end |
#auth ⇒ Object
Attrs
4 5 6 |
# File 'lib/nitro_pay/connection.rb', line 4 def auth @auth end |
#domain ⇒ Object
Returns the value of attribute domain.
6 7 8 |
# File 'lib/nitro_pay/connection.rb', line 6 def domain @domain end |
#end_point ⇒ Object
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_versioned ⇒ Object
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 |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/nitro_pay/connection.rb', line 5 def path @path end |
#protocol ⇒ Object
Returns the value of attribute protocol.
7 8 9 |
# File 'lib/nitro_pay/connection.rb', line 7 def protocol @protocol end |
#recurrent_tid ⇒ Object
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_params ⇒ Object
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_request ⇒ Object
DELETE json
90 91 92 93 94 |
# File 'lib/nitro_pay/connection.rb', line 90 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_request ⇒ Object
DELETE http
84 85 86 87 |
# File 'lib/nitro_pay/connection.rb', line 84 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_request ⇒ Object
GET json
56 57 58 59 |
# File 'lib/nitro_pay/connection.rb', line 56 def get_json_request resp = RestClient.get(self.url_requested) to_hash_with_symbols(resp).it_keys_to_sym end |
#get_request ⇒ Object
GET http
51 52 53 |
# File 'lib/nitro_pay/connection.rb', line 51 def get_request RestClient.get self.url_requested end |
#post_json_request ⇒ Object
POST json
67 68 69 70 |
# File 'lib/nitro_pay/connection.rb', line 67 def post_json_request resp = RestClient.post(self.url_requested, self.request_params) to_hash_with_symbols(resp) end |
#post_request ⇒ Object
POST http
62 63 64 |
# File 'lib/nitro_pay/connection.rb', line 62 def post_request RestClient.post self.url_requested, self.request_params end |
#put_json_request ⇒ Object
PUT json
78 79 80 81 |
# File 'lib/nitro_pay/connection.rb', line 78 def put_json_request resp = RestClient.put(self.url_requested, self.request_params) to_hash_with_symbols(resp) end |
#put_request ⇒ Object
PUT http
73 74 75 |
# File 'lib/nitro_pay/connection.rb', line 73 def put_request RestClient.put self.url_requested, self.request_params end |
#url_requested ⇒ Object
Full URL for the last request
46 47 48 |
# File 'lib/nitro_pay/connection.rb', line 46 def url_requested "#{self.end_point}/#{self.api_version}/#{self.path}" end |