Class: Nanoc3::Extra::CHiCk::Client Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc3/extra/chick.rb

Overview

Deprecated.

Use a HTTP library such as [Net::HTTP](ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or [Curb](curb.rubyforge.org/) instead.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :cache => {
    :metastore   => 'file:tmp/rack/cache.meta', 
    :entitystore => 'file:tmp/rack/cache.body'
  },
  :cache_controller => {
    :max_age => 60
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
# File 'lib/nanoc3/extra/chick.rb', line 27

def initialize(options={})
  # Get options
  @options = DEFAULT_OPTIONS.merge(options)
  @options[:cache] = DEFAULT_OPTIONS[:cache].merge(@options[:cache])
  @options[:cache_controller] = DEFAULT_OPTIONS[:cache_controller].merge(@options[:cache_controller])
end

Instance Method Details

#get(url) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nanoc3/extra/chick.rb', line 34

def get(url)
  # Build app
  options = @options
  @app ||= Rack::Builder.new {
    use Rack::Cache, options[:cache].merge(:verbose => true)
    use Nanoc3::Extra::CHiCk::CacheController, options[: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