Class: Rack::Prerender::Recacher
- Inherits:
-
Object
- Object
- Rack::Prerender::Recacher
- Defined in:
- lib/rack/prerender/recacher.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #api_url ⇒ Object
- #call(cached_url) ⇒ Object
-
#initialize(options = {}) ⇒ Recacher
constructor
A new instance of Recacher.
- #token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Recacher
Returns a new instance of Recacher.
6 7 8 |
# File 'lib/rack/prerender/recacher.rb', line 6 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/rack/prerender/recacher.rb', line 4 def @options end |
Instance Method Details
#api_url ⇒ Object
19 20 21 22 |
# File 'lib/rack/prerender/recacher.rb', line 19 def api_url [:prerender_recache_url] || ENV['PRERENDER_RECACHE_URL'] || 'http://api.prerender.io/recache' end |
#call(cached_url) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/rack/prerender/recacher.rb', line 10 def call(cached_url) uri = URI(api_url) Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') request.body = %({"prerenderToken":"#{token}","url":"#{cached_url}"}) http.request(request) # => Net::HTTPResponse object end end |
#token ⇒ Object
24 25 26 |
# File 'lib/rack/prerender/recacher.rb', line 24 def token [:prerender_token] || ENV['PRERENDER_TOKEN'] end |