bucketkit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +128 -0
- data/Rakefile +1 -0
- data/bucketkit.gemspec +24 -0
- data/lib/bucketkit.rb +22 -0
- data/lib/bucketkit/authentication.rb +15 -0
- data/lib/bucketkit/client.rb +157 -0
- data/lib/bucketkit/client/commits.rb +32 -0
- data/lib/bucketkit/client/pull_requests.rb +68 -0
- data/lib/bucketkit/configurable.rb +58 -0
- data/lib/bucketkit/default.rb +76 -0
- data/lib/bucketkit/repository.rb +36 -0
- data/lib/bucketkit/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a81cf9c98c0b1ebb090830ae672147cec6f77684
|
4
|
+
data.tar.gz: 2fec6ca1459b80ae9357f870cc64b483737d25d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cef03516b19ea4631943877aa943faa10f6b4aef054dccbbd414381f41cec373465231110ad8d61a33b7f5e860f768465019b5a000ccbf7ff6278b34a269c871
|
7
|
+
data.tar.gz: 2dbb18c034b1f98796133c1c420f884fcb147f4a1c98b503c0bb6e57fc680356ab4dc676277cc687a7094de9963ea338e06c97d775cfcd821f57feae47562a49
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Xystushi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Bucketkit
|
2
|
+
|
3
|
+
BucketKit is a BitBucket REST API client that is heavily inspired by [Octokit](octokit.github.io).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bucketkit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bucketkit
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Authentication
|
22
|
+
|
23
|
+
You can use either basic authentication:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
c = Bucketkit::Client.new(login: 'foo', password: 'bar')
|
27
|
+
```
|
28
|
+
|
29
|
+
Or two legged OAuth:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
c = Bucketkit::Client.new do |c|
|
33
|
+
c.login = 'foo'
|
34
|
+
c.oauth_tokens = {
|
35
|
+
{
|
36
|
+
consumer_key: 'BUCKETKIT_CONSUMER_KEY',
|
37
|
+
consumer_secret: 'BUCKETKIT_CONSUMER_SECRET',
|
38
|
+
token: 'BUCKETKIT_TOKEN',
|
39
|
+
token_secret: 'BUCKETKIT_TOKEN_SECRET'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
### Pull Requests
|
45
|
+
|
46
|
+
Get a list of pull requests:
|
47
|
+
|
48
|
+
c.pull_requests('xystushi/bucketkit')
|
49
|
+
|
50
|
+
Get single pull request by id:
|
51
|
+
|
52
|
+
c.pull_request('xystushi/bucketkit', 1)
|
53
|
+
|
54
|
+
Get commits on a pull request:
|
55
|
+
|
56
|
+
c.pull_request_commits('xystushi/bucketkit', 1)
|
57
|
+
|
58
|
+
Get comments on a pull request:
|
59
|
+
|
60
|
+
c.pull_request_comments('xystushi/bucketkit', 1)
|
61
|
+
|
62
|
+
Get the pull request activity:
|
63
|
+
|
64
|
+
c.pull_request_activity('xystushi/bucketkit', 1)
|
65
|
+
|
66
|
+
Get the diff of a pull request:
|
67
|
+
|
68
|
+
c.pull_request_diff('xystushi/bucketkit', 1)
|
69
|
+
|
70
|
+
Approve a pull request:
|
71
|
+
|
72
|
+
c.approve_pull_request('xystushi/bucketkit', 1)
|
73
|
+
|
74
|
+
Delete a pull request approval:
|
75
|
+
|
76
|
+
c.delete_pull_request_approval('xystushi/bucketkit', 1)
|
77
|
+
|
78
|
+
Merge a pull request:
|
79
|
+
|
80
|
+
c.merge_pull_request('xystushi/bucketkit', 1)
|
81
|
+
# or
|
82
|
+
c.accept_pull_request('xystushi/bucketkit', 1)
|
83
|
+
|
84
|
+
Decline a pull request:
|
85
|
+
|
86
|
+
c.decline_pull_request('xystushi/bucketkit', 1)
|
87
|
+
# or
|
88
|
+
c.reject_pull_request('xystushi/bucketkit', 1)
|
89
|
+
|
90
|
+
Create a pull request:
|
91
|
+
|
92
|
+
c.create_pull_request('xystushi/bucketkit', 'title', 'some/fork', 'master',
|
93
|
+
'this is a new pull request')
|
94
|
+
|
95
|
+
### Commits
|
96
|
+
|
97
|
+
Get a list of commits of a repository:
|
98
|
+
|
99
|
+
c.commits('xystushi/bucketkit')
|
100
|
+
|
101
|
+
Get a single commit of a repository:
|
102
|
+
|
103
|
+
c.commit('xystushi/bucketkit', 'abcdef123456')
|
104
|
+
|
105
|
+
Get comments on a commit:
|
106
|
+
|
107
|
+
c.commit_comments('xystushi/bucketkit', 'abcdef123456')
|
108
|
+
|
109
|
+
Get a single comment on a commit by id:
|
110
|
+
|
111
|
+
c.commit_comment('xystushi/bucketkit', 'abcdef123456', 1)
|
112
|
+
|
113
|
+
Approve a commit:
|
114
|
+
|
115
|
+
c.approve_commit('xystushi/bucketkit', 'abcdef123456')
|
116
|
+
|
117
|
+
Delete a commit's approval:
|
118
|
+
|
119
|
+
c.delete_commit_approval('xystushi/bucketkit', 'abcdef123456')
|
120
|
+
|
121
|
+
For more, please refer to [Bitbucket's API documentation](https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs)
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
1. Fork it ( http://github.com/xystushi/bucketkit/fork )
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bucketkit.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bucketkit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bucketkit'
|
8
|
+
spec.version = Bucketkit::VERSION
|
9
|
+
spec.authors = ['Xystushi']
|
10
|
+
spec.email = ['xystushi@gmail.com']
|
11
|
+
spec.summary = %q{A BitBucket REST API client.}
|
12
|
+
spec.homepage = 'https://github.com/xystushi/bucketkit'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_dependency 'sawyer', '~> 0.5', '>= 0.5.4'
|
23
|
+
spec.add_dependency 'faraday_middleware', '~> 0.9', '>= 0.9.1'
|
24
|
+
end
|
data/lib/bucketkit.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bucketkit/client'
|
2
|
+
require 'bucketkit/default'
|
3
|
+
|
4
|
+
module Bucketkit
|
5
|
+
class << self
|
6
|
+
include Bucketkit::Configurable
|
7
|
+
|
8
|
+
def client
|
9
|
+
@client = Bucketkit::Client.new(options) unless defined?(@client) && @client.same_options?(options)
|
10
|
+
@client
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return super unless client.respond_to?(method)
|
17
|
+
client.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Bucketkit.setup
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bucketkit
|
2
|
+
module Authentication
|
3
|
+
def basic_authenticated?
|
4
|
+
!!(@login && @password)
|
5
|
+
end
|
6
|
+
|
7
|
+
def oauth_authenticated?
|
8
|
+
!!@oauth_tokens
|
9
|
+
end
|
10
|
+
|
11
|
+
def user_authenticated?
|
12
|
+
basic_authenticated? || oauth_authenticated?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'sawyer'
|
2
|
+
require 'bucketkit/authentication'
|
3
|
+
require 'bucketkit/configurable'
|
4
|
+
require 'bucketkit/repository'
|
5
|
+
require 'bucketkit/client/pull_requests'
|
6
|
+
require 'bucketkit/client/commits'
|
7
|
+
require 'faraday_middleware'
|
8
|
+
|
9
|
+
module Bucketkit
|
10
|
+
class Client
|
11
|
+
include Bucketkit::Authentication
|
12
|
+
include Bucketkit::Configurable
|
13
|
+
include Bucketkit::Client::PullRequests
|
14
|
+
include Bucketkit::Client::Commits
|
15
|
+
|
16
|
+
CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
Bucketkit::Configurable.keys.each do |key|
|
20
|
+
instance_variable_set(:"@#{key}", options[key] || Bucketkit.instance_variable_get(:"@#{key}"))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def same_options?(opts)
|
25
|
+
opts.hash == options.hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(url, options={})
|
29
|
+
request :get, url, parse_query_and_convenience_headers(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def post(url, options={})
|
33
|
+
request :post, url, options
|
34
|
+
end
|
35
|
+
|
36
|
+
def put(url, options={})
|
37
|
+
request :put, url, options
|
38
|
+
end
|
39
|
+
|
40
|
+
def patch(url, options={})
|
41
|
+
request :patch, url, options
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(url, options={})
|
45
|
+
request :delete, url, options
|
46
|
+
end
|
47
|
+
|
48
|
+
def head(url, options={})
|
49
|
+
request :head, url, parse_query_and_convenience_headers(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
def paginate(url, options={}, &block)
|
53
|
+
opts = parse_query_and_convenience_headers(options.dup)
|
54
|
+
if @auto_paginate || @per_page
|
55
|
+
opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil)
|
56
|
+
end
|
57
|
+
data = request(:get, url, opts)
|
58
|
+
if @auto_paginate
|
59
|
+
loop do
|
60
|
+
break unless @last_response.rels[:next]
|
61
|
+
@last_response = @last_response.rels[:next].get
|
62
|
+
if block_given?
|
63
|
+
yield(data, @last_response)
|
64
|
+
else
|
65
|
+
data.concat(@last_response.data) if @last_response.data.is_a?(Array)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
data
|
70
|
+
end
|
71
|
+
|
72
|
+
def root
|
73
|
+
get '/'
|
74
|
+
end
|
75
|
+
|
76
|
+
def last_response
|
77
|
+
@last_response if defined? @last_response
|
78
|
+
end
|
79
|
+
|
80
|
+
def login=(value)
|
81
|
+
reset_agent
|
82
|
+
@login = value
|
83
|
+
end
|
84
|
+
|
85
|
+
def password=(value)
|
86
|
+
reset_agent
|
87
|
+
@password = value
|
88
|
+
end
|
89
|
+
|
90
|
+
def oauth_tokens=(value)
|
91
|
+
reset_agent
|
92
|
+
@oauth_tokens = value
|
93
|
+
end
|
94
|
+
|
95
|
+
def agent
|
96
|
+
@agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
|
97
|
+
http.headers[:accept] = default_media_type
|
98
|
+
http.headers[:content_type] = default_media_type
|
99
|
+
http.headers[:user_agent] = user_agent
|
100
|
+
if basic_authenticated?
|
101
|
+
http.basic_auth(@login, @password)
|
102
|
+
elsif oauth_authenticated?
|
103
|
+
http.request :oauth, @oauth_tokens
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def reset_agent
|
111
|
+
@agent = nil
|
112
|
+
end
|
113
|
+
|
114
|
+
def request(method, path, data, options={})
|
115
|
+
if data.is_a? Hash
|
116
|
+
options[:query] = data.delete(:query) || {}
|
117
|
+
options[:headers] = data.delete(:headers) || {}
|
118
|
+
accept = data.delete(:accept)
|
119
|
+
options[:headers][:accept] = accept if accept
|
120
|
+
end
|
121
|
+
|
122
|
+
@last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
|
123
|
+
response.data
|
124
|
+
end
|
125
|
+
|
126
|
+
def boolean_from_response(method, path, options={})
|
127
|
+
request method, path, options
|
128
|
+
@last_response.status == 204
|
129
|
+
end
|
130
|
+
|
131
|
+
def sawyer_options
|
132
|
+
opts = {
|
133
|
+
links_parser: Sawyer::LinkParsers::Simple.new
|
134
|
+
}
|
135
|
+
conn_opts = @connection_options
|
136
|
+
conn_opts[:builder] = @middleware if @middleware
|
137
|
+
conn_opts[:proxy] = @proxy if @proxy
|
138
|
+
opts[:faraday] = Faraday.new('https://api.bitbucket.org', conn_opts)
|
139
|
+
|
140
|
+
opts
|
141
|
+
end
|
142
|
+
|
143
|
+
def parse_query_and_convenience_headers(options)
|
144
|
+
headers = options.fetch(:headers, {})
|
145
|
+
CONVENIENCE_HEADERS.each do |h|
|
146
|
+
header = options.delete(h)
|
147
|
+
headers[h] = header if header
|
148
|
+
end
|
149
|
+
query = options.delete(:query)
|
150
|
+
opts = {query: options}
|
151
|
+
opts[:query].merge!(query) if query && query.is_a?(Hash)
|
152
|
+
opts[:headers] = headers unless headers.empty?
|
153
|
+
|
154
|
+
opts
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Bucketkit
|
2
|
+
class Client
|
3
|
+
# See https://confluence.atlassian.com/display/BITBUCKET/commits+or+commit+Resource
|
4
|
+
module Commits
|
5
|
+
API_ENDPOINT = 'api/2.0/repositories'.freeze
|
6
|
+
|
7
|
+
def commits(repo, options={})
|
8
|
+
paginate "#{API_ENDPOINT}/#{Repository.new(repo)}/commits", options
|
9
|
+
end
|
10
|
+
|
11
|
+
def commit(repo, revision, options={})
|
12
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/commit/#{revision}", options
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit_comments(repo, revision, options={})
|
16
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/commit/#{revision}/comments", options
|
17
|
+
end
|
18
|
+
|
19
|
+
def commit_comment(repo, revision, comment_id, options={})
|
20
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/commit/#{revision}/comments/#{comment_id}", options
|
21
|
+
end
|
22
|
+
|
23
|
+
def approve_commit(repo, revision, options={})
|
24
|
+
post "#{API_ENDPOINT}/#{Repository.new(repo)}/commit/#{revision}/approve", options
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_commit_approval(repo, revision, options={})
|
28
|
+
delete "#{API_ENDPOINT}/#{Repository.new(repo)}/commit/#{revision}/approve", options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Bucketkit
|
2
|
+
class Client
|
3
|
+
# See https://confluence.atlassian.com/display/BITBUCKET/pullrequests+Resource
|
4
|
+
module PullRequests
|
5
|
+
API_ENDPOINT = 'api/2.0/repositories'.freeze
|
6
|
+
|
7
|
+
def pull_requests(repo, options={})
|
8
|
+
paginate "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests", options
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_pull_request(repo, title, source, destination, description, options={})
|
12
|
+
pull = {
|
13
|
+
title: title,
|
14
|
+
description: description,
|
15
|
+
source: { branch: { name: source } },
|
16
|
+
destination: { branch: { name: destination } }
|
17
|
+
}
|
18
|
+
post "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests", options.merge(pull)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_pull_request(repo, number, options)
|
22
|
+
patch "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}", options
|
23
|
+
end
|
24
|
+
|
25
|
+
def pull_request(repo, number, options={})
|
26
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}", options
|
27
|
+
end
|
28
|
+
|
29
|
+
def pull_request_commits(repo, number, options={})
|
30
|
+
paginate "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/commits", options
|
31
|
+
end
|
32
|
+
|
33
|
+
def approve_pull_request(repo, number, options={})
|
34
|
+
post "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/approve", options
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_pull_request_approval(repo, number, options={})
|
38
|
+
delete "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/approve", options
|
39
|
+
end
|
40
|
+
|
41
|
+
def pull_request_diff(repo, number, options={})
|
42
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/diff", options
|
43
|
+
end
|
44
|
+
|
45
|
+
def pull_request_activity(repo, number=nil, options={})
|
46
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/activity", options
|
47
|
+
end
|
48
|
+
|
49
|
+
def merge_pull_request(repo, number, options={})
|
50
|
+
post "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/merge", options
|
51
|
+
end
|
52
|
+
alias :accept_pull_request :merge_pull_request
|
53
|
+
|
54
|
+
def decline_pull_request(repo, number, options={})
|
55
|
+
post "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/decline", options
|
56
|
+
end
|
57
|
+
alias :reject_pull_request :decline_pull_request
|
58
|
+
|
59
|
+
def pull_request_comments(repo, number, options={})
|
60
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/comments", options
|
61
|
+
end
|
62
|
+
|
63
|
+
def pull_request_comment(repo, number, comment_id, options={})
|
64
|
+
get "#{API_ENDPOINT}/#{Repository.new(repo)}/pullrequests/#{number}/comments/#{comment_id}", options
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Bucketkit
|
2
|
+
module Configurable
|
3
|
+
attr_accessor :oauth_tokens, :auto_paginate, :per_page,
|
4
|
+
:connection_options, :default_media_type,
|
5
|
+
:middleware, :proxy, :user_agent
|
6
|
+
attr_writer :password, :login, :web_endpoint, :api_endpoint
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def keys
|
10
|
+
@keys ||= [
|
11
|
+
:oauth_tokens,
|
12
|
+
:auto_paginate,
|
13
|
+
:per_page,
|
14
|
+
:api_endpoint,
|
15
|
+
:web_endpoint,
|
16
|
+
:login,
|
17
|
+
:password,
|
18
|
+
:connection_options,
|
19
|
+
:default_media_type,
|
20
|
+
:middleware,
|
21
|
+
:user_agent
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def configure
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset!
|
31
|
+
Bucketkit::Configurable.keys.each { |key|
|
32
|
+
instance_variable_set(:"@#{key}", Bucketkit::Default.options[key])
|
33
|
+
}
|
34
|
+
self
|
35
|
+
end
|
36
|
+
alias setup reset!
|
37
|
+
|
38
|
+
def api_endpoint
|
39
|
+
File.join @api_endpoint, ''
|
40
|
+
end
|
41
|
+
|
42
|
+
def web_endpoint
|
43
|
+
File.join @web_endpoint, ''
|
44
|
+
end
|
45
|
+
|
46
|
+
def login
|
47
|
+
@login ||= begin
|
48
|
+
user.login if basic_authenticated?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def options
|
55
|
+
Hash[Bucketkit::Configurable.keys.map {|k| [k, instance_variable_get(:"@#{k}")]}]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'bucketkit/version'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Bucketkit
|
5
|
+
module Default
|
6
|
+
WEB_ENDPOINT = 'https://bitbucket.org'.freeze
|
7
|
+
API_ENDPOINT = 'https://bitbucket.org'.freeze
|
8
|
+
USER_AGENT = "Bucketkit Ruby Gem #{Bucketkit::VERSION}".freeze
|
9
|
+
MEDIA_TYPE = 'application/json'.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def options
|
13
|
+
Hash[Bucketkit::Configurable.keys.map { |k| [k, send(k)]}]
|
14
|
+
end
|
15
|
+
|
16
|
+
def web_endpoint
|
17
|
+
ENV['BUCKETKIT_WEB_ENDPOINT'] || WEB_ENDPOINT
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_endpoint
|
21
|
+
ENV['BUCKETKIT_API_ENDPOINT'] || API_ENDPOINT
|
22
|
+
end
|
23
|
+
|
24
|
+
def oauth_tokens
|
25
|
+
{
|
26
|
+
consumer_key: ENV['BUCKETKIT_CONSUMER_KEY'],
|
27
|
+
consumer_secret: ENV['BUCKETKIT_CONSUMER_SECRET'],
|
28
|
+
token: ENV['BUCKETKIT_TOKEN'],
|
29
|
+
token_secret: ENV['BUCKETKIT_TOKEN_SECRET']
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def login
|
34
|
+
ENV['BUCKETKIT_LOGIN']
|
35
|
+
end
|
36
|
+
|
37
|
+
def password
|
38
|
+
ENV['BUCKETKIT_PASSWORD']
|
39
|
+
end
|
40
|
+
|
41
|
+
def connection_options
|
42
|
+
{
|
43
|
+
headers: {
|
44
|
+
content_type: default_media_type,
|
45
|
+
accept: default_media_type,
|
46
|
+
user_agent: user_agent
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_media_type
|
52
|
+
ENV['BUCKETKIT_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
|
53
|
+
end
|
54
|
+
|
55
|
+
def user_agent
|
56
|
+
ENV['BUCKETKIT_USER_AGENT'] || USER_AGENT
|
57
|
+
end
|
58
|
+
|
59
|
+
def middleware
|
60
|
+
Faraday::RackBuilder.new do |builder|
|
61
|
+
builder.request :oauth, oauth_tokens
|
62
|
+
builder.adapter Faraday.default_adapter
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def auto_paginate
|
67
|
+
ENV['BUCKETKIT_AUTO_PAGINATE']
|
68
|
+
end
|
69
|
+
|
70
|
+
def per_page
|
71
|
+
page_size = ENV['BUCKETKIT_PER_PAGE']
|
72
|
+
page_size.to_i if page_size
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Bucketkit
|
2
|
+
class Repository
|
3
|
+
attr_accessor :owner, :name
|
4
|
+
|
5
|
+
def initialize(repo)
|
6
|
+
case repo
|
7
|
+
when String
|
8
|
+
@owner, @name = repo.split('/')
|
9
|
+
when Repository
|
10
|
+
@owner, @name = repo.owner, repo.name
|
11
|
+
when Hash
|
12
|
+
@name = repo[:repo] ||= repo[:name]
|
13
|
+
@owner = repo[:owner] ||= repo[:user] ||= repo[:username]
|
14
|
+
else
|
15
|
+
raise "Couldn't initialize repository."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_url(url)
|
20
|
+
Repository.new(URI.parse(url).path[1..-1])
|
21
|
+
end
|
22
|
+
|
23
|
+
def slug
|
24
|
+
"#{@owner}/#{@name}"
|
25
|
+
end
|
26
|
+
alias :to_s :slug
|
27
|
+
|
28
|
+
def url
|
29
|
+
"#{Bucketkit.web_endpoint}#{slug}"
|
30
|
+
end
|
31
|
+
|
32
|
+
alias :user :owner
|
33
|
+
alias :username :owner
|
34
|
+
alias :repo :name
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bucketkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xystushi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sawyer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.5.4
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.5'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.5.4
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faraday_middleware
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.9'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.9.1
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.9'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.9.1
|
81
|
+
description:
|
82
|
+
email:
|
83
|
+
- xystushi@gmail.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- ".gitignore"
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- bucketkit.gemspec
|
94
|
+
- lib/bucketkit.rb
|
95
|
+
- lib/bucketkit/authentication.rb
|
96
|
+
- lib/bucketkit/client.rb
|
97
|
+
- lib/bucketkit/client/commits.rb
|
98
|
+
- lib/bucketkit/client/pull_requests.rb
|
99
|
+
- lib/bucketkit/configurable.rb
|
100
|
+
- lib/bucketkit/default.rb
|
101
|
+
- lib/bucketkit/repository.rb
|
102
|
+
- lib/bucketkit/version.rb
|
103
|
+
homepage: https://github.com/xystushi/bucketkit
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A BitBucket REST API client.
|
127
|
+
test_files: []
|