Class: GoApiClient::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
9
10
11
12
# File 'lib/go_api_client/client.rb', line 3

def initialize(options={})
  options = ({:uri => nil, :username => nil, :password => nil, :ssl_verify_mode => nil}).merge(options)
  @http_fetcher = GoApiClient::HttpFetcher.new(options)
  if options[:uri]
    @base_uri = options[:uri].chomp('/')
  else
    options = ({:host => 'localhost', :port => 8153, :ssl => false}).merge(options)
    @base_uri = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go"
  end
end

Instance Method Details

#api(name, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/go_api_client/client.rb', line 14

def api(name, options={})
  class_name = name.slice(0, 1).capitalize + name.slice(1..-1)
  api_class = "#{self.class.to_s.split('::').first}::Api::#{class_name}".split('::').inject(Object) { |n, c| n.const_get c }
  api_class.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher}.merge(options))
end