lib/berkshelf/api_client.rb in berkshelf-3.0.0.beta2 vs lib/berkshelf/api_client.rb in berkshelf-3.0.0.beta3
- old
+ new
@@ -1,17 +1,15 @@
-require 'addressable/uri'
-
module Berkshelf
# Used to communicate with a remotely hosted [Berkshelf API Server](https://github.com/riotgames/berkshelf-api).
#
# @example
- # client = Berkshelf::APIClient.new("http://api.berkshelf.com")
+ # client = Berkshelf::APIClient.new("https://api.berkshelf.com")
# client.universe #=> [...]
class APIClient < Faraday::Connection
require_relative 'api_client/remote_cookbook'
- # @return [Addressable::URI]
+ # @return [String]
attr_reader :url
# @return [Integer]
# how many retries to attempt on HTTP requests
attr_reader :retries
@@ -26,25 +24,25 @@
# how many retries to perform before giving up
# @option options [Float] :retry_interval
# how long to wait (in seconds) between each retry
def initialize(url, options = {})
options = options.reverse_merge(retries: 5, retry_interval: 0.5)
- @url = Addressable::URI.parse(url)
+ @url = url
@retries = options[:retries]
@retry_interval = options[:retry_interval]
- builder = Faraday::Builder.new do |b|
+ options[:builder] ||= Faraday::Builder.new do |b|
b.response :parse_json
b.response :gzip
b.request :retry,
max: self.retries,
interval: self.retry_interval,
exceptions: [ Faraday::Error::TimeoutError ]
b.adapter :net_http
end
- super(self.url, builder: builder)
+ super(self.url, options)
end
# Retrieves the entire universe of known cookbooks from the API source
#
# @return [Array<APIClient::RemoteCookbook>]