Class: BitbucketApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket-api/client.rb

Constant Summary collapse

BASE_URL =
'https://api.bitbucket.org/2.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bitbucket-api/client.rb', line 15

def initialize(options = {}, &block)
  config = BitbucketApi::Configuration.new(options)

  yield config if block_given?

  @connection = Faraday.new(url: BASE_URL) do |conn|
    conn.request :basic_auth, config.username, config.app_password
    conn.request :json
    conn.response :json
    
    # conn.use ::Middleware::HandleResponseException
    conn.adapter Faraday.default_adapter
  end
end

Instance Method Details

#get(url, params = nil) ⇒ Object



34
35
36
37
# File 'lib/bitbucket-api/client.rb', line 34

def get(url, params = nil)
  response = @connection.get(url, params)
  response.body
end

#patch(url, params) ⇒ Object



44
45
46
47
# File 'lib/bitbucket-api/client.rb', line 44

def patch(url, params)
  response = @connection.patch(url, params)
  response.body
end

#post(url, params) ⇒ Object



39
40
41
42
# File 'lib/bitbucket-api/client.rb', line 39

def post(url, params)
  response = @connection.post(url, params)
  response.body
end

#pull_requestObject



30
31
32
# File 'lib/bitbucket-api/client.rb', line 30

def pull_request
  @pull_request ||= BitbucketApi::Api::PullRequest.new(self)
end