Sha256: 70bb3413b2d9485f4222261c16f6b1bd1032ea05c572ff8e068c65234d336324

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

class BitbucketClient
  include HTTParty
  base_uri 'https://api.bitbucket.org/1.0/repositories'

  def initialize(username, password)
    self.class.basic_auth(username, password)
  end

  def commit_comments(slug, sha)
    response = get("/#{slug}/changesets/#{sha}/comments")
    openstruct(response)
  end

  def create_commit_comment(slug, sha, body, path, position)
    post("/#{slug}/changesets/#{sha}/comments", body, path, position)
  end

  def pull_comments(slug, pull_id)
    response = get("/#{slug}/pullrequests/#{pull_id}/comments")
    openstruct(response)
  end

  def pull_requests(slug)
    base = 'https://api.bitbucket.org/2.0/repositories'
    response = get("#{base}/#{slug}/pullrequests?state=OPEN")
    openstruct(response['values'])
  end

  def create_pull_comment(slug, pull_id, body, path, position)
    post("/#{slug}/pullrequests/#{pull_id}/comments", body, path, position)
  end

  private

  def openstruct(response)
    response.map { |r| OpenStruct.new(r) }
  end

  def post(url, body, path, position)
    options = {
      body: {
        content: body,
        line_to: position,
        filename: path
      }
    }
    self.class.post(url, options)
  end

  def get(url)
    self.class.get(url).parsed_response
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pronto-0.9.5 lib/pronto/clients/bitbucket_client.rb
pronto-0.9.4 lib/pronto/clients/bitbucket_client.rb
pronto-0.9.3 lib/pronto/clients/bitbucket_client.rb
pronto-0.9.2 lib/pronto/clients/bitbucket_client.rb
pronto-0.9.1 lib/pronto/clients/bitbucket_client.rb
pronto-0.9.0 lib/pronto/clients/bitbucket_client.rb