zz_bitbucket_rest_api 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/README.md +169 -0
- data/lib/bitbucket_rest_api.rb +91 -0
- data/lib/bitbucket_rest_api/api.rb +106 -0
- data/lib/bitbucket_rest_api/api/actions.rb +35 -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 +55 -0
- data/lib/bitbucket_rest_api/configuration.rb +106 -0
- data/lib/bitbucket_rest_api/connection.rb +98 -0
- data/lib/bitbucket_rest_api/constants.rb +58 -0
- data/lib/bitbucket_rest_api/core_ext/array.rb +7 -0
- data/lib/bitbucket_rest_api/core_ext/hash.rb +46 -0
- data/lib/bitbucket_rest_api/deprecation.rb +39 -0
- data/lib/bitbucket_rest_api/error.rb +38 -0
- data/lib/bitbucket_rest_api/error/bad_events.rb +9 -0
- data/lib/bitbucket_rest_api/error/bad_request.rb +12 -0
- data/lib/bitbucket_rest_api/error/blank_value.rb +9 -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/no_events.rb +9 -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/invitations.rb +15 -0
- data/lib/bitbucket_rest_api/issues.rb +230 -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/normalizer.rb +27 -0
- data/lib/bitbucket_rest_api/parameter_filter.rb +32 -0
- data/lib/bitbucket_rest_api/repos.rb +272 -0
- data/lib/bitbucket_rest_api/repos/changesets.rb +54 -0
- data/lib/bitbucket_rest_api/repos/commits.rb +40 -0
- data/lib/bitbucket_rest_api/repos/components.rb +36 -0
- data/lib/bitbucket_rest_api/repos/default_reviewers.rb +59 -0
- data/lib/bitbucket_rest_api/repos/download.rb +21 -0
- data/lib/bitbucket_rest_api/repos/following.rb +39 -0
- data/lib/bitbucket_rest_api/repos/forks.rb +69 -0
- data/lib/bitbucket_rest_api/repos/keys.rb +88 -0
- data/lib/bitbucket_rest_api/repos/pull_request.rb +160 -0
- data/lib/bitbucket_rest_api/repos/services.rb +103 -0
- data/lib/bitbucket_rest_api/repos/sources.rb +39 -0
- data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
- data/lib/bitbucket_rest_api/request.rb +76 -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 +53 -0
- data/lib/bitbucket_rest_api/response.rb +28 -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/result.rb +140 -0
- data/lib/bitbucket_rest_api/teams.rb +88 -0
- data/lib/bitbucket_rest_api/user.rb +101 -0
- data/lib/bitbucket_rest_api/users.rb +24 -0
- data/lib/bitbucket_rest_api/users/account.rb +53 -0
- data/lib/bitbucket_rest_api/utils/url.rb +56 -0
- data/lib/bitbucket_rest_api/validations.rb +25 -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 +44 -0
- data/lib/bitbucket_rest_api/validations/token.rb +43 -0
- data/lib/bitbucket_rest_api/version.rb +11 -0
- data/spec/bitbucket_rest_api/api/actions_spec.rb +17 -0
- data/spec/bitbucket_rest_api/api_factory_spec.rb +30 -0
- data/spec/bitbucket_rest_api/api_spec.rb +86 -0
- data/spec/bitbucket_rest_api/authorization_spec.rb +72 -0
- data/spec/bitbucket_rest_api/client_spec.rb +16 -0
- data/spec/bitbucket_rest_api/core_ext/array_spec.rb +12 -0
- data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +49 -0
- data/spec/bitbucket_rest_api/deprecation_spec.rb +30 -0
- data/spec/bitbucket_rest_api/error/bad_events_spec.rb +10 -0
- data/spec/bitbucket_rest_api/error/blank_value_spec.rb +13 -0
- data/spec/bitbucket_rest_api/error/no_events_spec.rb +10 -0
- data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
- data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
- data/spec/bitbucket_rest_api/issues/components_spec.rb +88 -0
- data/spec/bitbucket_rest_api/issues/milestones_spec.rb +88 -0
- data/spec/bitbucket_rest_api/issues_spec.rb +90 -0
- data/spec/bitbucket_rest_api/normalizer_spec.rb +30 -0
- data/spec/bitbucket_rest_api/parameter_filter_spec.rb +41 -0
- data/spec/bitbucket_rest_api/repos/changesets_spec.rb +43 -0
- data/spec/bitbucket_rest_api/repos/commits_spec.rb +20 -0
- data/spec/bitbucket_rest_api/repos/components_spec.rb +42 -0
- data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +64 -0
- data/spec/bitbucket_rest_api/repos/download_spec.rb +9 -0
- data/spec/bitbucket_rest_api/repos/following_spec.rb +52 -0
- data/spec/bitbucket_rest_api/repos/forks_spec.rb +45 -0
- data/spec/bitbucket_rest_api/repos/keys_spec.rb +72 -0
- data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +288 -0
- data/spec/bitbucket_rest_api/repos/sources_spec.rb +77 -0
- data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
- data/spec/bitbucket_rest_api/repos_spec.rb +157 -0
- data/spec/bitbucket_rest_api/request/jsonize_spec.rb +18 -0
- data/spec/bitbucket_rest_api/request/oauth_spec.rb +27 -0
- data/spec/bitbucket_rest_api/request_spec.rb +81 -0
- data/spec/bitbucket_rest_api/response/jsonize_spec.rb +12 -0
- data/spec/bitbucket_rest_api/response/mashify_spec.rb +32 -0
- data/spec/bitbucket_rest_api/response/raise_error_spec.rb +41 -0
- data/spec/bitbucket_rest_api/teams_spec.rb +135 -0
- data/spec/bitbucket_rest_api/user_spec.rb +77 -0
- data/spec/bitbucket_rest_api/utils/url_spec.rb +33 -0
- data/spec/bitbucket_rest_api/validations/format_spec.rb +29 -0
- data/spec/bitbucket_rest_api/validations/presence_spec.rb +12 -0
- data/spec/bitbucket_rest_api/validations/required_spec.rb +43 -0
- data/spec/bitbucket_rest_api/validations/token_spec.rb +16 -0
- data/spec/bitbucket_rest_api_spec.rb +17 -0
- data/spec/spec_helper.rb +24 -0
- metadata +378 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae2c975c0bd23c0339307e7b617771b03268269892ab21dc9bb11f68796020c6
|
4
|
+
data.tar.gz: b5090c4ff388deb4d8e12d5623340abf0042e59234731852e083f9a1efc8acd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93b62d49fab2b7d6d67d8883114068cd4fad1239e1e30f762b0c9ad01977ee279d250002cb8518b8f89a542731363c23845ac1e469115a4f19f2bdc797210e24
|
7
|
+
data.tar.gz: 1926bce213adf2531a02a7e5de9b141db551c6a11ff12ef80c9b3d1fb2fbacf17c4c8510a97a1c1e3f7d59c11005bb816b17dce46f071e109c249b1a9b5a4b97
|
data/LICENSE.txt
ADDED
@@ -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.
|
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 # 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,91 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bitbucket_rest_api/version'
|
4
|
+
require 'bitbucket_rest_api/configuration'
|
5
|
+
require 'bitbucket_rest_api/constants'
|
6
|
+
require 'bitbucket_rest_api/utils/url'
|
7
|
+
require 'bitbucket_rest_api/connection'
|
8
|
+
require 'bitbucket_rest_api/deprecation'
|
9
|
+
|
10
|
+
module BitBucket
|
11
|
+
extend Configuration
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# Handle for the client instance
|
16
|
+
attr_accessor :api_client
|
17
|
+
|
18
|
+
# Alias for BitBucket::Client.new
|
19
|
+
#
|
20
|
+
# @return [BitBucket::Client]
|
21
|
+
def new(options = { }, &block)
|
22
|
+
@api_client = BitBucket::Client.new(options, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Delegate to BitBucket::Client
|
26
|
+
#
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
return super unless new.respond_to?(method)
|
29
|
+
new.send(method, *args, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to?(method, include_private = false)
|
33
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module AutoloadHelper
|
39
|
+
|
40
|
+
def autoload_all(prefix, options)
|
41
|
+
options.each do |const_name, path|
|
42
|
+
autoload const_name, File.join(prefix, path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def register_constant(options)
|
47
|
+
options.each do |const_name, value|
|
48
|
+
const_set const_name.upcase.to_s, value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def lookup_constant(const_name)
|
53
|
+
const_get const_name.upcase.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
extend AutoloadHelper
|
59
|
+
|
60
|
+
autoload_all 'bitbucket_rest_api',
|
61
|
+
:API => 'api',
|
62
|
+
:ApiFactory => 'api_factory',
|
63
|
+
:Authorization => 'authorization',
|
64
|
+
:Authorizations => 'authorizations',
|
65
|
+
:Validations => 'validations',
|
66
|
+
:ParameterFilter => 'parameter_filter',
|
67
|
+
:Normalizer => 'normalizer',
|
68
|
+
:Client => 'client',
|
69
|
+
:CoreExt => 'core_ext',
|
70
|
+
:Request => 'request',
|
71
|
+
:Response => 'response',
|
72
|
+
:Result => 'result',
|
73
|
+
|
74
|
+
:Repos => 'repos',
|
75
|
+
#:Error => 'error',
|
76
|
+
:Issues => 'issues',
|
77
|
+
:User => 'user',
|
78
|
+
:Users => 'users',
|
79
|
+
:Invitations => 'invitations',
|
80
|
+
:Teams => 'teams'
|
81
|
+
|
82
|
+
#:Teams => 'teams',
|
83
|
+
#:PullRequests => 'pull_requests',
|
84
|
+
#:Users => 'users',
|
85
|
+
#:Events => 'events',
|
86
|
+
#:Search => 'search',
|
87
|
+
#:PageLinks => 'page_links',
|
88
|
+
#:PageIterator => 'page_iterator',
|
89
|
+
#:PagedRequest => 'paged_request'
|
90
|
+
|
91
|
+
end # BitBucket
|
@@ -0,0 +1,106 @@
|
|
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/api/actions'
|
10
|
+
require 'bitbucket_rest_api/api_factory'
|
11
|
+
|
12
|
+
module BitBucket
|
13
|
+
class API
|
14
|
+
include Authorization
|
15
|
+
include Connection
|
16
|
+
include Request
|
17
|
+
|
18
|
+
# TODO consider these optional in a stack
|
19
|
+
include Validations
|
20
|
+
include ParameterFilter
|
21
|
+
include Normalizer
|
22
|
+
|
23
|
+
attr_reader *Configuration::VALID_OPTIONS_KEYS
|
24
|
+
|
25
|
+
attr_accessor *VALID_API_KEYS
|
26
|
+
|
27
|
+
# Callback to update global configuration options
|
28
|
+
class_eval do
|
29
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
30
|
+
define_method "#{key}=" do |arg|
|
31
|
+
self.instance_variable_set("@#{key}", arg)
|
32
|
+
BitBucket.send("#{key}=", arg)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creates new API
|
38
|
+
def initialize(options={}, &block)
|
39
|
+
super()
|
40
|
+
setup options
|
41
|
+
set_api_client
|
42
|
+
|
43
|
+
self.instance_eval(&block) if block_given?
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup(options={})
|
47
|
+
options = BitBucket.options.merge(options)
|
48
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
49
|
+
send("#{key}=", options[key])
|
50
|
+
end
|
51
|
+
process_basic_auth(options[:basic_auth])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Extract login and password from basic_auth parameter
|
55
|
+
def process_basic_auth(auth)
|
56
|
+
case auth
|
57
|
+
when String
|
58
|
+
self.login, self.password = auth.split(':', 2)
|
59
|
+
when Hash
|
60
|
+
self.login = auth[:login]
|
61
|
+
self.password = auth[:password]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Assigns current api class
|
66
|
+
def set_api_client
|
67
|
+
BitBucket.api_client = self
|
68
|
+
end
|
69
|
+
|
70
|
+
# Responds to attribute query or attribute clear
|
71
|
+
def method_missing(method, *args, &block) # :nodoc:
|
72
|
+
case method.to_s
|
73
|
+
when /^(.*)\?$/
|
74
|
+
return !self.send($1.to_s).nil?
|
75
|
+
when /^clear_(.*)$/
|
76
|
+
self.send("#{$1.to_s}=", nil)
|
77
|
+
else
|
78
|
+
super
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def update_and_validate_user_repo_params(user_name, repo_name=nil)
|
83
|
+
_update_user_repo_params(user_name, repo_name)
|
84
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
85
|
+
end
|
86
|
+
|
87
|
+
def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
|
88
|
+
self.user = user_name || self.user
|
89
|
+
self.repo = repo_name || self.repo
|
90
|
+
end
|
91
|
+
|
92
|
+
def _merge_user_into_params!(params) # :nodoc:
|
93
|
+
params.merge!({ 'user' => self.user }) if user?
|
94
|
+
end
|
95
|
+
|
96
|
+
def _merge_user_repo_into_params!(params) # :nodoc:
|
97
|
+
{ 'user' => self.user, 'repo' => self.repo }.merge!(params)
|
98
|
+
end
|
99
|
+
|
100
|
+
def _merge_mime_type(resource, params) # :nodoc:
|
101
|
+
# params['resource'] = resource
|
102
|
+
# params['mime_type'] = params['mime_type'] || :raw
|
103
|
+
end
|
104
|
+
|
105
|
+
end # API
|
106
|
+
end # BitBucket
|
@@ -0,0 +1,35 @@
|
|
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
|
+
methods = []
|
21
|
+
(klass.send(:instance_methods, false) - ['actions']).sort.each do |method|
|
22
|
+
methods << method
|
23
|
+
end
|
24
|
+
klass.included_modules.each do |mod|
|
25
|
+
if mod.to_s =~ /#{klass}/
|
26
|
+
mod.instance_methods(false).each do |met|
|
27
|
+
methods << met
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
methods
|
32
|
+
end
|
33
|
+
|
34
|
+
end # API
|
35
|
+
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
|