Class: KalixaApi::V4::HttpService
- Inherits:
-
Object
- Object
- KalixaApi::V4::HttpService
- Defined in:
- lib/kalixa_api/v4/http_service.rb
Instance Attribute Summary collapse
-
#api_test_mode ⇒ Object
Returns the value of attribute api_test_mode.
-
#kalixa_api_password ⇒ Object
Returns the value of attribute kalixa_api_password.
-
#kalixa_api_user ⇒ Object
Returns the value of attribute kalixa_api_user.
-
#test_kalixa_api_password ⇒ Object
Returns the value of attribute test_kalixa_api_password.
-
#test_kalixa_api_user ⇒ Object
Returns the value of attribute test_kalixa_api_user.
Instance Method Summary collapse
- #connection ⇒ Object
- #get_request(url, data = {}) ⇒ Object
-
#initialize(username: nil, password: nil) ⇒ HttpService
constructor
A new instance of HttpService.
- #post_request(url, data = {}) ⇒ Object
- #test_conection ⇒ Object
Constructor Details
#initialize(username: nil, password: nil) ⇒ HttpService
Returns a new instance of HttpService.
7 8 9 10 11 12 13 14 |
# File 'lib/kalixa_api/v4/http_service.rb', line 7 def initialize(username: nil, password: nil) @kalixa_api_user = kalixa_api_user || KalixaApi.kalixa_api_user @kalixa_api_password = kalixa_api_password || KalixaApi.kalixa_api_password @test_kalixa_api_user = test_kalixa_api_user || KalixaApi.test_kalixa_api_user @test_kalixa_api_password = test_kalixa_api_password || KalixaApi.test_kalixa_api_password @api_test_mode = api_test_mode || KalixaApi.api_test_mode end |
Instance Attribute Details
#api_test_mode ⇒ Object
Returns the value of attribute api_test_mode.
5 6 7 |
# File 'lib/kalixa_api/v4/http_service.rb', line 5 def api_test_mode @api_test_mode end |
#kalixa_api_password ⇒ Object
Returns the value of attribute kalixa_api_password.
5 6 7 |
# File 'lib/kalixa_api/v4/http_service.rb', line 5 def kalixa_api_password @kalixa_api_password end |
#kalixa_api_user ⇒ Object
Returns the value of attribute kalixa_api_user.
5 6 7 |
# File 'lib/kalixa_api/v4/http_service.rb', line 5 def kalixa_api_user @kalixa_api_user end |
#test_kalixa_api_password ⇒ Object
Returns the value of attribute test_kalixa_api_password.
5 6 7 |
# File 'lib/kalixa_api/v4/http_service.rb', line 5 def test_kalixa_api_password @test_kalixa_api_password end |
#test_kalixa_api_user ⇒ Object
Returns the value of attribute test_kalixa_api_user.
5 6 7 |
# File 'lib/kalixa_api/v4/http_service.rb', line 5 def test_kalixa_api_user @test_kalixa_api_user end |
Instance Method Details
#connection ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/kalixa_api/v4/http_service.rb', line 16 def connection @connection ||= begin Faraday.new(:url => 'https://payments.kalixa.com') do |faraday| faraday.response :json, :content_type => /\bjson$/ faraday.basic_auth(@kalixa_api_user , @kalixa_api_password) faraday.adapter Faraday.default_adapter end end end |
#get_request(url, data = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kalixa_api/v4/http_service.rb', line 52 def get_request(url, data = {}) if @api_test_mode test_conection.get do |req| req.url url req.headers['Content-Type'] = 'application/json' end else connection.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = data.to_json end end end |
#post_request(url, data = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kalixa_api/v4/http_service.rb', line 36 def post_request(url, data = {}) if @api_test_mode test_conection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = data.to_json end else connection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = data.to_json end end end |
#test_conection ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/kalixa_api/v4/http_service.rb', line 26 def test_conection @test_connection ||= begin Faraday.new(:url => 'https://payments.test.kalixa.com') do |faraday| faraday.response :json, :content_type => /\bjson$/ faraday.basic_auth(@test_kalixa_api_user, @test_kalixa_api_password) faraday.adapter Faraday.default_adapter end end end |