Class: KalixaApi::V3::HttpService
- Inherits:
-
Object
- Object
- KalixaApi::V3::HttpService
- Defined in:
- lib/kalixa_api/v3/http_service.rb
Instance Attribute Summary collapse
-
#api_mode ⇒ Object
Returns the value of attribute api_mode.
-
#api_password ⇒ Object
Returns the value of attribute api_password.
-
#api_user ⇒ Object
Returns the value of attribute api_user.
-
#test_api_password ⇒ Object
Returns the value of attribute test_api_password.
-
#test_api_user ⇒ Object
Returns the value of attribute test_api_user.
Instance Method Summary collapse
- #connection ⇒ Object
- #get_request(url, data, xml_root) ⇒ Object
-
#initialize(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil) ⇒ HttpService
constructor
A new instance of HttpService.
- #post_request(url, data, xml_root) ⇒ Object
- #test_conection ⇒ Object
Constructor Details
#initialize(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil) ⇒ HttpService
Returns a new instance of HttpService.
7 8 9 10 11 12 13 |
# File 'lib/kalixa_api/v3/http_service.rb', line 7 def initialize(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil) @api_user = api_user || KalixaApi.api_user @api_password = api_password || KalixaApi.api_password @test_api_user = test_api_user || KalixaApi.test_api_user @test_api_password = test_api_password || KalixaApi.test_api_password @api_mode = api_mode || KalixaApi.api_mode end |
Instance Attribute Details
#api_mode ⇒ Object
Returns the value of attribute api_mode.
5 6 7 |
# File 'lib/kalixa_api/v3/http_service.rb', line 5 def api_mode @api_mode end |
#api_password ⇒ Object
Returns the value of attribute api_password.
5 6 7 |
# File 'lib/kalixa_api/v3/http_service.rb', line 5 def api_password @api_password end |
#api_user ⇒ Object
Returns the value of attribute api_user.
5 6 7 |
# File 'lib/kalixa_api/v3/http_service.rb', line 5 def api_user @api_user end |
#test_api_password ⇒ Object
Returns the value of attribute test_api_password.
5 6 7 |
# File 'lib/kalixa_api/v3/http_service.rb', line 5 def test_api_password @test_api_password end |
#test_api_user ⇒ Object
Returns the value of attribute test_api_user.
5 6 7 |
# File 'lib/kalixa_api/v3/http_service.rb', line 5 def test_api_user @test_api_user end |
Instance Method Details
#connection ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/kalixa_api/v3/http_service.rb', line 15 def connection @connection ||= begin Faraday.new(:url => 'https://api.kalixa.com') do |faraday| faraday.basic_auth(@api_user , @api_password) faraday.adapter Faraday.default_adapter end end end |
#get_request(url, data, xml_root) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kalixa_api/v3/http_service.rb', line 49 def get_request(url, data, xml_root) if @api_mode connection.get do |req| req.url url req.headers['Content-Type'] = 'application/xml; charset=utf-8' req.body = data.to_xml(:root => xml_root) end else test_conection.get do |req| req.url url req.headers['Content-Type'] = 'application/xml; charset=utf-8' req.body = data.to_xml(:root => xml_root) end end end |
#post_request(url, data, xml_root) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kalixa_api/v3/http_service.rb', line 33 def post_request(url, data, xml_root) if @api_mode connection.post do |req| req.url url req.headers['Content-Type'] = 'application/xml; charset=utf-8' req.body = data.to_xml(:root => xml_root) end else test_conection.post do |req| req.url url req.headers['Content-Type'] = 'application/xml; charset=utf-8' req.body = data.to_xml(:root => xml_root) end end end |
#test_conection ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/kalixa_api/v3/http_service.rb', line 24 def test_conection @connection ||= begin Faraday.new(:url => 'https://api.test.kalixa.com') do |faraday| faraday.basic_auth(@test_api_user, @test_api_password) faraday.adapter Faraday.default_adapter end end end |