Module: Bitbuckit::Connection

Includes:
Authentication
Included in:
Client
Defined in:
lib/bitbuckit/connection.rb

Instance Method Summary collapse

Methods included from Authentication

#application_authentication

Instance Method Details

#agentObject



35
36
37
38
39
40
# File 'lib/bitbuckit/connection.rb', line 35

def agent
  @agent ||= Sawyer::Agent.new(endpoint) do |http|
    http.headers[:content_type] = "application/json"
    http.params = http.params.merge application_authentication
  end
end

#get(url, options = {}) ⇒ Object



8
9
10
# File 'lib/bitbuckit/connection.rb', line 8

def get(url, options = {})
  request(:get, url, options).values
end

#last_responseObject



46
47
48
# File 'lib/bitbuckit/connection.rb', line 46

def last_response
  @last_response if defined? @last_response
end

#paginate(url, options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bitbuckit/connection.rb', line 20

def paginate(url, options = {}, &block)
  data = request(:get, url, options.dup)

  while @last_response.data.next
    request(:get, @last_response.data.next, options.dup)
    if block_given?
      yield(data.values, @last_response.data.values)
    else
      data.values.concat(@last_response.data.values)
    end
  end

  data.values
end

#post(url, options = {}) ⇒ Object



12
13
14
# File 'lib/bitbuckit/connection.rb', line 12

def post(url, options = {})
  request :post, url, options
end

#put(url, options = {}) ⇒ Object



16
17
18
# File 'lib/bitbuckit/connection.rb', line 16

def put(url, options = {})
  request :put, url, options
end

#rootObject



42
43
44
# File 'lib/bitbuckit/connection.rb', line 42

def root
  get "/"
end