bitbuckets 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/Rakefile +1 -0
  5. data/lib/bitbucket_rest_api.rb +86 -0
  6. data/lib/bitbucket_rest_api/api.rb +104 -0
  7. data/lib/bitbucket_rest_api/api/actions.rb +32 -0
  8. data/lib/bitbucket_rest_api/api_factory.rb +29 -0
  9. data/lib/bitbucket_rest_api/authorization.rb +31 -0
  10. data/lib/bitbucket_rest_api/client.rb +53 -0
  11. data/lib/bitbucket_rest_api/configuration.rb +103 -0
  12. data/lib/bitbucket_rest_api/connection.rb +97 -0
  13. data/lib/bitbucket_rest_api/constants.rb +57 -0
  14. data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
  15. data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
  16. data/lib/bitbucket_rest_api/deprecation.rb +36 -0
  17. data/lib/bitbucket_rest_api/error.rb +37 -0
  18. data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
  19. data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
  20. data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
  21. data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
  22. data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
  23. data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
  24. data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
  25. data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
  26. data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
  27. data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
  28. data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
  29. data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
  30. data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
  31. data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
  32. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
  33. data/lib/bitbucket_rest_api/error/validations.rb +17 -0
  34. data/lib/bitbucket_rest_api/invitations.rb +14 -0
  35. data/lib/bitbucket_rest_api/issues.rb +229 -0
  36. data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
  37. data/lib/bitbucket_rest_api/issues/components.rb +105 -0
  38. data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
  39. data/lib/bitbucket_rest_api/normalizer.rb +24 -0
  40. data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
  41. data/lib/bitbucket_rest_api/repos.rb +276 -0
  42. data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
  43. data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
  44. data/lib/bitbucket_rest_api/repos/components.rb +35 -0
  45. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
  46. data/lib/bitbucket_rest_api/repos/download.rb +15 -0
  47. data/lib/bitbucket_rest_api/repos/following.rb +38 -0
  48. data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
  49. data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
  50. data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
  51. data/lib/bitbucket_rest_api/repos/services.rb +101 -0
  52. data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
  53. data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
  54. data/lib/bitbucket_rest_api/request.rb +71 -0
  55. data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
  56. data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
  57. data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
  58. data/lib/bitbucket_rest_api/response.rb +26 -0
  59. data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
  60. data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
  61. data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
  62. data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
  63. data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
  64. data/lib/bitbucket_rest_api/result.rb +136 -0
  65. data/lib/bitbucket_rest_api/teams.rb +91 -0
  66. data/lib/bitbucket_rest_api/user.rb +87 -0
  67. data/lib/bitbucket_rest_api/users.rb +20 -0
  68. data/lib/bitbucket_rest_api/users/account.rb +50 -0
  69. data/lib/bitbucket_rest_api/utils/url.rb +61 -0
  70. data/lib/bitbucket_rest_api/validations.rb +23 -0
  71. data/lib/bitbucket_rest_api/validations/format.rb +21 -0
  72. data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
  73. data/lib/bitbucket_rest_api/validations/required.rb +37 -0
  74. data/lib/bitbucket_rest_api/validations/token.rb +38 -0
  75. data/lib/bitbucket_rest_api/version.rb +10 -0
  76. data/lib/bitbuckets.rb +2 -0
  77. data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
  78. data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
  79. data/spec/bitbucket_rest_api/api_spec.rb +87 -0
  80. data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
  81. data/spec/bitbucket_rest_api/client_spec.rb +17 -0
  82. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
  83. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
  84. data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
  85. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
  86. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
  87. data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
  88. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  89. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  90. data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
  91. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
  92. data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
  93. data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
  94. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
  95. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
  96. data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
  97. data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
  98. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
  99. data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
  100. data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
  101. data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
  102. data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
  103. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
  104. data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
  105. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  106. data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
  107. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
  108. data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
  109. data/spec/bitbucket_rest_api/request_spec.rb +88 -0
  110. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
  111. data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
  112. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
  113. data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
  114. data/spec/bitbucket_rest_api/user_spec.rb +78 -0
  115. data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
  116. data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
  117. data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
  118. data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
  119. data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
  120. data/spec/bitbucket_rest_api_spec.rb +17 -0
  121. data/spec/spec_helper.rb +24 -0
  122. metadata +358 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b6f47d85ae45f4b90abaf6b37f8a062230d646cf278f00aa54b83080b1b0e5bf
