Module: Github::Request
- Included in:
- API
- Defined in:
- lib/github_api/request.rb,
lib/github_api/requestable.rb,
lib/github_api/request/oauth2.rb,
lib/github_api/request/basic_auth.rb
Overview
Defines HTTP verbs
Defined Under Namespace
Classes: BasicAuth, Jsonize, OAuth2
Constant Summary collapse
- METHODS =
[:get, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[ :post, :put, :patch ]
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
Performs a request.
Instance Method Details
#delete_request(path, params = {}, options = {}) ⇒ Object
28 29 30 |
# File 'lib/github_api/request.rb', line 28 def delete_request(path, params = ParamsHash.empty) request(:delete, path, params) end |
#get_request(path, params = {}, options = {}) ⇒ Object
12 13 14 |
# File 'lib/github_api/request.rb', line 12 def get_request(path, params = ParamsHash.empty) request(:get, path, params).auto_paginate end |
#patch_request(path, params = {}, options = {}) ⇒ Object
16 17 18 |
# File 'lib/github_api/request.rb', line 16 def patch_request(path, params = ParamsHash.empty) request(:patch, path, params) end |
#post_request(path, params = {}, options = {}) ⇒ Object
20 21 22 |
# File 'lib/github_api/request.rb', line 20 def post_request(path, params = ParamsHash.empty) request(:post, path, params) end |
#put_request(path, params = {}, options = {}) ⇒ Object
24 25 26 |
# File 'lib/github_api/request.rb', line 24 def put_request(path, params = ParamsHash.empty) request(:put, path, params) end |
#request(method, path, params, options) ⇒ Object
Performs a request
method - The Symbol the HTTP verb path - String relative URL to access params - ParamsHash to configure the request API
Returns a Github::ResponseWrapper
40 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/github_api/request.rb', line 40 def request(method, path, params) # :nodoc: unless METHODS.include?(method) raise ArgumentError, "unkown http method: #{method}" end puts "EXECUTED: #{method} - #{path} with PARAMS: #{params}" if ENV['DEBUG'] = params. = .merge() conn = connection() 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') if params.has_key?('encoder') request.params.params_encoder(params.encoder) end request.url(path, params.to_hash) when *METHODS_WITH_BODIES request.url(path, [:query] || {}) request.body = params.data unless params.empty? end end ResponseWrapper.new(response, self) end |