Class: Grac::Client
- Inherits:
-
Object
- Object
- Grac::Client
- Defined in:
- lib/grac/client.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, options = {}) ⇒ Client
constructor
A new instance of Client.
- #path(path, variables = {}) ⇒ Object
- #set(options = {}) ⇒ Object
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, = {}) URI.parse(uri) @uri = uri = { :connecttimeout => [:connecttimeout] || 0.1, :timeout => [:timeout] || 15, :params => [:params] || {}, :headers => { "User-Agent" => "Grac v#{Grac::VERSION}" }.merge([:headers] || {}), :postprocessing => [:postprocessing] || {} } end |
Instance Attribute Details
#uri ⇒ Object (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}", ) end |
#set(options = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/grac/client.rb', line 25 def set( = {}) = .merge({ headers: [:headers].merge([:headers] || {}) }) self.class.new(@uri, .merge()) end |