Giter Club home page Giter Club logo

bitbucket's Introduction

BitBucketAPI

Gem Version

Wiki | RDocs

A Ruby wrapper for the BitBucket REST API.

Installation

Install the gem by issuing

gem install bitbucket_rest_api

or put it in your Gemfile and run bundle install

gem "bitbucket_rest_api"

Usage

Create a new client instance

bitbucket = 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:

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

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

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

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

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

or use convenience method:

bitbucket = 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

bitbucket.repos.changesets.all  'user-name', 'repo-name'
bitbucket.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

bitbucket.repos.list do |repo|
    puts repo.slug
end

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

bitbucket = BitBucket.new do |config|
  config.stack.insert_after BitBucket::Response::Helpers, CustomMiddleware
end

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

bitbucket = BitBucket.new do |config|
  config.adapter :excon

  config.stack do |builder|
    builder.use BitBucket::Response::Helpers
    builder.use BitBucket::Response::Jsonize
  end
end

API

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

BitBucket         - full API access

BitBucket::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

BitBucket::Issues::Create

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

>> BitBucket::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.

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

or

BitBucket.new(:oauth_token => YOUR_OAUTH_REQUEST_TOKEN, :oauth_secret => YOUR_OAUTH_REQUEST_TOKEN_SECRET)
BitBucket.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.

bitbucket's People

Contributors

andylinid45 avatar avalez avatar carlosramireziii avatar ckirby avatar clemenshelm avatar cltweedie avatar codenamev avatar dmgarland avatar georgephillips avatar ispyropoulos avatar jimmykarily avatar joeworkman avatar keithpitt avatar liubin avatar marcinwyszynski avatar meatherly avatar pcupueran avatar peterkovacs avatar pyro2927 avatar rashmi-rathi avatar ryosuzuki avatar simo2409 avatar twoism-dev avatar vongrippen avatar wadewinningham avatar xuhdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitbucket's Issues

Deleting a repository

I have scoured the documentation and examples and am unable to find any way of deleting a repository?

Could you please add an example of this somewhere

repo collaborators

Hello,
reading at the readme I noticed that there is mentioned 'collaborators' as an action for repo but actually I could not find anything about it in the code, is this my error checking or it's not implemented?

Thank you for your work

https://api.bitbucket.org/1.0/user/repositories endpoint stopped working

Something strange happens with this endpoint.
Net::HTTP throws EOFError which results in the following exception being raise from Faraday:

 end of file reached (Faraday::ConnectionFailed)

To reproduce simply run the following on latests master:

client = BitBucket.new(oauth_token: bitbucket_access_token, oauth_secret: bitbucket_access_token_secret)

client.user_api.repositories

The strange thing is that if I replace the API url from "https://api.bitbucket.org" to "https://bitbucket.org/api" it works. I compared the two requests and they are the same (except for the different url). This must have happened today because yesterday I'm sure it was working.

To make it more complicated, both urls behave the same when I use Postman (they both work) so I can't open an issue on Bitbucket for this. I turned debugging on with set_debug_output($stdout) on Net::HTTP and the only difference is the error:

Failing debug output:

