holidays_from_google_calendar 0.2.0 → 0.3.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: ddd84d5bf6b28a28dcbfbd7cdad2574e50d1d17f
4
- data.tar.gz: 3a9f0c5359768ce0ca1f136090c343b7e036e482
3
+ metadata.gz: ea98c95ad38a12d3c95ae95bce204eb9922fe556
4
+ data.tar.gz: e04b7ada90c239f80455c9db4d2b81decc2ba8da
5
5
  SHA512:
6
- metadata.gz: 43dca74914287410f8715ce941a2efb1f5ede23a06b5ca25b7d35e7db6ff8a3132d9204e83177c3a0420da78803a0425e49220a52ad65d13c6b192de4c7178a5
7
- data.tar.gz: 78dd94477bb25dd7ab5530d7dc2f6aa4e8234d3c82f354dbcb64a576d9f944b9320f29ed0bc56a30ae23225246f82bd24fcb1909680613fcde0216614538ef61
6
+ metadata.gz: d73607ef9df0b677747b7adae6a13efb66f3f31a4468a5c38d48cfa7af19f72694dbcd44ab2e3fd306f7c6150d722b621871eaf82d178ed8f631935f8de75b16
7
+ data.tar.gz: 3db9c1c44dcf6b6f76df199c0527fc24e4099a21f11a07b41607085f469ecef86994874ff624ae1b77c2b84dd9b9c9e57d73ca577888342fe82469bc739fcbf4
data/.rubocop.yml ADDED
@@ -0,0 +1,54 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ Exclude:
5
+ - 'bin/*'
6
+ - 'Gemfile'
7
+
8
+ # Accept single-line methods with no body
9
+ SingleLineMethods:
10
+ AllowIfMethodIsEmpty: true
11
+
12
+ # Top-level documentation of classes and modules are needless
13
+ Documentation:
14
+ Enabled: false
15
+
16
+ # Allow to chain of block after another block that spans multiple lines
17
+ MultilineBlockChain:
18
+ Enabled: false
19
+
20
+ # Allow `->` literal for multi line blocks
21
+ Lambda:
22
+ Enabled: false
23
+
24
+ # Both nested and compact are okay
25
+ ClassAndModuleChildren:
26
+ Enabled: false
27
+
28
+ # Specifying param names is unnecessary
29
+ Style/SingleLineBlockParams:
30
+ Enabled: false
31
+
32
+ # Prefer Kernel#sprintf
33
+ FormatString:
34
+ EnforcedStyle: sprintf
35
+
36
+ # Maximum line length
37
+ LineLength:
38
+ Max: 100
39
+
40
+ # Whatever we should use "postfix if/unless"
41
+ IfUnlessModifier:
42
+ MaxLineLength: 100
43
+
44
+ # Maximum method length
45
+ MethodLength:
46
+ Max: 20
47
+
48
+ # Tuned to MethodLength
49
+ Metrics/AbcSize:
50
+ Max: 30
51
+
52
+ # Prefer double_quotes strings unless your string literal contains escape chars
53
+ StringLiterals:
54
+ EnforcedStyle: double_quotes
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -10,46 +10,30 @@ require "active_support/core_ext"
10
10
 
11
11
  module HolidaysFromGoogleCalendar
12
12
  class Holidays
13
- class << self
14
- def configure
15
- @configuration = Configuration.new
16
- yield @configuration
17
- @client = Client.new(@configuration.to_h)
18
- end
19
-
20
- def in_year(date)
21
- response = @client.retrieve_from_google_calendar(
22
- date_min: date.beginning_of_year,
23
- date_max: date.end_of_year + 1.day
24
- )
25
- pack_response_in_struct(response)
26
- end
27
-
28
- def in_month(date)
29
- response = @client.retrieve_from_google_calendar(
30
- date_min: date.beginning_of_month,
31
- date_max: date.end_of_month + 1.day
32
- )
33
- pack_response_in_struct(response)
34
- end
13
+ def initialize
14
+ @configuration = Configuration.new
15
+ yield @configuration
16
+ @client = Client.new(@configuration)
17
+ end
35
18
 
