rack-cachely 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-cachely (0.0.1)
4
+ rack-cachely (0.1.0)
5
5
  rack
6
6
 
7
7
  GEM
@@ -6,8 +6,7 @@ module Rack
6
6
 
7
7
  def initialize(options = {})
8
8
  self.options = options
9
- self.options[:cachely_api_key] ||= ENV["CACHELY_API_KEY"]
10
- self.options[:cachely_url] = "#{(self.options[:cachely_url] ||= ENV["CACHELY_URL"])}/v1/cache?_token=#{self.options[:cachely_api_key]}"
9
+ self.options[:cachely_url] = "#{(self.options[:cachely_url] ||= ENV["CACHELY_URL"])}/v1/cache"
11
10
  end
12
11
 
13
12
  def method_missing(sym, *args, &block)
@@ -9,8 +9,17 @@ module Rack
9
9
 
10
10
  def get(key)
11
11
  remote do
12
- uri = URI("#{config.cachely_url}&url=#{CGI.escape(key.to_s)}")
13
- response = Net::HTTP.get_response(uri)
12
+ url = "#{config.cachely_url}?url=#{CGI.escape(key.to_s)}"
13
+ uri = URI(url)
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ request = Net::HTTP::Get.new(uri.request_uri)
16
+ matches = url.scan(/\/\/(.+)@/).flatten
17
+
18
+ if matches.any?
19
+ u, p = matches.first.split(":")
20
+ request.basic_auth(u, p)
21
+ end
22
+ response = http.request(request)
14
23
  if config.verbose
15
24
  logger.info "Cachely [uri]: #{uri}"
16
25
  logger.info "Cachely [response.code]: #{response.code}"
@@ -34,8 +43,7 @@ module Rack
34
43
  "document[url]" => key,
35
44
  "document[status]" => rack[0].to_i,
36
45
  "document[body]" => body,
37
- "document[age]" => options[:age] || 0,
38
- "_token" => Rack::Cachely.config.cachely_api_key
46
+ "document[age]" => options[:age] || 0
39
47
  }
40
48
  rack[1].each do |key, value|
41
49
  data["document[headers][#{key}]"] = value
@@ -53,7 +61,7 @@ module Rack
53
61
  end
54
62
 
55
63
  def delete(pattern)
56
- Net::HTTP.post_form(URI(config.cachely_url), {_method: "DELETE", pattern: pattern, _token: config.cachely_api_key})
64
+ Net::HTTP.post_form(URI(config.cachely_url), {_method: "DELETE", pattern: pattern})
57
65
  end
58
66
 
59
67
  def remote(&block)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Cachely
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -8,9 +8,14 @@ describe Rack::Cachely::Store do
8
8
  describe "get" do
9
9
 
10
10
  it "retreives a page from the service" do
11
- mock = double(code: "200", body: "hello!")
12
- mock.stub!(:each_header).and_yield("Content-Type", "text/html")
13
- Net::HTTP.stub!(:get_response).and_return(mock)
11
+ response_mock = double(code: "200", body: "hello!")
12
+ response_mock.stub!(:each_header).and_yield("Content-Type", "text/html")
13
+ Net::HTTP::Get.should_receive(:new).with("/v1/cache?url=http%3A%2F%2Fexample.com").and_return {
14
+ m = double
15
+ m.should_receive(:basic_auth).with("1234567890", nil)
16
+ m
17
+ }
18
+ Net::HTTP.should_receive(:new).with("www.cachelyapp.com", 80).and_return(double(request: response_mock))
14
19
 
15
20
  res = store.get(key)
16
21
  res[0].should eql(200)
@@ -42,8 +47,7 @@ describe Rack::Cachely::Store do
42
47
  "document[status]" => 200,
43
48
  "document[body]" => "hello!",
44
49
  "document[age]" => 30,
45
- "document[headers][Content-Type]"=>"text/html",
46
- "_token" => Rack::Cachely.config.cachely_api_key
50
+ "document[headers][Content-Type]" => "text/html"
47
51
  }
48
52
  end
49
53
 
data/spec/spec_helper.rb CHANGED
@@ -6,12 +6,14 @@ require 'rack-cachely' # and any other gems you need
6
6
  require 'active_support/core_ext'
7
7
  require 'vcr'
8
8
 
9
+ ENV["CACHELY_URL"] = "http://1234567890@www.cachelyapp.com"
10
+
9
11
  Dir[File.expand_path(File.join("support", "**", "*.rb"), File.dirname(__FILE__))].each {|f| require f}
10
12
 
11
13
  RSpec.configure do |config|
12
14
 
13
15
  config.before do
14
- Rack::Cachely.config = Rack::Cachely::Config.new(cachely_api_key: '1234567890', cachely_url: "http://localhost:9292")
16
+ Rack::Cachely.config = Rack::Cachely::Config.new
15
17
  end
16
18
 
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cachely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: