Class: BitbucketServer::Connection
- Inherits:
-
Object
- Object
- BitbucketServer::Connection
- Includes:
- ActionView::Helpers::SanitizeHelper, RetryWithDelay
- Defined in:
- lib/bitbucket_server/connection.rb
Constant Summary collapse
- DEFAULT_API_VERSION =
'1.0'
- SEPARATOR =
'/'
- NETWORK_ERRORS =
[ SocketError, OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Net::OpenTimeout, Net::ReadTimeout, URI::InvalidURIError, Gitlab::HTTP::BlockedUrlError ].freeze
- ConnectionError =
Class.new(StandardError)
Constants included from RetryWithDelay
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#delete(resource, path, body) ⇒ Object
We need to support two different APIs for deletion:.
- #get(path, extra_query = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, body) ⇒ Object
Methods included from RetryWithDelay
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
27 28 29 30 31 32 |
# File 'lib/bitbucket_server/connection.rb', line 27 def initialize( = {}) @api_version = .fetch(:api_version, DEFAULT_API_VERSION) @base_uri = [:base_uri] @username = [:user] @token = [:password] end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
23 24 25 |
# File 'lib/bitbucket_server/connection.rb', line 23 def api_version @api_version end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
23 24 25 |
# File 'lib/bitbucket_server/connection.rb', line 23 def base_uri @base_uri end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
23 24 25 |
# File 'lib/bitbucket_server/connection.rb', line 23 def token @token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
23 24 25 |
# File 'lib/bitbucket_server/connection.rb', line 23 def username @username end |
Instance Method Details
#delete(resource, path, body) ⇒ Object
We need to support two different APIs for deletion:
/rest/api/1.0/projects/projectKey/repos/repositorySlug/branches/default /rest/branch-utils/1.0/projects/projectKey/repos/repositorySlug/branches
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bitbucket_server/connection.rb', line 62 def delete(resource, path, body) url = delete_url(resource, path) response = retry_with_delay do Gitlab::HTTP.delete(url, basic_auth: auth, headers: post_headers, body: body) end check_errors!(response) response.parsed_response rescue *NETWORK_ERRORS => e raise ConnectionError, e end |
#get(path, extra_query = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bitbucket_server/connection.rb', line 34 def get(path, extra_query = {}) response = retry_with_delay do Gitlab::HTTP.get(build_url(path), basic_auth: auth, headers: accept_headers, query: extra_query) end check_errors!(response) response.parsed_response rescue *NETWORK_ERRORS => e raise ConnectionError, e end |
#post(path, body) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bitbucket_server/connection.rb', line 46 def post(path, body) response = retry_with_delay do Gitlab::HTTP.post(build_url(path), basic_auth: auth, headers: post_headers, body: body) end check_errors!(response) response.parsed_response rescue *NETWORK_ERRORS => e raise ConnectionError, e end |