Module: Nimbu::Request
- Includes:
- Utils::Constants
- Included in:
- Endpoint
- Defined in:
- lib/nimbu-api/request.rb,
lib/nimbu-api/request/oauth2.rb,
lib/nimbu-api/request/arguments.rb,
lib/nimbu-api/request/basic_auth.rb,
lib/nimbu-api/request/normalizer.rb,
lib/nimbu-api/request/validations.rb,
lib/nimbu-api/request/content_locale.rb,
lib/nimbu-api/request/parameter_filter.rb,
lib/nimbu-api/request/validations/token.rb,
lib/nimbu-api/request/validations/format.rb,
lib/nimbu-api/request/validations/presence.rb,
lib/nimbu-api/request/validations/required.rb
Overview
Defined Under Namespace
Modules: Normalizer, ParameterFilter, Validations
Classes: Arguments, BasicAuth, ContentLocale, Json, OAuth2, SiteHeader, UserAgent
Constant Summary
collapse
- METHODS =
[:get, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[ :post, :put, :patch ]
Utils::Constants::ACCEPT, Utils::Constants::ACCEPTED_OAUTH_SCOPES, Utils::Constants::ACCEPT_CHARSET, Utils::Constants::CACHE_CONTROL, Utils::Constants::CONTENT_LENGTH, Utils::Constants::CONTENT_TYPE, Utils::Constants::DATE, Utils::Constants::ETAG, Utils::Constants::HEADER_LAST, Utils::Constants::HEADER_LINK, Utils::Constants::HEADER_NEXT, Utils::Constants::LOCATION, Utils::Constants::META_FIRST, Utils::Constants::META_LAST, Utils::Constants::META_NEXT, Utils::Constants::META_PREV, Utils::Constants::META_REL, Utils::Constants::NIMBU_SITE, Utils::Constants::OAUTH_SCOPES, Utils::Constants::PARAM_PAGE, Utils::Constants::PARAM_PER_PAGE, Utils::Constants::PARAM_START_PAGE, Utils::Constants::RATELIMIT_LIMIT, Utils::Constants::RATELIMIT_REMAINING, Utils::Constants::SERVER, Utils::Constants::USER_AGENT
Instance Method Summary
collapse
-
#delete_request(path, params = {}, options = {}) ⇒ Object
-
#get_request(path, params = {}, options = {}) ⇒ Object
-
#patch_request(path, params = {}, options = {}) ⇒ Object
-
#post_request(path, params = {}, options = {}) ⇒ Object
-
#put_request(path, params = {}, options = {}) ⇒ Object
-
#request(method, path, params, options) ⇒ Object
Instance Method Details
#delete_request(path, params = {}, options = {}) ⇒ Object
37
38
39
|
# File 'lib/nimbu-api/request.rb', line 37
def delete_request(path, params={}, options={})
request(:delete, path, params, options)
end
|
#get_request(path, params = {}, options = {}) ⇒ Object
21
22
23
|
# File 'lib/nimbu-api/request.rb', line 21
def get_request(path, params={}, options={})
request(:get, path, params, options)
end
|
#patch_request(path, params = {}, options = {}) ⇒ Object
25
26
27
|
# File 'lib/nimbu-api/request.rb', line 25
def patch_request(path, params={}, options={})
request(:patch, path, params, options)
end
|
#post_request(path, params = {}, options = {}) ⇒ Object
29
30
31
|
# File 'lib/nimbu-api/request.rb', line 29
def post_request(path, params={}, options={})
request(:post, path, params, options)
end
|
#put_request(path, params = {}, options = {}) ⇒ Object
33
34
35
|
# File 'lib/nimbu-api/request.rb', line 33
def put_request(path, params={}, options={})
request(:put, path, params, options)
end
|
#request(method, path, params, options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/nimbu-api/request.rb', line 41
def request(method, path, params, options) if !METHODS.include?(method)
raise ArgumentError, "unkown http method: #{method}"
end
puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
conn = connection(options.merge(current_options))
if conn.path_prefix != '/' && path.index(conn.path_prefix) != 0
path = (conn.path_prefix + path).gsub(/\/(\/)*/, '/')
end
response = conn.send(method) do |request|
unless options[:with_attachments]
case method.to_sym
when *(METHODS - METHODS_WITH_BODIES)
request.body = params.delete('data') if params.has_key?('data')
request.url(path, params)
when *METHODS_WITH_BODIES
request.path = path
request.body = (params) unless params.empty?
end
else
request.body = params
request.url(path)
end
end
Response::Wrapper.new(response, self).auto_paginate
end
|