Class: Clientele::RequestBuilder

Inherits:
Object
  • Object
show all
Includes:
Utils, Enumerable
Defined in:
lib/clientele/request_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

deep_camelize_keys, ensure_trailing_slash, merge_paths

Constructor Details

#initialize(*request_components, client: API.client) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



10
11
12
13
# File 'lib/clientele/request_builder.rb', line 10

def initialize(*request_components, client: API.client)
  @stack = request_components.flatten
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



56
57
58
59
60
61
62
63
64
# File 'lib/clientele/request_builder.rb', line 56

def method_missing(method_name, *args, &block)
  if chain.respond_to? method_name, :public
    chain_method method_name, *args, &block
  elsif client.has_resource? method_name
    chain_resource method_name
  elsif should_paginate? method_name
    chain.send :each, build, &block
  else; super; end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/clientele/request_builder.rb', line 8

def client
  @client
end

#stackObject

Returns the value of attribute stack.



8
9
10
# File 'lib/clientele/request_builder.rb', line 8

def stack
  @stack
end

Instance Method Details

#callObject



15
16
17
# File 'lib/clientele/request_builder.rb', line 15

def call
  build.call
end