reenhanced_bitbucket_api 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +43 -0
- data/README.md +169 -0
- data/Rakefile +3 -0
- data/lib/bitbucket_rest_api/api/actions.rb +50 -0
- data/lib/bitbucket_rest_api/api.rb +120 -0
- data/lib/bitbucket_rest_api/api_factory.rb +30 -0
- data/lib/bitbucket_rest_api/authorization.rb +34 -0
- data/lib/bitbucket_rest_api/client.rb +58 -0
- data/lib/bitbucket_rest_api/compatibility.rb +23 -0
- data/lib/bitbucket_rest_api/configuration.rb +101 -0
- data/lib/bitbucket_rest_api/connection.rb +96 -0
- data/lib/bitbucket_rest_api/constants.rb +58 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +17 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +56 -0
- data/lib/bitbucket_rest_api/core_ext/ordered_hash.rb +107 -0
- data/lib/bitbucket_rest_api/deprecation.rb +39 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
- data/lib/bitbucket_rest_api/error/client_error.rb +20 -0
- data/lib/bitbucket_rest_api/error/forbidden.rb +12 -0
- data/lib/bitbucket_rest_api/error/internal_server_error.rb +12 -0
- data/lib/bitbucket_rest_api/error/invalid_options.rb +18 -0
- data/lib/bitbucket_rest_api/error/not_found.rb +12 -0
- data/lib/bitbucket_rest_api/error/required_params.rb +18 -0
- data/lib/bitbucket_rest_api/error/service_error.rb +19 -0
- data/lib/bitbucket_rest_api/error/service_unavailable.rb +12 -0
- data/lib/bitbucket_rest_api/error/unauthorized.rb +12 -0
- data/lib/bitbucket_rest_api/error/unknown_value.rb +18 -0
- data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +12 -0
- data/lib/bitbucket_rest_api/error/validations.rb +18 -0
- data/lib/bitbucket_rest_api/error.rb +35 -0
- data/lib/bitbucket_rest_api/invitations.rb +15 -0
- data/lib/bitbucket_rest_api/issues/comments.rb +118 -0
- data/lib/bitbucket_rest_api/issues/components.rb +106 -0
- data/lib/bitbucket_rest_api/issues/milestones.rb +107 -0
- data/lib/bitbucket_rest_api/issues.rb +230 -0
- data/lib/bitbucket_rest_api/normalizer.rb +27 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
- data/lib/bitbucket_rest_api/repos/following.rb +39 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +87 -0
- data/lib/bitbucket_rest_api/repos/services.rb +103 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +31 -0
- data/lib/bitbucket_rest_api/repos.rb +238 -0
- data/lib/bitbucket_rest_api/request/basic_auth.rb +31 -0
- data/lib/bitbucket_rest_api/request/jsonize.rb +46 -0
- data/lib/bitbucket_rest_api/request/oauth.rb +51 -0
- data/lib/bitbucket_rest_api/request.rb +67 -0
- data/lib/bitbucket_rest_api/response/helpers.rb +21 -0
- data/lib/bitbucket_rest_api/response/jsonize.rb +30 -0
- data/lib/bitbucket_rest_api/response/mashify.rb +24 -0
- data/lib/bitbucket_rest_api/response/raise_error.rb +31 -0
- data/lib/bitbucket_rest_api/response/xmlize.rb +26 -0
- data/lib/bitbucket_rest_api/response.rb +28 -0
- data/lib/bitbucket_rest_api/result.rb +140 -0
- data/lib/bitbucket_rest_api/user.rb +101 -0
- data/lib/bitbucket_rest_api/users/account.rb +53 -0
- data/lib/bitbucket_rest_api/users.rb +24 -0
- data/lib/bitbucket_rest_api/utils/url.rb +56 -0
- data/lib/bitbucket_rest_api/validations/format.rb +24 -0
- data/lib/bitbucket_rest_api/validations/presence.rb +25 -0
- data/lib/bitbucket_rest_api/validations/required.rb +24 -0
- data/lib/bitbucket_rest_api/validations/token.rb +43 -0
- data/lib/bitbucket_rest_api/validations.rb +25 -0
- data/lib/bitbucket_rest_api/version.rb +11 -0
- data/lib/bitbucket_rest_api.rb +91 -0
- metadata +338 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d277a40d6a0329bdffe0c73a4f763114ab5bce42
|
4
|
+
data.tar.gz: a57c2f43ffbf60bb800b1118054d3a10637b6c39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25fdcd0f4b728c37f7bb4ecaa6dc10c300f335dfd83647de539732da2f62e4d9cf986797e4402c5c5431257764504fde6fe1efab8b466b1cb9123a68a3612b00
|
7
|
+
data.tar.gz: bb139a3ab32b6ef2ce5a372c13ccb778e6b0ec6d435a8a09f27cfe7d4cf89d993c3db69e7533f731e7c83e7ebb37245c406f39a5e5c8d8e0e2c949d0aecccdcb
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Copyright (c) 2013 James M Cochran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Original github_api project:
|
24
|
+
Copyright (c) 2011 Piotr Murach
|
25
|
+
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
27
|
+
a copy of this software and associated documentation files (the
|
28
|
+
"Software"), to deal in the Software without restriction, including
|
29
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
30
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
31
|
+
permit persons to whom the Software is furnished to do so, subject to
|
32
|
+
the following conditions:
|
33
|
+
|
34
|
+
The above copyright notice and this permission notice shall be
|
35
|
+
included in all copies or substantial portions of the Software.
|
36
|
+
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
38
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
39
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
40
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
41
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
42
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
43
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -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 # Differenct 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.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BitBucket
|
4
|
+
class API
|
5
|
+
|
6
|
+
# Returns all API public methods for a given class.
|
7
|
+
def self.inherited(klass)
|
8
|
+
klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
9
|
+
def self.actions
|
10
|
+
self.new.api_methods_in(#{klass})
|
11
|
+
end
|
12
|
+
def actions
|
13
|
+
api_methods_in(#{klass})
|
14
|
+
end
|
15
|
+
RUBY_EVAL
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_methods_in(klass)
|
20
|
+
puts "---"
|
21
|
+
(klass.send(:instance_methods, false) - ['actions']).sort.each do |method|
|
22
|
+
puts "|--> #{method}"
|
23
|
+
end
|
24
|
+
klass.included_modules.each do |mod|
|
25
|
+
if mod.to_s =~ /#{klass}/
|
26
|
+
puts "| \\ #{mod.to_s}"
|
27
|
+
mod.instance_methods(false).each do |met|
|
28
|
+
puts "| |--> #{met}"
|
29
|
+
end
|
30
|
+
puts "| /"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
puts "---"
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def append_arguments(method)
|
38
|
+
_method = self.method(method)
|
39
|
+
if _method.arity == 0
|
40
|
+
args = "()"
|
41
|
+
elsif _method.arity > 0
|
42
|
+
args = "(few)"
|
43
|
+
else
|
44
|
+
args = "(else)"
|
45
|
+
end
|
46
|
+
args
|
47
|
+
end
|
48
|
+
|
49
|
+
end # API
|
50
|
+
end # BitBucket
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'bitbucket_rest_api/configuration'
|
4
|
+
require 'bitbucket_rest_api/connection'
|
5
|
+
require 'bitbucket_rest_api/validations'
|
6
|
+
require 'bitbucket_rest_api/request'
|
7
|
+
require 'bitbucket_rest_api/core_ext/hash'
|
8
|
+
require 'bitbucket_rest_api/core_ext/array'
|
9
|
+
require 'bitbucket_rest_api/compatibility'
|
10
|
+
require 'bitbucket_rest_api/api/actions'
|
11
|
+
require 'bitbucket_rest_api/api_factory'
|
12
|
+
|
13
|
+
module BitBucket
|
14
|
+
class API
|
15
|
+
include Authorization
|
16
|
+
include Connection
|
17
|
+
include Request
|
18
|
+
|
19
|
+
# TODO consider these optional in a stack
|
20
|
+
include Validations
|
21
|
+
include ParameterFilter
|
22
|
+
include Normalizer
|
23
|
+
|
24
|
+
attr_reader *Configuration::VALID_OPTIONS_KEYS
|
25
|
+
|
26
|
+
attr_accessor *VALID_API_KEYS
|
27
|
+
|
28
|
+
# Callback to update global configuration options
|
29
|
+
class_eval do
|
30
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
31
|
+
define_method "#{key}=" do |arg|
|
32
|
+
self.instance_variable_set("@#{key}", arg)
|
33
|
+
BitBucket.send("#{key}=", arg)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates new API
|
39
|
+
def initialize(options={}, &block)
|
40
|
+
super()
|
41
|
+
setup options
|
42
|
+
set_api_client
|
43
|
+
|
44
|
+
self.instance_eval(&block) if block_given?
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup(options={})
|
48
|
+
options = BitBucket.options.merge(options)
|
49
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
50
|
+
send("#{key}=", options[key])
|
51
|
+
end
|
52
|
+
process_basic_auth(options[:basic_auth])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Extract login and password from basic_auth parameter
|
56
|
+
def process_basic_auth(auth)
|
57
|
+
case auth
|
58
|
+
when String
|
59
|
+
self.login, self.password = auth.split(':', 2)
|
60
|
+
when Hash
|
61
|
+
self.login = auth[:login]
|
62
|
+
self.password = auth[:password]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Assigns current api class
|
67
|
+
def set_api_client
|
68
|
+
BitBucket.api_client = self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Responds to attribute query or attribute clear
|
72
|
+
def method_missing(method, *args, &block) # :nodoc:
|
73
|
+
case method.to_s
|
74
|
+
when /^(.*)\?$/
|
75
|
+
return !self.send($1.to_s).nil?
|
76
|
+
when /^clear_(.*)$/
|
77
|
+
self.send("#{$1.to_s}=", nil)
|
78
|
+
else
|
79
|
+
super
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
|
84
|
+
self.user = user_name || self.user
|
85
|
+
self.repo = repo_name || self.repo
|
86
|
+
end
|
87
|
+
|
88
|
+
def _merge_user_into_params!(params) # :nodoc:
|
89
|
+
params.merge!({ 'user' => self.user }) if user?
|
90
|
+
end
|
91
|
+
|
92
|
+
def _merge_user_repo_into_params!(params) # :nodoc:
|
93
|
+
{ 'user' => self.user, 'repo' => self.repo }.merge!(params)
|
94
|
+
end
|
95
|
+
|
96
|
+
# TODO: See whether still needed, consider adding to core_exts
|
97
|
+
def _hash_traverse(hash, &block)
|
98
|
+
hash.each do |key, val|
|
99
|
+
block.call(key)
|
100
|
+
case val
|
101
|
+
when Hash
|
102
|
+
val.keys.each do |k|
|
103
|
+
_hash_traverse(val, &block)
|
104
|
+
end
|
105
|
+
when Array
|
106
|
+
val.each do |item|
|
107
|
+
_hash_traverse(item, &block)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
return hash
|
112
|
+
end
|
113
|
+
|
114
|
+
def _merge_mime_type(resource, params) # :nodoc:
|
115
|
+
# params['resource'] = resource
|
116
|
+
# params['mime_type'] = params['mime_type'] || :raw
|
117
|
+
end
|
118
|
+
|
119
|
+
end # API
|
120
|
+
end # BitBucket
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bitbucket_rest_api/core_ext/hash'
|
4
|
+
|
5
|
+
module BitBucket
|
6
|
+
class ApiFactory
|
7
|
+
|
8
|
+
# Instantiates a new bitbucket api object
|
9
|
+
def self.new(klass, options={})
|
10
|
+
return create_instance(klass, options) if klass
|
11
|
+
raise ArgumentError, 'must provide klass to be instantiated'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Passes configuration options to instantiated class
|
15
|
+
def self.create_instance(klass, options)
|
16
|
+
options.symbolize_keys!
|
17
|
+
instance = convert_to_constant(klass.to_s).new options
|
18
|
+
BitBucket.api_client = instance
|
19
|
+
instance
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.convert_to_constant(classes)
|
23
|
+
constant = BitBucket
|
24
|
+
classes.split('::').each do |klass|
|
25
|
+
constant = constant.const_get klass
|
26
|
+
end
|
27
|
+
return constant
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BitBucket
|
4
|
+
class Client < API
|
5
|
+
|
6
|
+
# This is a read-only API to the BitBucket events.
|
7
|
+
# These events power the various activity streams on the site.
|
8
|
+
def events(options = {})
|
9
|
+
raise "Unimplemented"
|
10
|
+
#@events ||= ApiFactory.new 'Events', options
|
11
|
+
end
|
12
|
+
|
13
|
+
def issues(options = {})
|
14
|
+
@issues ||= ApiFactory.new 'Issues', options
|
15
|
+
end
|
16
|
+
|
17
|
+
# An API for users to manage their own tokens.
|
18
|
+
def oauth(options = {})
|
19
|
+
raise "Unimpletmented"
|
20
|
+
#@oauth ||= ApiFactory.new 'Authorizations', options
|
21
|
+
end
|
22
|
+
alias :authorizations :oauth
|
23
|
+
|
24
|
+
def teams(options = {})
|
25
|
+
raise "Unimplemented"
|
26
|
+
#@teams ||= ApiFactory.new 'teams', options
|
27
|
+
end
|
28
|
+
|
29
|
+
def pull_requests(options = {})
|
30
|
+
raise "Unimplemented"
|
31
|
+
#@pull_requests ||= ApiFactory.new 'PullRequests', options
|
32
|
+
end
|
33
|
+
|
34
|
+
def repos(options = {})
|
35
|
+
@repos ||= ApiFactory.new 'Repos', options
|
36
|
+
end
|
37
|
+
alias :repositories :repos
|
38
|
+
|
39
|
+
def search(options = {})
|
40
|
+
raise "Unimplemented"
|
41
|
+
#@search ||= ApiFactory.new 'Search', options
|
42
|
+
end
|
43
|
+
|
44
|
+
# Many of the resources on the users API provide a shortcut for getting
|
45
|
+
# information about the currently authenticated user.
|
46
|
+
def users(options = {})
|
47
|
+
@users ||= ApiFactory.new 'Users', options
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_api(options = {})
|
51
|
+
@user_api ||= ApiFactory.new 'User', options
|
52
|
+
end
|
53
|
+
|
54
|
+
def invitations(options = {})
|
55
|
+
@invitations ||= ApiFactory.new "Invitations", options
|
56
|
+
end
|
57
|
+
end # Client
|
58
|
+
end # BitBucket
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module BitBucket
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:adapter,
|
8
|
+
:client_id,
|
9
|
+
:client_secret,
|
10
|
+
:oauth_token,
|
11
|
+
:oauth_secret,
|
12
|
+
:endpoint,
|
13
|
+
:mime_type,
|
14
|
+
:user_agent,
|
15
|
+
:connection_options,
|
16
|
+
:repo,
|
17
|
+
:user,
|
18
|
+
:login,
|
19
|
+
:password,
|
20
|
+
:basic_auth
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
# Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
|
24
|
+
DEFAULT_ADAPTER = :net_http
|
25
|
+
|
26
|
+
# By default, don't set an application key
|
27
|
+
DEFAULT_CLIENT_ID = nil
|
28
|
+
|
29
|
+
# By default, don't set an application secret
|
30
|
+
DEFAULT_CLIENT_SECRET = nil
|
31
|
+
|
32
|
+
# By default, don't set a user oauth access token
|
33
|
+
DEFAULT_OAUTH_TOKEN = nil
|
34
|
+
|
35
|
+
# By default, don't set a user oauth access token secret
|
36
|
+
DEFAULT_OAUTH_SECRET = nil
|
37
|
+
|
38
|
+
# By default, don't set a user login name
|
39
|
+
DEFAULT_LOGIN = nil
|
40
|
+
|
41
|
+
# By default, don't set a user password
|
42
|
+
DEFAULT_PASSWORD = nil
|
43
|
+
|
44
|
+
# By default, don't set a user basic authentication
|
45
|
+
DEFAULT_BASIC_AUTH = nil
|
46
|
+
|
47
|
+
# The endpoint used to connect to BitBucket if none is set, in the event that BitBucket is ever available on location
|
48
|
+
DEFAULT_ENDPOINT = 'https://bitbucket.org/api/1.0'.freeze
|
49
|
+
|
50
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
51
|
+
DEFAULT_USER_AGENT = "BitBucket Ruby Gem #{BitBucket::VERSION::STRING}".freeze
|
52
|
+
|
53
|
+
# By default the <tt>Accept</tt> header will make a request for <tt>JSON</tt>
|
54
|
+
DEFAULT_MIME_TYPE = :json
|
55
|
+
|
56
|
+
# By default uses the Faraday connection options if none is set
|
57
|
+
DEFAULT_CONNECTION_OPTIONS = { }
|
58
|
+
|
59
|
+
# By default, don't set user name
|
60
|
+
DEFAULT_USER = nil
|
61
|
+
|
62
|
+
# By default, don't set repository name
|
63
|
+
DEFAULT_REPO = nil
|
64
|
+
|
65
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
66
|
+
|
67
|
+
# Convenience method to allow for global setting of configuration options
|
68
|
+
def configure
|
69
|
+
yield self
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.extended(base)
|
73
|
+
base.set_defaults
|
74
|
+
end
|
75
|
+
|
76
|
+
def options
|
77
|
+
options = { }
|
78
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
79
|
+
options
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_defaults
|
83
|
+
self.adapter = DEFAULT_ADAPTER
|
84
|
+
self.client_id = DEFAULT_CLIENT_ID
|
85
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
86
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
87
|
+
self.oauth_secret = DEFAULT_OAUTH_SECRET
|
88
|
+
self.endpoint = DEFAULT_ENDPOINT
|
89
|
+
self.user_agent = DEFAULT_USER_AGENT
|
90
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
91
|
+
self.mime_type = DEFAULT_MIME_TYPE
|
92
|
+
self.user = DEFAULT_USER
|
93
|
+
self.repo = DEFAULT_REPO
|
94
|
+
self.login = DEFAULT_LOGIN
|
95
|
+
self.password = DEFAULT_PASSWORD
|
96
|
+
self.basic_auth = DEFAULT_BASIC_AUTH
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
end # Configuration
|
101
|
+
end # BitBucket
|