Class: Jimson::Client

Inherits:
BlankSlate
  • Object
show all
Defined in:
lib/jimson/client.rb,
lib/jimson/client/error.rb

Defined Under Namespace

Modules: Error

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, opts = {}, namespace = nil, client_opts = {}) ⇒ Client

Returns a new instance of Client.



160
161
162
163
# File 'lib/jimson/client.rb', line 160

def initialize(url, opts = {}, namespace = nil, client_opts = {})
  @url, @opts, @namespace, @client_opts = url, opts, namespace, client_opts
  @helper = ClientHelper.new(url, opts, namespace, client_opts)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



165
166
167
168
# File 'lib/jimson/client.rb', line 165

def method_missing(sym, *args, &block)
  args = args.first if args.size == 1 && args.first.is_a?(Hash)
  @helper.process_call(sym, args) 
end

Class Method Details

.batch(client) {|batch_client| ... } ⇒ Object

Yields:

  • (batch_client)


153
154
155
156
157
158
# File 'lib/jimson/client.rb', line 153

def self.batch(client)
  helper = client.instance_variable_get(:@helper)
  batch_client = BatchClient.new(helper)
  yield batch_client
  helper.send_batch
end

Instance Method Details

#[](method, *args) ⇒ Object



170
171
172
173
174
175
176
177
# File 'lib/jimson/client.rb', line 170

def [](method, *args)
  if method.is_a?(Symbol)
    # namespace requested
    new_ns = @namespace.nil? ? "#{method}." : "#@namespace#{method}."
    return Client.new(@url, @opts, new_ns)
  end
  @helper.process_call(method, args) 
end