tinybucket gem
A Ruby client library for Bitbucket REST API v2 with OAuth Authentication.
WARNING This gem is under development.
This gem is inspired by vongrippen/bitbucket. Thanks.
yard doc (master branch)
Installation
Add this line to your application's Gemfile:
gem 'tinybucket'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tinybucket
Usage
WARNING These specs will be changed at any time.
NOTE: x
mark means Already implemented.
.
Configure
logger = Logger.new($stdout)
logger.level = Logger::WARN
Tinybucket.configure do |config|
config.logger = logger
config.cache_store_options = { store: Rails.cache, logger: logger }
config.access_token = 'your_access_token'
config.oauth_token = 'key'
config.oauth_secret = 'secret'
end
After v1.0.0, tinybucket gem support lazy enumerator !
This feature make your code more rubyish, like this.
repos = bucket.repos('myname')
repos = repos('my_name').select do |repo|
repo.pull_requests.size > 2
end.map(&:full_name)
This enumerable feature depends on Paging through object collections at Bitbucket Cloud REST API.
NOTE: About size
attribute
object collections wrapper has size
attribute at Bitbucket Cloud REST API.
The size
attribute describe as optional
attribute.
In tinybucket gem, collection size depend on side
attribute of object collections wrapper in Bitbucket Cloud REST API.
So enumerator's size
attribute may return nil
.
init
bucket = Tinybucket.new
Endpoints
teams Endpoint
team = bucket.team('team name')
members = team.members
followers = team.followers
following = team.following
repos = team.repos
users Endpoint
user = bucket.user('user name')
followers = user.followers
followings = user.followings
repos = user.repos
repositories Endpoint
repos = bucket.repos
repos = bucket.repos('someone')
repository Resource
Collection Methods
repos = bucket.repos('myname')
repos.create(params)
Object Methods
repo = bucket.repo('someone', 'great_repo')
repo.load
repo.destroy
watchers = repo.watchers
repos = repo.forks
pullrequests Resource
Collection Methods
repo = bucket.repo('someone', 'great_repo')
pull_requests = repo.pull_requests(options)
pull_requests.create(params)
activities = pull_requests.activities(options)
Object Methods
repo = bucket.repo('someone', 'great_repo')
pull_request = repo.pull_request(pr_id)
pull_request.update(params)
commits = pull_request.commits
pull_request.approve
pull_request.unapprove
diff = pull_request.diff
activities = pull_request.activities(options)
pull_request.merge(options)
pull_request.decline(options)
comments = pull_request.comments
comment = pull_request.comment(comment_id)
commits or commit Resource
Collection Methods
repo = bucket.repo('someone', 'great_repo')
commits = repo.commits(options)
Object Methods
repo = bucket.repo('someone', 'great_repo')
commit = repo.commit('revision')
comments = commit.comments
comment = commit.comment(comment_id)
commit.approve
commit.unapprove
branches Resource
Collection Methods
repo = bucket.repo('someone', 'great_repo')
branches = repo.branches(options)
Object Methods
repo = bucket.repo('someone', 'great_repo')
branch = repo.branch(branch_name)
branch-restrictions Resource
Collection Methods
repo = bucket.repo('someone', 'great_repo')
restrictions = repo.branch_restrictions
new_restriction = restrictions.create(params)
Object Methods
repo = bucket.repo('someone', 'great_repo').find
restriction = repo.branch_restriction(restriction_id)
restriction.update(params)
restriction.destroy
diff Resource
repo = bucket.repo('someone', 'great_repo')
COMMIT_ID = '7e968c5'
diff = repo.diff(COMMIT_ID)
patch = repo.patch(COMMIT_ID)
statuses/build Resource
Collection Methods
repo = bucket.repo('someone', 'great_repo')
COMMIT_ID = '7e968c5'
commit = repo.commit(COMMIT_ID)
BUILD_STATUS_KEY = 'tinybucket'
commit.build_statuses.create(
key: BUILD_STATUS_KEY,
state: 'INPROGRESS',
name: 'Name of build',
url: 'link to the build result',
description: 'about build'
)
Object Methods
repo = bucket.repo('someone', 'great_repo')
COMMIT_ID = '7e968c5'
commit = repo.commit(COMMIT_ID)
BUILD_STATUS_KEY = 'tinybucket'
# [x] GET the build status for a commit
status = commit.build_status(BUILD_STATUS_KEY)
# [x] PUT a build status for a commit
status.update(
state: 'SUCCESSFUL',
name: 'Name of build',
url: 'link to the build result',
description: 'about build'
)
Contribution
- Fork it ( https://github.com/[my-github-username]/bitbucket/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
See LICENSE file.
Author
hirakiuc