Class: Grac::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Client

Returns a new instance of Client


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/grac/client.rb', line 12

def initialize(uri, options = {})
  URI.parse(uri)

  @uri = uri
  @options = {
    :connecttimeout => options[:connecttimeout] || 0.1,
    :timeout        => options[:timeout]        || 15,
    :params         => options[:params]         || {},
    :headers        => { "User-Agent" => "Grac v#{Grac::VERSION}" }.merge(options[:headers] || {}),
    :postprocessing => options[:postprocessing] || {}
  }
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri


10
11
12
# File 'lib/grac/client.rb', line 10

def uri
  @uri
end

Instance Method Details

#path(path, variables = {}) ⇒ Object


33
34
35
36
37
38
# File 'lib/grac/client.rb', line 33

def path(path, variables = {})
  variables.each do |key, value|
    path = path.gsub("{#{key}}", value)
  end
  self.class.new("#{@uri}#{path}", @options)
end

#set(options = {}) ⇒ Object


25
26
27
28
29
30
31
# File 'lib/grac/client.rb', line 25

def set(options = {})
  options = options.merge({
    headers: @options[:headers].merge(options[:headers] || {})
  })

  self.class.new(@uri, @options.merge(options))
end