reenhanced_bitbucket_api 0.1.6 → 0.3.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 +4 -4
- data/lib/bitbucket_rest_api/api/arguments.rb +248 -0
- data/lib/bitbucket_rest_api/api/config/property.rb +30 -0
- data/lib/bitbucket_rest_api/api/config/property_set.rb +118 -0
- data/lib/bitbucket_rest_api/api/config.rb +107 -0
- data/lib/bitbucket_rest_api/api/factory.rb +29 -0
- data/lib/bitbucket_rest_api/api.rb +155 -33
- data/lib/bitbucket_rest_api/{invitations.rb → client/invitations.rb} +4 -3
- data/lib/bitbucket_rest_api/{issues → client/issues}/comments.rb +2 -11
- data/lib/bitbucket_rest_api/{issues → client/issues}/components.rb +3 -6
- data/lib/bitbucket_rest_api/{issues → client/issues}/milestones.rb +3 -7
- data/lib/bitbucket_rest_api/{issues.rb → client/issues.rb} +9 -25
- data/lib/bitbucket_rest_api/{repos → client/repos}/changesets.rb +3 -2
- data/lib/bitbucket_rest_api/{repos → client/repos}/following.rb +2 -1
- data/lib/bitbucket_rest_api/{repos → client/repos}/keys.rb +2 -1
- data/lib/bitbucket_rest_api/client/repos/pull_requests/activity.rb +22 -0
- data/lib/bitbucket_rest_api/client/repos/pull_requests/comments.rb +40 -0
- data/lib/bitbucket_rest_api/client/repos/pull_requests/commits.rb +24 -0
- data/lib/bitbucket_rest_api/client/repos/pull_requests.rb +205 -0
- data/lib/bitbucket_rest_api/{repos → client/repos}/services.rb +2 -1
- data/lib/bitbucket_rest_api/{repos → client/repos}/sources.rb +2 -1
- data/lib/bitbucket_rest_api/{repos.rb → client/repos.rb} +26 -40
- data/lib/bitbucket_rest_api/{user.rb → client/user.rb} +2 -7
- data/lib/bitbucket_rest_api/{users → client/users}/account.rb +2 -1
- data/lib/bitbucket_rest_api/client/users.rb +14 -0
- data/lib/bitbucket_rest_api/client.rb +28 -32
- data/lib/bitbucket_rest_api/configuration.rb +24 -67
- data/lib/bitbucket_rest_api/connection.rb +15 -50
- data/lib/bitbucket_rest_api/constants.rb +1 -9
- data/lib/bitbucket_rest_api/core_ext/array.rb +1 -1
- data/lib/bitbucket_rest_api/error/invalid_options.rb +1 -1
- data/lib/bitbucket_rest_api/error/required_params.rb +1 -1
- data/lib/bitbucket_rest_api/error/unknown_value.rb +1 -1
- data/lib/bitbucket_rest_api/ext/faraday.rb +38 -0
- data/lib/bitbucket_rest_api/middleware.rb +31 -0
- data/lib/bitbucket_rest_api/null_encoder.rb +25 -0
- data/lib/bitbucket_rest_api/page_iterator.rb +90 -0
- data/lib/bitbucket_rest_api/page_links.rb +33 -0
- data/lib/bitbucket_rest_api/paged_request.rb +29 -0
- data/lib/bitbucket_rest_api/pagination.rb +98 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +1 -1
- data/lib/bitbucket_rest_api/params_hash.rb +100 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +4 -2
- data/lib/bitbucket_rest_api/request/jsonize.rb +5 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +3 -3
- data/lib/bitbucket_rest_api/request/verbs.rb +53 -0
- data/lib/bitbucket_rest_api/request.rb +60 -36
- data/lib/bitbucket_rest_api/response/header.rb +68 -0
- data/lib/bitbucket_rest_api/response_wrapper.rb +157 -0
- data/lib/bitbucket_rest_api/result.rb +5 -77
- data/lib/bitbucket_rest_api/users.rb +4 -8
- data/lib/bitbucket_rest_api/validations/presence.rb +16 -11
- data/lib/bitbucket_rest_api/validations.rb +6 -6
- data/lib/bitbucket_rest_api/version.rb +2 -2
- data/lib/bitbucket_rest_api.rb +89 -44
- metadata +39 -131
- data/lib/bitbucket_rest_api/api_factory.rb +0 -30
@@ -0,0 +1,205 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BitBucket
|
4
|
+
class Client::Repos::PullRequests < API
|
5
|
+
|
6
|
+
# Load all the modules after initializing Repos to avoid superclass mismatch
|
7
|
+
require_all 'bitbucket_rest_api/client/repos/pull_requests',
|
8
|
+
'comments',
|
9
|
+
'commits',
|
10
|
+
'activity'
|
11
|
+
|
12
|
+
VALID_PULL_REQUEST_PARAM_NAMES = %w[
|
13
|
+
title
|
14
|
+
description
|
15
|
+
source
|
16
|
+
destination
|
17
|
+
reviewers
|
18
|
+
close_source_branch
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
VALID_PULL_REQUEST_STATE_VALUES = {
|
22
|
+
state: ['OPEN', 'MERGED', 'DECLINED']
|
23
|
+
}
|
24
|
+
|
25
|
+
@version = '2.0'
|
26
|
+
|
27
|
+
# Access to Client::Repos::PullRequests::Comments API
|
28
|
+
namespace :comments
|
29
|
+
namespace :commits
|
30
|
+
|
31
|
+
# List pull requests for a repository
|
32
|
+
#
|
33
|
+
# = Inputs
|
34
|
+
# <tt>:state</tt> - Optional - State of the pull request (OPEN, MERGED, DECLINED)
|
35
|
+
#
|
36
|
+
def list(*args)
|
37
|
+
args = { user: self.user, repo: self.repo.downcase, state: 'OPEN'}.merge(Hash[*args])
|
38
|
+
#_update_user_repo_params(user_name, repo_name)
|
39
|
+
#_validate_user_repo_params(user, repo) unless user? && repo?
|
40
|
+
params = arguments([args], required: [:user, :repo]) do
|
41
|
+
assert_values VALID_PULL_REQUEST_STATE_VALUES
|
42
|
+
end.params
|
43
|
+
|
44
|
+
# Bitbucket requires the state to be all caps or it returns all
|
45
|
+
params['state'] = params['state'].upcase
|
46
|
+
|
47
|
+
response = get_request("/repositories/#{args[:user]}/#{args[:repo]}/pullrequests", params)
|
48
|
+
|
49
|
+
return response unless block_given?
|
50
|
+
response.each { |el| yield el }
|
51
|
+
end
|
52
|
+
alias :all :list
|
53
|
+
|
54
|
+
# Get a single pull request
|
55
|
+
#
|
56
|
+
# = Examples
|
57
|
+
# bitbucket = BitBucket.new
|
58
|
+
# bitbucket.repos.pull_requests.find 'user-name', 'repo-name', 'pull-request-id'
|
59
|
+
#
|
60
|
+
def get(user_name, repo_name, pull_request_id, params={ })
|
61
|
+
_update_user_repo_params(user_name, repo_name)
|
62
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
63
|
+
_validate_presence_of pull_request_id
|
64
|
+
|
65
|
+
normalize! params
|
66
|
+
|
67
|
+
get_request("/repositories/#{user}/#{repo.downcase}/pullrequests/#{pull_request_id}", params)
|
68
|
+
end
|
69
|
+
|
70
|
+
alias :find :get
|
71
|
+
|
72
|
+
# Create a pull request
|
73
|
+
#
|
74
|
+
# = Inputs
|
75
|
+
# <tt>:title</tt> - Required string
|
76
|
+
# <tt>:description</tt> - Optional string
|
77
|
+
# <tt>:source</tt> - Required hash - The source branch name and/or repository (for example, { develop)
|
78
|
+
# * <tt>{ "branch": { "name": "REQUIRED branch_name" }, "repository": { "full_name": "owner/repo_slug" } }</tt>
|
79
|
+
# <tt>:destination</tt> - Optional hash - The destination branch or commit
|
80
|
+
# * <tt>{ "branch": { "name": "branch_name" }, "commit": { "hash": "name" } }</tt>
|
81
|
+
# <tt>:reviewers</tt> - Optional array - Users currently reviewiing the pull
|
82
|
+
# * <tt>[{ "username": "accountname" }]</tt>
|
83
|
+
#
|
84
|
+
# = Examples
|
85
|
+
# bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
|
86
|
+
# bitbucket.repos.pull_requests.create
|
87
|
+
# "title" => "Fixes a bug",
|
88
|
+
# "description" => "Fixes not being able to see anything.",
|
89
|
+
# "source" => { "branch" => { "name" => "bug-fixes" } },
|
90
|
+
# "destination" => { "branch" => { "name" => "master" } },
|
91
|
+
# "reviewers" => [ { "username" => "octocat" } ],
|
92
|
+
# "close_source_branch" => true
|
93
|
+
#
|
94
|
+
def create(user_name, repo_name, params={})
|
95
|
+
_update_user_repo_params(user_name, repo_name)
|
96
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
97
|
+
|
98
|
+
normalize! params
|
99
|
+
filter! VALID_PULL_REQUEST_PARAM_NAMES , params
|
100
|
+
assert_required_keys(%w[ title source ], params)
|
101
|
+
|
102
|
+
post_request("/repositories/#{user}/#{repo.downcase}/pullrequests/", params)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Edit a pull request
|
106
|
+
#
|
107
|
+
# = Inputs
|
108
|
+
# <tt>:title</tt> - Required string
|
109
|
+
# <tt>:description</tt> - Optional string
|
110
|
+
# <tt>:destination</tt> - Optional hash - The destination branch or commit
|
111
|
+
# * <tt>{ "branch": { "name": "branch_name" }, "commit": { "hash": "name" } }</tt>
|
112
|
+
# <tt>:reviewers</tt> - Optional array - Users currently reviewiing the pull
|
113
|
+
# * <tt>[{ "username": "accountname" }]</tt>
|
114
|
+
#
|
115
|
+
# = Examples
|
116
|
+
# bitbucket = BitBucket.new
|
117
|
+
# bitbucket.repos.pull_requests.update 'user-name', 'repo-name', 'pull-request-id',
|
118
|
+
# "title" => "Fixes a bug",
|
119
|
+
# "description" => "Fixes not being able to see anything.",
|
120
|
+
# "destination" => { "branch" => { "name" => "master" } },
|
121
|
+
# "reviewers" => [ { "username" => "octocat" } ],
|
122
|
+
# "close_source_branch" => true
|
123
|
+
#
|
124
|
+
def update(user_name, repo_name, pull_request_id, params={})
|
125
|
+
_update_user_repo_params(user_name, repo_name)
|
126
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
127
|
+
_validate_presence_of pull_request_id
|
128
|
+
|
129
|
+
# BitBucket will drop any data if it is not included, so we have to check for pre-existing data
|
130
|
+
existing_pull = get(user_name, repo_name, pull_request_id)
|
131
|
+
existing_pull_data = {
|
132
|
+
'title' => existing_pull.title,
|
133
|
+
'description' => existing_pull.description,
|
134
|
+
'destination' => {
|
135
|
+
'branch' => existing_pull.destination.branch
|
136
|
+
},
|
137
|
+
'reviewers' => existing_pull.reviewers,
|
138
|
+
'close_source_branch' => existing_pull.close_source_branch
|
139
|
+
}
|
140
|
+
params = normalize!(existing_pull_data).merge!(normalize!(params))
|
141
|
+
|
142
|
+
filter! VALID_PULL_REQUEST_PARAM_NAMES.reject{|param| param == 'source'}, params
|
143
|
+
assert_required_keys(%w[ title ], params)
|
144
|
+
|
145
|
+
put_request("/repositories/#{user}/#{repo.downcase}/pullrequests/#{pull_request_id}/", params)
|
146
|
+
end
|
147
|
+
alias :edit :update
|
148
|
+
|
149
|
+
# Decline or reject a single pull request
|
150
|
+
#
|
151
|
+
# = Examples
|
152
|
+
# bitbucket = BitBucket.new
|
153
|
+
# bitbucket.repos.pull_requests.reject 'user-name', 'repo-name', 'pull-request-id'
|
154
|
+
#
|
155
|
+
def decline(user_name, repo_name, pull_request_id)
|
156
|
+
_update_user_repo_params(user_name, repo_name)
|
157
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
158
|
+
_validate_presence_of pull_request_id
|
159
|
+
|
160
|
+
post_request("/repositories/#{user}/#{repo}/pullrequests/#{pull_request_id}/decline")
|
161
|
+
end
|
162
|
+
alias :reject :decline
|
163
|
+
|
164
|
+
# Give approval on a pull request
|
165
|
+
#
|
166
|
+
# = Examples
|
167
|
+
# bitbucket = BitBucket.new
|
168
|
+
# bitbucket.repos.pull_requests.approve 'user-name', 'repo-name', 'pull-request-id'
|
169
|
+
#
|
170
|
+
def approve(user_name, repo_name, pull_request_id)
|
171
|
+
_update_user_repo_params(user_name, repo_name)
|
172
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
173
|
+
_validate_presence_of pull_request_id
|
174
|
+
|
175
|
+
post_request("/repositories/#{user}/#{repo}/pullrequests/#{pull_request_id}/approve")
|
176
|
+
end
|
177
|
+
|
178
|
+
# Get the diff for a pull request
|
179
|
+
#
|
180
|
+
# = Examples
|
181
|
+
# bitbucket = BitBucket.new
|
182
|
+
# bitbucket.repos.pull_requests.diff 'user-name', 'repo-name', 'pull-request-id'
|
183
|
+
#
|
184
|
+
def diff(user_name, repo_name, pull_request_id)
|
185
|
+
_update_user_repo_params(user_name, repo_name)
|
186
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
187
|
+
_validate_presence_of pull_request_id
|
188
|
+
|
189
|
+
get_request("/repositories/#{user}/#{repo}/pullrequests/#{pull_request_id}/diff")
|
190
|
+
end
|
191
|
+
|
192
|
+
# Get a log of all activity for a pull request
|
193
|
+
#
|
194
|
+
# = Examples
|
195
|
+
# bitbucket = BitBucket.new
|
196
|
+
# bitbucket.repos.pull_requests.activity 'user-name', 'repo-name'
|
197
|
+
#
|
198
|
+
def activity(user_name, repo_name)
|
199
|
+
_update_user_repo_params(user_name, repo_name)
|
200
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
201
|
+
|
202
|
+
get_request("/repositories/#{user}/#{repo}/pullrequests/activity")
|
203
|
+
end
|
204
|
+
end # Repos::PullRequests
|
205
|
+
end # BitBucket
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module BitBucket
|
4
|
-
class Repos < API
|
5
|
-
extend AutoloadHelper
|
4
|
+
class Client::Repos < API
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
require_all 'bitbucket_rest_api/client/repos',
|
7
|
+
'changesets',
|
8
|
+
'keys',
|
9
|
+
'services',
|
10
|
+
'following',
|
11
|
+
'sources',
|
12
|
+
'pull_requests'
|
13
|
+
|
14
|
+
@version = '1.0'
|
14
15
|
|
15
16
|
DEFAULT_REPO_OPTIONS = {
|
16
17
|
"website" => "",
|
@@ -34,35 +35,23 @@ module BitBucket
|
|
34
35
|
scm
|
35
36
|
].freeze
|
36
37
|
|
37
|
-
# Creates new Repositories API
|
38
|
-
def initialize(options = { })
|
39
|
-
super(options)
|
40
|
-
end
|
41
|
-
|
42
38
|
# Access to Repos::Commits API
|
43
|
-
|
44
|
-
@changesets ||= ApiFactory.new 'Repos::Changesets'
|
45
|
-
end
|
39
|
+
namespace :changesets
|
46
40
|
|
47
41
|
# Access to Repos::Keys API
|
48
|
-
|
49
|
-
@keys ||= ApiFactory.new 'Repos::Keys'
|
50
|
-
end
|
42
|
+
namespace :keys
|
51
43
|
|
52
44
|
# Access to Repos::Watchin API
|
53
|
-
|
54
|
-
@following ||= ApiFactory.new 'Repos::Following'
|
55
|
-
end
|
45
|
+
namespace :following
|
56
46
|
|
57
47
|
# Access to Repos::Commits API
|
58
|
-
|
59
|
-
@sources ||= ApiFactory.new 'Repos::Sources'
|
60
|
-
end
|
48
|
+
namespace :sources
|
61
49
|
|
62
50
|
# Access to Repos::Services API
|
63
|
-
|
64
|
-
|
65
|
-
|
51
|
+
namespace :services
|
52
|
+
|
53
|
+
# Access to Repos::PullRequests API
|
54
|
+
namespace :pull_requests
|
66
55
|
|
67
56
|
# List branches
|
68
57
|
#
|
@@ -196,17 +185,14 @@ module BitBucket
|
|
196
185
|
# bitbucket.repos.list :user => 'user-name'
|
197
186
|
# bitbucket.repos.list :user => 'user-name', { |repo| ... }
|
198
187
|
def list(*args)
|
199
|
-
params
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
# For authenticated user
|
208
|
-
get_request("/user/repositories", params)
|
209
|
-
#end
|
188
|
+
#_merge_user_into_params!(params) unless params.has_key?('user')
|
189
|
+
arguments(args) do
|
190
|
+
permit %w[ user type ]
|
191
|
+
end
|
192
|
+
params = arguments.params
|
193
|
+
|
194
|
+
response = get_request("/user/repositories", params)
|
195
|
+
|
210
196
|
return response unless block_given?
|
211
197
|
response.each { |el| yield el }
|
212
198
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module BitBucket
|
4
|
-
class User < API
|
5
|
-
|
4
|
+
class Client::User < API
|
5
|
+
@version = '1.0'
|
6
6
|
|
7
7
|
DEFAULT_USER_OPTIONS = {
|
8
8
|
"first_name" => "",
|
@@ -12,11 +12,6 @@ module BitBucket
|
|
12
12
|
# "resource_uri" => ""
|
13
13
|
}.freeze
|
14
14
|
|
15
|
-
# Creates new User API
|
16
|
-
def initialize(options = { })
|
17
|
-
super(options)
|
18
|
-
end
|
19
|
-
|
20
15
|
# Gets the basic information associated with an account and
|
21
16
|
# a list of all of the repositories owned by the user.
|
22
17
|
# See https://confluence.atlassian.com/display/BITBUCKET/user+Endpoint#userEndpoint-GETauserprofile
|
@@ -3,56 +3,52 @@
|
|
3
3
|
module BitBucket
|
4
4
|
class Client < API
|
5
5
|
|
6
|
+
require_all 'bitbucket_rest_api/client',
|
7
|
+
'issues',
|
8
|
+
'repos',
|
9
|
+
'users',
|
10
|
+
'invitations'
|
11
|
+
|
12
|
+
require_all 'bitbucket_rest_api/client/users', 'account'
|
13
|
+
|
14
|
+
namespace :issues
|
15
|
+
|
16
|
+
namespace :pull_requests
|
17
|
+
|
18
|
+
namespace :repos
|
19
|
+
alias :repositories :repos
|
20
|
+
|
21
|
+
# Many of the resources on the users API provide a shortcut for getting
|
22
|
+
# information about the currently authenticated user.
|
23
|
+
namespace :users
|
24
|
+
|
25
|
+
namespace :user
|
26
|
+
alias :user_api :user
|
27
|
+
|
28
|
+
namespace :invitations
|
29
|
+
|
6
30
|
# This is a read-only API to the BitBucket events.
|
7
31
|
# These events power the various activity streams on the site.
|
8
32
|
def events(options = {})
|
9
33
|
raise "Unimplemented"
|
10
|
-
#@events ||=
|
11
|
-
end
|
12
|
-
|
13
|
-
def issues(options = {})
|
14
|
-
@issues ||= ApiFactory.new 'Issues', options
|
34
|
+
#@events ||= Api::Factory.new 'Events', options
|
15
35
|
end
|
16
36
|
|
17
37
|
# An API for users to manage their own tokens.
|
18
38
|
def oauth(options = {})
|
19
39
|
raise "Unimpletmented"
|
20
|
-
#@oauth ||=
|
40
|
+
#@oauth ||= Api::Factory.new 'Authorizations', options
|
21
41
|
end
|
22
42
|
alias :authorizations :oauth
|
23
43
|
|
24
44
|
def teams(options = {})
|
25
45
|
raise "Unimplemented"
|
26
|
-
#@teams ||=
|
46
|
+
#@teams ||= Api::Factory.new 'teams', options
|
27
47
|
end
|
28
48
|
|
29
|
-
def pull_requests(options = {})
|
30
|
-
raise "Unimplemented"
|
31
|
-
#@pull_requests ||= ApiFactory.new 'PullRequests', options
|
32
|
-
end
|
33
|
-
|
34
|
-
def repos(options = {})
|
35
|
-
@repos ||= ApiFactory.new 'Repos', options
|
36
|
-
end
|
37
|
-
alias :repositories :repos
|
38
|
-
|
39
49
|
def search(options = {})
|
40
50
|
raise "Unimplemented"
|
41
|
-
#@search ||=
|
42
|
-
end
|
43
|
-
|
44
|
-
# Many of the resources on the users API provide a shortcut for getting
|
45
|
-
# information about the currently authenticated user.
|
46
|
-
def users(options = {})
|
47
|
-
@users ||= ApiFactory.new 'Users', options
|
48
|
-
end
|
49
|
-
|
50
|
-
def user_api(options = {})
|
51
|
-
@user_api ||= ApiFactory.new 'User', options
|
52
|
-
end
|
53
|
-
|
54
|
-
def invitations(options = {})
|
55
|
-
@invitations ||= ApiFactory.new "Invitations", options
|
51
|
+
#@search ||= Api::Factory.new 'Search', options
|
56
52
|
end
|
57
53
|
end # Client
|
58
54
|
end # BitBucket
|
@@ -1,101 +1,58 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'bitbucket_rest_api/api/config'
|
4
|
+
|
3
5
|
module BitBucket
|
4
|
-
|
5
|
-
|
6
|
-
VALID_OPTIONS_KEYS = [
|
7
|
-
:adapter,
|
8
|
-
:client_id,
|
9
|
-
:client_secret,
|
10
|
-
:oauth_token,
|
11
|
-
:oauth_secret,
|
12
|
-
:endpoint,
|
13
|
-
:mime_type,
|
14
|
-
:user_agent,
|
15
|
-
:connection_options,
|
16
|
-
:repo,
|
17
|
-
:user,
|
18
|
-
:login,
|
19
|
-
:password,
|
20
|
-
:basic_auth
|
21
|
-
].freeze
|
6
|
+
# Stores the configuration
|
7
|
+
class Configuration < API::Config
|
22
8
|
|
23
9
|
# Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
|
24
|
-
|
10
|
+
property :adapter, default: :net_http
|
25
11
|
|
26
12
|
# By default, don't set an application key
|
27
|
-
|
13
|
+
property :client_id, default: nil
|
28
14
|
|
29
15
|
# By default, don't set an application secret
|
30
|
-
|
16
|
+
property :client_secret, default: nil
|
31
17
|
|
32
18
|
# By default, don't set a user oauth access token
|
33
|
-
|
19
|
+
property :oauth_token, default: nil
|
34
20
|
|
35
21
|
# By default, don't set a user oauth access token secret
|
36
|
-
|
22
|
+
property :oauth_secret, default: nil
|
37
23
|
|
38
24
|
# By default, don't set a user login name
|
39
|
-
|
25
|
+
property :login, default: nil
|
40
26
|
|
41
27
|
# By default, don't set a user password
|
42
|
-
|
28
|
+
property :password, default: nil
|
43
29
|
|
44
30
|
# By default, don't set a user basic authentication
|
45
|
-
|
31
|
+
property :basic_auth, default: nil
|
46
32
|
|
47
33
|
# The endpoint used to connect to BitBucket if none is set, in the event that BitBucket is ever available on location
|
48
|
-
|
34
|
+
property :endpoint, default: 'https://bitbucket.org/api/1.0'.freeze
|
49
35
|
|
50
36
|
# The value sent in the http header for 'User-Agent' if none is set
|
51
|
-
|
37
|
+
property :user_agent, default: "BitBucket Ruby Gem #{BitBucket::VERSION::STRING}".freeze
|
52
38
|
|
53
39
|
# By default the <tt>Accept</tt> header will make a request for <tt>JSON</tt>
|
54
|
-
|
40
|
+
property :mime_type, default: :json
|
55
41
|
|
56
42
|
# By default uses the Faraday connection options if none is set
|
57
|
-
|
43
|
+
property :connection_options, default: { }
|
58
44
|
|
59
45
|
# By default, don't set user name
|
60
|
-
|
46
|
+
property :user, default: nil
|
61
47
|
|
62
48
|
# By default, don't set repository name
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.extended(base)
|
73
|
-
base.set_defaults
|
74
|
-
end
|
75
|
-
|
76
|
-
def options
|
77
|
-
options = { }
|
78
|
-
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
79
|
-
options
|
80
|
-
end
|
81
|
-
|
82
|
-
def set_defaults
|
83
|
-
self.adapter = DEFAULT_ADAPTER
|
84
|
-
self.client_id = DEFAULT_CLIENT_ID
|
85
|
-
self.client_secret = DEFAULT_CLIENT_SECRET
|
86
|
-
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
87
|
-
self.oauth_secret = DEFAULT_OAUTH_SECRET
|
88
|
-
self.endpoint = DEFAULT_ENDPOINT
|
89
|
-
self.user_agent = DEFAULT_USER_AGENT
|
90
|
-
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
91
|
-
self.mime_type = DEFAULT_MIME_TYPE
|
92
|
-
self.user = DEFAULT_USER
|
93
|
-
self.repo = DEFAULT_REPO
|
94
|
-
self.login = DEFAULT_LOGIN
|
95
|
-
self.password = DEFAULT_PASSWORD
|
96
|
-
self.basic_auth = DEFAULT_BASIC_AUTH
|
97
|
-
self
|
98
|
-
end
|
49
|
+
property :repo, default: nil
|
50
|
+
|
51
|
+
# By default, don't auto-paginate results
|
52
|
+
property :auto_pagination, default: false
|
53
|
+
|
54
|
+
# Add Faraday::RackBuilder to overwrite middleware
|
55
|
+
property :stack
|
99
56
|
|
100
57
|
end # Configuration
|
101
58
|
end # BitBucket
|
@@ -1,16 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
|
-
require 'bitbucket_rest_api/response'
|
6
|
-
require 'bitbucket_rest_api/response/mashify'
|
7
|
-
require 'bitbucket_rest_api/response/jsonize'
|
8
|
-
require 'bitbucket_rest_api/response/helpers'
|
9
|
-
require 'bitbucket_rest_api/response/raise_error'
|
10
|
-
require 'bitbucket_rest_api/request/oauth'
|
11
|
-
require 'bitbucket_rest_api/request/basic_auth'
|
12
|
-
require 'bitbucket_rest_api/request/jsonize'
|
13
|
-
|
14
3
|
module BitBucket
|
15
4
|
module Connection
|
16
5
|
extend self
|
@@ -21,46 +10,21 @@ module BitBucket
|
|
21
10
|
:url,
|
22
11
|
:params,
|
23
12
|
:request,
|
24
|
-
:ssl
|
13
|
+
:ssl,
|
14
|
+
:builder,
|
15
|
+
:api
|
25
16
|
].freeze
|
26
17
|
|
27
18
|
def default_options(options={})
|
28
19
|
{
|
29
20
|
:headers => {
|
30
|
-
USER_AGENT => user_agent
|
21
|
+
USER_AGENT => options[:user_agent]
|
31
22
|
},
|
32
23
|
:ssl => { :verify => false },
|
33
24
|
:url => options.fetch(:endpoint) { BitBucket.endpoint }
|
34
25
|
}.merge(options)
|
35
26
|
end
|
36
27
|
|
37
|
-
# Default middleware stack that uses default adapter as specified at
|
38
|
-
# configuration stage.
|
39
|
-
#
|
40
|
-
def default_middleware(options={})
|
41
|
-
Proc.new 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? and 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
28
|
def clear_cache
|
65
29
|
@connection = nil
|
66
30
|
end
|
@@ -72,24 +36,25 @@ module BitBucket
|
|
72
36
|
# Exposes middleware builder to facilitate custom stacks and easy
|
73
37
|
# addition of new extensions such as cache adapter.
|
74
38
|
#
|
75
|
-
def stack(options={}
|
39
|
+
def stack(options={})
|
76
40
|
@stack ||= begin
|
77
|
-
|
78
|
-
|
79
|
-
else
|
80
|
-
Faraday::RackBuilder.new(&default_middleware(options))
|
81
|
-
end
|
41
|
+
builder_class = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
|
42
|
+
builder_class.new(&BitBucket.default_middleware(options))
|
82
43
|
end
|
83
44
|
end
|
84
45
|
|
85
46
|
# Returns a Fraday::Connection object
|
86
47
|
#
|
87
|
-
def connection(options = {})
|
88
|
-
|
48
|
+
def connection(api, options = {})
|
49
|
+
connection_options = default_options(options)
|
89
50
|
clear_cache unless options.empty?
|
90
|
-
|
51
|
+
builder = api.stack ? api.stack : stack(options.merge!(api: api))
|
52
|
+
connection_options.merge!(builder: builder)
|
53
|
+
connection_options.keep_if {|key, value| ALLOWED_OPTIONS.include?(key) }
|
54
|
+
|
55
|
+
puts "OPTIONS:#{connection_options.inspect}" if ENV['DEBUG']
|
91
56
|
|
92
|
-
@connection ||= Faraday.new(
|
57
|
+
@connection ||= Faraday.new(connection_options)
|
93
58
|
end
|
94
59
|
|
95
60
|
end # Connection
|