class Ekispert::Client
Public Class Methods
connection_options()
click to toggle source
# File lib/ekispert/client.rb, line 11 def self.connection_options { url: "#{Config.host}/#{Config.version}/xml", proxy: Config.http_proxy, headers: { 'Content-Type' => 'application/xml;charset=utf-8' }, params: { key: Ekispert::Config.api_key }, request: { timeout: 5, open_timeout: 2 } } end
get(path, params=nil)
click to toggle source
# File lib/ekispert/client.rb, line 3 def self.get(path, params=nil) set_connection if @connection.nil? || connection_options_update? res = @connection.get(path, params) return parse_xml(res.body) if res.status == 200 raise_error(res) end
set_connection()
click to toggle source
# File lib/ekispert/client.rb, line 21 def self.set_connection @connection_options = connection_options @connection = Faraday.new(@connection_options) do |c| c.adapter Faraday.default_adapter end end
Private Class Methods
connection_options_update?()
click to toggle source
Below are private class methods
# File lib/ekispert/client.rb, line 30 def self.connection_options_update? @connection_options != connection_options end
parse_xml(xml)
click to toggle source
# File lib/ekispert/client.rb, line 34 def self.parse_xml(xml) Nokogiri::XML.parse(xml).xpath('//ResultSet') end
raise_error(res)
click to toggle source
# File lib/ekispert/client.rb, line 38 def self.raise_error(res) case res.status when 1 raise Error::InternalError, 'Engine Error' when 400 raise Error::BadRequest, res when 403 raise Error::Forbidden, res when 404 raise Error::NotFound, res when 400..499 raise Error::ClientError, res when 500..599 raise Error::ServerError, 'OMG!' end end