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

Defines HTTP verbs

Defined Under Namespace

Classes: BasicAuth, Jsonize, OAuth2

Constant Summary

HTTP_METHODS =
[:get, :head, :post, :put, :delete, :patch]
METHODS_WITH_BODIES =
[:post, :put, :patch]

Instance Method Summary (collapse)

Instance Method Details

- (Object) delete_request(path, params = ParamsHash.empty)



28
29
30
# File 'lib/github_api/request.rb', line 28

def delete_request(path, params = ParamsHash.empty)
  request(:delete, path, params)
end

- (Object) get_request(path, params = ParamsHash.empty)



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

- (Object) patch_request(path, params = ParamsHash.empty)



16
17
18
# File 'lib/github_api/request.rb', line 16

def patch_request(path, params = ParamsHash.empty)
  request(:patch, path, params)
end

- (Object) post_request(path, params = ParamsHash.empty)



20
21
22
# File 'lib/github_api/request.rb', line 20

def post_request(path, params = ParamsHash.empty)
  request(:post, path, params)
end

- (Object) put_request(path, params = ParamsHash.empty)



24
25
26
# File 'lib/github_api/request.rb', line 24

def put_request(path, params = ParamsHash.empty)
  request(:put, path, params)
end

- (Github::ResponseWrapper) request(method, path, params)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs a request

Parameters:

  • method (Symbol)
    • The Symbol the HTTP verb

  • path (String)
    • String relative URL to access

  • params (ParamsHash)
    • ParamsHash to configure the request API

Returns:



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
70
# File 'lib/github_api/request.rb', line 41

def request(method, path, params) # :nodoc:
  unless HTTP_METHODS.include?(method)
    raise ArgumentError, "unknown http method: #{method}"
  end

  puts "EXECUTED: #{method} - #{path} with PARAMS: #{params}" if ENV['DEBUG']

  request_options    = params.options
  connection_options = current_options.merge(request_options)
  conn               = connection(connection_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 *(HTTP_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, connection_options[:query] || {})
      request.body = params.data unless params.empty?
    end
  end
  ResponseWrapper.new(response, self)
end