Class: Github::Request
- Inherits:
-
Object
- Object
- Github::Request
- Includes:
- Connection
- Defined in:
- lib/github_api2/request.rb,
lib/github_api2/request/verbs.rb,
lib/github_api2/request/oauth2.rb,
lib/github_api2/request/basic_auth.rb
Overview
A class responsible for dispatching http requests
Defined Under Namespace
Modules: Verbs Classes: BasicAuth, Jsonize, OAuth2
Constant Summary collapse
- HTTP_METHODS =
[:get, :head, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[:post, :put, :patch]
Constants included from Connection
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::RATELIMIT_RESET, Constants::SERVER, Constants::USER_AGENT
Instance Attribute Summary collapse
-
#action ⇒ Symbol
readonly
Return http verb.
-
#api ⇒ Github::API
readonly
Return api this request is associated with.
-
#path ⇒ String
Return url.
Instance Method Summary collapse
-
#call(current_options, params) ⇒ Github::ResponseWrapper
private
Performs a request.
-
#initialize(action, path, api) ⇒ Github::Request
constructor
Create a new Request.
Methods included from Connection
#connection, #default_headers, #default_options, #stack
Constructor Details
#initialize(action, path, api) ⇒ Github::Request
Create a new Request
38 39 40 41 42 |
# File 'lib/github_api2/request.rb', line 38 def initialize(action, path, api) @action = action @path = path @api = api end |
Instance Attribute Details
#action ⇒ Symbol (readonly)
Return http verb
21 22 23 |
# File 'lib/github_api2/request.rb', line 21 def action @action end |
#api ⇒ Github::API (readonly)
Return api this request is associated with
31 32 33 |
# File 'lib/github_api2/request.rb', line 31 def api @api end |
#path ⇒ String
Return url
26 27 28 |
# File 'lib/github_api2/request.rb', line 26 def path @path end |
Instance Method Details
#call(current_options, params) ⇒ Github::ResponseWrapper
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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/github_api2/request.rb', line 52 def call(, params) unless HTTP_METHODS.include?(action) raise ArgumentError, "unknown http method: #{action}" end puts "EXECUTED: #{action} - #{path} with PARAMS: #{params.request_params}" if ENV['DEBUG'] = params. = .merge() conn = connection(api, ) 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, [:query] || {}) request.body = params.data unless params.empty? end end ResponseWrapper.new(response, api) end |