Class: Ekispert::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ekispert/client.rb

Class Method Summary collapse

Class Method Details

.connection_optionsObject



11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



3
4
5
6
7
8
9
# 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_connectionObject



21
22
23
24
25
26
# 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