Class: Clientele::Request

Inherits:
Struct
  • Object
show all
Includes:
Utils
Defined in:
lib/clientele/request.rb

Constant Summary collapse

VERBS =
Faraday::Connection::METHODS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

deep_camelize_keys, ensure_trailing_slash, merge_paths

Constructor Details

#initialize(props = {}) ⇒ Request

Returns a new instance of Request.



39
40
41
42
# File 'lib/clientele/request.rb', line 39

def initialize(props = {})
  apply self.class.defaults
  apply props
end

Class Method Details

.defaultsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/clientele/request.rb', line 101

def defaults
  {
    verb:     :get,
    path:     '',
    query:    {},
    body:     {},
    headers:  {},
    options:  {},
    callback: nil,
    resource: nil,
    client:   nil,
  }
end

Instance Method Details

#+(other) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/clientele/request.rb', line 63

def + other
  self.class.new(
    verb:     other.verb || verb,
    path:     merge_paths(path, other.path),
    query:    query.merge(other.query),
    body:     body.merge(other.body),
    headers:  headers.merge(other.headers),
    options:  options.merge(other.options),
    callback: other.callback || callback,
    resource: other.resource || resource,
    client:   client || other.client,
  )
end

#async?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/clientele/request.rb', line 44

def async?
  !!callback
end

#callObject



58
59
60
61
# File 'lib/clientele/request.rb', line 58

def call
  options.deep_merge! client.configuration.to_hash if client
  callback ? callback.call(result) : result
end

#to_request(options = {}) ⇒ Object



52
53
54
55
56
# File 'lib/clientele/request.rb', line 52

def to_request(options={})
  tap do |request|
    request.options.deep_merge! options
  end
end

#urlObject



48
49
50
# File 'lib/clientele/request.rb', line 48

def url
  ensure_trailing_slash merge_paths options[:root_url], path
end