bitbuckets 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/README.md +169 -0
- data/Rakefile +1 -0
- data/lib/bitbucket_rest_api.rb +86 -0
- data/lib/bitbucket_rest_api/api.rb +104 -0
- data/lib/bitbucket_rest_api/api/actions.rb +32 -0
- data/lib/bitbucket_rest_api/api_factory.rb +29 -0
- data/lib/bitbucket_rest_api/authorization.rb +31 -0
- data/lib/bitbucket_rest_api/client.rb +53 -0
- data/lib/bitbucket_rest_api/configuration.rb +103 -0
- data/lib/bitbucket_rest_api/connection.rb +97 -0
- data/lib/bitbucket_rest_api/constants.rb +57 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
- data/lib/bitbucket_rest_api/deprecation.rb +36 -0
- data/lib/bitbucket_rest_api/error.rb +37 -0
- data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
- data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
- data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
- data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
- data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
- data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
- data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
- data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
- data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
- data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
- data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
- data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
- data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
- data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
- data/lib/bitbucket_rest_api/error/validations.rb +17 -0
- data/lib/bitbucket_rest_api/invitations.rb +14 -0
- data/lib/bitbucket_rest_api/issues.rb +229 -0
- data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
- data/lib/bitbucket_rest_api/issues/components.rb +105 -0
- data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
- data/lib/bitbucket_rest_api/normalizer.rb +24 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
- data/lib/bitbucket_rest_api/repos.rb +276 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
- data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
- data/lib/bitbucket_rest_api/repos/components.rb +35 -0
- data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
- data/lib/bitbucket_rest_api/repos/download.rb +15 -0
- data/lib/bitbucket_rest_api/repos/following.rb +38 -0
- data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
- data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
- data/lib/bitbucket_rest_api/repos/services.rb +101 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
- data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
- data/lib/bitbucket_rest_api/request.rb +71 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
- data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
- data/lib/bitbucket_rest_api/response.rb +26 -0
- data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
- data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
- data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
- data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
- data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
- data/lib/bitbucket_rest_api/result.rb +136 -0
- data/lib/bitbucket_rest_api/teams.rb +91 -0
- data/lib/bitbucket_rest_api/user.rb +87 -0
- data/lib/bitbucket_rest_api/users.rb +20 -0
- data/lib/bitbucket_rest_api/users/account.rb +50 -0
- data/lib/bitbucket_rest_api/utils/url.rb +61 -0
- data/lib/bitbucket_rest_api/validations.rb +23 -0
- data/lib/bitbucket_rest_api/validations/format.rb +21 -0
- data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
- data/lib/bitbucket_rest_api/validations/required.rb +37 -0
- data/lib/bitbucket_rest_api/validations/token.rb +38 -0
- data/lib/bitbucket_rest_api/version.rb +10 -0
- data/lib/bitbuckets.rb +2 -0
- data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
- data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
- data/spec/bitbucket_rest_api/api_spec.rb +87 -0
- data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
- data/spec/bitbucket_rest_api/client_spec.rb +17 -0
- data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
- data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
- data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
- data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
- data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
- data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
- data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
- data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
- data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
- data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
- data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
- data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
- data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
- data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
- data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
- data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
- data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
- data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
- data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
- data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
- data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
- data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
- data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
- data/spec/bitbucket_rest_api/request_spec.rb +88 -0
- data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
- data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
- data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
- data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
- data/spec/bitbucket_rest_api/user_spec.rb +78 -0
- data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
- data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
- data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
- data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
- data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
- data/spec/bitbucket_rest_api_spec.rb +17 -0
- data/spec/spec_helper.rb +24 -0
- metadata +358 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module BitBucket
|
|
3
|
+
class Client < API
|
|
4
|
+
# This is a read-only API to the BitBucket events.
|
|
5
|
+
# These events power the various activity streams on the site.
|
|
6
|
+
def events(_options = {})
|
|
7
|
+
raise 'Unimplemented'
|
|
8
|
+
# @events ||= ApiFactory.new 'Events', options
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def issues(options = {})
|
|
12
|
+
@issues ||= ApiFactory.new 'Issues', options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# An API for users to manage their own tokens.
|
|
16
|
+
def oauth(options = {})
|
|
17
|
+
@oauth ||= ApiFactory.new 'Request::OAuth', options
|
|
18
|
+
end
|
|
19
|
+
alias authorizations oauth
|
|
20
|
+
|
|
21
|
+
def teams(options = {})
|
|
22
|
+
@teams ||= ApiFactory.new 'Teams', options
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def pull_requests(options = {})
|
|
26
|
+
@pull_requests ||= ApiFactory.new 'Repos::PullRequest', options
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def repos(options = {})
|
|
30
|
+
@repos ||= ApiFactory.new 'Repos', options
|
|
31
|
+
end
|
|
32
|
+
alias repositories repos
|
|
33
|
+
|
|
34
|
+
def search(_options = {})
|
|
35
|
+
raise 'Unimplemented'
|
|
36
|
+
# @search ||= ApiFactory.new 'Search', options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Many of the resources on the users API provide a shortcut for getting
|
|
40
|
+
# information about the currently authenticated user.
|
|
41
|
+
def users(options = {})
|
|
42
|
+
@users ||= ApiFactory.new 'Users', options
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def user_api(options = {})
|
|
46
|
+
@user_api ||= ApiFactory.new 'User', options
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def invitations(options = {})
|
|
50
|
+
@invitations ||= ApiFactory.new 'Invitations', options
|
|
51
|
+
end
|
|
52
|
+
end # Client
|
|
53
|
+
end # BitBucket
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module BitBucket
|
|
3
|
+
module Configuration
|
|
4
|
+
VALID_OPTIONS_KEYS = %i[
|
|
5
|
+
adapter
|
|
6
|
+
client_id
|
|
7
|
+
client_secret
|
|
8
|
+
new_access_token
|
|
9
|
+
oauth_token
|
|
10
|
+
oauth_secret
|
|
11
|
+
endpoint
|
|
12
|
+
mime_type
|
|
13
|
+
user_agent
|
|
14
|
+
connection_options
|
|
15
|
+
repo
|
|
16
|
+
user
|
|
17
|
+
login
|
|
18
|
+
password
|
|
19
|
+
basic_auth
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
# Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
|
|
23
|
+
DEFAULT_ADAPTER = :net_http
|
|
24
|
+
|
|
25
|
+
# By default, don't set an application key
|
|
26
|
+
DEFAULT_CLIENT_ID = nil
|
|
27
|
+
|
|
28
|
+
# By default, don't set an application secret
|
|
29
|
+
DEFAULT_CLIENT_SECRET = nil
|
|
30
|
+
|
|
31
|
+
# By default, don't set an access token
|
|
32
|
+
DEFAULT_ACCESS_TOKEN = nil
|
|
33
|
+
|
|
34
|
+
# By default, don't set a user oauth access token
|
|
35
|
+
DEFAULT_OAUTH_TOKEN = nil
|
|
36
|
+
|
|
37
|
+
# By default, don't set a user oauth access token secret
|
|
38
|
+
DEFAULT_OAUTH_SECRET = nil
|
|
39
|
+
|
|
40
|
+
# By default, don't set a user login name
|
|
41
|
+
DEFAULT_LOGIN = nil
|
|
42
|
+
|
|
43
|
+
# By default, don't set a user password
|
|
44
|
+
DEFAULT_PASSWORD = nil
|
|
45
|
+
|
|
46
|
+
# By default, don't set a user basic authentication
|
|
47
|
+
DEFAULT_BASIC_AUTH = nil
|
|
48
|
+
|
|
49
|
+
# The endpoint used to connect to BitBucket if none is set, in the event that BitBucket is ever available on location
|
|
50
|
+
DEFAULT_ENDPOINT = 'https://api.bitbucket.org'
|
|
51
|
+
|
|
52
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
|
53
|
+
DEFAULT_USER_AGENT = "BitBucket Ruby Gem #{BitBucket::VERSION::STRING}"
|
|
54
|
+
|
|
55
|
+
# By default the <tt>Accept</tt> header will make a request for <tt>JSON</tt>
|
|
56
|
+
DEFAULT_MIME_TYPE = :json
|
|
57
|
+
|
|
58
|
+
# By default uses the Faraday connection options if none is set
|
|
59
|
+
DEFAULT_CONNECTION_OPTIONS = {}.freeze
|
|
60
|
+
|
|
61
|
+
# By default, don't set user name
|
|
62
|
+
DEFAULT_USER = nil
|
|
63
|
+
|
|
64
|
+
# By default, don't set repository name
|
|
65
|
+
DEFAULT_REPO = nil
|
|
66
|
+
|
|
67
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
|
68
|
+
|
|
69
|
+
# Convenience method to allow for global setting of configuration options
|
|
70
|
+
def configure
|
|
71
|
+
yield self
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.extended(base)
|
|
75
|
+
base.set_defaults
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def options
|
|
79
|
+
options = {}
|
|
80
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
|
81
|
+
options
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def set_defaults
|
|
85
|
+
self.adapter = DEFAULT_ADAPTER
|
|
86
|
+
self.client_id = DEFAULT_CLIENT_ID
|
|
87
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
|
88
|
+
self.new_access_token = DEFAULT_ACCESS_TOKEN
|
|
89
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
|
90
|
+
self.oauth_secret = DEFAULT_OAUTH_SECRET
|
|
91
|
+
self.endpoint = DEFAULT_ENDPOINT
|
|
92
|
+
self.user_agent = DEFAULT_USER_AGENT
|
|
93
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
|
94
|
+
self.mime_type = DEFAULT_MIME_TYPE
|
|
95
|
+
self.user = DEFAULT_USER
|
|
96
|
+
self.repo = DEFAULT_REPO
|
|
97
|
+
self.login = DEFAULT_LOGIN
|
|
98
|
+
self.password = DEFAULT_PASSWORD
|
|
99
|
+
self.basic_auth = DEFAULT_BASIC_AUTH
|
|
100
|
+
self
|
|
101
|
+
end
|
|
102
|
+
end # Configuration
|
|
103
|
+
end # BitBucket
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'faraday'
|
|
3
|
+
require 'faraday_middleware'
|
|
4
|
+
require 'bitbucket_rest_api/response'
|
|
5
|
+
require 'bitbucket_rest_api/response/mashify'
|
|
6
|
+
require 'bitbucket_rest_api/response/jsonize'
|
|
7
|
+
require 'bitbucket_rest_api/response/helpers'
|
|
8
|
+
require 'bitbucket_rest_api/response/raise_error'
|
|
9
|
+
require 'bitbucket_rest_api/request/oauth'
|
|
10
|
+
require 'bitbucket_rest_api/request/basic_auth'
|
|
11
|
+
require 'bitbucket_rest_api/request/jsonize'
|
|
12
|
+
|
|
13
|
+
module BitBucket
|
|
14
|
+
module Connection
|
|
15
|
+
module_function
|
|
16
|
+
|
|
17
|
+
include BitBucket::Constants
|
|
18
|
+
|
|
19
|
+
ALLOWED_OPTIONS = %i[
|
|
20
|
+
headers
|
|
21
|
+
url
|
|
22
|
+
params
|
|
23
|
+
request
|
|
24
|
+
ssl
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
def default_options(options = {})
|
|
28
|
+
{
|
|
29
|
+
headers: {
|
|
30
|
+
USER_AGENT => user_agent
|
|
31
|
+
},
|
|
32
|
+
ssl: { verify: false },
|
|
33
|
+
url: options.fetch(:endpoint) { BitBucket.endpoint }
|
|
34
|
+
}.merge(options)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Default middleware stack that uses default adapter as specified at
|
|
38
|
+
# configuration stage.
|
|
39
|
+
#
|
|
40
|
+
def default_middleware(options = {})
|
|
41
|
+
proc do |builder|
|
|
42
|
+
# builder.use BitBucket::Request::Jsonize
|
|
43
|
+
builder.use Faraday::Request::Multipart
|
|
44
|
+
builder.use Faraday::Request::UrlEncoded
|
|
45
|
+
builder.use FaradayMiddleware::OAuth, consumer_key: client_id, consumer_secret: client_secret, token: oauth_token, token_secret: oauth_secret if client_id? && client_secret?
|
|
46
|
+
builder.use BitBucket::Request::BasicAuth, authentication if basic_authed?
|
|
47
|
+
builder.use FaradayMiddleware::EncodeJson
|
|
48
|
+
|
|
49
|
+
builder.use Faraday::Response::Logger if ENV['DEBUG']
|
|
50
|
+
builder.use BitBucket::Response::Helpers
|
|
51
|
+
unless options[:raw]
|
|
52
|
+
builder.use BitBucket::Response::Mashify
|
|
53
|
+
builder.use BitBucket::Response::Jsonize
|
|
54
|
+
end
|
|
55
|
+
builder.use BitBucket::Response::RaiseError
|
|
56
|
+
builder.adapter adapter
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@connection = nil
|
|
61
|
+
|
|
62
|
+
@stack = nil
|
|
63
|
+
|
|
64
|
+
def clear_cache
|
|
65
|
+
@connection = nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def caching?
|
|
69
|
+
!@connection.nil?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Exposes middleware builder to facilitate custom stacks and easy
|
|
73
|
+
# addition of new extensions such as cache adapter.
|
|
74
|
+
#
|
|
75
|
+
def stack(options = {}, &block)
|
|
76
|
+
@stack ||= begin
|
|
77
|
+
if block_given?
|
|
78
|
+
Faraday::RackBuilder.new(&block)
|
|
79
|
+
else
|
|
80
|
+
Faraday::RackBuilder.new(&default_middleware(options))
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Returns a Fraday::Connection object
|
|
86
|
+
#
|
|
87
|
+
def connection(options = {})
|
|
88
|
+
conn_options = default_options(options)
|
|
89
|
+
clear_cache unless options.empty?
|
|
90
|
+
puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
|
|
91
|
+
|
|
92
|
+
@connection ||= Faraday.new(conn_options.merge(builder: stack(options))) do |faraday|
|
|
93
|
+
faraday.response :logger if ENV['DEBUG']
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end # Connection
|
|
97
|
+
end # BitBucket
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module BitBucket
|
|
3
|
+
module Constants
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
# Response headers
|
|
7
|
+
RATELIMIT_REMAINING = 'X-RateLimit-Remaining'
|
|
8
|
+
|
|
9
|
+
RATELIMIT_LIMIT = 'X-RateLimit-Limit'
|
|
10
|
+
|
|
11
|
+
CONTENT_TYPE = 'Content-Type'
|
|
12
|
+
|
|
13
|
+
CONTENT_LENGTH = 'content-length'
|
|
14
|
+
|
|
15
|
+
CACHE_CONTROL = 'cache-control'
|
|
16
|
+
|
|
17
|
+
ETAG = 'ETag'
|
|
18
|
+
|
|
19
|
+
SERVER = 'Server'
|
|
20
|
+
|
|
21
|
+
DATE = 'Date'
|
|
22
|
+
|
|
23
|
+
LOCATION = 'Location'
|
|
24
|
+
|
|
25
|
+
USER_AGENT = 'User-Agent'
|
|
26
|
+
|
|
27
|
+
ACCEPT = 'Accept'
|
|
28
|
+
|
|
29
|
+
ACCEPT_CHARSET = 'Accept-Charset'
|
|
30
|
+
|
|
31
|
+
# Link headers
|
|
32
|
+
HEADER_LINK = 'Link'
|
|
33
|
+
|
|
34
|
+
HEADER_NEXT = 'X-Next'
|
|
35
|
+
|
|
36
|
+
HEADER_LAST = 'X-Last'
|
|
37
|
+
|
|
38
|
+
META_REL = 'rel'
|
|
39
|
+
|
|
40
|
+
META_LAST = 'last'
|
|
41
|
+
|
|
42
|
+
META_NEXT = 'next'
|
|
43
|
+
|
|
44
|
+
META_FIRST = 'first'
|
|
45
|
+
|
|
46
|
+
META_PREV = 'prev'
|
|
47
|
+
|
|
48
|
+
PARAM_PAGE = 'page'
|
|
49
|
+
|
|
50
|
+
PARAM_PER_PAGE = 'per_page'
|
|
51
|
+
|
|
52
|
+
PARAM_START_PAGE = 'start_page'
|
|
53
|
+
|
|
54
|
+
# URI parsing
|
|
55
|
+
QUERY_STR_SEP = '?'
|
|
56
|
+
end # Constants
|
|
57
|
+
end # BitBucket
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
class Hash # :nodoc:
|
|
3
|
+
unless method_defined?(:symbolize_keys)
|
|
4
|
+
def symbolize_keys # :nodoc:
|
|
5
|
+
each_with_object({}) do |(key, value), hash|
|
|
6
|
+
hash[(begin
|
|
7
|
+
key.to_sym
|
|
8
|
+
rescue StandardError
|
|
9
|
+
key
|
|
10
|
+
end) || key] = value
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
unless method_defined?(:symbolize_keys!)
|
|
16
|
+
def symbolize_keys! # :nodoc:
|
|
17
|
+
hash = symbolize_keys
|
|
18
|
+
hash.each do |key, val|
|
|
19
|
+
hash[key] = case val
|
|
20
|
+
when Hash
|
|
21
|
+
val.symbolize_keys!
|
|
22
|
+
when Array
|
|
23
|
+
val.map do |item|
|
|
24
|
+
item.is_a?(Hash) ? item.symbolize_keys! : item
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
val
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
hash
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
unless method_defined?(:serialize)
|
|
35
|
+
def serialize # :nodoc:
|
|
36
|
+
map { |key, val| [key, val].join('=') }.join('&')
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
unless method_defined?(:all_keys)
|
|
41
|
+
def all_keys # :nodoc:
|
|
42
|
+
keys = self.keys
|
|
43
|
+
keys.each do |key|
|
|
44
|
+
if self[key].is_a?(Hash)
|
|
45
|
+
keys << self[key].all_keys.compact.flatten
|
|
46
|
+
next
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
keys.flatten
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
unless method_defined?(:has_deep_key?)
|
|
54
|
+
def has_deep_key?(key)
|
|
55
|
+
all_keys.include? key
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end # Hash
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module BitBucket
|
|
3
|
+
DEPRECATION_PREFIX = '[BitBucketAPI] Deprecation warning:'
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
attr_writer :deprecation_tracker
|
|
7
|
+
|
|
8
|
+
def deprecation_tracker
|
|
9
|
+
@deprecation_tracker ||= []
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Displays deprecation message to the user.
|
|
13
|
+
# Each message is printed once.
|
|
14
|
+
def deprecate(method, alternate_method = nil)
|
|
15
|
+
return if deprecation_tracker.include? method
|
|
16
|
+
|
|
17
|
+
deprecation_tracker << method
|
|
18
|
+
|
|
19
|
+
message = <<~NOTICE
|
|
20
|
+
#{DEPRECATION_PREFIX}
|
|
21
|
+
|
|
22
|
+
* #{method} is deprecated.
|
|
23
|
+
NOTICE
|
|
24
|
+
if alternate_method
|
|
25
|
+
message << <<~ADDITIONAL
|
|
26
|
+
* please use #{alternate_method} instead.
|
|
27
|
+
ADDITIONAL
|
|
28
|
+
end
|
|
29
|
+
warn_deprecation(message)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def warn_deprecation(message)
|
|
33
|
+
send :warn, message
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end # BitBucket
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module BitBucket
|
|
3
|
+
module Error
|
|
4
|
+
class BitBucketError < StandardError
|
|
5
|
+
attr_reader :response_message, :response_headers
|
|
6
|
+
|
|
7
|
+
def initialize(message)
|
|
8
|
+
super message
|
|
9
|
+
@response_message = message
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# def inspect
|
|
13
|
+
# %(#<#{self.class}>)
|
|
14
|
+
# end
|
|
15
|
+
end
|
|
16
|
+
end # Error
|
|
17
|
+
end # BitBucket
|
|
18
|
+
|
|
19
|
+
%w[
|
|
20
|
+
service_error
|
|
21
|
+
not_found
|
|
22
|
+
forbidden
|
|
23
|
+
bad_request
|
|
24
|
+
unauthorized
|
|
25
|
+
service_unavailable
|
|
26
|
+
internal_server_error
|
|
27
|
+
unprocessable_entity
|
|
28
|
+
client_error
|
|
29
|
+
invalid_options
|
|
30
|
+
required_params
|
|
31
|
+
unknown_value
|
|
32
|
+
bad_events
|
|
33
|
+
no_events
|
|
34
|
+
blank_value
|
|
35
|
+
].each do |error|
|
|
36
|
+
require "bitbucket_rest_api/error/#{error}"
|
|
37
|
+
end
|