opening connection to api.bitbucket.org:443...
opened
starting SSL for api.bitbucket.org:443...
SSL established
Net::HTTP#set_debug_output called after HTTP started
<- "GET /1.0/user/repositories HTTP/1.1\r\nUser-Agent: BitBucket Ruby Gem 0.1.7\r\nAuthorization: OAuth oauth_consumer_key=\"sensitive_credentials_here\", oauth_nonce=\"f3edbddd965663cf27a93a67aaedeede\", oauth_signature=\"vT0VE7diL0myLGQWwMI0PfyFKoI%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1465571418\", oauth_token=\"sensitive_credentials\", oauth_version=\"1.0\"\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nConnection: close\r\nHost: api.bitbucket.org\r\n\r\n"
Conn close because of error end of file reached, and retry
opening connection to api.bitbucket.org:443...
opened
starting SSL for api.bitbucket.org:443...
SSL established
<- "GET /1.0/user/repositories HTTP/1.1\r\nUser-Agent: BitBucket Ruby Gem 0.1.7\r\nAuthorization: OAuth oauth_consumer_key=\"sensitive_credentials_here\", oauth_nonce=\"f3edbddd965663cf27a93a67aaedeede\", oauth_signature=\"vT0VE7diL0myLGQWwMI0PfyFKoI%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1465571418\", oauth_token=\"sensitive_credentials_here\", oauth_version=\"1.0\"\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nConnection: close\r\nHost: api.bitbucket.org\r\n\r\n"
Conn close because of error end of file reached
Conn close because of error end of file reached
/home/dimitris/.rvm/gems/ruby-2.3.0@katana/gems/spring-1.3.6/lib/spring/application.rb:156:in `fork': end of file reached (Faraday::ConnectionFailed)

Working debug output:

opening connection to bitbucket.org:443...
opened
starting SSL for bitbucket.org:443...
SSL established
Net::HTTP#set_debug_output called after HTTP started
<- "GET /api/1.0/user/repositories HTTP/1.1\r\nUser-Agent: BitBucket Ruby Gem 0.1.7\r\nAuthorization: OAuth oauth_consumer_key=\"sensitive_debug_output\", oauth_nonce=\"c3fa96d07995b57c84aedd62b3bf28d1\", oauth_signature=\"FNFPkXpOiD6AUGE97yn%2Ff53UujU%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1465571438\", oauth_token=\"sensitive_debug_output\", oauth_version=\"1.0\"\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nConnection: close\r\nHost: bitbucket.org\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Server: nginx/1.6.2\r\n"
-> "Vary: Authorization, Cookie\r\n"
-> "Vary: Accept-Encoding\r\n"
-> "Content-Type: application/json; charset=utf-8\r\n"
-> "X-OAuth-Scopes: webhook, repository:admin, repository, account\r\n"
-> "Content-Encoding: gzip\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Date: Fri, 10 Jun 2016 15:09:29 GMT\r\n"
-> "X-Served-By: app-111\r\n"
-> "X-Static-Version: 660dd275ada4\r\n"
-> "ETag: \"87914e45bea56a015507239d2b9c0883\"\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "X-Render-Time: 0.0379409790039\r\n"
-> "X-Accepted-OAuth-Scopes: repository\r\n"
-> "Connection: close\r\n"
-> "X-Version: 660dd275ada4\r\n"
-> "X-Request-Count: 156\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "\r\n"
reading all...

...

(and the rest is the repository results in JSON format)

It seems that the first case is retried once before exiting with error.

how do you get commits?

I can instantiate an instance of Bitbucket, I can authenticate, I can get repos, but given an authenticated bitbucket instance, how do you actually retrieve a list of commits? I have tried setting the repo attribute to a repo name (returned from .repos.list) and I've tried setting the repo attribute to a repo object, and have tried bitbucket.repo.commits but always get nil. Can you give me some guidance? Thanks for any help.

Can't get oAuth to work with omniauth-bitbucket

Hey,

Forgive my ignorance, but for the lack of a better idea, I need some help with debugging this oAuth problem - which I'm sure your sick of by now ๐Ÿ˜„

I've successfully gotten a token/secret by using https://github.com/sishen/omniauth-bitbucket.

I'm trying to access the BitBucket API like so:

omniauth       = request.env['omniauth.auth']
token          = omniauth['credentials']['token']
secret         = omniauth['credentials']['secret']
bitbucket      = BitBucket.new(oauth_secret: secret, oauth_token: token)

But I'm getting a BitBucket::Error::Unauthorized on every call. Do I have to include my consumer key/secret or something? Am I storing the wrong thing from the bitbucket omniauth auth_hash perhaps?

Keith

OAuth token/secret

Hi, I'm trying to connect to my BitBucket repos:

bb = BitBucket.new do |config|
    config.oauth_token   = ''
    config.oauth_secret  = ''
    config.client_id     = '*********'
    config.client_secret = '**************************'
    config.adapter       = :net_http
end

I've generated consumer key:secret pair, but how I can get oauth token:secret pair?

Without them I am not able to connect to API :(

repos.pull_request.all: Calling links on LinkHashie::Mash Result Causes NameError

Using 0.1.7:

r = cl.repos.pull_request.all("zck", "2048.el")
r.values[1].each do |pr|
  p pr.author.username
  p pr.links.self.href
  # This does not cause the error
  # p pr["links"].self.href
end

Error is:

/Users/sshaw/.rvm/gems/ruby-2.2.3/gems/bitbucket_rest_api-0.1.7/lib/bitbucket_rest_api/result.rb:64:in `links': uninitialized constant BitBucket::PageLinks (NameError)
	from bb.rb:32:in `block in <main>'
	from bb.rb:30:in `each'
	from bb.rb:30:in `<main>'

Calling pr["links"].self.href does not cause the error.

Warning: You are setting a key that conflicts with a built-in method Hashie::Mash

Not sure why I'm getting this using what appears to be the appropriate API method:

irb [2.2.3] (export-pull-requests)$ cl = BitBucket.new
=> #<BitBucket::Client:0x007fa1754bc198 @adapter=:net_http, @client_id=nil, @client_secret=nil, @new_access_token=nil, @oauth_token=nil, @oauth_secret=nil, @endpoint="https://bitbucket.org/api", @mime_type=:json, @user_agent="BitBucket Ruby Gem 0.1.7", @connection_options={}, @repo="2048.el", @user="zck", @login="sshaw_", @password="hsomob1999", @basic_auth=nil>
irb [2.2.3] (export-pull-requests)$ cl.repos.pull_request.list("zck", "2048.el")
W, [2017-07-23T10:14:24.583659 #31632]  WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#merge defined at /Users/sshaw/.rvm/gems/ruby-2.2.3/gems/hashie-3.5.5/lib/hashie/mash.rb:202. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
....

each_page does not work due to no PageIterator object

When trying to do:

bitbucket.client.repos.pull_request.list('user', 'repo').each_page do |page|
  # stuff
end

it throws this error: uninitialized constant BitBucket::PageIterator

I can't find the PageIterator in this repo, or am I missing something?

No tests?

Hi, Iโ€™m trying to contribute to this project, but it seems there are no tests although it states so in the Development section of the readme. Also rspec and cucumber are added as development dependencies, but never used.

Would you be ok with me adding specs at least for the stuff that i contribute?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

download repos

I cant download repos and recieve message " bad URI(is not URI?): /api/1.0/repositories/#User:0x000000045aff10/demo_1 "
I think this gem version api 1.0, so cant download
Please, help me.
def index
@repositories = set_bitbucket(current_user).repos
@repos = @repositories.get(current_user,"demo_1")
end
def set_bitbucket(user)
bitbucket = BitBucket.new do |config|
config.oauth_token = user.oauth_token
config.oauth_secret = user.oauth_secret
config.client_id = Settings.BITBUCKET_CLIENT_ID
config.client_secret = Settings.BITBUCKET_CLIENT_SECRET
config.adapter = :net_http
end
end

can't modify frozen NilClass on service delete

Hello! I'm doing this:

   bitbucket.repos.services.delete repo_organization, repo_name, webhook_id

And service was deleted, but exception was raised:

can't modify frozen NilClass
/vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/response/helpers.rb:17:in block in on_complete' /vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/response/helpers.rb:17:ininstance_eval'
/vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/response/helpers.rb:17:in on_complete' /vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/response.rb:9:inblock in call'
/vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/response.rb:63:in on_complete' /vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/response.rb:8:incall'
/vagrant/vendor/bundle/ruby/2.2.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/request/encode_json.rb:23:in call' /vagrant/vendor/bundle/ruby/2.2.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/request/oauth.rb:42:incall'
/vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/request/url_encoded.rb:14:in call' /vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/request/multipart.rb:13:incall'
/vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/connection.rb:253:in run_request' /vagrant/vendor/bundle/ruby/2.2.0/gems/faraday-0.8.9/lib/faraday/connection.rb:106:indelete'
/vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/request.rb:41:in request' /vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/request.rb:27:indelete_request'
/vagrant/vendor/bundle/ruby/2.2.0/gems/bitbucket_rest_api-0.1.5/lib/bitbucket_rest_api/repos/services.rb:99:in delete' /vagrant/lib/bitbucket_manager.rb:34:indelete_web_hook'

I'm doing something wrong?

Using Oauth won't work

Hi,

I've tried connecting to bitbucket using the Oauth tokens and for some reason I can't get no results of any kind.

Using the basic auth it works great.

Faraday 0.9.x?

This gem currently requires faraday ~> 0.8.1, is there any known problem using it with faraday's 0.9.x?

Status of searching for a maintainer

Hi,

Can you share with us what's the status? Are you still searching for a new maintainer?

This is quite an urgent issue as Bitbucket started to migrate to it's new V2 API - for example you can't register a V1 webhook from the Bitbucket web UI anymore - and your GEM is still by far the most popular one.

OAuth not working

Howdy.

I've seen the other OAuth issue and I can definitely guarantee that my key and secret are what they should be.

Here's the code I have...

require 'bitbucket_rest_api'

ENV['DEBUG'] = 'wtf'

bitbucket = BitBucket.new do |config|
    config.oauth_token = "<redacted>"
    config.oauth_secret = "<redacted>"
    config.adapter = :net_http
end

pp bitbucket.repos.list

And here's the debug info...

EXECUTED: get - /user/repositories with {} and {}
OPTIONS:{:headers=>{"User-Agent"=>"BitBucket Ruby Gem 0.1.1"}, :ssl=>{:verify=>false}, :url=>"https://bitbucket.org/api/1.0"}
I, [2013-01-31T20:14:26.168358 #18994]  INFO -- : get https://bitbucket.org/api/1.0/user/repositories
D, [2013-01-31T20:14:26.168490 #18994] DEBUG -- request: User-Agent: "BitBucket Ruby Gem 0.1.1"
Authorization: "OAuth oauth_nonce=\"cea1a1e17bad92529dd2ce92ea12c68c\", oauth_signature=\"C9LPWYfXaMNIoenrD2R3BviX6PU%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1359681266\", oauth_token=\"<redacted>\", oauth_version=\"1.0\""
I, [2013-01-31T20:14:26.665307 #18994]  INFO -- Status: 302
D, [2013-01-31T20:14:26.665494 #18994] DEBUG -- response: server: "nginx/1.2.4"
date: "Fri, 01 Feb 2013 01:14:26 GMT"
content-type: "text/html; charset=utf-8"
transfer-encoding: "chunked"
connection: "close"
x-served-by: "bitbucket05"
x-version: "908585ddfd1f"
location: "https://bitbucket.org/account/signin/?next=/api/1.0/user/repositories"
x-static-version: "e2e3e99aa1fa"
x-request-count: "333"
strict-transport-security: "max-age=2592000"

The pp line simply outputs nil because bitbucket.repos.list returns nil. Does the gem need to be updated or something?

Webhook creation fails with BitBucket::Error::Unauthorized

When attempting to create a webhook via the gem, e.g.

client.repos.webhooks.create('repo_owner', 'repo_name', description: "Test Webhook", url: 'http://www.example.com/callbacks/bitbucket', active: false, events: ['repo:push'])

results in

BitBucket::Error::Unauthorized: #<struct Faraday::Env method=:post, body="", url=#<URI::HTTPS https://api.bitbucket.org/2.0/repositories/testributor/katana/hooks>, request=#<Faraday::RequestOptions oauth=true>, request_headers={"User-Agent"=>"BitBucket Ruby Gem 0.1.7", "Content-Type"=>"application/x-www-form-urlencoded", "Authorization"=>"OAuth oauth_consumer_key=\"7CjsrYVQ9SCdTioSU3v\", oauth_nonce=\"bafb5f3924d2f606c4ed3beaaf2b1f29\", oauth_signature=\"Mdm%2BjIqfceg%2BdZ1l887nad%2BcmyY%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1459954879\", oauth_token=\"4XqGMTY2UnyFnhcudm\", oauth_version=\"1.0\""}, ssl=#<Faraday::SSLOptions (empty)>, parallel_manager=nil, params=nil, response=#<Faraday::Response:0x007fdbf0376878 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:post @body="" @url=#<URI::HTTPS https://api.bitbucket.org/2.0/repositories/testributor/katana/hooks> @request=#<Faraday::RequestOptions oauth=true> @request_headers={"User-Agent"=>"BitBucket Ruby Gem 0.1.7", "Content-Type"=>"application/x-www-form-urlencoded", "Authorization"=>"OAuth oauth_consumer_key=\"7CjsrYVQ9SCdTioSU3v\", oauth_nonce=\"bafb5f3924d2f606c4ed3beaaf2b1f29\", oauth_signature=\"Mdm%2BjIqfceg%2BdZ1l887nad%2BcmyY%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1459954879\", oauth_token=\"4XqGMTY2UnyFnhcudm\", oauth_version=\"1.0\""} @ssl=#<Faraday::SSLOptions (empty)> @response=#<Faraday::Response:0x007fdbf0376878 ...> @response_headers={"server"=>"nginx/1.6.2", "vary"=>"Cookie", "www-authenticate"=>"Basic realm=\"Bitbucket.org HTTP\"", "content-type"=>"text/html; charset=utf-8", "strict-transport-security"=>"max-age=31536000", "date"=>"Wed, 06 Apr 2016 15:01:20 GMT", "x-served-by"=>"app-113", "x-static-version"=>"195aa3f25c29", "etag"=>"\"d41d8cd98f00b204e9800998ecf8427e\"", "x-render-time"=>"0.0133571624756", "connection"=>"close", "x-version"=>"195aa3f25c29", "x-request-count"=>"378", "x-frame-options"=>"SAMEORIGIN", "content-length"=>"0"} @status=401>>, response_headers={"server"=>"nginx/1.6.2", "vary"=>"Cookie", "www-authenticate"=>"Basic realm=\"Bitbucket.org HTTP\"", "content-type"=>"text/html; charset=utf-8", "strict-transport-security"=>"max-age=31536000", "date"=>"Wed, 06 Apr 2016 15:01:20 GMT", "x-served-by"=>"app-113", "x-static-version"=>"195aa3f25c29", "etag"=>"\"d41d8cd98f00b204e9800998ecf8427e\"", "x-render-time"=>"0.0133571624756", "connection"=>"close", "x-version"=>"195aa3f25c29", "x-request-count"=>"378", "x-frame-options"=>"SAMEORIGIN", "content-length"=>"0"}, status=401>

Now, the response code is misleading. Bitbucket's API shouldn't return 401, as there's no problem with the authorization. I retried other calls with the same keys and they work just fine.

The problem is the "Content-Type"=>"application/x-www-form-urlencoded". This should be application/json. If one attempts to replicate the same call via Postman or curl, the results are consistent. With the gem's incorrect method a 401 is returned, but with the correct method, 201 (Created) is returned.

It also seems that this 0e53c0e does not fix the problem.

SSL verification turned off by default

By the looks of it ( https://github.com/bitbucket-rest-api/bitbucket/blob/master/lib/bitbucket_rest_api/connection.rb#L32 ), by default SSL verification is turned off in the gem.
This is greatly discouraged practice ( see Solutions To Avoid https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates ), as we now have the same guarantees about validity of our peer as if we were to use an HTTP connection.

I'd encourage for this gem to turn SSL verification on to guarantee peer validation in the default scenario and thus for it to be a secure default.

list all repos same name ?

I use Bitbucket.repos.list to show all repos, (many repos are same name)
But i want to show only list repos name "example".
I found method get but don't know use,
Tell me, Please.

Add support for DELETE issues

Add to issues.rb the following (copy-paste of get method):

# Delete a single issue
#
# = Examples
#  bitbucket = BitBucket.new
#  bitbucket.issues.delete 'user-name', 'repo-name', 'issue-id'
#
def delete(user_name, repo_name, issue_id, params={ })
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  _validate_presence_of issue_id

  normalize! params
  # _merge_mime_type(:issue, params)

  delete_request("/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
end

Tag & Release 0.1.5

Can you please tag & release 0.1.5? I would like to use it as a dependency for one of the gems that I am developing.

"Create a repository for a team" doesn't work

I tried to create a repository for a team (which I have access to):

bb.repos.create owner: 'some_owner', name: 'test'

But it didn't really work. It created a repository under my name. The owner is still my user name instead of the team name.

I also tried to add an owner parameter using BitBucket REST API Console, and it works there. So I think there may be something wrong happening here.

Thanks.

download repos

how to download repos?
this is my code, but cant download repos

in controller :
`def set_bitbucket(user)
bitbucket = BitBucket.new do |config|
config.oauth_token = user.oauth_token
config.oauth_secret = user.oauth_secret
config.client_id = Settings.BITBUCKET_CLIENT_ID
config.client_secret = Settings.BITBUCKET_CLIENT_SECRET
config.adapter = :net_http
end
end

