class KalixaApi::V3::HttpService

Attributes

api_mode[RW]
api_password[RW]
api_user[RW]
test_api_password[RW]
test_api_user[RW]

Public Class Methods

new(api_user: nil, api_password: nil, test_api_user: nil, test_api_password: nil, api_mode: nil) click to toggle source
# 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

Public Instance Methods

connection() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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