36
- def holiday?(date)
37
- return true if date.wday.in?([0, 6]) # If Sunday or Saturday
38
- response = @client.retrieve_from_google_calendar(date_min: date, date_max: date + 1.day)
39
- response.items.size > 0
40
- end
19
+ def in_year(date)
20
+ @client.retrieve_from_google_calendar(
21
+ date_min: date.beginning_of_year,
22
+ date_max: date.end_of_year + 1.day
23
+ )
24
+ end
41
25
 
42
- private
26
+ def in_month(date)
27
+ @client.retrieve_from_google_calendar(
28
+ date_min: date.beginning_of_month,
29
+ date_max: date.end_of_month + 1.day
30
+ )
31
+ end
43
32
 
44
- def pack_response_in_struct(response)
45
- response.items.reduce([]) do |array, item|
46
- holiday = Holiday.new(
47
- name: item.summary,
48
- date: Date.parse(item.start.date)
49
- )
50
- array.push(holiday)
51
- end
52
- end
33
+ def holiday?(date)
34
+ return true if date.wday.in?([0, 6]) # If Sunday or Saturday
35
+ response = @client.retrieve_from_google_calendar(date_min: date, date_max: date + 1.day)
36
+ response.items.size > 0
53
37
  end
54
38
  end
55
39
  end
@@ -1,21 +1,23 @@
1
1
  module HolidaysFromGoogleCalendar
2
2
  class Client
3
- def initialize(nation: "usa", language: "en", api_key: nil)
4
- @nation = nation
5
- @language = language
6
- @api_key = api_key
3
+ def initialize(configuration)
4
+ @nation = configuration.calendar[:nation]
5
+ @language = configuration.calendar[:language]
6
+ @api_key = configuration.credential[:api_key]
7
7
  end
8
8
 
9
9
  def retrieve_from_google_calendar(date_min: nil, date_max: nil)
10
10
  service = Google::Apis::CalendarV3::CalendarService.new
11
11
  service.key = @api_key
12
- service.list_events(
12
+
13
+ response = service.list_events(
13
14
  calendar_id,
14
15
  single_events: true,
15
16
  order_by: "startTime",
16
17
  time_min: date_to_time(date_min),
17
18
  time_max: date_to_time(date_max)
18
19
  )
20
+ pack_response_in_object(response)
19
21
  end
20
22
 
21
23
  private
@@ -27,5 +29,15 @@ module HolidaysFromGoogleCalendar
27
29
  def date_to_time(date)
28
30
  Time.parse(date.iso8601).iso8601
29
31
  end
32
+
33
+ def pack_response_in_object(response)
34
+ response.items.reduce([]) do |array, item|
35
+ holiday = Holiday.new(
36
+ name: item.summary,
37
+ date: Date.parse(item.start.date)
38
+ )
39
+ array.push(holiday)
40
+ end
41
+ end
30
42
  end
31
43
  end
@@ -1,13 +1,15 @@
1
1
  module HolidaysFromGoogleCalendar
2
2
  class Configuration
3
- ATTRIBUTES = %i(nation language api_key)
3
+ CALENDAR_ATTRIBUTES = %i(nation language).freeze
4
+ CREDENTIAL_ATTRIBUTES = %i(api_key).freeze
4
5
 
5
- attr_accessor(*ATTRIBUTES)
6
+ attr_accessor :calendar, :credential
6
7
 
7
- def to_h
8
- ATTRIBUTES.reduce({}) do |hash, attribute|
9
- hash.merge(attribute => public_send(attribute))
10
- end
8
+ def initialize
9
+ @calendar = {
10
+ nation: "japanese",
11
+ language: "ja"
12
+ }
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module HolidaysFromGoogleCalendar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holidays_from_google_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - necojackarc
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
+ - ".rubocop.yml"
92
93
  - ".travis.yml"
93
94
  - CODE_OF_CONDUCT.md
94
95
  - Gemfile