google_holiday_calendar 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ff02c8c74a34ae2db1d25e804e745673a5365f
4
- data.tar.gz: e025c7f86ea9dcb8922e74c956cb6b9260c549b0
3
+ metadata.gz: a4e1d29ab01f9ca5714f4378aae0d5cbe6c84240
4
+ data.tar.gz: e6ef5a072140fe6c554a94bd64c25fb255d04888
5
5
  SHA512:
6
- metadata.gz: fa3d7ec59f3e7387b0b4ff9f00e560c7388dcf36817118444d9c7e5da07d7f2f6b5edaf3b3a12ead4db1d6ce0f3cf0537968296e04ff9046c3e3791f776cf41c
7
- data.tar.gz: b8f6ba4975fda277f2286abe8ad8e883cbf055a79d512c0c20f392380a3561890a1e4b23858f4e3a91a08468d76fb0d1ba4f77f5a9cfa44c40c41c175d465460
6
+ metadata.gz: 216fee75103099dfcff4032cc910a47097a7e534f5b86f34953badea4e448d6e5e23e0ced9f6f357334518b2464e21c44e2b540f857e89034f955d7e9a46b32d
7
+ data.tar.gz: 9f17d2eea3c0290c1ec473bf7299e94eaf4fde8a9d05afca48bab200aafb4417940fe388464c3f9be447fde5705888ccfd39def05c5dadd17eafff641d0b00a0
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ GOOGLE_API_KEY=
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .env
19
+
data/.travis.yml CHANGED
@@ -1,10 +1,24 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - ruby-head
7
+ before_script:
8
+ - export COVERAGE=true
9
+ script:
10
+ - bundle exec rspec
6
11
  branches:
7
12
  only:
8
13
  - master
14
+ env:
15
+ global:
16
+ secure: "PUaG7vOmYf3MhO6KJR7kaOeDk+MiP31JCMI6m47z7y+4SGBj0+pxdYK9CY50McGkjjNajXC6RoNJiaVwlQduLS7mM8WKusGKgtnr/APHtZqbVy+KSXdXLvVD/GPaGxb+W7/SlTj5lLAe75hFj48hMWH2g7qDERmbEksEMqXM8CE="
9
17
  notifications:
10
18
  email: false
19
+ slack:
20
+ secure: LFMFNHkB88zWrcjwRstw7Ri+pKVndjkz11H8r73GbrJOL76Lt4llVsraYLRrCnx859kRZul4SjbUIlYsRl28Wv2IJmIhvDnK9n5gX4nSbEfjrZGsaMOmJhY8MxazM4757TFEY6ugzwRD3hzWKEK6bIY6nRu5KAFaZhPjDbSaEpA=
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: 2.2
24
+ - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## master
2
- [full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.0.2...master)
2
+ [full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.1.0...master)
3
+
4
+ ## v0.1.0
5
+ [full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.0.2...v0.1.0)
6
+
7
+ * Use Google Calendar API v3
8
+ * relax dependency gem version
3
9
 
4
10
  ## v0.0.2
