codenamev_bitbucket_api 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +43 -0
  3. data/README.md +169 -0
  4. data/Rakefile +3 -0
  5. data/lib/bitbucket_rest_api/api/actions.rb +50 -0
  6. data/lib/bitbucket_rest_api/api/arguments.rb +248 -0
  7. data/lib/bitbucket_rest_api/api/config/property.rb +30 -0
  8. data/lib/bitbucket_rest_api/api/config/property_set.rb +118 -0
  9. data/lib/bitbucket_rest_api/api/config.rb +107 -0
  10. data/lib/bitbucket_rest_api/api/factory.rb +29 -0
  11. data/lib/bitbucket_rest_api/api.rb +242 -0
  12. data/lib/bitbucket_rest_api/authorization.rb +34 -0
  13. data/lib/bitbucket_rest_api/client/invitations.rb +16 -0
  14. data/lib/bitbucket_rest_api/client/issues/comments.rb +109 -0
  15. data/lib/bitbucket_rest_api/client/issues/components.rb +103 -0
  16. data/lib/bitbucket_rest_api/client/issues/milestones.rb +103 -0
  17. data/lib/bitbucket_rest_api/client/issues.rb +214 -0
  18. data/lib/bitbucket_rest_api/client/repos/changesets.rb +55 -0
  19. data/lib/bitbucket_rest_api/client/repos/following.rb +40 -0
  20. data/lib/bitbucket_rest_api/client/repos/keys.rb +88 -0
  21. data/lib/bitbucket_rest_api/client/repos/pull_requests/comments.rb +42 -0
  22. data/lib/bitbucket_rest_api/client/repos/pull_requests/commits.rb +24 -0
  23. data/lib/bitbucket_rest_api/client/repos/pull_requests.rb +199 -0
  24. data/lib/bitbucket_rest_api/client/repos/services.rb +104 -0
  25. data/lib/bitbucket_rest_api/client/repos/sources.rb +32 -0
  26. data/lib/bitbucket_rest_api/client/repos.rb +224 -0
  27. data/lib/bitbucket_rest_api/client/user.rb +96 -0
  28. data/lib/bitbucket_rest_api/client/users/account.rb +54 -0
  29. data/lib/bitbucket_rest_api/client/users.rb +14 -0
  30. data/lib/bitbucket_rest_api/client.rb +54 -0
  31. data/lib/bitbucket_rest_api/compatibility.rb +23 -0
  32. data/lib/bitbucket_rest_api/configuration.rb +59 -0
  33. data/lib/bitbucket_rest_api/connection.rb +61 -0
  34. data/lib/bitbucket_rest_api/constants.rb +50 -0
  35. data/lib/bitbucket_rest_api/core_ext/array.rb +17 -0
  36. data/lib/bitbucket_rest_api/core_ext/hash.rb +56 -0
  37. data/lib/bitbucket_rest_api/core_ext/ordered_hash.rb +107 -0
  38. data/lib/bitbucket_rest_api/deprecation.rb +39 -0
  39. data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
  40. data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
  41. data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
  42. data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
  43. data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
  44. data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
  45. data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
  46. data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
  47. data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
  48. data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
  49. data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
  50. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
  51. data/lib/bitbucket_rest_api/error/validations.rb +18 -0
  52. data/lib/bitbucket_rest_api/error.rb +35 -0
  53. data/lib/bitbucket_rest_api/ext/faraday.rb +38 -0
  54. data/lib/bitbucket_rest_api/middleware.rb +31 -0
  55. data/lib/bitbucket_rest_api/normalizer.rb +27 -0
  56. data/lib/bitbucket_rest_api/null_encoder.rb +25 -0
  57. data/lib/bitbucket_rest_api/page_iterator.rb +90 -0
  58. data/lib/bitbucket_rest_api/page_links.rb +33 -0
  59. data/lib/bitbucket_rest_api/paged_request.rb +29 -0
  60. data/lib/bitbucket_rest_api/pagination.rb +97 -0
  61. data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
  62. data/lib/bitbucket_rest_api/params_hash.rb +100 -0
  63. data/lib/bitbucket_rest_api/request/basic_auth.rb +33 -0
  64. data/lib/bitbucket_rest_api/request/jsonize.rb +51 -0
  65. data/lib/bitbucket_rest_api/request/oauth.rb +51 -0
  66. data/lib/bitbucket_rest_api/request/verbs.rb +53 -0
  67. data/lib/bitbucket_rest_api/request.rb +91 -0
  68. data/lib/bitbucket_rest_api/response/header.rb +68 -0
  69. data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
  70. data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
  71. data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
  72. data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
  73. data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
  74. data/lib/bitbucket_rest_api/response.rb +28 -0
  75. data/lib/bitbucket_rest_api/response_wrapper.rb +157 -0
  76. data/lib/bitbucket_rest_api/result.rb +68 -0
  77. data/lib/bitbucket_rest_api/users.rb +20 -0
  78. data/lib/bitbucket_rest_api/utils/url.rb +56 -0
  79. data/lib/bitbucket_rest_api/validations/format.rb +24 -0
  80. data/lib/bitbucket_rest_api/validations/presence.rb +30 -0
  81. data/lib/bitbucket_rest_api/validations/required.rb +24 -0
  82. data/lib/bitbucket_rest_api/validations/token.rb +43 -0
  83. data/lib/bitbucket_rest_api/validations.rb +25 -0
  84. data/lib/bitbucket_rest_api/version.rb +11 -0
  85. data/lib/bitbucket_rest_api.rb +136 -0
  86. metadata +238 -0
