Class: Nanoc3::Extra::CHiCk::Client
CHiCk::Client provides a simple API for issuing HTTP requests.
Constants
- DEFAULT_OPTIONS
- { :cache => { :metastore => 'file:tmp/rack/cache.meta', :entitystore => 'file:tmp/rack/cache.body' }, :cache_controller => { :max_age => 60 } }
Constructor Summary
public
initialize(options = {})
[View source]
23 24 25 26 27 28 |
# File 'lib/nanoc3/extra/chick.rb', line 23 def initialize(={}) # Get options = DEFAULT_OPTIONS.merge() [:cache] = DEFAULT_OPTIONS[:cache].merge([:cache]) [:cache_controller] = DEFAULT_OPTIONS[:cache_controller].merge([:cache_controller]) end |
Public Visibility
Public Instance Method Summary
| #get(url) |
|---|
Public Instance Method Details
get
public
get(url)
[View source]
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/nanoc3/extra/chick.rb', line 30 def get(url) # Build app = @app ||= Rack::Builder.new { use Rack::Cache, [:cache].merge(:verbose => true) use Nanoc3::Extra::CHiCk::CacheController, [:cache_controller] run Nanoc3::Extra::CHiCk::RackClient } # Build environment for request env = Rack::MockRequest.env_for(url, :method => 'GET') # Fetch puts "[CHiCk] Fetching #{url}..." if $DEBUG status, headers, body_parts = @app.call(env) puts "[CHiCk] #{url}: #{headers['X-Rack-Cache']}" if $DEBUG # Join body body = '' body_parts.each { |part| body << part } # Done [ status, headers, body ] end |