Class: Berkshelf::API::SiteConnector::Supermarket
- Inherits:
-
Object
- Object
- Berkshelf::API::SiteConnector::Supermarket
- Includes:
- Logging
- Defined in:
- lib/berkshelf/api/site_connector/supermarket.rb
Constant Summary collapse
- V1_API =
The default API server
'https://supermarket.getchef.com/'.freeze
- TIMEOUT =
The timeout for the HTTP request
15
Instance Attribute Summary collapse
- #api_url ⇒ String readonly
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Supermarket
constructor
A new instance of Supermarket.
- #universe ⇒ Hash
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Supermarket
Returns a new instance of Supermarket.
40 41 42 |
# File 'lib/berkshelf/api/site_connector/supermarket.rb', line 40 def initialize( = {}) @api_url = [:url] || V1_API end |
Instance Attribute Details
#api_url ⇒ String (readonly)
36 37 38 |
# File 'lib/berkshelf/api/site_connector/supermarket.rb', line 36 def api_url @api_url end |
Instance Method Details
#universe ⇒ Hash
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/berkshelf/api/site_connector/supermarket.rb', line 45 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}" rescue Timeout::Error log.error "Failed to get `#{universe_url}' in #{TIMEOUT} seconds!" rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ENETUNREACH, OpenURI::HTTPError => e log.error "Failed to get `#{universe_url}': #{e}" end |