4
+ data.tar.gz: 5933a332390d9759e5bd7cc23f5103357354b331f742640987d02de16bde7504
5
+ SHA512:
6
+ metadata.gz: 80fa406450ea309f0adc940f1950003c39528afa2f3a06ba04969c2b3c594d30f9e602184df8e2e1398e8879e2079c111b2508c84b6af6911434ddaf8b407d48
7
+ data.tar.gz: 58e9c623291ade237684e4586cef209fb69484effb16db16d1ed3dc64e451b47aabc4317e9a2544caa158ed66f6057497902ac56c1f98cbab0868ca52bc7ee22
@@ -0,0 +1,7 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,169 @@
1
+ # BitBucketAPI
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/bitbucket_rest_api.png)](http://badge.fury.io/rb/bitbucket_rest_api)
4
+
5
+ [Wiki](https://github.com/vongrippen/bitbucket/wiki) | [RDocs](http://rubydoc.info/github/vongrippen/bitbucket/master/frames)
6
+
7
+ A Ruby wrapper for the BitBucket REST API.
8
+
9
+ ## Installation
10
+
11
+ Install the gem by issuing
12
+
13
+ ```ruby
14
+ gem install bitbucket_rest_api
15
+ ```
16
+
17
+ or put it in your Gemfile and run `bundle install`
18
+
19
+ ```ruby
20
+ gem "bitbucket_rest_api"
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Create a new client instance
26
+
27
+ ```ruby
28
+ bitbucket = BitBucket.new
29
+ ```
30
+
31
+ At this stage you can also supply various configuration parameters, such as `:user`,`:repo`, `:oauth_token`, `:oauth_secret`, `:basic_auth` which are used throughout the API. These can be passed directly as hash options:
32
+
33
+ ```ruby
34
+ bitbucket = BitBucket.new oauth_token: 'request_token', oauth_secret: 'request_secret'
35
+ ```
36
+
37
+ Alternatively, you can configure the BitBucket settings by passing a block:
38
+
39
+ ```ruby
40
+ bitbucket = BitBucket.new do |config|
41
+ config.oauth_token = 'request_token'
42
+ config.oauth_secret = 'request_secret'
43
+ config.client_id = 'consumer_key'
44
+ config.client_secret = 'consumer_secret'
45
+ config.adapter = :net_http
46
+ end
47
+ ```
48
+
49
+ You can authenticate either using OAuth authentication or through basic authentication by passing your login and password credentials
50
+
51
+ ```ruby
52
+ bitbucket = BitBucket.new login:'vongrippen', password:'...'
53
+ ```
54
+
55
+ or use convenience method:
56
+
57
+ ```ruby
58
+ bitbucket = BitBucket.new basic_auth: 'login:password'
59
+ ```
60
+
61
+ You can interact with BitBucket interface, for example repositories, by issuing following calls that correspond directly to the BitBucket API hierarchy
62
+
63
+ ```ruby
64
+ bitbucket.repos.changesets.all 'user-name', 'repo-name'
65
+ bitbucket.repos.keys.list 'user-name', 'repo-name'
66
+ ```
67
+
68
+ The response is of type [Hashie::Mash] and allows to traverse all the json response attributes like method calls.
69
+
70
+ ## Inputs
71
+
72
+ Some API methods apart from required parameters such as username or repository name
73
+ allow you to switch the way the data is returned to you, for instance by passing
74
+ a block you can iterate over the list of repositories
75
+
76
+ ```ruby
77
+ bitbucket.repos.list do |repo|
78
+ puts repo.slug
79
+ end
80
+ ```
81
+
82
+ ## Advanced Configuration
83
+
84
+ The `bitbucket_rest_api` gem will use the default middleware stack which is exposed by calling `stack` on client instance. However, this stack can be freely modified with methods such as `insert`, `insert_after`, `delete` and `swap`. For instance to add your `CustomMiddleware` do
85
+
86
+ ```ruby
87
+ bitbucket = BitBucket.new do |config|
88
+ config.stack.insert_after BitBucket::Response::Helpers, CustomMiddleware
89
+ end
90
+ ```
91
+
92
+ Furthermore, you can build your entire custom stack and specify other connection options such as `adapter`
93
+
94
+ ```ruby
95
+ bitbucket = BitBucket.new do |config|
96
+ config.adapter :excon
97
+
98
+ config.stack do |builder|
99
+ builder.use BitBucket::Response::Helpers
100
+ builder.use BitBucket::Response::Jsonize
101
+ end
102
+ end
103
+ ```
104
+
105
+ ## API
106
+
107
+ Main API methods are grouped into the following classes that can be instantiated on their own
108
+
109
+ ```ruby
110
+ BitBucket - full API access
111
+
112
+ BitBucket::Repos BitBucket::Issues
113
+ ```
114
+
115
+ Some parts of BitBucket API require you to be authenticated, for instance the following are examples of APIs only for the authenticated user
116
+
117
+ ```ruby
118
+ BitBucket::Issues::Create
119
+ ```
120
+
121
+ You can find out supported methods by calling `actions` on a class instance in your `irb`:
122
+
123
+ ```ruby
124
+ >> BitBucket::Repos.actions >> bitbucket.issues.actions
125
+ --- ---
126
+ |--> all |--> all
127
+ |--> branches |--> comments
128
+ |--> collaborators |--> create
129
+ |--> commits |--> edit
130
+ |--> contribs |--> events
131
+ |--> contributors |--> find
132
+ |--> create |--> get
133
+ |--> downloads |--> labels
134
+ |--> edit |--> list
135
+ |--> find |--> list_repo
136
+ |--> forks |--> list_repository
137
+ |--> get |--> milestones
138
+ |--> hooks ...
139
+ ...
140
+ ```
141
+
142
+ ## Configuration
143
+
144
+ Certain methods require authentication. To get your BitBucket OAuth credentials,
145
+ register an app with BitBucket.
146
+
147
+ ```ruby
148
+ BitBucket.configure do |config|
149
+ config.oauth_token = YOUR_OAUTH_REQUEST_TOKEN # Different for each user
150
+ config.oauth_secret = YOUR_OAUTH_REQUEST_TOKEN_SECRET # Different for each user
151
+ config.client_id = YOUR_OAUTH_CONSUMER_TOKEN
152
+ config.client_secret = YOUR_OAUTH_CONSUMER_TOKEN_SECRET
153
+ config.basic_auth = 'login:password'
154
+ end
155
+
156
+ or
157
+
158
+ BitBucket.new(:oauth_token => YOUR_OAUTH_REQUEST_TOKEN, :oauth_secret => YOUR_OAUTH_REQUEST_TOKEN_SECRET)
159
+ BitBucket.new(:basic_auth => 'login:password')
160
+ ```
161
+
162
+ ## Development
163
+
164
+ Questions or problems? Please post them on the [issue tracker](https://bitbucket.com/vongrippen/bitbucket/issues). You can contribute changes by forking the project and submitting a pull request. You can ensure the tests are passing by running `bundle` and `rake`.
165
+
166
+ ## Copyright
167
+
168
+ Copyright (c) 2012 James M Cochran.
169
+ Original github_api gem Copyright (c) 2011-2012 Piotr Murach. See LICENSE.txt for further details.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ require 'bitbucket_rest_api/version'
3
+ require 'bitbucket_rest_api/configuration'
4
+ require 'bitbucket_rest_api/constants'
5
+ require 'bitbucket_rest_api/utils/url'
6
+ require 'bitbucket_rest_api/connection'
7
+ require 'bitbucket_rest_api/deprecation'
8
+
9
+ module BitBucket
10
+ extend Configuration
11
+
12
+ class << self
13
+ # Handle for the client instance
14
+ attr_accessor :api_client
15
+
16
+ # Alias for BitBucket::Client.new
17
+ #
18
+ # @return [BitBucket::Client]
19
+ def new(options = {}, &block)
20
+ @api_client = BitBucket::Client.new(options, &block)
21
+ end
22
+
23
+ # Delegate to BitBucket::Client
24
+ #
25
+ def method_missing(method, *args, &block)
26
+ return super unless new.respond_to?(method)
27
+
28
+ new.send(method, *args, &block)
29
+ end
30
+
31
+ def respond_to?(method, include_private = false)
32
+ new.respond_to?(method, include_private) || super(method, include_private)
33
+ end
34
+ end
35
+
36
+ module AutoloadHelper
37
+ def autoload_all(prefix, options)
38
+ options.each do |const_name, path|
39
+ autoload const_name, File.join(prefix, path)
40
+ end
41
+ end
42
+
43
+ def register_constant(options)
44
+ options.each do |const_name, value|
45
+ const_set const_name.upcase.to_s, value
46
+ end
47
+ end
48
+
49
+ def lookup_constant(const_name)
50
+ const_get const_name.upcase.to_s
51
+ end
52
+ end
53
+
54
+ extend AutoloadHelper
55
+
56
+ autoload_all 'bitbucket_rest_api',
57
+ API: 'api',
58
+ ApiFactory: 'api_factory',
59
+ Authorization: 'authorization',
60
+ Authorizations: 'authorizations',
61
+ Validations: 'validations',
62
+ ParameterFilter: 'parameter_filter',
63
+ Normalizer: 'normalizer',
64
+ Client: 'client',
65
+ CoreExt: 'core_ext',
66
+ Request: 'request',
67
+ Response: 'response',
68
+ Result: 'result',
69
+
70
+ Repos: 'repos',
71
+ #:Error => 'error',
72
+ Issues: 'issues',
73
+ User: 'user',
74
+ Users: 'users',
75
+ Invitations: 'invitations',
76
+ Teams: 'teams'
77
+
78
+ #:Teams => 'teams',
79
+ #:PullRequests => 'pull_requests',
80
+ #:Users => 'users',
81
+ #:Events => 'events',
82
+ #:Search => 'search',
83
+ #:PageLinks => 'page_links',
84
+ #:PageIterator => 'page_iterator',
85
+ #:PagedRequest => 'paged_request'
86
+ end # BitBucket
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+ require 'bitbucket_rest_api/configuration'
3
+ require 'bitbucket_rest_api/connection'
4
+ require 'bitbucket_rest_api/validations'
5
+ require 'bitbucket_rest_api/request'
6
+ require 'bitbucket_rest_api/core_ext/hash'
7
+ require 'bitbucket_rest_api/core_ext/array'
8
+ require 'bitbucket_rest_api/api/actions'
9
+ require 'bitbucket_rest_api/api_factory'
10
+
11
+ module BitBucket
12
+ class API
13
+ include Authorization
14
+ include Connection
15
+ include Request
16
+
17
+ # TODO: consider these optional in a stack
18
+ include Validations
19
+ include ParameterFilter
20
+ include Normalizer
21
+
22
+ attr_reader *Configuration::VALID_OPTIONS_KEYS
23
+
24
+ attr_accessor *VALID_API_KEYS
25
+
26
+ # Callback to update global configuration options
27
+ class_eval do
28
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
29
+ define_method "#{key}=" do |arg|
30
+ instance_variable_set("@#{key}", arg)
31
+ BitBucket.send("#{key}=", arg)
32
+ end
33
+ end
34
+ end
35
+
36
+ # Creates new API
37
+ def initialize(options = {}, &block)
38
+ super()
39
+ setup options
40
+ set_api_client
41
+
42
+ instance_eval(&block) if block_given?
43
+ end
44
+
45
+ def setup(options = {})
46
+ options = BitBucket.options.merge(options)
47
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
48
+ send("#{key}=", options[key])
49
+ end
50
+ process_basic_auth(options[:basic_auth])
51
+ end
52
+
53
+ # Extract login and password from basic_auth parameter
54
+ def process_basic_auth(auth)
55
+ case auth
56
+ when String
57
+ self.login, self.password = auth.split(':', 2)
58
+ when Hash
59
+ self.login = auth[:login]
60
+ self.password = auth[:password]
61
+ end
62
+ end
63
+
64
+ # Assigns current api class
65
+ def set_api_client
66
+ BitBucket.api_client = self
67
+ end
68
+
69
+ # Responds to attribute query or attribute clear
70
+ def method_missing(method, *args, &block) # :nodoc:
71
+ case method.to_s
72
+ when /^(.*)\?$/
73
+ !send(Regexp.last_match(1).to_s).nil?
74
+ when /^clear_(.*)$/
75
+ send("#{Regexp.last_match(1)}=", nil)
76
+ else
77
+ super
78
+ end
79
+ end
80
+
81
+ def update_and_validate_user_repo_params(user_name, repo_name = nil)
82
+ _update_user_repo_params(user_name, repo_name)
83
+ _validate_user_repo_params(user, repo) unless user? && repo?
84
+ end
85
+
86
+ def _update_user_repo_params(user_name, repo_name = nil) # :nodoc:
87
+ self.user = user_name || user
88
+ self.repo = repo_name || repo
89
+ end
90
+
91
+ def _merge_user_into_params!(params) # :nodoc:
92
+ params.merge!('user' => user) if user?
93
+ end
94
+
95
+ def _merge_user_repo_into_params!(params) # :nodoc:
96
+ { 'user' => user, 'repo' => repo }.merge!(params)
97
+ end
98
+
99
+ def _merge_mime_type(resource, params) # :nodoc:
100
+ # params['resource'] = resource
101
+ # params['mime_type'] = params['mime_type'] || :raw
102
+ end
103
+ end # API
104
+ end # BitBucket
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ class API
4
+ # Returns all API public methods for a given class.
5
+ def self.inherited(klass)
6
+ klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
7
+ def self.actions
8
+ self.new.api_methods_in(#{klass})
9
+ end
10
+ def actions
11
+ api_methods_in(#{klass})
12
+ end
13
+ RUBY_EVAL
14
+ super
15
+ end
16
+
17
+ def api_methods_in(klass)
18
+ methods = []
19
+ (klass.send(:instance_methods, false) - ['actions']).sort.each do |method|
20
+ methods << method
21
+ end
22
+ klass.included_modules.each do |mod|
23
+ next unless mod.to_s =~ /#{klass}/
24
+
25
+ mod.instance_methods(false).each do |met|
26
+ methods << met
27
+ end
28
+ end
29
+ methods
30
+ end
31
+ end # API
32
+ end # BitBucket
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require 'bitbucket_rest_api/core_ext/hash'
3
+
4
+ module BitBucket
5
+ class ApiFactory
6
+ # Instantiates a new bitbucket api object
7
+ def self.new(klass, options = {})
8
+ return create_instance(klass, options) if klass
9
+
10
+ raise ArgumentError, 'must provide klass to be instantiated'
11
+ end
12
+
13
+ # Passes configuration options to instantiated class
14
+ def self.create_instance(klass, options)
15
+ options.symbolize_keys!
16
+ instance = convert_to_constant(klass.to_s).new options
17
+ BitBucket.api_client = instance
18
+ instance
19
+ end
20
+
21
+ def self.convert_to_constant(classes)
22
+ constant = BitBucket
23
+ classes.split('::').each do |klass|
24
+ constant = constant.const_get klass
25
+ end
26
+ constant
27
+ end
28
+ end
29
+ end # BitBucket
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Authorization
4
+ # Check whether authentication credentials are present
5
+ def authenticated?
6
+ basic_authed? || oauth_token?
7
+ end
8
+
9
+ # Check whether basic authentication credentials are present
10
+ def basic_authed?
11
+ basic_auth? || (login? && password?)
12
+ end
13
+
14
+ # Select authentication parameters
15
+ def authentication
16
+ if basic_auth?
17
+ { basic_auth: basic_auth }
18
+ elsif login? && password?
19
+ { login: login, password: password }
20
+ else
21
+ {}
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def _verify_client # :nodoc:
28
+ raise ArgumentError, 'Need to provide client_id and client_secret' unless client_id? && client_secret?
29
+ end
30
+ end # Authorization
31
+ end # BitBucket