Revisions
-
Andrea Campi created this gist
Sep 28, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ class Chef module Mixin module ConsumeJson def consume_json(url) Chef::Log.debug "consume_json: requesting url: #{url}" info = nil fetch(url) do |data| info = JSON.parse(data) Chef::Log.debug "consume_json: parsed: #{info.inspect}" yield(info) if block_given? end info end protected def fetch(url) Chef::REST.new(url, nil, nil, http_client_opts).fetch(url) do |raw_file| data = File.read(raw_file.path) yield(data) end end def http_client_opts {} end end end end Chef::Recipe.send(:include, Chef::Mixin::ConsumeJson)