@@ -0,0 +1,199 @@
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
+
11
+ REQUIRED_PULL_REQUEST_OPTIONS = %w[
12
+ title
13
+ source
14
+ ]
15
+
16
+ VALID_PULL_REQUEST_PARAM_NAMES = %w[
17
+ title
18
+ description
19
+ source
20
+ destination
21
+ reviewers
22
+ close_source_branch
23
+ ].freeze
24
+
25
+ VALID_PULL_REQUEST_STATE_VALUES = {
26
+ state: ['OPEN', 'MERGED', 'DECLINED']
27
+ }
28
+
29
+ @version = '2.0'
30
+
31
+ # Access to Client::Repos::PullRequests::Comments API
32
+ namespace :comments
33
+ namespace :commits
34
+
35
+ # List pull requests for a repository
36
+ #
37
+ # = Inputs
38
+ # <tt>:state</tt> - Optional - State of the pull request (OPEN, MERGED, DECLINED)
39
+ #
40
+ def list(*args)
41
+ arguments(args, required: [:user, :repo], optional: [:state])
42
+ params = arguments.params
43
+ user = arguments.user
44
+ repo = arguments.repo
45
+
46
+ params['state'] ||= 'OPEN'
47
+ # Bitbucket requires the state to be all caps or it returns all
48
+ params['state'] = params['state'].upcase
49
+
50
+ response = get_request("/repositories/#{user}/#{repo}/pullrequests/", params)
51
+
52
+ return response unless block_given?
53
+ response.each { |el| yield el }
54
+ end
55
+ alias :all :list
56
+
57
+ # Get a single pull request
58
+ #
59
+ # = Examples
60
+ # bitbucket = BitBucket.new
61
+ # bitbucket.repos.pull_requests.find 'user-name', 'repo-name', 'pull-request-id'
62
+ #
63
+ def get(*args)
64
+ arguments(args, required: [:user, :repo, :pull_request_id])
65
+
66
+ get_request("/repositories/#{arguments.user}/#{arguments.repo.downcase}/pullrequests/#{arguments.pull_request_id}", arguments.params)
67
+ end
68
+
69
+ alias :find :get
70
+
71
+ # Create a pull request
72
+ #
73
+ # = Inputs
74
+ # <tt>:title</tt> - Required string
75
+ # <tt>:description</tt> - Optional string
76
+ # <tt>:source</tt> - Required hash - The source branch name and/or repository (for example, { develop)
77
+ # * <tt>{ "branch": { "name": "REQUIRED branch_name" }, "repository": { "full_name": "owner/repo_slug" } }</tt>
78
+ # <tt>:destination</tt> - Optional hash - The destination branch or commit
79
+ # * <tt>{ "branch": { "name": "branch_name" }, "commit": { "hash": "name" } }</tt>
80
+ # <tt>:reviewers</tt> - Optional array - Users currently reviewiing the pull
81
+ # * <tt>[{ "username": "accountname" }]</tt>
82
+ #
83
+ # = Examples
84
+ # bitbucket = BitBucket.new
85
+ # bitbucket.repos.pull_requests.create 'user-name', 'repo-name',
86
+ # "title" => "Fixes a bug",
87
+ # "description" => "Fixes not being able to see anything.",
88
+ # "source" => { "branch" => { "name" => "bug-fixes" } },
89
+ # "destination" => { "branch" => { "name" => "master" } },
90
+ # "reviewers" => [ { "username" => "octocat" } ],
91
+ # "close_source_branch" => true
92
+ #
93
+ def create(*args)
94
+ arguments(args, required: [:user, :repo]) do
95
+ permit VALID_PULL_REQUEST_PARAM_NAMES
96
+ assert_required REQUIRED_PULL_REQUEST_OPTIONS
97
+ end
98
+
99
+ post_request("/repositories/#{arguments.user}/#{arguments.repo.downcase}/pullrequests", arguments.params)
100
+ end
101
+
102
+ # Edit a pull request
103
+ #
104
+ # = Inputs
105
+ # <tt>:title</tt> - Required string
106
+ # <tt>:description</tt> - Optional string
107
+ # <tt>:destination</tt> - Optional hash - The destination branch or commit
108
+ # * <tt>{ "branch": { "name": "branch_name" }, "commit": { "hash": "name" } }</tt>
109
+ # <tt>:reviewers</tt> - Optional array - Users currently reviewiing the pull
110
+ # * <tt>[{ "username": "accountname" }]</tt>
111
+ #
112
+ # = Examples
113
+ # bitbucket = BitBucket.new
114
+ # bitbucket.repos.pull_requests.update 'user-name', 'repo-name', 'pull-request-id',
115
+ # "title" => "Fixes a bug",
116
+ # "description" => "Fixes not being able to see anything.",
117
+ # "destination" => { "branch" => { "name" => "master" } },
118
+ # "reviewers" => [ { "username" => "octocat" } ],
119
+ # "close_source_branch" => true
120
+ #
121
+ def update(*args)
122
+ arguments(args, required: [:user, :repo, :pull_request_id]) do
123
+ permit VALID_PULL_REQUEST_PARAM_NAMES
124
+ end
125
+
126
+ user = arguments.user
127
+ repo = arguments.repo
128
+ pull_request_id = arguments.pull_request_id
129
+
130
+ # BitBucket will drop any data if it is not included, so we have to check for pre-existing data
131
+ existing_pull = get(user, repo, pull_request_id)
132
+ existing_pull_data = {
133
+ 'title' => existing_pull.title,
134
+ 'description' => existing_pull.description,
135
+ 'destination' => {
136
+ 'branch' => existing_pull.destination.branch
137
+ },
138
+ 'reviewers' => existing_pull.reviewers,
139
+ 'close_source_branch' => existing_pull.close_source_branch
140
+ }
141
+ params = normalize!(existing_pull_data).merge!(normalize!(arguments.params))
142
+
143
+ put_request("/repositories/#{user}/#{repo.downcase}/pullrequests/#{pull_request_id}/", params)
144
+ end
145
+ alias :edit :update
146
+
147
+ # Decline or reject a single pull request
148
+ #
149
+ # = Examples
150
+ # bitbucket = BitBucket.new
151
+ # bitbucket.repos.pull_requests.reject 'user-name', 'repo-name', 'pull-request-id'
152
+ #
153
+ def decline(user_name, repo_name, pull_request_id)
154
+ arguments(args, required: [:user, :repo, :pull_request_id])
155
+
156
+ post_request("/repositories/#{arguments.user}/#{arguments.repo}/pullrequests/#{arguments.pull_request_id}/decline")
157
+ end
158
+ alias :reject :decline
159
+
160
+ # Give approval on a pull request
161
+ #
162
+ # = Examples
163
+ # bitbucket = BitBucket.new
164
+ # bitbucket.repos.pull_requests.approve 'user-name', 'repo-name', 'pull-request-id'
165
+ #
166
+ def approve(user_name, repo_name, pull_request_id)
167
+ arguments(args, required: [:user, :repo, :pull_request_id])
168
+
169
+ post_request("/repositories/#{arguments.user}/#{arguments.repo}/pullrequests/#{arguments.pull_request_id}/approve")
170
+ end
171
+
172
+ # Get the diff for a pull request
173
+ #
174
+ # = Examples
175
+ # bitbucket = BitBucket.new
176
+ # bitbucket.repos.pull_requests.diff 'user-name', 'repo-name', 'pull-request-id'
177
+ #
178
+ def diff(user_name, repo_name, pull_request_id)
179
+ arguments(args, required: [:user, :repo, :pull_request_id])
180
+
181
+ get_request("/repositories/#{arguments.user}/#{arguments.repo}/pullrequests/#{arguments.pull_request_id}/diff")
182
+ end
183
+
184
+ # Get a log of all activity for a pull request
185
+ #
186
+ # = Examples
187
+ # bitbucket = BitBucket.new
188
+ # bitbucket.repos.pull_requests.activity 'user-name', 'repo-name'
189
+ #
190
+ def activity(*args)
191
+ arguments(args, required: [:user, :repo, :pull_request_id])
192
+
193
+ response = get_request("/repositories/#{arguments.user}/#{arguments.repo}/pullrequests/#{arguments.pull_request_id}/activity")
194
+
195
+ return response unless block_given?
196
+ response.each { |el| yield el }
197
+ end
198
+ end # Repos::PullRequests
199
+ end # BitBucket
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Repos::Services < API
5
+ @version = '2.0'
6
+
7
+ REQUIRED_KEY_PARAM_NAMES = %w[ type ].freeze
8
+
9
+ # List services
10
+ #
11
+ # = Examples
12
+ # bitbucket = BitBucket.new
13
+ # bitbucket.repos.services.list 'user-name', 'repo-name'
14
+ # bitbucket.repos.services.list 'user-name', 'repo-name' { |service| ... }
15
+ #
16
+ def list(user_name, repo_name, params={})
17
+ _update_user_repo_params(user_name, repo_name)
18
+ _validate_user_repo_params(user, repo) unless user? && repo?
19
+ normalize! params
20
+
21
+ response = get_request("/repositories/#{user}/#{repo.downcase}/services", params)
22
+ return response unless block_given?
23
+ response.each { |el| yield el }
24
+ end
25
+ alias :all :list
26
+
27
+ # Gets a single service
28
+ #
29
+ # = Examples
30
+ # @bitbucket = BitBucket.new
31
+ # @bitbucket.repos.services.get 'user-name', 'repo-name', 109172378)
32
+ #
33
+ def get(user_name, repo_name, service_id, params={})
34
+ _update_user_repo_params(user_name, repo_name)
35
+ _validate_user_repo_params(user, repo) unless user? && repo?
36
+ _validate_presence_of(service_id)
37
+ normalize! params
38
+
39
+ get_request("/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
40
+ end
41
+ alias :find :get
42
+
43
+ # Create a service
44
+ #
45
+ # = Inputs
46
+ # * <tt>:type</tt> - One of the supported services. The type is a case-insensitive value.
47
+ #
48
+ # = Examples
49
+ # bitbucket = BitBucket.new
50
+ # bitbucket.repos.services.create 'user-name', 'repo-name',
51
+ # "type" => "Basecamp",
52
+ # "Password" => "...",
53
+ # "Username" => "...",
54
+ # "Discussion URL" => "..."
55
+ #
56
+ def create(user_name, repo_name, params={})
57
+ _update_user_repo_params(user_name, repo_name)
58
+ _validate_user_repo_params(user, repo) unless user? && repo?
59
+ normalize! params
60
+ assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)
61
+
62
+ post_request("/repositories/#{user}/#{repo.downcase}/services", params)
63
+ end
64
+
65
+ # Edit a service
66
+ #
67
+ # = Inputs
68
+ # * <tt>:type</tt> - One of the supported services. The type is a case-insensitive value.
69
+ #
70
+ # = Examples
71
+ # bitbucket = BitBucket.new
72
+ # bitbucket.repos.services.edit 'user-name', 'repo-name', 109172378,
73
+ # "type" => "Basecamp",
74
+ # "Password" => "...",
75
+ # "Username" => "...",
76
+ # "Discussion URL" => "..."
77
+ #
78
+ def edit(user_name, repo_name, service_id, params={})
79
+ _update_user_repo_params(user_name, repo_name)
80
+ _validate_user_repo_params(user, repo) unless user? && repo?
81
+ _validate_presence_of(service_id)
82
+
83
+ normalize! params
84
+
85
+ put_request("/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
86
+ end
87
+
88
+ # Delete service
89
+ #
90
+ # = Examples
91
+ # @bitbucket = BitBucket.new
92
+ # @bitbucket.repos.services.delete 'user-name', 'repo-name', 109172378
93
+ #
94
+ def delete(user_name, repo_name, service_id, params={})
95
+ _update_user_repo_params(user_name, repo_name)
96
+ _validate_user_repo_params(user, repo) unless user? && repo?
97
+ _validate_presence_of(service_id)
98
+ normalize! params
99
+
100
+ delete_request("/repositories/#{user}/#{repo.downcase}/services/#{service_id}", params)
101
+ end
102
+
103
+ end # Repos::Keys
104
+ end # BitBucket
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Repos::Sources < API
5
+ @version = '1.0'
6
+
7
+ REQUIRED_COMMENT_PARAMS = %w[
8
+ body
9
+ changeset_id
10
+ line
11
+ path
12
+ position
13
+ ].freeze
14
+
15
+ # Gets a source of repo
16
+ #
17
+ # = Examples
18
+ # @bitbucket = BitBucket.new
19
+ # @bitbucket.repos.sources.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6', 'app/contorllers/')
20
+ #
21
+ def get(user_name, repo_name, sha, path, params={})
22
+ _update_user_repo_params(user_name, repo_name)
23
+ _validate_user_repo_params(user, repo) unless user? && repo?
24
+ _validate_presence_of sha
25
+ normalize! params
26
+
27
+ get_request("/repositories/#{user}/#{repo.downcase}/src/#{sha}/#{path}", params)
28
+ end
29
+ alias :find :get
30
+
31
+ end # Repos::Sources
32
+ end # BitBucket
@@ -0,0 +1,224 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Repos < API
5
+
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'
15
+
16
+ DEFAULT_REPO_OPTIONS = {
17
+ "website" => "",
18
+ "is_private" => false,
19
+ "has_issues" => false,
20
+ "has_wiki" => false,
21
+ "scm" => "git",
22
+ "no_public_forks" => false
23
+ }.freeze
24
+
25
+ VALID_REPO_OPTIONS = %w[
26
+ owner
27
+ name
28
+ description
29
+ website
30
+ is_private
31
+ has_issues
32
+ has_wiki
33
+ no_public_forks
34
+ language
35
+ scm
36
+ ].freeze
37
+
38
+ # Access to Repos::Commits API
39
+ namespace :changesets
40
+
41
+ # Access to Repos::Keys API
42
+ namespace :keys
43
+
44
+ # Access to Repos::Watchin API
45
+ namespace :following
46
+
47
+ # Access to Repos::Commits API
48
+ namespace :sources
49
+
50
+ # Access to Repos::Services API
51
+ namespace :services
52
+
53
+ # Access to Repos::PullRequests API
54
+ namespace :pull_requests
55
+
56
+ # List branches
57
+ #
58
+ # = Examples
59
+ #
60
+ # bitbucket = BitBucket.new
61
+ # bibucket.repos.branches 'user-name', 'repo-name'
62
+ #
63
+ # repos = BitBucket::Repos.new
64
+ # repos.branches 'user-name', 'repo-name'
65
+ #
66
+ def branches(user_name, repo_name, params={ })
67
+ _update_user_repo_params(user_name, repo_name)
68
+ _validate_user_repo_params(user, repo) unless (user? && repo?)
69
+ normalize! params
70
+
71
+ response = get_request("/repositories/#{user}/#{repo.downcase}/branches/", params)
72
+ return response unless block_given?
73
+ response.each { |el| yield el }
74
+ end
75
+
76
+ alias :list_branches :branches
77
+
78
+ # Create a new repository for the authenticated user.
79
+ #
80
+ # = Parameters
81
+ # <tt>:name</tt> - Required string
82
+ # <tt>:description</tt> - Optional string
83
+ # <tt>:website</tt> - Optional string
84
+ # <tt>:is_private</tt> - Optional boolean - <tt>true</tt> to create a private repository, <tt>false</tt> to create a public one.
85
+ # <tt>:has_issues</tt> - Optional boolean - <tt>true</tt> to enable issues for this repository, <tt>false</tt> to disable them
86
+ # <tt>:has_wiki</tt> - Optional boolean - <tt>true</tt> to enable the wiki for this repository, <tt>false</tt> to disable it. Default is <tt>true</tt>
87
+ # <tt>:owner</tt> Optional string - The team in which this repository will be created
88
+ #
89
+ # = Examples
90
+ # bitbucket = BitBucket.new
91
+ # bitbucket.repos.create "name" => 'repo-name'
92
+ # "description": "This is your first repo",
93
+ # "website": "https://bitbucket.com",
94
+ # "is_private": false,
95
+ # "has_issues": true,
96
+ # "has_wiki": true
97
+ #
98
+ # Create a new repository in this team. The authenticated user
99
+ # must be a member of this team
100
+ #
101
+ # Examples:
102
+ # bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
103
+ # bitbucket.repos.create :name => 'repo-name', :owner => 'team-name'
104
+ #
105
+ def create(*args)
106
+ params = args.extract_options!
107
+ normalize! params
108
+ filter! VALID_REPO_OPTIONS + %w[ org ], params
109
+ assert_required_keys(%w[ name ], params)
110
+
111
+ # Requires authenticated user
112
+ post_request("/repositories/", DEFAULT_REPO_OPTIONS.merge(params))
113
+ end
114
+
115
+ # Edit a repository
116
+ #
117
+ # = Parameters
118
+ # * <tt>:name</tt> Required string
119
+ # * <tt>:description</tt> Optional string
120
+ # * <tt>:website</tt> Optional string
121
+ # * <tt>:private</tt> - Optional boolean - <tt>false</tt> to create public reps, <tt>false</tt> to create a private one
122
+ # * <tt>:has_issues</tt> Optional boolean - <tt>true</tt> to enable issues for this repository, <tt>false</tt> to disable them
123
+ # * <tt>:has_wiki</tt> Optional boolean - <tt>true</tt> to enable the wiki for this repository, <tt>false</tt> to disable it. Default is <tt>true</tt>
124
+ # * <tt>:has_downloads</tt> Optional boolean - <tt>true</tt> to enable downloads for this repository
125
+ #
126
+ # = Examples
127
+ #
128
+ # bitbucket = BitBucket.new
129
+ # bitbucket.repos.edit 'user-name', 'repo-name',
130
+ # :name => 'hello-world',
131
+ # :description => 'This is your first repo',
132
+ # :website => "https://bitbucket.com",
133
+ # :public => true, :has_issues => true
134
+ #
135
+ def edit(user_name, repo_name, params={ })
136
+ _update_user_repo_params(user_name, repo_name)
137
+ _validate_user_repo_params(user, repo) unless user? && repo?
138
+
139
+ normalize! params
140
+ filter! VALID_REPO_OPTIONS, params
141
+
142
+ put_request("/repositories/#{user}/#{repo.downcase}/", DEFAULT_REPO_OPTIONS.merge(params))
143
+ end
144
+
145
+ # Get a repository
146
+ #
147
+ # = Examples
148
+ # bitbucket = BitBucket.new
149
+ # bitbucket.repos.get 'user-name', 'repo-name'
150
+ #
151
+ def get(user_name, repo_name, params={ })
152
+ _update_user_repo_params(user_name, repo_name)
153
+ _validate_user_repo_params(user, repo) unless user? && repo?
154
+ normalize! params
155
+
156
+ get_request("/repositories/#{user}/#{repo.downcase}", params)
157
+ end
158
+
159
+ alias :find :get
160
+
161
+ # Delete a repository
162
+ #
163
+ # = Examples
164
+ # @bitbucket = BitBucket.new
165
+ # @bitbucket.repos.delete 'user-name', 'repo-name'
166
+ #
167
+ def delete(user_name, repo_name)
168
+ _update_user_repo_params(user_name, repo_name)
169
+ _validate_user_repo_params(user, repo) unless user? && repo?
170
+
171
+ delete_request("/repositories/#{user}/#{repo.downcase}")
172
+ end
173
+
174
+ # List repositories for the authenticated user
175
+ #
176
+ # = Examples
177
+ # bitbucket = BitBucket.new :oauth_token => '...', :oauth_secret => '...'
178
+ # bitbucket.repos.list
179
+ # bitbucket.repos.list { |repo| ... }
180
+ #
181
+ # List public repositories for the specified user.
182
+ #
183
+ # = Examples
184
+ # bitbucket = BitBucket.new
185
+ # bitbucket.repos.list :user => 'user-name'
186
+ # bitbucket.repos.list :user => 'user-name', { |repo| ... }
187
+ def list(*args)
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
+
196
+ return response unless block_given?
197
+ response.each { |el| yield el }
198
+ end
199
+
200
+ alias :all :list
201
+
202
+ # List tags
203
+ #
204
+ # = Examples
205
+ # bitbucket = BitBucket.new
206
+ # bitbucket.repos.tags 'user-name', 'repo-name'
207
+ # bitbucket.repos.tags 'user-name', 'repo-name' { |tag| ... }
208
+ #
209
+ def tags(user_name, repo_name, params={ })
210
+ _update_user_repo_params(user_name, repo_name)
211
+ _validate_user_repo_params(user, repo) unless user? && repo?
212
+ normalize! params
213
+
214
+ response = get_request("/repositories/#{user}/#{repo.downcase}/tags/", params)
215
+ return response unless block_given?
216
+ response.each { |el| yield el }
217
+ end
218
+
219
+ alias :list_tags :tags
220
+ alias :repo_tags :tags
221
+ alias :repository_tags :tags
222
+
223
+ end # Repos
224
+ end # BitBucket
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::User < API
5
+ @version = '1.0'
6
+
7
+ DEFAULT_USER_OPTIONS = {
8
+ "first_name" => "",
9
+ "last_name" => "",
10
+ "avatar" => ""
11
+ # TODO: can this filed be modified?
12
+ # "resource_uri" => ""
13
+ }.freeze
14
+
15
+ # Gets the basic information associated with an account and
16
+ # a list of all of the repositories owned by the user.
17
+ # See https://confluence.atlassian.com/display/BITBUCKET/user+Endpoint#userEndpoint-GETauserprofile
18
+ #
19
+ # = Examples
20
+ # bitbucket = BitBucket.new
21
+ # bitbucket.user_api.profile
22
+ #
23
+ def profile
24
+ get_request("/user")
25
+ end
26
+
27
+
28
+ # Update a user
29
+
30
+ # = Parameters
31
+ # * <tt>:first_name</tt> Optional string
32
+ # * <tt>:last_name</tt> Optional string
33
+ # * <tt>:avatar</tt> Optional string
34
+ # * <tt>:resource_uri</tt> Optional string
35
+ #
36
+ # = Examples
37
+ #
38
+ # bitbucket = BitBucket.new
39
+ # bitbucket.user_api.update :first_name => 'first-name', :last_name => 'last-name'
40
+ #
41
+
42
+ def update( params={ })
43
+ normalize! params
44
+ filter! DEFAULT_USER_OPTIONS, params
45
+
46
+ put_request("/user", DEFAULT_USER_OPTIONS.merge(params))
47
+
48
+ end
49
+
50
+
51
+ # GET a list of user privileges
52
+ def privileges
53
+ get_request("/user/privileges")
54
+ end
55
+
56
+
57
+
58
+ # GET a list of repositories an account follows
59
+ # Gets the details of the repositories that the individual or team account follows.
60
+ # This call returns the full data about the repositories including
61
+ # if the repository is a fork of another repository.
62
+ # An account always "follows" its own repositories.
63
+ def follows
64
+ get_request("/user/follows")
65
+ end
66
+
67
+
68
+ # GET a list of repositories visible to an account
69
+ # Gets the details of the repositories that the user owns
70
+ # or has at least read access to.
71
+ # Use this if you're looking for a full list of all of the repositories associated with a user.
72
+ def repositories
73
+ get_request("/user/repositories")
74
+ end
75
+
76
+ alias :repos :repositories
77
+
78
+
79
+
80
+ # GET a list of repositories the account is following
81
+ # Gets a list of the repositories the account follows.
82
+ # This is the same list that appears on the Following tab on your account dashboard.
83
+ def overview
84
+ get_request("/user/repositories/overview")
85
+ end
86
+
87
+
88
+
89
+ # GET the list of repositories on the dashboard
90
+ # Gets the repositories list from the account's dashboard.
91
+ def dashboard
92
+ get_request("/user/repositories/dashboard")
93
+ end
94
+
95
+ end # User
96
+ end # BitBucket