Class: BitBucket::Request
- Inherits:
-
Object
- Object
- BitBucket::Request
- Includes:
- Connection
- Defined in:
- lib/bitbucket_rest_api/request.rb,
lib/bitbucket_rest_api/request/oauth.rb,
lib/bitbucket_rest_api/request/verbs.rb,
lib/bitbucket_rest_api/request/basic_auth.rb
Overview
A class responsible for dispatching http requests
Defined Under Namespace
Modules: Verbs Classes: BasicAuth, Jsonize, OAuth
Constant Summary collapse
- HTTP_METHODS =
[:get, :post, :put, :delete, :patch]
- METHODS_WITH_BODIES =
[ :post, :put, :patch ]
Constants included from Connection
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::PARAM_PAGE, Constants::PARAM_START_PAGE, Constants::QUERY_STR_SEP, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT
Instance Attribute Summary collapse
-
#action ⇒ Symbol
readonly
Return http verb.
-
#api ⇒ BitBucket::API
readonly
Return api this request is associated with.
-
#path ⇒ String
Return url.
Instance Method Summary collapse
-
#call(current_options, params) ⇒ BitBucket::ResponseWrapper
private
Performs a request.
-
#initialize(action, path, api) ⇒ BitBucket::Request
constructor
Create a new Request.
Methods included from Connection
#caching?, #clear_cache, #connection, #default_options, #stack
Constructor Details
#initialize(action, path, api) ⇒ BitBucket::Request
Create a new Request
37 38 39 40 41 |
# File 'lib/bitbucket_rest_api/request.rb', line 37 def initialize(action, path, api) @action = action @path = path @api = api end |
Instance Attribute Details
#action ⇒ Symbol (readonly)
Return http verb
20 21 22 |
# File 'lib/bitbucket_rest_api/request.rb', line 20 def action @action end |
#api ⇒ BitBucket::API (readonly)
Return api this request is associated with
30 31 32 |
# File 'lib/bitbucket_rest_api/request.rb', line 30 def api @api end |
#path ⇒ String
Return url
25 26 27 |
# File 'lib/bitbucket_rest_api/request.rb', line 25 def path @path end |
Instance Method Details
#call(current_options, params) ⇒ BitBucket::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 |
# File 'lib/bitbucket_rest_api/request.rb', line 52 def call(, params) unless HTTP_METHODS.include?(action) raise ArgumentError, "unknown http method: #{method}" end puts "EXECUTED: #{action} - #{path} with PARAMS: #{params}" if ENV['DEBUG'] = params. = .merge() conn = connection(api, ) 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.has_key?('data') if params.has_key?('encoder') request.params.params_encoder(params.encoder) end request.url(self.path, params.to_hash) when *METHODS_WITH_BODIES request.url(self.path, [:query] || {}) request.body = extract_data_from_params(params) unless params.empty? end end ResponseWrapper.new(response, api) end |