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 24 25 26 27 28 29 |
# File 'lib/grac/client.rb', line 12 def initialize(uri, = {}) URI.parse(uri) @uri = uri @options = { :connecttimeout => [:connecttimeout] || 0.1, :timeout => [:timeout] || 15, :params => [:params] || {}, :headers => { "User-Agent" => "Grac v#{Grac::VERSION}" }.merge([:headers] || {}), :postprocessing => [:postprocessing] || {}, :middleware => [:middleware] || [] } @options.freeze [:params, :headers, :postprocessing, :middleware].each do |k| @options[k].freeze end @uri.freeze 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
40 41 42 43 44 45 |
# File 'lib/grac/client.rb', line 40 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
31 32 33 34 35 36 37 38 |
# File 'lib/grac/client.rb', line 31 def set( = {}) = .merge({ headers: @options[:headers].merge([:headers] || {}), middleware: @options[:middleware] + ([:middleware] || []) }) self.class.new(@uri, @options.merge()) end |