class Berkshelf::API::SiteConnector::Supermarket
Constants
- EMPTY_UNIVERSE
- TIMEOUT
The timeout for the HTTP request
- V1_API
The default
API
server
Attributes
api_url[R]
@return [String]
Public Class Methods
new(options = {})
click to toggle source
@option options [String] :url ({V1_API})
url of community site
# File lib/berkshelf/api/site_connector/supermarket.rb, line 41 def initialize(options = {}) @api_url = options[:url] || V1_API end
Public Instance Methods
universe()
click to toggle source
@return [Hash]
# File lib/berkshelf/api/site_connector/supermarket.rb, line 46 def universe universe_url = URI.parse(File.join(api_url, 'universe.json')).to_s log.debug "Loading universe from `#{universe_url}'..." Timeout.timeout(TIMEOUT) do response = open(universe_url, 'User-Agent' => USER_AGENT) JSON.parse(response.read) end rescue JSON::ParserError => e log.error "Failed to parse JSON: #{e}" EMPTY_UNIVERSE rescue Timeout::Error log.error "Failed to get `#{universe_url}' in #{TIMEOUT} seconds!" EMPTY_UNIVERSE rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ENETUNREACH, OpenURI::HTTPError => e log.error "Failed to get `#{universe_url}': #{e}" EMPTY_UNIVERSE end