Module: Github::Request
- Included in:
- API
- Defined in:
- lib/github_api/request.rb,
lib/github_api/request/oauth2.rb,
lib/github_api/request/basic_auth.rb
Overview
Defined Under Namespace
Classes: BasicAuth, Jsonize, OAuth2
Constant Summary
- METHODS =
[:get, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[ :post, :put, :patch ]
Instance Method Summary
(collapse)
Instance Method Details
- (Object) delete_request(path, params = {})
27
28
29
|
# File 'lib/github_api/request.rb', line 27
def delete_request(path, params={})
request(:delete, path, params)
end
|
- (Object) get_request(path, params = {})
11
12
13
|
# File 'lib/github_api/request.rb', line 11
def get_request(path, params={})
request(:get, path, params).auto_paginate
end
|
- (Object) patch_request(path, params = {})
15
16
17
|
# File 'lib/github_api/request.rb', line 15
def patch_request(path, params={})
request(:patch, path, params)
end
|
- (Object) post_request(path, params = {})
19
20
21
|
# File 'lib/github_api/request.rb', line 19
def post_request(path, params={})
request(:post, path, params)
end
|
- (Object) put_request(path, params = {})
23
24
25
|
# File 'lib/github_api/request.rb', line 23
def put_request(path, params={})
request(:put, path, params)
end
|
- (Object) request(method, path, params)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/github_api/request.rb', line 31
def request(method, path, params) if !METHODS.include?(method)
raise ArgumentError, "unkown http method: #{method}"
end
puts "EXECUTED: #{method} - #{path} with PARAMS: #{params}" if ENV['DEBUG']
conn_options = params.options.merge(current_options)
conn = connection(conn_options)
if conn.path_prefix != '/' && path.index(conn.path_prefix) != 0
path = (conn.path_prefix + path).gsub(/\/(\/)*/, '/')
end
response = conn.send(method) do |request|
case method.to_sym
when *(METHODS - METHODS_WITH_BODIES)
request.body = params.data if params.has_key?('data')
request.url(path, params.to_hash)
when *METHODS_WITH_BODIES
request.path = path
request.body = params.data unless params.empty?
end
end
ResponseWrapper.new(response, self)
end
|