Module: BitBucket::Request
- Included in:
- API
- Defined in:
- lib/bitbucket_rest_api/request.rb,
lib/bitbucket_rest_api/request/oauth.rb,
lib/bitbucket_rest_api/request/basic_auth.rb
Overview
Defined Under Namespace
Classes: BasicAuth, Jsonize, OAuth
Constant Summary
collapse
- METHODS =
%i[get post put delete patch].freeze
- METHODS_WITH_BODIES =
%i[post put patch].freeze
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
24
25
26
|
# File 'lib/bitbucket_rest_api/request.rb', line 24
def delete_request(path, params = {}, options = {})
request(:delete, path, params, options)
end
|
#get_request(path, params = {}, options = {}) ⇒ Object
8
9
10
|
# File 'lib/bitbucket_rest_api/request.rb', line 8
def get_request(path, params = {}, options = {})
request(:get, path, params, options)
end
|
#patch_request(path, params = {}, options = {}) ⇒ Object
12
13
14
|
# File 'lib/bitbucket_rest_api/request.rb', line 12
def patch_request(path, params = {}, options = {})
request(:patch, path, params, options)
end
|
#post_request(path, params = {}, options = {}) ⇒ Object
16
17
18
|
# File 'lib/bitbucket_rest_api/request.rb', line 16
def post_request(path, params = {}, options = {})
request(:post, path, params, options)
end
|
#put_request(path, params = {}, options = {}) ⇒ Object
20
21
22
|
# File 'lib/bitbucket_rest_api/request.rb', line 20
def put_request(path, params = {}, options = {})
request(:put, path, params, options)
end
|
#request(method, path, params, options = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/bitbucket_rest_api/request.rb', line 28
def request(method, path, params, options = {})
raise ArgumentError, "unkown http method: #{method}" unless METHODS.include?(method)
puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
conn = connection(options)
path = (conn.path_prefix + path).gsub(%r{//}, '/') if conn.path_prefix != '/'
response = conn.send(method) do |request|
request['Authorization'] = "Bearer #{new_access_token}" unless new_access_token.nil?
case method.to_sym
when *(METHODS - METHODS_WITH_BODIES)
request.body = params.delete('data') if params.key?('data')
request.url(path, params)
when *METHODS_WITH_BODIES
request.path = path
unless params.empty?
request.body = MultiJson.dump(params)
end
end
end
response.body
end
|