class Github::Request
A class responsible for dispatching http requests
A class responsible for dispatching http requests
Defines HTTP verbs
Constants
- HTTP_METHODS
- METHODS
- METHODS_WITH_BODIES
Attributes
action[R]
Return http verb
@return [Symbol]
api[R]
Return api this request is associated with
@return [Github::API]
path[RW]
Return url
@return [String]
Public Class Methods
new(action, path, api)
click to toggle source
Create a new Request
@return [Github::Request]
@api public
# File lib/github_api/request.rb, line 37 def initialize(action, path, api) @action = action @path = path @api = api end
Public Instance Methods
call(current_options, params)
click to toggle source
Performs a request
@param [Symbol] method - The Symbol the HTTP verb @param [String] path - String relative URL to access @param [ParamsHash] params - ParamsHash to configure the request API
@return [Github::ResponseWrapper]
@api private
# File lib/github_api/request.rb, line 52 def call(current_options, params) unless HTTP_METHODS.include?(action) raise ArgumentError, "unknown http method: #{method}" end puts "EXECUTED: #{action} - #{path} with PARAMS: #{params}" if ENV['DEBUG'] request_options = params.options connection_options = current_options.merge(request_options) conn = connection(api, connection_options) self.path = Utils::Url.normalize(self.path) if conn.path_prefix != '/' && self.path.index(conn.path_prefix) != 0 self.path = (conn.path_prefix + self.path).gsub(/\/(\/)*/, '/') end response = conn.send(action) do |request| case action.to_sym when *(HTTP_METHODS - METHODS_WITH_BODIES) request.body = params.data if params.key?('data') if params.key?('encoder') request.params.params_encoder(params.encoder) end request.url(self.path, params.request_params) when *METHODS_WITH_BODIES request.url(self.path, connection_options[:query] || {}) request.body = params.data unless params.empty? end end ResponseWrapper.new(response, api) end
delete_request(path, params={}, options={})
click to toggle source
# File lib/github_api/requestable.rb, line 25 def delete_request(path, params={}, options={}) request(:delete, path, params, options) end
get_request(path, params={}, options={})
click to toggle source
# File lib/github_api/requestable.rb, line 9 def get_request(path, params={}, options={}) request(:get, path, params, options) end
patch_request(path, params={}, options={})
click to toggle source
# File lib/github_api/requestable.rb, line 13 def patch_request(path, params={}, options={}) request(:patch, path, params, options) end
post_request(path, params={}, options={})
click to toggle source
# File lib/github_api/requestable.rb, line 17 def post_request(path, params={}, options={}) request(:post, path, params, options) end
put_request(path, params={}, options={})
click to toggle source
# File lib/github_api/requestable.rb, line 21 def put_request(path, params={}, options={}) request(:put, path, params, options) end
request(method, path, params, options)
click to toggle source
# File lib/github_api/requestable.rb, line 29 def request(method, path, params, options) if !METHODS.include?(method) raise ArgumentError, "unkown http method: #{method}" end # _extract_mime_type(params, options) puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG'] conn = connection(options) path = (conn.path_prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/' response = conn.send(method) do |request| 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 = extract_data_from_params(params) unless params.empty? end end response.body end