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,54 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client::Users::Account < API
5
+ @version = '1.0'
6
+
7
+ # API about users/account , please refer to
8
+ # https://confluence.atlassian.com/display/BITBUCKET/account+Resource
9
+ #
10
+
11
+
12
+ # GET the account profile
13
+ #
14
+ def profile(accountname)
15
+ response = get_request("/users/#{accountname}")
16
+ end
17
+
18
+ # GET the account plan
19
+ def plan(accountname)
20
+ response = get_request("/users/#{accountname}/plan")
21
+ end
22
+
23
+ # GET the emails
24
+ def emails(accountname)
25
+ response = get_request("/users/#{accountname}/emails")
26
+ end
27
+
28
+ # GET the followers
29
+ def followers(accountname)
30
+ response = get_request("/users/#{accountname}/followers")
31
+ end
32
+
33
+ # GET the events
34
+ def events(accountname)
35
+ response = get_request("/users/#{accountname}/events")
36
+ end
37
+
38
+ #GET the keys
39
+ def keys(accountname)
40
+ response = get_request("/users/#{accountname}/ssh-keys")
41
+ end
42
+
43
+ #POST a new key
44
+ # params should be in format {key: "", label:""}
45
+ def new_key(accountname, params)
46
+ response = post_request("/users/#{accountname}/ssh-keys/", params)
47
+ end
48
+
49
+ #DELETE a key
50
+ def delete_key(accountname, key_id)
51
+ response = delete_request("/users/#{accountname}/ssh-keys/#{key_id}")
52
+ end
53
+ end # Users::Account
54
+ end # BitBucket
@@ -0,0 +1,14 @@
1
+
2
+ # encoding: utf-8
3
+
4
+ module BitBucket
5
+ class Client::Users < API
6
+
7
+ require_all 'bitbucket_rest_api/client/users', 'account'
8
+
9
+ @version = '1.0'
10
+
11
+ namespace :account
12
+
13
+ end # Client
14
+ end # BitBucket
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ class Client < API
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
+
30
+ # This is a read-only API to the BitBucket events.
31
+ # These events power the various activity streams on the site.
32
+ def events(options = {})
33
+ raise "Unimplemented"
34
+ #@events ||= Api::Factory.new 'Events', options
35
+ end
36
+
37
+ # An API for users to manage their own tokens.
38
+ def oauth(options = {})
39
+ raise "Unimpletmented"
40
+ #@oauth ||= Api::Factory.new 'Authorizations', options
41
+ end
42
+ alias :authorizations :oauth
43
+
44
+ def teams(options = {})
45
+ raise "Unimplemented"
46
+ #@teams ||= Api::Factory.new 'teams', options
47
+ end
48
+
49
+ def search(options = {})
50
+ raise "Unimplemented"
51
+ #@search ||= Api::Factory.new 'Search', options
52
+ end
53
+ end # Client
54
+ end # BitBucket
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ if RUBY_VERSION < "1.9"
4
+
5
+ def ruby_18 #:nodoc:
6
+ yield
7
+ end
8
+
9
+ def ruby_19 #:nodoc:
10
+ false
11
+ end
12
+
13
+ else
14
+
15
+ def ruby_18 #:nodoc:
16
+ false
17
+ end
18
+
19
+ def ruby_19 #:nodoc:
20
+ yield
21
+ end
22
+
23
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bitbucket_rest_api/api/config'
4
+
5
+ module BitBucket
6
+ # Stores the configuration
7
+ class Configuration < API::Config
8
+
9
+ # Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
10
+ property :adapter, default: :net_http
11
+
12
+ # By default, don't set an application key
13
+ property :client_id, default: nil
14
+
15
+ # By default, don't set an application secret
16
+ property :client_secret, default: nil
17
+
18
+ # By default, don't set a user oauth access token
19
+ property :oauth_token, default: nil
20
+
21
+ # By default, don't set a user oauth access token secret
22
+ property :oauth_secret, default: nil
23
+
24
+ # By default, don't set a user login name
25
+ property :login, default: nil
26
+
27
+ # By default, don't set a user password
28
+ property :password, default: nil
29
+
30
+ # By default, don't set a user basic authentication
31
+ property :basic_auth, default: nil
32
+
33
+ # The endpoint used to connect to BitBucket if none is set, in the event that BitBucket is ever available on location
34
+ property :endpoint, default: 'https://bitbucket.org/api/1.0'.freeze
35
+ property :endpoint_v2, default: 'https://api.bitbucket.org/2.0'.freeze
36
+
37
+ # The value sent in the http header for 'User-Agent' if none is set
38
+ property :user_agent, default: "BitBucket Ruby Gem #{BitBucket::VERSION::STRING}".freeze
39
+
40
+ # By default the <tt>Accept</tt> header will make a request for <tt>JSON</tt>
41
+ property :mime_type, default: :json
42
+
43
+ # By default uses the Faraday connection options if none is set
44
+ property :connection_options, default: { }
45
+
46
+ # By default, don't set user name
47
+ property :user, default: nil
48
+
49
+ # By default, don't set repository name
50
+ property :repo, default: nil
51
+
52
+ # By default, don't auto-paginate results
53
+ property :auto_pagination, default: false
54
+
55
+ # Add Faraday::RackBuilder to overwrite middleware
56
+ property :stack
57
+
58
+ end # Configuration
59
+ end # BitBucket
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ module Connection
5
+ extend self
6
+ include BitBucket::Constants
7
+
8
+ ALLOWED_OPTIONS = [
9
+ :headers,
10
+ :url,
11
+ :params,
12
+ :request,
13
+ :ssl,
14
+ :builder,
15
+ :api
16
+ ].freeze
17
+
18
+ def default_options(options={})
19
+ {
20
+ :headers => {
21
+ USER_AGENT => options[:user_agent]
22
+ },
23
+ :ssl => { :verify => false },
24
+ :url => options.fetch(:endpoint) { BitBucket.endpoint }
25
+ }.merge(options)
26
+ end
27
+
28
+ def clear_cache
29
+ @connection = nil
30
+ end
31
+
32
+ def caching?
33
+ !@connection.nil?
34
+ end
35
+
36
+ # Exposes middleware builder to facilitate custom stacks and easy
37
+ # addition of new extensions such as cache adapter.
38
+ #
39
+ def stack(options={})
40
+ @stack ||= begin
41
+ builder_class = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
42
+ builder_class.new(&BitBucket.default_middleware(options))
43
+ end
44
+ end
45
+
46
+ # Returns a Fraday::Connection object
47
+ #
48
+ def connection(api, options = {})
49
+ connection_options = default_options(options)
50
+ clear_cache unless options.empty?
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']
56
+
57
+ @connection ||= Faraday.new(connection_options)
58
+ end
59
+
60
+ end # Connection
61
+ end # BitBucket
@@ -0,0 +1,50 @@
1
+ module BitBucket
2
+ module Constants
3
+ extend self
4
+
5
+ # Response headers
6
+ RATELIMIT_REMAINING = 'X-RateLimit-Remaining'.freeze
7
+
8
+ RATELIMIT_LIMIT = 'X-RateLimit-Limit'.freeze
9
+
10
+ CONTENT_TYPE = 'Content-Type'.freeze
11
+
12
+ CONTENT_LENGTH = 'content-length'.freeze
13
+
14
+ CACHE_CONTROL = 'cache-control'.freeze
15
+
16
+ ETAG = 'ETag'.freeze
17
+
18
+ SERVER = 'Server'.freeze
19
+
20
+ DATE = 'Date'.freeze
21
+
22
+ LOCATION = 'Location'.freeze
23
+
24
+ USER_AGENT = 'User-Agent'.freeze
25
+
26
+ ACCEPT = 'Accept'.freeze
27
+
28
+ ACCEPT_CHARSET = 'Accept-Charset'.freeze
29
+
30
+ # Link params
31
+ META_REL = "rel".freeze
32
+
33
+ META_LAST = "last".freeze
34
+
35
+ META_NEXT = "next".freeze
36
+
37
+ META_FIRST = "first".freeze
38
+
39
+ META_PREV = "prev".freeze
40
+
41
+ PARAM_PAGE = "page".freeze
42
+
43
+ PARAM_START_PAGE = "start_page".freeze
44
+
45
+ # URI parsing
46
+ QUERY_STR_SEP = '?'.freeze
47
+
48
+
49
+ end # Constants
50
+ end # BitBucket
@@ -0,0 +1,17 @@
1
+ class Array # :nodoc:
2
+
3
+ def except(*keys) # :nodoc:
4
+ self.dup.except!(*keys)
5
+ end unless method_defined?(:except)
6
+
7
+ def except!(*items) # :nodoc:
8
+ copy = self.dup
9
+ copy.reject! { |item| items.include? item }
10
+ copy
11
+ end unless method_defined?(:except!)
12
+
13
+ def extract_options!
14
+ last.is_a?(::Hash) ? pop : {}
15
+ end unless method_defined?(:extract_options!)
16
+
17
+ end # Array
@@ -0,0 +1,56 @@
1
+ class Hash # :nodoc:
2
+
3
+ def except(*items) # :nodoc:
4
+ self.dup.except!(*items)
5
+ end unless method_defined?(:except)
6
+
7
+ def except!(*keys) # :nodoc:
8
+ copy = self.dup
9
+ keys.each { |key| copy.delete!(key) }
10
+ copy
11
+ end unless method_defined?(:except!)
12
+
13
+ def symbolize_keys # :nodoc:
14
+ inject({}) do |hash, (key, value)|
15
+ hash[(key.to_sym rescue key) || key] = value
16
+ hash
17
+ end
18
+ end unless method_defined?(:symbolize_keys)
19
+
20
+ def symbolize_keys! # :nodoc:
21
+ hash = symbolize_keys
22
+ hash.each do |key, val|
23
+ hash[key] = case val
24
+ when Hash
25
+ val.symbolize_keys!
26
+ when Array
27
+ val.map do |item|
28
+ item.is_a?(Hash) ? item.symbolize_keys! : item
29
+ end
30
+ else
31
+ val
32
+ end
33
+ end
34
+ return hash
35
+ end unless method_defined?(:symbolize_keys!)
36
+
37
+ def serialize # :nodoc:
38
+ self.map { |key, val| [key, val].join("=") }.join("&")
39
+ end unless method_defined?(:serialize)
40
+
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 unless method_defined?(:all_keys)
51
+
52
+ def has_deep_key?(key)
53
+ self.all_keys.include? key
54
+ end unless method_defined?(:has_deep_key?)
55
+
56
+ end # Hash
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ module CoreExt #:nodoc:
5
+
6
+ if RUBY_VERSION >= '1.9'
7
+ class OrderedHash < ::Hash; end
8
+ else
9
+ class OrderedHash < ::Hash
10
+ attr_accessor :order
11
+
12
+ class << self
13
+ def [](*args)
14
+ hsh = OrderedHash.new
15
+ if Hash == args[0]
16
+ hsh.replace args[0]
17
+ elsif (args.size % 2) != 0
18
+ pp args
19
+ raise ArgumentError, "odd number of elements for Hash"
20
+ else
21
+ 0.step(args.size - 1, 2) do |a|
22
+ b = a + 1
23
+ hsh[args[a]] = args[b]
24
+ end
25
+ end
26
+ hsh
27
+ end
28
+ end
29
+
30
+ def initialize(*args, &block)
31
+ super
32
+ @order = []
33
+ end
34
+
35
+ def []=(key, value)
36
+ @order.push key unless member?(key)
37
+ super key, value
38
+ end
39
+
40
+ def ==(hsh2)
41
+ return false if @order != hsh2.order
42
+ super hsh2
43
+ end
44
+
45
+ def clear
46
+ @order = []
47
+ super
48
+ end
49
+
50
+ def delete(key)
51
+ @order.delete key
52
+ super
53
+ end
54
+
55
+ def each_key
56
+ @order.each { |k| yield k }
57
+ self
58
+ end
59
+
60
+ def each_value
61
+ @order.each { |k| yield self[k] }
62
+ self
63
+ end
64
+
65
+ def each
66
+ @order.each { |k| yield k, self[k] }
67
+ self
68
+ end
69
+ alias :each_pair :each
70
+
71
+ def delete_if
72
+ @order.clone.each { |k| delete k if yield }
73
+ self
74
+ end
75
+
76
+ def values
77
+ ary = []
78
+ @order.each { |k| ary.push self[k] }
79
+ ary
80
+ end
81
+
82
+ def keys
83
+ @order
84
+ end
85
+
86
+ def replace(hsh2)
87
+ @order = hsh2.keys
88
+ super hsh2
89
+ end
90
+
91
+ def shift
92
+ key = @order.first
93
+ key ? [key, delete(key)] : super
94
+ end
95
+
96
+ def class
97
+ Hash
98
+ end
99
+
100
+ def __class__
101
+ OrderedHash
102
+ end
103
+ end # OrderedHash
104
+ end
105
+
106
+ end # CoreExt
107
+ end # BitBucket
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+
5
+ DEPRECATION_PREFIX = "[BitBucketAPI] Deprecation warning:"
6
+
7
+ class << self
8
+
9
+ attr_writer :deprecation_tracker
10
+
11
+ def deprecation_tracker
12
+ @deprecation_tracker ||= []
13
+ end
14
+
15
+ # Displays deprecation message to the user.
16
+ # Each message is printed once.
17
+ def deprecate(method, alternate_method=nil)
18
+ return if deprecation_tracker.include? method
19
+ deprecation_tracker << method
20
+
21
+ message = <<-NOTICE
22
+ #{DEPRECATION_PREFIX}
23
+
24
+ * #{method} is deprecated.
25
+ NOTICE
26
+ if alternate_method
27
+ message << <<-ADDITIONAL
28
+ * please use #{alternate_method} instead.
29
+ ADDITIONAL
30
+ end
31
+ warn_deprecation(message)
32
+ end
33
+
34
+ def warn_deprecation(message)
35
+ send :warn, message
36
+ end
37
+ end
38
+
39
+ end # BitBucket
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket
4
+ module Error
5
+ # Raised when BitBucket returns the HTTP status code 400
6
+ class BadRequest < ServiceError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end
12
+ end # BitBucket
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns the HTTP status code 404
5
+ module Error
6
+ class ClientError < BitBucketError
7
+ attr_reader :problem, :summary, :resolution
8
+
9
+ def initialize(message)
10
+ super(message)
11
+ end
12
+
13
+ def generate_message(attributes)
14
+ "\nProblem:\n #{attributes[:problem]}"+
15
+ "\nSummary:\n #{attributes[:summary]}"+
16
+ "\nResolution:\n #{attributes[:resolution]}"
17
+ end
18
+ end
19
+ end # Error
20
+ end # BitBucket
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns the HTTP status code 403
5
+ module Error
6
+ class Forbidden < BitBucketError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # BitBucket
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns the HTTP status code 500
5
+ module Error
6
+ class InternalServerError < BitBucketError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # BitBucket
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when invalid options are passed to a request body
5
+ module Error
6
+ class InvalidOptions < ClientError
7
+ def initialize(invalid, valid)
8
+ super(
9
+ generate_message(
10
+ :problem => "Invalid option #{invalid.keys.join(', ')} provided for this request.",
11
+ :summary => "BitBucket gem checks the request parameters passed to ensure that bitbucket api is not hit unnecessairly and to fail fast.",
12
+ :resolution => "Valid options are: #{valid.join(', ')}, make sure these are the ones you are using"
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end # Error
18
+ end # BitBucket
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns the HTTP status code 404
5
+ module Error
6
+ class NotFound < ServiceError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # BitBucket
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when invalid options are passed to a request body
5
+ module Error
6
+ class RequiredParams < ClientError
7
+ def initialize(provided, required)
8
+ super(
9
+ generate_message(
10
+ :problem => "Missing required parameters: #{provided.keys.join(', ')} provided for this request.",
11
+ :summary => "BitBucket gem checks the request parameters passed to ensure that bitbucket api is not hit unnecessairly and to fail fast.",
12
+ :resolution => "Required parameters are: #{required.join(', ')}, make sure these are the ones you are using"
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end # Error
18
+ end # BitBucket
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns any of the HTTP status codes
5
+ module Error
6
+ class ServiceError < BitBucketError
7
+ attr_accessor :http_headers
8
+
9
+ def initialize(env)
10
+ super(generate_message(env))
11
+ @http_headers = env[:response_headers]
12
+ end
13
+
14
+ def generate_message(env)
15
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]} #{env[:body]}"
16
+ end
17
+ end
18
+ end # Error
19
+ end # BitBucket
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module BitBucket #:nodoc
4
+ # Raised when BitBucket returns the HTTP status code 404
5
+ module Error
6
+ class ServiceUnavailable < BitBucketError
7
+ def initialize(env)
8
+ super(env)
9
+ end
10
+ end
11
+ end # Error
12
+ end # BitBucket