module Bitbuckit::Connection
Public Instance Methods
agent()
click to toggle source
# File lib/bitbuckit/connection.rb, line 37 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 = {})
click to toggle source
# File lib/bitbuckit/connection.rb, line 8 def get(url, options = {}) request(:get, url, options) end
last_response()
click to toggle source
# File lib/bitbuckit/connection.rb, line 48 def last_response @last_response if defined? @last_response end
paginate(url, options = {}) { |values, data.values| ... }
click to toggle source
# File lib/bitbuckit/connection.rb, line 20 def paginate(url, options = {}, &block) data = request(:get, url, options.dup) if options[:auto_paginate] 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 end data.values end
post(url, options = {})
click to toggle source
# File lib/bitbuckit/connection.rb, line 12 def post(url, options = {}) request :post, url, options end
put(url, options = {})
click to toggle source
# File lib/bitbuckit/connection.rb, line 16 def put(url, options = {}) request :put, url, options end
root()
click to toggle source
# File lib/bitbuckit/connection.rb, line 44 def root get "/" end
Protected Instance Methods
endpoint()
click to toggle source
# File lib/bitbuckit/connection.rb, line 54 def endpoint api_endpoint end
Private Instance Methods
request(method, path, data, options = {})
click to toggle source
# File lib/bitbuckit/connection.rb, line 64 def request(method, path, data, options = {}) opts = { query: data } @last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, opts) puts response.inspect response.data end
reset_agent()
click to toggle source
# File lib/bitbuckit/connection.rb, line 60 def reset_agent @agent = nil end