nextday 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -0
- data/lib/nextday/json.rb +23 -0
- data/lib/nextday/version.rb +1 -1
- data/nextday.gemspec +3 -1
- data/spec/lib/nextday/json_spec.rb +31 -0
- metadata +55 -4
data/README.md
CHANGED
@@ -45,6 +45,33 @@ DateTime.today.delivery_day
|
|
45
45
|
Time.now.delivery_day
|
46
46
|
```
|
47
47
|
|
48
|
+
## Rack Application
|
49
|
+
|
50
|
+
To make caching easier you can mount the ```Nextday::JSON``` in your application so you can poll it every few minutes and have next to real time data.
|
51
|
+
|
52
|
+
It will return so:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
{
|
56
|
+
"cut_off_time": "16:00",
|
57
|
+
"working_day": false,
|
58
|
+
"next_working_day": "2012-06-11",
|
59
|
+
"previous_working_day": "2012-06-08",
|
60
|
+
"despatch_day": "2012-06-11",
|
61
|
+
"delivery_day": "2012-06-12"
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
### Rails
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'nextday/json'
|
69
|
+
|
70
|
+
YourAmazing::Application.routes.draw do
|
71
|
+
mount Nextday::JSON.new, :at => "/nextday.json"
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
48
75
|
## Configuration
|
49
76
|
|
50
77
|
To set the cut off time to a different value:
|
data/lib/nextday/json.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'json'
|
3
|
+
require 'nextday'
|
4
|
+
|
5
|
+
module Nextday
|
6
|
+
class JSON
|
7
|
+
def call(env)
|
8
|
+
[200, {"Content-Type" => "application/json"}, [data.to_json]]
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def data(current_time = Time.now)
|
13
|
+
{
|
14
|
+
:cut_off_time => Nextday::Config.cut_off_time,
|
15
|
+
:working_day => current_time.working_day?,
|
16
|
+
:next_working_day => current_time.next_working_day,
|
17
|
+
:previous_working_day => current_time.previous_working_day,
|
18
|
+
:despatch_day => current_time.despatch_day,
|
19
|
+
:delivery_day => current_time.delivery_day
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/nextday/version.rb
CHANGED
data/nextday.gemspec
CHANGED
@@ -25,5 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency('rspec', '~> 2.10.0')
|
26
26
|
s.add_development_dependency('yard')
|
27
27
|
s.add_development_dependency('rake')
|
28
|
-
|
28
|
+
s.add_development_dependency('rack-test')
|
29
|
+
s.add_runtime_dependency "json"
|
30
|
+
s.add_runtime_dependency "rack"
|
29
31
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../../spec_helper.rb'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'nextday/json'
|
4
|
+
|
5
|
+
describe Nextday::JSON do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
Nextday::JSON.new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
get '/'
|
14
|
+
end
|
15
|
+
|
16
|
+
it { last_response.should be_ok }
|
17
|
+
|
18
|
+
it { last_response.header["Content-Type"].should eql("application/json") }
|
19
|
+
|
20
|
+
it "should return the correct json" do
|
21
|
+
current_time = Time.now
|
22
|
+
JSON.parse(last_response.body).should eql({
|
23
|
+
"cut_off_time" => Nextday::Config.cut_off_time,
|
24
|
+
"working_day" => current_time.working_day?,
|
25
|
+
"next_working_day" => current_time.next_working_day.to_s,
|
26
|
+
"previous_working_day" => current_time.previous_working_day.to_s,
|
27
|
+
"despatch_day" => current_time.despatch_day.to_s,
|
28
|
+
"delivery_day" => current_time.delivery_day.to_s
|
29
|
+
})
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nextday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,6 +59,54 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rack
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
62
110
|
description: ! "\n Finds the Next Working Day even if holidays are in the way.\n
|
63
111
|
\ Extends Date with a .next_working_day instance method.\n "
|
64
112
|
email:
|
@@ -80,6 +128,7 @@ files:
|
|
80
128
|
- lib/nextday/date_extension.rb
|
81
129
|
- lib/nextday/holiday.rb
|
82
130
|
- lib/nextday/holidays.rb
|
131
|
+
- lib/nextday/json.rb
|
83
132
|
- lib/nextday/public_holidays.rb
|
84
133
|
- lib/nextday/version.rb
|
85
134
|
- nextday.gemspec
|
@@ -87,6 +136,7 @@ files:
|
|
87
136
|
- spec/lib/nextday/core_ext/date_spec.rb
|
88
137
|
- spec/lib/nextday/holiday_spec.rb
|
89
138
|
- spec/lib/nextday/holidays_spec.rb
|
139
|
+
- spec/lib/nextday/json_spec.rb
|
90
140
|
- spec/spec_helper.rb
|
91
141
|
homepage: https://github.com/robwilliams/nextday
|
92
142
|
licenses: []
|
@@ -102,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
152
|
version: '0'
|
103
153
|
segments:
|
104
154
|
- 0
|
105
|
-
hash:
|
155
|
+
hash: -2514156019871276712
|
106
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
157
|
none: false
|
108
158
|
requirements:
|
@@ -111,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
161
|
version: '0'
|
112
162
|
segments:
|
113
163
|
- 0
|
114
|
-
hash:
|
164
|
+
hash: -2514156019871276712
|
115
165
|
requirements: []
|
116
166
|
rubyforge_project: nextday
|
117
167
|
rubygems_version: 1.8.24
|
@@ -123,5 +173,6 @@ test_files:
|
|
123
173
|
- spec/lib/nextday/core_ext/date_spec.rb
|
124
174
|
- spec/lib/nextday/holiday_spec.rb
|
125
175
|
- spec/lib/nextday/holidays_spec.rb
|
176
|
+
- spec/lib/nextday/json_spec.rb
|
126
177
|
- spec/spec_helper.rb
|
127
178
|
has_rdoc:
|