Skip to content
Browse files

Updating README. Add test for Memorial Day.

  • Loading branch information...
1 parent 0de4bd2 commit 9ae6cb5fd40106b626354f9e2ff4ba6bc31aecda @czarneckid committed May 28, 2012
Showing with 60 additions and 3 deletions.
  1. +33 −3 README.md
  2. +6 −0 isitaholiday/api_v2.rb
  3. +21 −0 spec/isitaholiday/api_v2_spec.rb
View
36 README.md
@@ -2,15 +2,17 @@
This is an API to check if it is a holiday.
-## API
+## API v1
It has one endpoint you care about:
```
/api/v1/check/:holiday/
```
-The API will also accept a `timezone` parameter to check to see if it's still a holiday in the timezone where you live!
+The API will also accept a `timezone` parameter to check to see if
+it's still a holiday in the timezone where you live! The default
+timezone is set to `America/New_York`.
All API responses are in JSON.
@@ -28,7 +30,7 @@ Sample endpoints and JSON responses (assuming it actually IS Cinco de Mayo):
{"status":true,"name":"Cinco de Mayo"}
```
-## Known Holidays
+### Known Holidays
The current list of known holidays. Format is :holiday - Full holiday name.
@@ -38,6 +40,34 @@ The current list of known holidays. Format is :holiday - Full holiday name.
* `thanksgiving` - Thanksgiving
* `christmas` - Christmas
+## API v2
+
+It has one endpoint you care about:
+
+```
+/api/v2/holidays/:holiday/
+```
+
+The API will also accept a `timezone` parameter to check to see if
+it's still a holiday in the timezone where you live! The default
+timezone is set to `America/New_York`.
+
+All API responses are in JSON.
+
+### Known holidays
+
+This endpoint uses the [holidays](https://github.com/alexdunae/holidays) gem
+to get its holiday information.
+
+You can use the `:holiday` parameter value of `today` to return all holidays
+for the current day.
+
+Below are a few sample API responses:
+
+```json
+{:status=>true, :holidays=>[{:date=>Mon, 28 May 2012, :name=>"Pfingstmontag", :regions=>[:at, :de, :li]}, {:date=>Mon, 28 May 2012, :name=>"2. Pinsedag", :regions=>[:dk]}, {:date=>Mon, 28 May 2012, :name=>"Lundi de Pentecôte", :regions=>[:fr]}, {:date=>Mon, 28 May 2012, :name=>"Annar í hvítasunnu", :regions=>[:is]}, {:date=>Mon, 28 May 2012, :name=>"Pinksteren", :regions=>[:nl]}, {:date=>Mon, 28 May 2012, :name=>"2. pinsedag", :regions=>[:no]}, {:date=>Mon, 28 May 2012, :name=>"Bank Holiday", :regions=>[:gb]}, {:date=>Mon, 28 May 2012, :name=>"Memorial Day", :regions=>[:us, :nyse, :ups]}]}
+```
+
## Contributing
1. Fork it
View
6 isitaholiday/api_v2.rb
@@ -16,6 +16,12 @@ class API::V2 < Grape::API
error_format :json
rescue_from :all
+ resource :status do
+ get '/ping' do
+ {:status => 'pong'}
+ end
+ end
+
resource :holidays do
get '/today' do
params[:timezone] ||= 'America/New_York'
View
21 spec/isitaholiday/api_v2_spec.rb
@@ -7,6 +7,16 @@ def app
IsItAHoliday::API::V2
end
+ describe 'status' do
+ describe '#ping' do
+ it 'should respond with pong' do
+ get '/api/v2/status/ping'
+ last_response.should be_ok
+ JSON.parse(last_response.body)['status'].should == 'pong'
+ end
+ end
+ end
+
describe 'holidays' do
describe 'today' do
it 'should respond with all the holidays on may 31st' do
@@ -44,6 +54,17 @@ def app
end
end
+ it 'should respond correctly if it is Memorial Day' do
+ Timecop.freeze(Time.local(2012, 5, 28, 12, 0, 0)) do
+ get '/api/v2/holidays/memorial_day/'
+ last_response.should be_ok
+ JSON.parse(last_response.body).tap do |json|
+ json['status'].should == true
+ json['holidays'].size.should == 1
+ end
+ end
+ end
+
it 'should respond correctly if it is Christmas' do
Timecop.freeze(Time.local(2012, 12, 25, 12, 0, 0)) do
get '/api/v2/holidays/christmas_day/'

0 comments on commit 9ae6cb5

Please sign in to comment.
Something went wrong with that request. Please try again.