rack-time-zone-header 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/HISTORY.rdoc +3 -0
- data/LICENSE.txt +7 -0
- data/README.rdoc +21 -0
- data/Rakefile +49 -0
- data/lib/rack-time-zone-header.rb +1 -0
- data/lib/rack/time_zone_header.rb +20 -0
- data/lib/rack/time_zone_header/version.rb +11 -0
- data/spec/rack/time_zone_header_spec.rb +56 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +7 -0
- metadata +144 -0
data/.gitignore
ADDED
data/HISTORY.rdoc
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright © 2010 Square, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= Rack::TimeZoneHeader
|
2
|
+
|
3
|
+
Rack middleware for parsing IETF draft {Time-Zone}[http://tools.ietf.org/html/draft-sharhalakis-httptz-05] HTTP headers.
|
4
|
+
|
5
|
+
== Prerequisites
|
6
|
+
|
7
|
+
* {Rack}[http://rack.rubyforge.org/]
|
8
|
+
|
9
|
+
== Testing
|
10
|
+
|
11
|
+
Testing requires the RSpec gem:
|
12
|
+
|
13
|
+
* {Rspec}[http://rspec.info/]
|
14
|
+
|
15
|
+
To test, run:
|
16
|
+
`rake`
|
17
|
+
|
18
|
+
== License
|
19
|
+
|
20
|
+
Copyright © 2010 Square, Inc.
|
21
|
+
See LICENSE.txt in this directory.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), 'lib', 'rack', 'time_zone_header', 'version')
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gemspec|
|
10
|
+
gemspec.version = Rack::TimeZoneHeader::VERSION::STRING
|
11
|
+
gemspec.name = "rack-time-zone-header"
|
12
|
+
gemspec.summary = "Rack middleware for Time-Zone HTTP headers"
|
13
|
+
gemspec.description = "Allow web service clients to specify the request time zone in an HTTP header."
|
14
|
+
gemspec.email = "github@squareup.com"
|
15
|
+
gemspec.homepage = "http://github.com/square/rack-time-zone-header"
|
16
|
+
gemspec.authors = [
|
17
|
+
"Randy Reddig",
|
18
|
+
"Cameron Walters",
|
19
|
+
]
|
20
|
+
gemspec.extra_rdoc_files = [
|
21
|
+
'README.rdoc',
|
22
|
+
'HISTORY.rdoc',
|
23
|
+
'LICENSE.txt',
|
24
|
+
]
|
25
|
+
gemspec.add_dependency "rack", ">=1.0.0"
|
26
|
+
gemspec.add_dependency "tzinfo", ">=0.3.14"
|
27
|
+
gemspec.add_development_dependency "rack-test", ">=0.5.3"
|
28
|
+
gemspec.add_development_dependency "rspec", ">=1.3.0"
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run all specs"
|
35
|
+
Spec::Rake::SpecTask.new do |t|
|
36
|
+
t.spec_opts = ["--options", "spec/spec.opts"]
|
37
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
38
|
+
t.rcov = ENV["RCOV"]
|
39
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/}
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :spec => :check_dependencies
|
44
|
+
task :default => :spec
|
45
|
+
|
46
|
+
desc "Remove trailing whitespace"
|
47
|
+
task :whitespace do
|
48
|
+
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
49
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/time_zone_header'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rack/time_zone_header/version'
|
2
|
+
require 'tzinfo'
|
3
|
+
|
4
|
+
# Code to parse headers in this format:
|
5
|
+
# http://tools.ietf.org/html/draft-sharhalakis-httptz-05
|
6
|
+
|
7
|
+
module Rack
|
8
|
+
class TimeZoneHeader
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
header = env["HTTP_TIME_ZONE"] || env["HTTP_X_TIME_ZONE"] || env["HTTP_TIMEZONE"]
|
15
|
+
zone = TZInfo::Timezone.get(header.split(";").last) rescue nil
|
16
|
+
env["time.zone"] = zone if zone
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rack::TimeZoneHeader do
|
4
|
+
before :each do
|
5
|
+
@app = lambda { |env| [200, {"Content-Type" => "text/plain"}, [""]] }
|
6
|
+
end
|
7
|
+
|
8
|
+
["HTTP_TIME_ZONE", "HTTP_X_TIME_ZONE", "HTTP_TIMEZONE"].each do |header_name|
|
9
|
+
[
|
10
|
+
nil,
|
11
|
+
"",
|
12
|
+
";;;",
|
13
|
+
"*",
|
14
|
+
"US/Mint_Plaza",
|
15
|
+
"PONIES",
|
16
|
+
].each do |header_value|
|
17
|
+
describe "with invalid header #{header_name}: #{header_value}" do
|
18
|
+
before :each do
|
19
|
+
@request = Rack::MockRequest.env_for("/", header_name => header_value, :lint => true, :fatal => true)
|
20
|
+
@status, @headers, @response = described_class.new(@app).call(@request)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not assign a TZInfo::Timezone instance to env['time.zone']" do
|
24
|
+
@request['time.zone'].should be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
[
|
30
|
+
"America/Los_Angeles",
|
31
|
+
"US/Pacific",
|
32
|
+
";;US/Eastern",
|
33
|
+
"2010-05-13T16:00:05-7:00;;US/Pacific",
|
34
|
+
"2010-05-12T18:42:20+7:00;;Asia/Bangkok",
|
35
|
+
"2010-05-13T18:20:21-4:00;;US/Eastern",
|
36
|
+
"2010-05-13T19:17:59-3:00;;America/Sao_Paulo",
|
37
|
+
].each do |header_value|
|
38
|
+
describe "with valid header #{header_name}: #{header_value}" do
|
39
|
+
before :each do
|
40
|
+
@request = Rack::MockRequest.env_for("/", header_name => header_value, :lint => true, :fatal => true)
|
41
|
+
@time_zone_name = header_value.split(";").last
|
42
|
+
@zime_zone = TZInfo::Timezone.get(@time_zone_name)
|
43
|
+
@status, @headers, @response = described_class.new(@app).call(@request)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "assigns a TZInfo::Timezone instance to env['time.zone']" do
|
47
|
+
@request['time.zone'].should be_a_kind_of(TZInfo::Timezone)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "the TZInfo::Timezone instance should reflect the header value" do
|
51
|
+
@request['time.zone'].should == @zime_zone
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-time-zone-header
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Randy Reddig
|
14
|
+
- Cameron Walters
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-07-18 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rack
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: tzinfo
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 15
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 3
|
50
|
+
- 14
|
51
|
+
version: 0.3.14
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rack-test
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 13
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 5
|
66
|
+
- 3
|
67
|
+
version: 0.5.3
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id003
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 27
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 3
|
82
|
+
- 0
|
83
|
+
version: 1.3.0
|
84
|
+
type: :development
|
85
|
+
version_requirements: *id004
|
86
|
+
description: Allow web service clients to specify the request time zone in an HTTP header.
|
87
|
+
email: github@squareup.com
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files:
|
93
|
+
- HISTORY.rdoc
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.rdoc
|
96
|
+
files:
|
97
|
+
- .gitignore
|
98
|
+
- HISTORY.rdoc
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
- Rakefile
|
102
|
+
- lib/rack-time-zone-header.rb
|
103
|
+
- lib/rack/time_zone_header.rb
|
104
|
+
- lib/rack/time_zone_header/version.rb
|
105
|
+
- spec/rack/time_zone_header_spec.rb
|
106
|
+
- spec/spec.opts
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://github.com/square/rack-time-zone-header
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- --charset=UTF-8
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.3.7
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Rack middleware for Time-Zone HTTP headers
|
142
|
+
test_files:
|
143
|
+
- spec/rack/time_zone_header_spec.rb
|
144
|
+
- spec/spec_helper.rb
|