5
11
  [full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.0.1...v0.0.2)
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # GoogleHolidayCalendar [![Gem Version](https://badge.fury.io/rb/google_holiday_calendar.png)](http://badge.fury.io/rb/google_holiday_calendar) [![Build Status](https://travis-ci.org/sue445/google_holiday_calendar.png?branch=master)](https://travis-ci.org/sue445/google_holiday_calendar) [![Coverage Status](https://coveralls.io/repos/sue445/google_holiday_calendar/badge.png)](https://coveralls.io/r/sue445/google_holiday_calendar) [![Dependency Status](https://gemnasium.com/sue445/google_holiday_calendar.png)](https://gemnasium.com/sue445/google_holiday_calendar) [![Code Climate](https://codeclimate.com/github/sue445/google_holiday_calendar.png)](https://codeclimate.com/github/sue445/google_holiday_calendar)
1
+ # GoogleHolidayCalendar
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/google_holiday_calendar.png)](http://badge.fury.io/rb/google_holiday_calendar)
4
+ [![Build Status](https://travis-ci.org/sue445/google_holiday_calendar.png?branch=master)](https://travis-ci.org/sue445/google_holiday_calendar)
5
+ [![Coverage Status](https://coveralls.io/repos/sue445/google_holiday_calendar/badge.png)](https://coveralls.io/r/sue445/google_holiday_calendar)
6
+ [![Dependency Status](https://gemnasium.com/sue445/google_holiday_calendar.png)](https://gemnasium.com/sue445/google_holiday_calendar)
7
+ [![Code Climate](https://codeclimate.com/github/sue445/google_holiday_calendar.png)](https://codeclimate.com/github/sue445/google_holiday_calendar)
2
8
 
3
9
  Get holidays via Google Calendar.
4
10
 
@@ -93,6 +99,14 @@ $ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --countr
93
99
  ## More reference
94
100
  http://rubydoc.info/github/sue445/google_holiday_calendar
95
101
 
102
+ ## Testing
103
+ get api key on [API Console](https://code.google.com/apis/console/) and enable Google Calendar API
104
+
105
+ ```bash
106
+ cp .env.example .env
107
+ vi .env
108
+ ```
109
+
96
110
  ## Contributing
97
111
 
98
112
  1. Fork it ( http://github.com/sue445/google_holiday_calendar/fork )
@@ -20,15 +20,16 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "activesupport", "~> 4.0.0"
23
+ spec.add_dependency "activesupport", ">= 4.0.0"
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "bundler", ">= 1.5"
26
26
  spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec", "3.0.0.beta1"
27
+ spec.add_development_dependency "rspec", "~> 3.1.0"
28
28
  spec.add_development_dependency "rspec-its"
29
29
  spec.add_development_dependency "rspec-collection_matchers"
30
30
  spec.add_development_dependency "delorean"
31
31
  spec.add_development_dependency "yard"
32
32
  spec.add_development_dependency "memoist"
33
33
  spec.add_development_dependency "coveralls"
34
+ spec.add_development_dependency "dotenv"
34
35
  end
@@ -1,14 +1,16 @@
1
1
  module GoogleHolidayCalendar
2
2
  require 'open-uri'
3
+ require 'cgi'
3
4
 
4
5
  class Calendar
5
6
  attr_reader :country, :lang
6
7
 
7
8
  # @param country [String]
8
9
  # @param lang [String]
9
- def initialize(country: "usa", lang: "en")
10
+ def initialize(country: "usa", lang: "en", api_key: nil)
10
11
  @country = country.downcase
11
12
  @lang = lang.downcase
13
+ @api_key = api_key
12
14
  end
13
15
 
14
16
  # get holidays via google calendar
@@ -21,23 +23,24 @@ module GoogleHolidayCalendar
21
23
  start_date = Date.today unless start_date
22
24
  end_date = to_date(start_date) + 1.month unless end_date
23
25
 
24
- url = "http://www.google.com/calendar/feeds/#{@country}__#{@lang}@holiday.calendar.google.com/public/full?"
26
+ calendar_id = "#{@lang}.#{@country}#holiday@group.v.calendar.google.com"
27
+ url = "https://www.googleapis.com/calendar/v3/calendars/#{CGI.escape(calendar_id)}/events?"
25
28
  params = {
26
- "alt" => "json",
27
- "start-min" => to_ymd(start_date),
28
- "start-max" => to_ymd(end_date),
29
- "max-results" => limit,
29
+ "key" => @api_key,
30
+ "timeMin" => to_ymd(start_date),
31
+ "timeMax" => to_ymd(end_date),
32
+ "maxResults" => limit,
30
33
  }
31
34
  url += params.to_query
32
35
 
33
36
  calendar_response = fetch(url)
34
37
 
35
- entries = calendar_response["feed"]["entry"]
38
+ entries = calendar_response["items"]
36
39
  return {} unless entries
37
40
 
38
- holidays = entries.inject({}){ |res, entry|
39
- date = Date.parse(entry["gd$when"][0]["startTime"])
40
- title = entry["title"]["$t"]
41
+ holidays = entries.inject({}){ |res, item|
42
+ date = Date.parse(item['start']['date'])
43
+ title = item["summary"]
41
44
  res[date] =title
42
45
  res
43
46
  }
@@ -65,7 +68,7 @@ module GoogleHolidayCalendar
65
68
  # @return [String] YYYY-MM-DD
66
69
  def to_ymd(arg)
67
70
  date = to_date(arg)
68
- date.strftime("%Y-%m-%d")
71
+ date.strftime("%Y-%m-%d") + "T00:00:00Z"
69
72
  end
70
73
 
71
74
  # @param arg [Date,String]
@@ -1,3 +1,3 @@
1
1
  module GoogleHolidayCalendar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "google_holiday_calendar/version"
2
2
  require "google_holiday_calendar/calendar"
3
- require "active_support/core_ext"
3
+ require "active_support/all"
4
4
 
5
5
  module GoogleHolidayCalendar
6
6
  # Your code goes here...
@@ -7,13 +7,13 @@ describe GoogleHolidayCalendar::Calendar do
7
7
  let(:end_date) { "2014-01-31" }
8
8
 
9
9
  context "Without country and lang" do
10
- let(:calendar){ GoogleHolidayCalendar::Calendar.new }
10
+ let(:calendar){ GoogleHolidayCalendar::Calendar.new(api_key: ENV["GOOGLE_API_KEY"]) }
11
11
 
12
12
  its(:count){ should > 0 }
13
13
  end
14
14
 
15
15
  context "With country and lang" do
16
- let(:calendar){ GoogleHolidayCalendar::Calendar.new(country: country, lang: lang) }
16
+ let(:calendar){ GoogleHolidayCalendar::Calendar.new(country: country, lang: lang, api_key: ENV["GOOGLE_API_KEY"]) }
17
17
 
18
18
  context "When holidays in Japan" do
19
19
  let(:country) { "japanese" }
@@ -64,7 +64,7 @@ describe GoogleHolidayCalendar::Calendar do
64
64
  describe "#holiday?" do
65
65
  subject{ calendar.holiday?(date) }
66
66
 
67
- let(:calendar){ GoogleHolidayCalendar::Calendar.new(country: country, lang: lang) }
67
+ let(:calendar){ GoogleHolidayCalendar::Calendar.new(country: country, lang: lang, api_key: ENV["GOOGLE_API_KEY"]) }
68
68
  let(:country) { "japanese" }
69
69
  let(:lang) { "ja" }
70
70
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,8 @@
1
+ if ENV["COVERAGE"]
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
1
6
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
7
  require 'google_holiday_calendar'
3
8
 
@@ -6,9 +11,8 @@ require 'rspec/its'
6
11
  require 'rspec/collection_matchers'
7
12
  require 'delorean'
8
13
  require 'memoist'
9
-
10
- require 'coveralls'
11
- Coveralls.wear!
14
+ require 'dotenv'
15
+ Dotenv.load
12
16
 
13
17
  # Requires supporting ruby files with custom matchers and macros, etc,
14
18
  # in spec/support/ and its subdirectories.
@@ -1,7 +1,5 @@
1
1
  shared_examples :holidays_in_japan_at_jan do
2
- its(:count){ should == 4 }
2
+ its(:count){ should == 2 }
3
3
  it{ should include(date("2014-01-01") => "元日") }
4
- it{ should include(date("2014-01-02") => "銀行休業日") }
5
- it{ should include(date("2014-01-03") => "銀行休業日") }
6
4
  it{ should include(date("2014-01-13") => "成人の日") }
7
5
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_holiday_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-26 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0.beta1
61
+ version: 3.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0.beta1
68
+ version: 3.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dotenv
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Get holidays via Google Calendar.
154
168
  email:
155
169
  - sue445@sue445.net
@@ -159,6 +173,7 @@ extensions: []
159
173
  extra_rdoc_files: []
160
174
  files:
161
175
  - ".coveralls.yml"
176
+ - ".env.example"
162
177
  - ".gitignore"
163
178
  - ".rspec"
164
179
  - ".travis.yml"