bitrise-io/bitbucket

Name: bitbucket

Owner: Bitrise

Description: In search of a new maintainer, I just don't have the time or the need to focus on this project.

Created: 2015-04-13 12:46:09.0

Updated: 2016-03-09 16:24:14.0

Pushed: 2015-02-27 15:43:56.0

Homepage:

Size: 357

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

BitBucketAPI

Gem Version

Wiki | RDocs

A Ruby wrapper for the BitBucket REST API.

Installation

Install the gem by issuing

install bitbucket_rest_api

or put it in your Gemfile and run bundle install

"bitbucket_rest_api"
Usage

Create a new client instance

ucket = BitBucket.new

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:

ucket = BitBucket.new oauth_token: 'request_token', oauth_secret: 'request_secret'

Alternatively, you can configure the BitBucket settings by passing a block:

ucket = BitBucket.new do |config|
nfig.oauth_token   = 'request_token'
nfig.oauth_secret  = 'request_secret'
nfig.client_id     = 'consumer_key'
nfig.client_secret = 'consumer_secret'
nfig.adapter       = :net_http

You can authenticate either using OAuth authentication or through basic authentication by passing your login and password credentials

ucket = BitBucket.new login:'vongrippen', password:'...'

or use convenience method:

ucket = BitBucket.new basic_auth: 'login:password'

You can interact with BitBucket interface, for example repositories, by issuing following calls that correspond directly to the BitBucket API hierarchy

ucket.repos.changesets.all  'user-name', 'repo-name'
ucket.repos.keys.list     'user-name', 'repo-name'

The response is of type [Hashie::Mash] and allows to traverse all the json response attributes like method calls.

Inputs

Some API methods apart from required parameters such as username or repository name allow you to switch the way the data is returned to you, for instance by passing a block you can iterate over the list of repositories

ucket.repos.list do |repo|
puts repo.slug

Advanced Configuration

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

ucket = BitBucket.new do |config|
nfig.stack.insert_after BitBucket::Response::Helpers, CustomMiddleware

Furthermore, you can build your entire custom stack and specify other connection options such as adapter

ucket = BitBucket.new do |config|
nfig.adapter :excon

nfig.stack do |builder|
builder.use BitBucket::Response::Helpers
builder.use BitBucket::Response::Jsonize
d

API

Main API methods are grouped into the following classes that can be instantiated on their own

ucket         - full API access

ucket::Repos           BitBucket::Issues

Some parts of BitBucket API require you to be authenticated, for instance the following are examples of APIs only for the authenticated user

ucket::Issues::Create

You can find out supported methods by calling actions on a class instance in your irb:

itBucket::Repos.actions                 >> bitbucket.issues.actions
                                        ---
 all                                    |--> all
 branches                               |--> comments
 collaborators                          |--> create
 commits                                |--> edit
 contribs                               |--> events
 contributors                           |--> find
 create                                 |--> get
 downloads                              |--> labels
 edit                                   |--> list
 find                                   |--> list_repo
 forks                                  |--> list_repository
 get                                    |--> milestones
 hooks                                  ...

Configuration

Certain methods require authentication. To get your BitBucket OAuth credentials, register an app with BitBucket.

ucket.configure do |config|
nfig.oauth_token   = YOUR_OAUTH_REQUEST_TOKEN          # Different for each user
nfig.oauth_secret  = YOUR_OAUTH_REQUEST_TOKEN_SECRET   # Different for each user
nfig.client_id     = YOUR_OAUTH_CONSUMER_TOKEN
nfig.client_secret = YOUR_OAUTH_CONSUMER_TOKEN_SECRET
nfig.basic_auth    = 'login:password'




ucket.new(:oauth_token => YOUR_OAUTH_REQUEST_TOKEN, :oauth_secret => YOUR_OAUTH_REQUEST_TOKEN_SECRET)
ucket.new(:basic_auth => 'login:password')
Development

Questions or problems? Please post them on the issue tracker. 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.

Copyright

Copyright (c) 2012 James M Cochran. Original github_api gem Copyright (c) 2011-2012 Piotr Murach. See LICENSE.txt for further details.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.