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,107 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bitbucket_rest_api/api/config/property'
4
+ require 'bitbucket_rest_api/api/config/property_set'
5
+
6
+ module BitBucket
7
+
8
+ class API
9
+ # A base class for constructing api configuration
10
+ class Config
11
+
12
+ # Defines a property on an object's class or instance
13
+ #
14
+ # @example
15
+ # class Configuration < Api::Config
16
+ # property :adapter, default: :net_http
17
+ # property :user, required: true
18
+ # end
19
+ #
20
+ # @param [Symbol] name
21
+ # the name of a property
22
+ #
23
+ # @param [#to_hash] options
24
+ # the extra options
25
+ #
26
+ # @return [self]
27
+ #
28
+ # @api public
29
+ def self.property(name, options = {})
30
+ self.property_set << Property.new(name, options)
31
+ update_subclasses(name, options)
32
+ self
33
+ end
34
+
35
+ def self.update_subclasses(name, options)
36
+ if defined?(@subclasses) && @subclasses
37
+ @subclasses.each { |klass| klass.property(name, options) }
38
+ end
39
+ end
40
+
41
+ # Check if property is defined
42
+ #
43
+ # @param [Symbol] name
44
+ # the name to check
45
+ #
46
+ # @return [Boolean]
47
+ #
48
+ # @api public
49
+ def self.property?(name)
50
+ property_set.include?(name)
51
+ end
52
+
53
+ class << self
54
+ attr_reader :property_set
55
+ end
56
+
57
+ instance_variable_set("@property_set", PropertySet.new(self))
58
+
59
+ def self.inherited(descendant)
60
+ super
61
+ (@subclasses ||= Set.new) << descendant
62
+ descendant.instance_variable_set('@property_set',
63
+ PropertySet.new(descendant, self.property_set.properties.dup))
64
+ end
65
+
66
+ def initialize(&block)
67
+ super(&block)
68
+ end
69
+
70
+ def property_names
71
+ self.class.property_set.properties.map(&:name)
72
+ end
73
+
74
+ def self.property_names
75
+ property_set.properties.map(&:name)
76
+ end
77
+
78
+ # Fetach all the properties and their values
79
+ #
80
+ # @return [Hash[Symbol]]
81
+ #
82
+ # @api public
83
+ def fetch(value = nil)
84
+ if value
85
+ self.class.property_set[value]
86
+ else
87
+ self.class.property_set.to_hash
88
+ end
89
+ end
90
+
91
+ # Provide access to properties
92
+ #
93
+ # @example
94
+ # config.call do |config|
95
+ # config.adapter = :net_http
96
+ # end
97
+ #
98
+ # @return [self]
99
+ #
100
+ # @api private
101
+ def call(&block)
102
+ block.call(self) if block_given?
103
+ self
104
+ end
105
+ end # Config
106
+ end # Api
107
+ end # BitBucket
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bitbucket_rest_api/core_ext/hash'
4
+
5
+ module BitBucket
6
+ class API
7
+ class Factory
8
+
9
+ # Instantiates a new bitbucket api object
10
+ def self.new(klass, options={}, &block)
11
+ return create_instance(klass, options, &block) if klass
12
+ raise ArgumentError, 'must provide klass to be instantiated'
13
+ end
14
+
15
+ # Passes configuration options to instantiated class
16
+ def self.create_instance(klass, options, &block)
17
+ options.symbolize_keys!
18
+ convert_to_constant(klass.to_s).new options, &block
19
+ end
20
+
21
+ def self.convert_to_constant(classes)
22
+ classes.split('::').inject(BitBucket) do |constant, klass|
23
+ constant.const_get klass
24
+ end
25
+ end
26
+
27
+ end # Factory
28
+ end # Api
29
+ end # BitBucket
@@ -0,0 +1,242 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'bitbucket_rest_api/configuration'
4
+ require 'bitbucket_rest_api/core_ext/hash'
5
+ require 'bitbucket_rest_api/core_ext/array'
6
+ require 'bitbucket_rest_api/compatibility'
7
+ require 'bitbucket_rest_api/null_encoder'
8
+
9
+ require 'bitbucket_rest_api/request/verbs'
10
+
11
+ require 'bitbucket_rest_api/api/actions'
12
+ require 'bitbucket_rest_api/api/factory'
13
+ require 'bitbucket_rest_api/api/arguments'
14
+
15
+ module BitBucket
16
+ class API
17
+ extend BitBucket::ClassMethods
18
+ include Constants
19
+ include Authorization
20
+ include Request::Verbs
21
+
22
+ # TODO consider these optional in a stack
23
+ include Validations
24
+ include ParameterFilter
25
+ include Normalizer
26
+
27
+ @version = '1.0'
28
+
29
+ attr_reader *BitBucket.configuration.property_names
30
+
31
+ attr_accessor *Validations::VALID_API_KEYS
32
+
33
+ attr_accessor :current_options
34
+
35
+ # Callback to update global configuration options
36
+ class_eval do
37
+ BitBucket.configuration.property_names.each do |key|
38
+ define_method "#{key}=" do |arg|
39
+ self.instance_variable_set("@#{key}", arg)
40
+ self.current_options.merge!({:"#{key}" => arg})
41
+ end
42
+ end
43
+ end
44
+
45
+ # Creates new API
46
+ def initialize(options={}, &block)
47
+ super()
48
+ setup(options)
49
+ yield_or_eval(&block) if block_given?
50
+ end
51
+
52
+ def yield_or_eval(&block)
53
+ return unless block
54
+ block.arity > 0 ? yield(self) : self.instance_eval(&block)
55
+ end
56
+
57
+ def setup(options={})
58
+ options = BitBucket.configuration.fetch.merge(options)
59
+ self.current_options = options
60
+ if self.class.instance_variable_get('@version') == '2.0'
61
+ options[:endpoint] = BitBucket.endpoint_v2
62
+ end
63
+ BitBucket.configuration.property_names.each do |key|
64
+ send("#{key}=", options[key])
65
+ end
66
+ process_basic_auth(options[:basic_auth])
67
+ end
68
+
69
+ # Extract login and password from basic_auth parameter
70
+ def process_basic_auth(auth)
71
+ case auth
72
+ when String
73
+ self.login, self.password = auth.split(':', 2)
74
+ when Hash
75
+ self.login = auth[:login]
76
+ self.password = auth[:password]
77
+ end
78
+ end
79
+
80
+ # Assigns current api class
81
+ def set_api_client
82
+ BitBucket.api_client = self
83
+ end
84
+
85
+ # Responds to attribute query or attribute clear
86
+ def method_missing(method, *args, &block) # :nodoc:
87
+ case method.to_s
88
+ when /^(.*)\?$/
89
+ return !self.send($1.to_s).nil?
90
+ when /^clear_(.*)$/
91
+ self.send("#{$1.to_s}=", nil)
92
+ else
93
+ super
94
+ end
95
+ end
96
+
97
+ # Acts as setter and getter for api requests arguments parsing.
98
+ #
99
+ # Returns Arguments instance.
100
+ #
101
+ def arguments(args=(not_set = true), options={}, &block)
102
+ if not_set
103
+ @arguments
104
+ else
105
+ @arguments = Arguments.new(options.merge!(api: self)).parse(*args, &block)
106
+ end
107
+ end
108
+
109
+ # Scope for passing request required arguments.
110
+ #
111
+ def with(args)
112
+ case args
113
+ when Hash
114
+ set args
115
+ when /.*\/.*/i
116
+ user, repo = args.split('/')
117
+ set :user => user, :repo => repo
118
+ else
119
+ ::Kernel.raise ArgumentError, 'This api does not support passed in arguments'
120
+ end
121
+ end
122
+
123
+ # Set a configuration option for a given namespace
124
+ #
125
+ # @param [String] option
126
+ # @param [Object] value
127
+ # @param [Boolean] ignore_setter
128
+ #
129
+ # @return [self]
130
+ #
131
+ # @api public
132
+ def set(option, value=(not_set=true), ignore_setter=false, &block)
133
+ raise ArgumentError, 'value not set' if block and !not_set
134
+ return self if !not_set and value.nil?
135
+
136
+ if not_set
137
+ set_options option
138
+ return self
139
+ end
140
+
141
+ if respond_to?("#{option}=") and not ignore_setter
142
+ return __send__("#{option}=", value)
143
+ end
144
+
145
+ define_accessors option, value
146
+ self
147
+ end
148
+
149
+ # Defines a namespace
150
+ #
151
+ # @param [Array[Symbol]] names
152
+ # the name for the scope
153
+ #
154
+ # @return [self]
155
+ #
156
+ # @api public
157
+ def self.namespace(*names)
158
+ options = names.last.is_a?(Hash) ? names.pop : {}
159
+ names = names.map(&:to_sym)
160
+ name = names.pop
161
+ return if public_method_defined?(name)
162
+
163
+ class_name = extract_class_name(name, options)
164
+ define_method(name) do |*args, &block|
165
+ options = args.last.is_a?(Hash) ? args.pop : {}
166
+ API::Factory.new(class_name, current_options.merge(options), &block)
167
+ end
168
+ self
169
+ end
170
+
171
+ # Extracts class name from options
172
+ #
173
+ # @param [Hash] options
174
+ # @option options [String] :full_name
175
+ # the full name for the class
176
+ # @option options [Boolean] :root
177
+ # if the class is at the root or not
178
+ #
179
+ # @return [String]
180
+ #
181
+ # @api private
182
+ def self.extract_class_name(name, options)
183
+ converted = options.fetch(:full_name, name).to_s
184
+ converted = converted.split('_').map(&:capitalize).join
185
+ class_name = options.fetch(:root, false) ? '': "#{self.name}::"
186
+ class_name += converted
187
+ class_name
188
+ end
189
+
190
+ def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
191
+ self.user = user_name || self.user
192
+ self.repo = repo_name || self.repo
193
+ end
194
+
195
+ def _merge_user_into_params!(params) # :nodoc:
196
+ params.merge!({ 'user' => self.user }) if user?
197
+ end
198
+
199
+ def _merge_user_repo_into_params!(params) # :nodoc:
200
+ { 'user' => self.user, 'repo' => self.repo }.merge!(params)
201
+ end
202
+
203
+
204
+ private
205
+
206
+ # Set multiple options
207
+ #
208
+ # @api private
209
+ def set_options(options)
210
+ unless options.respond_to?(:each)
211
+ raise ArgumentError, 'cannot iterate over value'
212
+ end
213
+ options.each { |key, value| set(key, value) }
214
+ end
215
+
216
+ # Define setters and getters
217
+ #
218
+ # @api private
219
+ def define_accessors(option, value)
220
+ setter = proc { |val| set option, val, true }
221
+ getter = proc { value }
222
+
223
+ define_singleton_method("#{option}=", setter) if setter
224
+ define_singleton_method(option, getter) if getter
225
+ end
226
+
227
+ # Dynamically define a method for setting request option
228
+ #
229
+ # @api private
230
+ def define_singleton_method(method_name, content=Proc.new)
231
+ (class << self; self; end).class_eval do
232
+ undef_method(method_name) if method_defined?(method_name)
233
+ if String === content
234
+ class_eval("def #{method_name}() #{content}; end")
235
+ else
236
+ define_method(method_name, &content)
237
+ end
238
+ end
239
+ end
240
+
241
+ end # API
242
+ end # BitBucket
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ module Authorization
5
+
6
+ # Check whether authentication credentials are present
7
+ def authenticated?
8
+ basic_authed? || oauth_token?
9
+ end
10
+
11
+ # Check whether basic authentication credentials are present
12
+ def basic_authed?
13
+ basic_auth? || (login? && password?)
14
+ end
15
+
16
+ # Select authentication parameters
17
+ def authentication
18
+ if basic_auth?
19
+ { :basic_auth => basic_auth }
20
+ elsif login? && password?
21
+ { :login => login, :password => password }
22
+ else
23
+ { }
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def _verify_client # :nodoc:
30
+ raise ArgumentError, 'Need to provide client_id and client_secret' unless client_id? && client_secret?
31
+ end
32
+
33
+ end # Authorization
34
+ end # BitBucket
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Invitations < API
5
+ @version = '1.0'
6
+
7
+ def invite(user_name, repo_name, emailaddress, perm)
8
+ _update_user_repo_params(user_name, repo_name)
9
+ _validate_user_repo_params(user, repo) unless user? && repo?
10
+ _validate_presence_of emailaddress
11
+ perm ||= "write"
12
+
13
+ post_request("/invitations/#{user}/#{repo.downcase}/#{emailaddress}", permission: perm)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Issues::Comments < API
5
+ @version = '1.0'
6
+
7
+ VALID_ISSUE_COMMENT_PARAM_NAME = %w[
8
+ content
9
+ ].freeze
10
+
11
+ # List comments on an issue
12
+ #
13
+ # = Examples
14
+ # bitbucket = BitBucket.new
15
+ # bitbucket.issues.comments.all 'user-name', 'repo-name', 'issue-id'
16
+ # bitbucket.issues.comments.all 'user-name', 'repo-name', 'issue-id' {|com| .. }
17
+ #
18
+ def list(user_name, repo_name, issue_id, params={})
19
+ _update_user_repo_params(user_name, repo_name)
20
+ _validate_user_repo_params(user, repo) unless user? && repo?
21
+ _validate_presence_of issue_id
22
+
23
+ normalize! params
24
+
25
+ response = get_request("/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
26
+ return response unless block_given?
27
+ response.each { |el| yield el }
28
+ end
29
+ alias :all :list
30
+
31
+ # Get a single comment
32
+ #
33
+ # = Examples
34
+ # bitbucket = BitBucket.new
35
+ # bitbucket.issues.comments.find 'user-name', 'repo-name', 'comment-id'
36
+ #
37
+ def get(user_name, repo_name, comment_id, params={})
38
+ _update_user_repo_params(user_name, repo_name)
39
+ _validate_user_repo_params(user, repo) unless user? && repo?
40
+ _validate_presence_of comment_id
41
+
42
+ normalize! params
43
+
44
+ get_request("/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
45
+ end
46
+ alias :find :get
47
+
48
+ # Create a comment
49
+ #
50
+ # = Inputs
51
+ # <tt>:content</tt> Required string
52
+ #
53
+ # = Examples
54
+ # bitbucket = BitBucket.new
55
+ # bitbucket.issues.comments.create 'user-name', 'repo-name', 'issue-id',
56
+ # "content" => 'a new comment'
57
+ #
58
+ def create(user_name, repo_name, issue_id, params={})
59
+ _update_user_repo_params(user_name, repo_name)
60
+ _validate_user_repo_params(user, repo) unless user? && repo?
61
+ _validate_presence_of issue_id
62
+
63
+ normalize! params
64
+ filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
65
+ assert_required_keys(%w[ content ], params)
66
+
67
+ post_request("/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/comments/", params)
68
+ end
69
+
70
+ # Edit a comment
71
+ #
72
+ # = Inputs
73
+ # <tt>:content</tt> Required string
74
+ #
75
+ # = Examples
76
+ # bitbucket = BitBucket.new
77
+ # bitbucket.issues.comments.edit 'user-name', 'repo-name', 'comment-id',
78
+ # "content" => 'a new comment'
79
+ #
80
+ def edit(user_name, repo_name, comment_id, params={})
81
+ _update_user_repo_params(user_name, repo_name)
82
+ _validate_user_repo_params(user, repo) unless user? && repo?
83
+ _validate_presence_of comment_id
84
+
85
+ normalize! params
86
+ filter! VALID_ISSUE_COMMENT_PARAM_NAME, params
87
+ assert_required_keys(%w[ content ], params)
88
+
89
+ put_request("/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}")
90
+ end
91
+
92
+ # Delete a comment
93
+ #
94
+ # = Examples
95
+ # bitbucket = BitBucket.new
96
+ # bitbucket.issues.comments.delete 'user-name', 'repo-name', 'comment-id'
97
+ #
98
+ def delete(user_name, repo_name, comment_id, params={})
99
+ _update_user_repo_params(user_name, repo_name)
100
+ _validate_user_repo_params(user, repo) unless user? && repo?
101
+ _validate_presence_of comment_id
102
+
103
+ normalize! params
104
+
105
+ delete_request("/repositories/#{user}/#{repo.downcase}/issues/comments/#{comment_id}", params)
106
+ end
107
+
108
+ end # Issues::Comments
109
+ end # BitBucket
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Issues::Components < API
5
+ @version = '1.0'
6
+
7
+ VALID_COMPONENT_INPUTS = %w[ name ].freeze
8
+
9
+ # List all components for a repository
10
+ #
11
+ # = Examples
12
+ # bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
13
+ # bitbucket.issues.components.list
14
+ # bitbucket.issues.components.list { |component| ... }
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}/issues/components", params)
22
+ return response unless block_given?
23
+ response.each { |el| yield el }
24
+ end
25
+ alias :all :list
26
+
27
+ # Get a single component
28
+ #
29
+ # = Examples
30
+ # bitbucket = BitBucket.new
31
+ # bitbucket.issues.components.find 'user-name', 'repo-name', 'component-id'
32
+ #
33
+ def get(user_name, repo_name, component_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 component_id
37
+ normalize! params
38
+
39
+ get_request("/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
40
+ end
41
+ alias :find :get
42
+
43
+ # Create a component
44
+ #
45
+ # = Inputs
46
+ # <tt>:name</tt> - Required string
47
+ #
48
+ # = Examples
49
+ # bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
50
+ # bitbucket.issues.components.create :name => 'API'
51
+ #
52
+ def create(user_name, repo_name, params={})
53
+ _update_user_repo_params(user_name, repo_name)
54
+ _validate_user_repo_params(user, repo) unless user? && repo?
55
+
56
+ normalize! params
57
+ filter! VALID_COMPONENT_INPUTS, params
58
+ assert_required_keys(VALID_COMPONENT_INPUTS, params)
59
+
60
+ post_request("/repositories/#{user}/#{repo.downcase}/issues/components", params)
61
+ end
62
+
63
+ # Update a component
64
+ #
65
+ # = Inputs
66
+ # <tt>:name</tt> - Required string
67
+ #
68
+ # = Examples
69
+ # @bitbucket = BitBucket.new
70
+ # @bitbucket.issues.components.update 'user-name', 'repo-name', 'component-id',
71
+ # :name => 'API'
72
+ #
73
+ def update(user_name, repo_name, component_id, params={})
74
+ _update_user_repo_params(user_name, repo_name)
75
+ _validate_user_repo_params(user, repo) unless user? && repo?
76
+ _validate_presence_of component_id
77
+
78
+ normalize! params
79
+ filter! VALID_COMPONENT_INPUTS, params
80
+ assert_required_keys(VALID_COMPONENT_INPUTS, params)
81
+
82
+ put_request("/repositories/#{user}/#{repo.downcase}/issues/components/#{component_id}", params)
83
+ end
84
+ alias :edit :update
85
+
86
+ # Delete a component
87
+ #
88
+ # = Examples
89
+ # bitbucket = BitBucket.new
90
+ # bitbucket.issues.components.delete 'user-name', 'repo-name', 'component-id'
91
+ #
92
+ def delete(user_name, repo_name, component_id, params={})
93
+ _update_user_repo_params(user_name, repo_name)
94
+ _validate_user_repo_params(user, repo) unless user? && repo?
95
+
96
+ _validate_presence_of component_id
97
+ normalize! params
98
+
99
+ delete_request("/repositories/#{user}/#{repo.downcase}/labels/components/#{component_id}", params)
100
+ end
101
+
102
+ end # Issues::Components
103
+ end # BitBucket