rack-api 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -4
- data/README.rdoc +1 -1
- data/lib/rack/api/app.rb +7 -7
- data/lib/rack/api/middleware/limit.rb +4 -4
- data/lib/rack/api/runner.rb +2 -0
- data/lib/rack/api/version.rb +1 -1
- data/lib/rack/api.rb +1 -1
- data/rack-api.gemspec +3 -3
- data/spec/rack-api/url_for_spec.rb +8 -0
- metadata +8 -8
data/Gemfile.lock
CHANGED
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
|
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
|
-
#
|
102
|
-
#
|
103
|
-
#
|
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
|
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
|
data/lib/rack/api/runner.rb
CHANGED
data/lib/rack/api/version.rb
CHANGED
data/lib/rack/api.rb
CHANGED
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", "
|
21
|
-
s.add_dependency "rack-mount", "
|
22
|
-
s.add_dependency "activesupport", "
|
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.
|
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-
|
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.
|
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.
|
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.
|
45
|
+
version: 3.0.0
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|