def index
@repositories = set_bitbucket(current_user).repos
end
**in view :**

<%= link_to "download", @repositories.download.get('dongpp_57', 'demo') %> ` **it's result:** https://bitbucket.org/dongpp_57/demo/get/.tar.gz (**error)**

i read file download.rb in api, but i dont how to get params[:commit_hash] and understand REQUIRED_KEY_PARAM_NAMES.
@vongrippen please help me, thank you.

in download.rb :
`module BitBucket
class Repos::Download < API
REQUIRED_KEY_PARAM_NAMES = %w[ commit_hash ].freeze
def get(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?

normalize! params

#assert_required_keys(REQUIRED_KEY_PARAM_NAMES, params)

https://bitbucket.org/jhanley85/eternum_canvas_demo/get/fd931f96f12d.zip

"https://bitbucket.org/#{user}/#{repo.downcase}/get/#{params[:commit_hash]}.tar.gz"
end
end # Repos::Keys
end # BitBucket
`

New features, no release?

Looks like lots of pieces have been added here with support for webhooks, getting individual pull requests etc... but there has been no new version release in a while?

Is there something that still needs to be done in order to get a new release out?

list_repo always returning the same results

No matter the filter, limiter or start I try to use on this method, the result is always the same, it keeps returning me the last 15 issues.

This is what I'm using:

  #in my ApplicationController
  def bitbucket
    @bitbucket ||= BitBucket.new login:'usr', password:'xxx'
  end 

  #index controller
  @list = bitbucket.issues.list_repo 'usr', 'myrep', :start => 5
  @list = bitbucket.issues.list_repo 'usr', 'myrep', :limit => "20"
  @list = bitbucket.issues.list_repo 'usr', 'myrep', :filter => "kind=enhancement"

All of these return the same 15 issues each time.

The commented out example above the method definition is not working either, but I'm guessing that's based on an older version of this method?

    bitbucket = BitBucket.new :user => 'usr', :repo => 'myrep'
    bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement'

Consumer key not working

bitbucket.repos.all

BitBucket::Error::Unauthorized: #<struct Faraday::Env method=:get, body="", url=#<URI::HTTPS https://bitbucket.org/api/1.0/user/repositories>, request=#<Faraday::RequestOptions proxy=#<Faraday::ProxyOptions uri=#<URI::HTTP http://10.6.13.77:8080/>>, oauth=true>, request_headers={"User-Agent"=>"BitBucket Ruby Gem 0.1.7", "Authorization"=>"OAuth oauth_consumer_key="XXX", oauth_nonce="d161352d7fd1b7ba7207a457c43038cf", oauth_signature="%2BsDwJGrBRMcSYkoxmDc%2BVJFtAZg%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1459756974", oauth_token="", oauth_version="1.0""}, ssl=#<Faraday::SSLOptions (empty)>, parallel_manager=nil, params=nil, response=#<Faraday::Response:0x000000021c3318 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @Body="" @url=#<URI::HTTPS https://bitbucket.org/api/1.0/user/repositories> @request=#<Faraday::RequestOptions proxy=#<Faraday::ProxyOptions uri=#<URI::HTTP http://10.6.13.77:8080/>>, oauth=true> @request_headers={"User-Agent"=>"BitBucket Ruby Gem 0.1.7", "Authorization"=>"OAuth oauth_consumer_key="XXX", oauth_nonce="d161352d7fd1b7ba7207a457c43038cf", oauth_signature="%2BsDwJGrBRMcSYkoxmDc%2BVJFtAZg%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1459756974", oauth_token="", oauth_version="1.0""} @ssl=#<Faraday::SSLOptions (empty)> @response=#<Faraday::Response:0x000000021c3318 ...> @response_headers={"server"=>"nginx/1.6.2", "vary"=>"Cookie", "www-authenticate"=>"Basic realm="Bitbucket.org HTTP"", "content-type"=>"text/html; charset=utf-8", "strict-transport-security"=>"max-age=31536000", "date"=>"Mon, 04 Apr 2016 08:02:54 GMT", "x-served-by"=>"app-113", "x-static-version"=>"9d27a7681f21", "etag"=>""d41d8cd98f00b204e9800998ecf8427e"", "x-render-time"=>"0.00727915763855", "connection"=>"close", "x-version"=>"9d27a7681f21", "x-request-count"=>"212", "x-frame-options"=>"SAMEORIGIN", "content-length"=>"0"} @status=401>>, response_headers={"server"=>"nginx/1.6.2", "vary"=>"Cookie", "www-authenticate"=>"Basic realm="Bitbucket.org HTTP"", "content-type"=>"text/html; charset=utf-8", "strict-transport-security"=>"max-age=31536000", "date"=>"Mon, 04 Apr 2016 08:02:54 GMT", "x-served-by"=>"app-113", "x-static-version"=>"9d27a7681f21", "etag"=>""d41d8cd98f00b204e9800998ecf8427e"", "x-render-time"=>"0.00727915763855", "connection"=>"close", "x-version"=>"9d27a7681f21", "x-request-count"=>"212", "x-frame-options"=>"SAMEORIGIN", "content-length"=>"0"}, status=401>
`

Need help to understand how to achieve this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.