rack-api 0.2.0 → 0.2.1

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,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-api (0.2.0)
5
- activesupport (~> 3.0.7)
6
- rack (~> 1.2.1)
7
- rack-mount (~> 0.6.14)
4
+ rack-api (0.2.1)
5
+ activesupport (>= 3.0.0)
6
+ rack (>= 1.0.0)
7
+ rack-mount (>= 0.6.0)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -187,7 +187,7 @@ Build an URL by merging segments, default URL options and hash with parameters.
187
187
 
188
188
  === Rack::API::Middleware::SSL
189
189
 
190
- This middleware will accept only HTTPS requests. Any request on HTTP will be dropped.
190
+ This middleware will accept only HTTPS requests. Any request over HTTP will be dropped.
191
191
 
192
192
  Rack::API.app do
193
193
  use Rack::API::Middleware::SSL
data/lib/rack/api/app.rb CHANGED
@@ -49,11 +49,11 @@ module Rack
49
49
  attr_accessor :url_options
50
50
 
51
51
  def initialize(options)
52
- @url_options = {}
53
-
54
52
  options.each do |name, value|
55
53
  instance_variable_set("@#{name}", value)
56
54
  end
55
+
56
+ @url_options ||= {}
57
57
  end
58
58
 
59
59
  # Always log to the standard output.
@@ -98,9 +98,9 @@ module Rack
98
98
  #
99
99
  # Valid options are:
100
100
  #
101
- # # <tt>:status</tt>: a HTTP status code. Defaults to 403.
102
- # # <tt>:message</tt>: a message that will be rendered as the response body. Defaults to "Forbidden".
103
- # # <tt>:headers</tt>: the response headers. Defaults to <tt>{"Content-Type" => "text/plain"}</tt>.
101
+ # * <tt>:status</tt>: a HTTP status code. Defaults to 403.
102
+ # * <tt>:message</tt>: a message that will be rendered as the response body. Defaults to "Forbidden".
103
+ # * <tt>:headers</tt>: the response headers. Defaults to <tt>{"Content-Type" => "text/plain"}</tt>.
104
104
  #
105
105
  # You can also provide a object that responds to <tt>to_rack</tt>. In this case, this
106
106
  # method must return a valid Rack response (a 3-item array).
@@ -186,8 +186,8 @@ module Rack
186
186
  # url_for :users, :filters => [:name, :age]
187
187
  # #=> /users?filters[]=name&filters[]=age
188
188
  #
189
- # URL segments can be any kind of object, first checking it responds to the
190
- # <tt>to_param</tt> method. If not, converts object to string by using the
189
+ # URL segments can be any kind of object. First it'll be checked if it responds to
190
+ # the <tt>to_param</tt> method. If not, converts object to string by using the
191
191
  # <tt>to_s</tt> method.
192
192
  #
193
193
  def url_for(*args)
@@ -26,24 +26,24 @@ module Rack
26
26
  end
27
27
 
28
28
  private
29
- def authorized?
29
+ def authorized? # :nodoc:
30
30
  count = redis.incr(key)
31
31
  redis.expire(key, 3600)
32
32
 
33
33
  count <= options[:limit] || redis.sismember("api:whitelist", identifier)
34
34
  end
35
35
 
36
- def redis
36
+ def redis # :nodoc:
37
37
  options[:with]
38
38
  end
39
39
 
40
- def identifier
40
+ def identifier # :nodoc:
41
41
  @identifier ||= begin
42
42
  options[:key].respond_to?(:call) ? options[:key].call(env).to_s : env[options[:key].to_s]
43
43
  end
44
44
  end
45
45
 
46
- def key
46
+ def key # :nodoc:
47
47
  @key ||= begin
48
48
  "api:#{identifier}:#{Time.now.strftime("%Y%m%d%H")}"
49
49
  end
@@ -94,6 +94,8 @@ module Rack
94
94
  # * <tt>:port</tt> – Optionally specify the port to connect to.
95
95
  # * <tt>:base_path</tt> – Optionally specify a base path.
96
96
  #
97
+ # Some usage examples:
98
+ #
97
99
  # default_url_options :host => "myhost.com"
98
100
  # #=> http://myhost.com
99
101
  #
@@ -3,7 +3,7 @@ module Rack
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 2
6
- PATCH = 0
6
+ PATCH = 1
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
9
9
  end
data/lib/rack/api.rb CHANGED
@@ -50,7 +50,7 @@ module Rack
50
50
  # Initialize a new Rack::API::Middleware instance, so
51
51
  # we can use it on other class methods.
52
52
  #
53
- def self.runner
53
+ def self.runner # :nodoc:
54
54
  @runner ||= Runner.new
55
55
  end
56
56
  end
data/rack-api.gemspec CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "rack", "~> 1.2.1"
21
- s.add_dependency "rack-mount", "~> 0.6.14"
22
- s.add_dependency "activesupport", "~> 3.0.7"
20
+ s.add_dependency "rack", ">= 1.0.0"
21
+ s.add_dependency "rack-mount", ">= 0.6.0"
22
+ s.add_dependency "activesupport", ">= 3.0.0"
23
23
  s.add_development_dependency "rspec", "~> 2.5.0"
24
24
  s.add_development_dependency "rack-test", "~> 0.5.7"
25
25
  s.add_development_dependency "redis", "~> 2.2.0"
@@ -21,6 +21,14 @@ describe Rack::API::App, "#url_for" do
21
21
  subject.url_for.should == "http://example.org/v1"
22
22
  end
23
23
 
24
+ it "sets default url options hash" do
25
+ subject = Rack::API::App.new(:version => "v1", :url_options => nil, :env => Rack::MockRequest.env_for("/v1"))
26
+
27
+ expect {
28
+ subject.url_for(:things, 1)
29
+ }.to_not raise_error
30
+ end
31
+
24
32
  it "uses a different host" do
25
33
  subject.url_options.merge!(:host => "mysite.com")
26
34
  subject.url_for.should == "http://mysite.com/v1"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rack-api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-19 00:00:00 Z
13
+ date: 2011-05-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -18,9 +18,9 @@ dependencies:
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.1
23
+ version: 1.0.0
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -29,9 +29,9 @@ dependencies:
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
- - - ~>
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.6.14
34
+ version: 0.6.0
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ dependencies:
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 3.0.7
45
+ version: 3.0.0
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency