diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 33271ed..1297b13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6.10 + ruby-version: 3.2.8 bundler-cache: true - name: Run tests run: bundle exec rake test diff --git a/.ruby-version b/.ruby-version index a04abec..f092941 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.10 +3.2.8 diff --git a/Gemfile b/Gemfile index 56b2eae..d727cc8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ -source "http://rubygems.org" +source "https://rubygems.org" -ruby '2.6.10' +ruby '3.2.8' # Add dependencies required to use your gem here. # Example: @@ -12,16 +12,14 @@ gem 'httparty', '~> 0.21.0' group :development do gem "bundler" - gem "jeweler" gem "simplecov" gem "rdoc" gem "shoulda" - gem "minitest" + gem "minitest", "~> 5.0" end group :test do gem 'webmock' gem 'vcr' - gem 'turn' gem 'rake' end diff --git a/Gemfile.lock b/Gemfile.lock index 553a2ec..bfad8df 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,114 +1,94 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - activesupport (5.2.4.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - ansi (1.5.0) - builder (3.2.4) - concurrent-ruby (1.1.7) - crack (0.4.3) - safe_yaml (~> 1.0.0) - descendants_tracker (0.0.4) - thread_safe (~> 0.3, >= 0.3.1) - docile (1.3.2) - faraday (0.9.2) - multipart-post (>= 1.2, < 3) - git (1.7.0) - rchardet (~> 1.8) - github_api (0.11.3) - addressable (~> 2.3) - descendants_tracker (~> 0.0.1) - faraday (~> 0.8, < 0.10) - hashie (>= 1.2) - multi_json (>= 1.7.5, < 2.0) - nokogiri (~> 1.6.0) - oauth2 - hashdiff (1.0.1) - hashie (4.1.0) - highline (2.0.3) + activesupport (8.0.2) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + base64 (0.3.0) + benchmark (0.4.1) + bigdecimal (3.2.2) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + crack (1.0.0) + bigdecimal + rexml + date (3.4.1) + docile (1.4.1) + drb (2.2.3) + erb (5.0.2) + hashdiff (1.2.0) httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.8.5) + i18n (1.14.7) concurrent-ruby (~> 1.0) - jeweler (2.3.5) - builder - bundler (>= 1.0) - git (>= 1.2.5) - github_api (~> 0.11.0) - highline (>= 1.6.15) - nokogiri (>= 1.5.10) - psych (~> 2.2) - rake - rdoc - semver2 - jwt (2.2.2) + logger (1.7.0) mini_mime (1.1.5) - mini_portile2 (2.1.0) - minitest (5.14.1) - multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.1.1) - nokogiri (1.6.8.1) - mini_portile2 (~> 2.1.0) - oauth2 (1.4.4) - faraday (>= 0.8, < 2.0) - jwt (>= 1.0, < 3.0) - multi_json (~> 1.3) - multi_xml (~> 0.5) - rack (>= 1.2, < 3) - psych (2.2.4) - public_suffix (4.0.5) - rack (2.2.3) - rake (13.0.1) - rchardet (1.8.0) - rdoc (6.2.1) - safe_yaml (1.0.5) - semver2 (3.4.2) + minitest (5.25.5) + multi_xml (0.7.2) + bigdecimal (~> 3.1) + psych (5.2.6) + date + stringio + public_suffix (6.0.2) + rake (13.3.0) + rdoc (6.14.2) + erb + psych (>= 4.0.0) + rexml (3.4.1) + securerandom (0.4.1) shoulda (4.0.0) shoulda-context (~> 2.0) shoulda-matchers (~> 4.0) shoulda-context (2.0.0) - shoulda-matchers (4.4.0) + shoulda-matchers (4.5.1) activesupport (>= 4.2.0) - simplecov (0.18.5) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) - simplecov-html (0.12.2) - thread_safe (0.3.6) - turn (0.9.6) - ansi - tzinfo (1.2.7) - thread_safe (~> 0.1) - vcr (6.0.0) - webmock (3.8.3) - addressable (>= 2.3.6) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.2) + simplecov_json_formatter (0.1.4) + stringio (3.1.7) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.0.3) + vcr (6.3.1) + base64 + webmock (3.25.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS + arm64-darwin-24 ruby DEPENDENCIES bundler httparty (~> 0.21.0) - jeweler - minitest + minitest (~> 5.0) rake rdoc shoulda simplecov - turn vcr webmock RUBY VERSION - ruby 2.6.10p210 + ruby 3.2.8p263 BUNDLED WITH - 2.0.2 + 2.7.0 diff --git a/Rakefile b/Rakefile index 2fbaf4c..6d15492 100644 --- a/Rakefile +++ b/Rakefile @@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e end require 'rake' -require 'jeweler' -Jeweler::Tasks.new do |gem| - # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options - gem.name = "enrico" - gem.homepage = "https://github.com/easyPEP/enrico" - gem.license = "MIT" - gem.summary = "A ruby wrapper around enrico holiday API" - gem.description = "https://github.com/easyPEP/enrico" - gem.email = "kalle@easypep.de" - gem.authors = ["Kalle Saas"] - # dependencies defined in Gemfile -end -Jeweler::RubygemsDotOrgTasks.new - require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'lib' << 'test' diff --git a/lib/enrico.rb b/lib/enrico.rb index 55d6f24..016f2f9 100644 --- a/lib/enrico.rb +++ b/lib/enrico.rb @@ -2,7 +2,6 @@ require "httparty" require 'json' -require 'active_support/all' require "addressable/uri" Dir[File.dirname(__FILE__) + '/enrico/*.rb'].each do |file| diff --git a/lib/enrico/country.rb b/lib/enrico/country.rb index f073dcc..d4bb93f 100644 --- a/lib/enrico/country.rb +++ b/lib/enrico/country.rb @@ -43,7 +43,7 @@ def is_public_holiday?(date) end def method_missing(name, *args, &block) - method_name = name.to_s.camelize(:lower) + method_name = name.to_s.gsub(/_([a-z])/) { $1.upcase } details.has_key?(method_name) ? details[method_name] : super end @@ -60,13 +60,13 @@ def vacation_days_from_response(response) end def country_parameters(params, holiday_type: nil) - { + result = { country: self.country_code, region: self.region - } - .merge(params) - .tap { |result| result[:holidayType] = holiday_type if holiday_type.present? } - .to_query + }.merge(params) + result[:holidayType] = holiday_type if holiday_type && !holiday_type.empty? + + URI.encode_www_form(result.compact) end def is_public_holiday(date) diff --git a/lib/enrico/vacation_day.rb b/lib/enrico/vacation_day.rb index 2092e9c..e0b730e 100644 --- a/lib/enrico/vacation_day.rb +++ b/lib/enrico/vacation_day.rb @@ -7,7 +7,7 @@ class VacationDay def initialize(args) self.date = Date.new( args["date"]["year"].to_i, args["date"]["month"].to_i, args["date"]["day"].to_i ) self.local_name = args["name"][0]["text"] - self.english_name = args["name"][1].present? ? args["name"][1]["text"] : args["name"][0]["text"] + self.english_name = args["name"][1] && !args["name"][1].empty? ? args["name"][1]["text"] : args["name"][0]["text"] end end end diff --git a/mise.toml b/mise.toml index 4763b1e..ce6bd0a 100644 --- a/mise.toml +++ b/mise.toml @@ -1,2 +1,2 @@ [tools] -ruby = "2.6.10" +ruby = "3.2.8" diff --git a/spec/fixtures/vcr_cassettes/holidays_in_date_range.yml b/spec/fixtures/vcr_cassettes/holidays_in_date_range.yml index cfb18e3..101a846 100644 --- a/spec/fixtures/vcr_cassettes/holidays_in_date_range.yml +++ b/spec/fixtures/vcr_cassettes/holidays_in_date_range.yml @@ -2,69 +2,7 @@ http_interactions: - request: method: get - uri: http://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange&country=deu&fromDate=01-01-2020®ion=&toDate=01-03-2020 - body: - encoding: US-ASCII - string: '' - headers: {} - response: - status: - code: 200 - message: OK - headers: - Server: - - openresty - Date: - - Wed, 08 Apr 2020 18:04:50 GMT - Content-Type: - - application/json - Content-Length: - - '169' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New - Year''s Day"}],"holidayType":"public_holiday"}]' - recorded_at: Wed, 08 Apr 2020 18:04:50 GMT -- request: - method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange&country=deu&fromDate=01-01-2020®ion=&toDate=01-03-2020 - body: - encoding: US-ASCII - string: '' - headers: {} - response: - status: - code: 200 - message: OK - headers: - Server: - - openresty - Date: - - Tue, 14 Apr 2020 09:31:33 GMT - Content-Type: - - application/json - Content-Length: - - '169' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New - Year''s Day"}],"holidayType":"public_holiday"}]' - recorded_at: Tue, 14 Apr 2020 09:31:35 GMT -- request: - method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange&country=deu&fromDate=01-01-2020®ion=&toDate=31-03-2020 + uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange&country=deu&fromDate=01-01-2020&toDate=31-03-2020 body: encoding: US-ASCII string: '' @@ -83,7 +21,7 @@ http_interactions: Server: - openresty Date: - - Tue, 17 Jun 2025 12:38:32 GMT + - Fri, 18 Jul 2025 13:15:54 GMT Content-Type: - application/json Transfer-Encoding: @@ -106,5 +44,5 @@ http_interactions: der Sommerzeit"},{"lang":"en","text":"Daylight Saving Time Starts"}],"note":[{"lang":"de","text":"Die Uhr wird um eine Stunde von 2:00 Uhr auf 3:00 Uhr vorgestellt"},{"lang":"en","text":"A one-hour shift occurs at 02:00 local time, the clock jumps forward to 03:00"}],"holidayType":"other_day"}]' - recorded_at: Tue, 17 Jun 2025 12:38:32 GMT -recorded_with: VCR 6.0.0 + recorded_at: Fri, 18 Jul 2025 13:15:27 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/holidays_in_month.yml b/spec/fixtures/vcr_cassettes/holidays_in_month.yml index 49c9738..acc76f3 100644 --- a/spec/fixtures/vcr_cassettes/holidays_in_month.yml +++ b/spec/fixtures/vcr_cassettes/holidays_in_month.yml @@ -2,43 +2,17 @@ http_interactions: - request: method: get - uri: http://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForMonth&country=deu&month=1®ion=&year=2020 + uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForMonth&country=deu&month=1&year=2020 body: encoding: US-ASCII string: '' - headers: {} - response: - status: - code: 200 - message: OK headers: - Server: - - openresty - Date: - - Wed, 08 Apr 2020 18:04:51 GMT - Content-Type: - - application/json - Content-Length: - - '169' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New - Year''s Day"}],"holidayType":"public_holiday"}]' - http_version: - recorded_at: Wed, 08 Apr 2020 18:04:50 GMT -- request: - method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForMonth&country=deu&month=1®ion=&year=2020 - body: - encoding: US-ASCII - string: '' - headers: {} + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby response: status: code: 200 @@ -47,21 +21,24 @@ http_interactions: Server: - openresty Date: - - Tue, 14 Apr 2020 09:31:33 GMT + - Fri, 18 Jul 2025 13:15:54 GMT Content-Type: - application/json - Content-Length: - - '169' + Transfer-Encoding: + - chunked Connection: - keep-alive + Keep-Alive: + - timeout=10 Vary: - Accept-Encoding Access-Control-Allow-Origin: - "*" + Alt-Svc: + - h3=":443"; ma=86400 body: - encoding: UTF-8 + encoding: ASCII-8BIT string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New Year''s Day"}],"holidayType":"public_holiday"}]' - http_version: - recorded_at: Tue, 14 Apr 2020 09:31:35 GMT -recorded_with: VCR 2.8.0 + recorded_at: Fri, 18 Jul 2025 13:15:28 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/holidays_in_year.yml b/spec/fixtures/vcr_cassettes/holidays_in_year.yml index f3843d2..75140f4 100644 --- a/spec/fixtures/vcr_cassettes/holidays_in_year.yml +++ b/spec/fixtures/vcr_cassettes/holidays_in_year.yml @@ -2,59 +2,17 @@ http_interactions: - request: method: get - uri: http://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForYear&country=deu®ion=&year=2020 + uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForYear&country=deu&year=2020 body: encoding: US-ASCII string: '' - headers: {} - response: - status: - code: 200 - message: OK headers: - Server: - - openresty - Date: - - Wed, 08 Apr 2020 18:04:51 GMT - Content-Type: - - application/json - Content-Length: - - '2646' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New - Year''s Day"}],"holidayType":"public_holiday"},{"date":{"day":29,"month":3,"year":2020,"dayOfWeek":7},"name":[{"lang":"de","text":"Beginn - der Sommerzeit"},{"lang":"en","text":"Daylight Saving Time Starts"}],"note":[{"lang":"de","text":"Die - Uhr wird um eine Stunde von 2:00 Uhr auf 3:00 Uhr vorgestellt"},{"lang":"en","text":"A - one-hour shift occurs at 02:00 local time, the clock jumps forward to 03:00"}],"holidayType":"other_day"},{"date":{"day":10,"month":4,"year":2020,"dayOfWeek":5},"name":[{"lang":"de","text":"Karfreitag"},{"lang":"en","text":"Good - Friday"}],"holidayType":"public_holiday"},{"date":{"day":13,"month":4,"year":2020,"dayOfWeek":1},"name":[{"lang":"de","text":"Ostermontag"},{"lang":"en","text":"Easter - Monday"}],"holidayType":"public_holiday"},{"date":{"day":1,"month":5,"year":2020,"dayOfWeek":5},"name":[{"lang":"de","text":"Tag - der Arbeit"},{"lang":"en","text":"Labour Day"}],"holidayType":"public_holiday"},{"date":{"day":10,"month":5,"year":2020,"dayOfWeek":7},"name":[{"lang":"de","text":"Muttertag"},{"lang":"en","text":"Mother''s - Day"}],"holidayType":"other_day"},{"date":{"day":21,"month":5,"year":2020,"dayOfWeek":4},"name":[{"lang":"de","text":"Christi - Himmelfahrt"},{"lang":"en","text":"Ascension Day"}],"holidayType":"public_holiday"},{"date":{"day":21,"month":5,"year":2020,"dayOfWeek":4},"name":[{"lang":"de","text":"Vatertag"},{"lang":"en","text":"Father''s - Day"}],"holidayType":"other_day"},{"date":{"day":1,"month":6,"year":2020,"dayOfWeek":1},"name":[{"lang":"de","text":"Pfingstmontag"},{"lang":"en","text":"Whit - Monday"}],"holidayType":"public_holiday"},{"date":{"day":3,"month":10,"year":2020,"dayOfWeek":6},"name":[{"lang":"de","text":"Tag - der Deutschen Einheit"},{"lang":"en","text":"German Unity Day"}],"holidayType":"public_holiday"},{"date":{"day":25,"month":10,"year":2020,"dayOfWeek":7},"name":[{"lang":"de","text":"Ende - der Sommerzeit"},{"lang":"en","text":"Daylight Saving Time Ends"}],"note":[{"lang":"de","text":"Die - Uhr wird um eine Stunde von 3:00 Uhr auf 2:00 Uhr zur\u00fcckgestellt"},{"lang":"en","text":"A - one-hour shift occurs at 03:00 local time, the clock jumps backward to 02:00"}],"holidayType":"other_day"},{"date":{"day":25,"month":12,"year":2020,"dayOfWeek":5},"name":[{"lang":"de","text":"Weihnachtstag"},{"lang":"en","text":"Christmas - Day"}],"holidayType":"public_holiday"},{"date":{"day":26,"month":12,"year":2020,"dayOfWeek":6},"name":[{"lang":"de","text":"Zweiter - Weihnachtsfeiertag"},{"lang":"en","text":"Boxing Day"}],"holidayType":"public_holiday"}]' - http_version: - recorded_at: Wed, 08 Apr 2020 18:04:50 GMT -- request: - method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForYear&country=deu®ion=&year=2020 - body: - encoding: US-ASCII - string: '' - headers: {} + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby response: status: code: 200 @@ -63,19 +21,23 @@ http_interactions: Server: - openresty Date: - - Tue, 14 Apr 2020 09:31:34 GMT + - Fri, 18 Jul 2025 13:15:54 GMT Content-Type: - application/json - Content-Length: - - '2834' + Transfer-Encoding: + - chunked Connection: - keep-alive + Keep-Alive: + - timeout=10 Vary: - Accept-Encoding Access-Control-Allow-Origin: - "*" + Alt-Svc: + - h3=":443"; ma=86400 body: - encoding: UTF-8 + encoding: ASCII-8BIT string: '[{"date":{"day":1,"month":1,"year":2020,"dayOfWeek":3},"name":[{"lang":"de","text":"Neujahrstag"},{"lang":"en","text":"New Year''s Day"}],"holidayType":"public_holiday"},{"date":{"day":8,"month":3,"year":2020,"dayOfWeek":7},"name":[{"lang":"de","text":"Internationaler Frauentag"},{"lang":"en","text":"International Women''s Day"}],"holidayType":"other_day"},{"date":{"day":29,"month":3,"year":2020,"dayOfWeek":7},"name":[{"lang":"de","text":"Beginn @@ -95,6 +57,5 @@ http_interactions: one-hour shift occurs at 03:00 local time, the clock jumps backward to 02:00"}],"holidayType":"other_day"},{"date":{"day":25,"month":12,"year":2020,"dayOfWeek":5},"name":[{"lang":"de","text":"Weihnachtstag"},{"lang":"en","text":"Christmas Day"}],"holidayType":"public_holiday"},{"date":{"day":26,"month":12,"year":2020,"dayOfWeek":6},"name":[{"lang":"de","text":"Zweiter Weihnachtsfeiertag"},{"lang":"en","text":"Boxing Day"}],"holidayType":"public_holiday"}]' - http_version: - recorded_at: Tue, 14 Apr 2020 09:31:35 GMT -recorded_with: VCR 2.8.0 + recorded_at: Fri, 18 Jul 2025 13:15:28 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/fixtures/vcr_cassettes/is_public_holiday.yml b/spec/fixtures/vcr_cassettes/is_public_holiday.yml index d698de2..8b260c9 100644 --- a/spec/fixtures/vcr_cassettes/is_public_holiday.yml +++ b/spec/fixtures/vcr_cassettes/is_public_holiday.yml @@ -2,42 +2,17 @@ http_interactions: - request: method: get - uri: http://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=29-01-2020®ion= + uri: https://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=01-01-2020 body: encoding: US-ASCII string: '' - headers: {} - response: - status: - code: 200 - message: OK headers: - Server: - - openresty - Date: - - Wed, 08 Apr 2020 18:04:51 GMT - Content-Type: - - application/json - Content-Length: - - '25' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '{"isPublicHoliday":false}' - http_version: - recorded_at: Wed, 08 Apr 2020 18:04:50 GMT -- request: - method: get - uri: http://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=01-01-2020®ion= - body: - encoding: US-ASCII - string: '' - headers: {} + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby response: status: code: 200 @@ -46,60 +21,38 @@ http_interactions: Server: - openresty Date: - - Wed, 08 Apr 2020 18:04:51 GMT + - Fri, 18 Jul 2025 13:16:10 GMT Content-Type: - application/json Content-Length: - '24' Connection: - keep-alive + Keep-Alive: + - timeout=10 Vary: - Accept-Encoding Access-Control-Allow-Origin: - "*" + Alt-Svc: + - h3=":443"; ma=86400 body: encoding: UTF-8 string: '{"isPublicHoliday":true}' - http_version: - recorded_at: Wed, 08 Apr 2020 18:04:51 GMT + recorded_at: Fri, 18 Jul 2025 13:15:44 GMT - request: method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=01-01-2020®ion= + uri: https://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=29-01-2020 body: encoding: US-ASCII string: '' - headers: {} - response: - status: - code: 200 - message: OK headers: - Server: - - openresty - Date: - - Tue, 14 Apr 2020 09:34:53 GMT - Content-Type: - - application/json - Content-Length: - - '24' - Connection: - - keep-alive - Vary: - - Accept-Encoding - Access-Control-Allow-Origin: - - "*" - body: - encoding: UTF-8 - string: '{"isPublicHoliday":true}' - http_version: - recorded_at: Tue, 14 Apr 2020 09:34:55 GMT -- request: - method: get - uri: https://kayaposoft.com/enrico/json/v2.0/?action=isPublicHoliday&country=deu&date=29-01-2020®ion= - body: - encoding: US-ASCII - string: '' - headers: {} + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby response: status: code: 200 @@ -108,20 +61,23 @@ http_interactions: Server: - openresty Date: - - Tue, 14 Apr 2020 09:34:53 GMT + - Fri, 18 Jul 2025 13:18:13 GMT Content-Type: - application/json Content-Length: - '25' Connection: - keep-alive + Keep-Alive: + - timeout=10 Vary: - Accept-Encoding Access-Control-Allow-Origin: - "*" + Alt-Svc: + - h3=":443"; ma=86400 body: encoding: UTF-8 string: '{"isPublicHoliday":false}' - http_version: - recorded_at: Tue, 14 Apr 2020 09:34:55 GMT -recorded_with: VCR 2.8.0 + recorded_at: Fri, 18 Jul 2025 13:17:47 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/lib/enrico/country_public_holidays_for_month_spec.rb b/spec/lib/enrico/country_public_holidays_for_month_spec.rb index 22dff03..f4fe2be 100644 --- a/spec/lib/enrico/country_public_holidays_for_month_spec.rb +++ b/spec/lib/enrico/country_public_holidays_for_month_spec.rb @@ -8,7 +8,7 @@ describe "GET getHolidaysForMonth" do before(:each) do - VCR.insert_cassette 'holidays_in_month', :record => :new_episodes + VCR.insert_cassette 'holidays_in_month' end after(:each) do @@ -26,7 +26,7 @@ describe "GET getHolidaysForYear" do before(:each) do - VCR.insert_cassette 'holidays_in_year', :record => :new_episodes + VCR.insert_cassette 'holidays_in_year' end after(:each) do @@ -48,7 +48,7 @@ describe "GET getForDateRange" do before(:each) do - VCR.insert_cassette 'holidays_in_date_range', :record => :new_episodes + VCR.insert_cassette 'holidays_in_date_range' end after(:each) do diff --git a/spec/lib/enrico/country_spec.rb b/spec/lib/enrico/country_spec.rb index 38cd693..105c14e 100644 --- a/spec/lib/enrico/country_spec.rb +++ b/spec/lib/enrico/country_spec.rb @@ -7,7 +7,7 @@ describe Enrico::Country do before(:each) do - VCR.insert_cassette 'supported_countries', :record => :new_episodes + VCR.insert_cassette 'supported_countries' end after(:each) do @@ -87,4 +87,75 @@ end + describe "method_missing" do + let(:country) { Enrico::Country.new("deu") } + + before do + # Mock the details method to return a hash with test data + def country.details + { + "fullName" => "Germany", + "countryCode" => "deu", + "fromDate" => {"day"=>1, "month"=>1, "year"=>2011}, + "toDate" => {"day"=>31, "month"=>12, "year"=>32767} + } + end + end + + it "converts snake_case method names to camelCase for accessing details" do + _(country.full_name).must_equal "Germany" + _(country.country_code).must_equal "deu" + end + + it "handles already camelCase properties" do + _(country.fromDate).must_equal({"day"=>1, "month"=>1, "year"=>2011}) + _(country.toDate).must_equal({"day"=>31, "month"=>12, "year"=>32767}) + end + + it "raises NoMethodError for non-existent properties" do + assert_raises(NoMethodError) do + country.non_existent_property + end + end + end + + describe "country_parameters" do + let(:country) { Enrico::Country.new("deu", "by") } + let(:country_no_region) { Enrico::Country.new("deu") } + + it "includes country code and region in parameters" do + params = country.country_parameters({month: 1, year: 2024}) + _(params).must_include "country=deu" + _(params).must_include "region=by" + _(params).must_include "month=1" + _(params).must_include "year=2024" + end + + it "excludes nil region from parameters" do + params = country_no_region.country_parameters({month: 1, year: 2024}) + _(params).must_include "country=deu" + _(params).wont_include "region=" + end + + it "includes holiday_type when provided and not empty" do + params = country.country_parameters({month: 1}, holiday_type: "public_holiday") + _(params).must_include "holidayType=public_holiday" + end + + it "excludes holiday_type when nil" do + params = country.country_parameters({month: 1}, holiday_type: nil) + _(params).wont_include "holidayType" + end + + it "excludes holiday_type when empty string" do + params = country.country_parameters({month: 1}, holiday_type: "") + _(params).wont_include "holidayType" + end + + it "properly encodes parameters for URL" do + params = country.country_parameters({date: "01-01-2024"}) + _(params).must_equal "country=deu®ion=by&date=01-01-2024" + end + end + end diff --git a/spec/lib/enrico/is_public_holiday_spec.rb b/spec/lib/enrico/is_public_holiday_spec.rb index e1f68f5..fc84cd9 100644 --- a/spec/lib/enrico/is_public_holiday_spec.rb +++ b/spec/lib/enrico/is_public_holiday_spec.rb @@ -8,7 +8,7 @@ describe "GET isPublicHoliday" do before(:each) do - VCR.insert_cassette 'is_public_holiday', :record => :new_episodes + VCR.insert_cassette 'is_public_holiday' end after(:each) do VCR.eject_cassette diff --git a/spec/lib/enrico/vacation_day_spec.rb b/spec/lib/enrico/vacation_day_spec.rb index 2625678..f10631c 100644 --- a/spec/lib/enrico/vacation_day_spec.rb +++ b/spec/lib/enrico/vacation_day_spec.rb @@ -1,52 +1,95 @@ # encoding: utf-8 require_relative '../../spec_helper' -# For Ruby < 1.9.3, use this instead of require_relative -# require (File.expand_path('./../../../spec_helper', __FILE__)) describe Enrico::VacationDay do - describe "default instance attributes" do - it "test initializer methods" do - beginning_of_year = Date.today.beginning_of_year + describe "initialization" do + before(:each) do + VCR.insert_cassette 'holidays_in_month' + end + + after(:each) do + VCR.eject_cassette + end + + it "creates VacationDay from real API response" do + country = Enrico::Country.new("deu") + vacation_days = country.holidays_for_month(Date.parse('2020-01-15')) + + day = vacation_days.first + _(day).must_be_instance_of Enrico::VacationDay + _(day.date).must_equal Date.new(2020, 1, 1) + _(day.local_name).must_equal "Neujahrstag" + _(day.english_name).must_equal "New Year's Day" + end + + it "handles multi-language holidays" do rsp = { - "date"=>{"day"=> beginning_of_year.day, "month" => beginning_of_year.month, "year"=>beginning_of_year.year, "dayOfWeek"=>beginning_of_year.wday}, + "date"=>{"day"=>1, "month"=>1, "year"=>2020, "dayOfWeek"=>3}, "name"=>[ - { - "lang"=>"de", - "text"=>"Neujahrstag" - }, - { - "lang"=>"en", - "text"=>"New Year's Day" - } + {"lang"=>"de", "text"=>"Neujahrstag"}, + {"lang"=>"en", "text"=>"New Year's Day"} ], "holidayType"=>"public_holiday" } day = Enrico::VacationDay.new(rsp) - _(day.date).must_equal Date.today.beginning_of_year + _(day.date).must_equal Date.new(2020, 1, 1) _(day.local_name).must_equal "Neujahrstag" _(day.english_name).must_equal "New Year's Day" end - describe 'when country has only one language' do - it "returns same names" do - beginning_of_year = Date.today.beginning_of_year - rsp = { - "date"=>{"day"=> beginning_of_year.day, "month" => beginning_of_year.month, "year"=>beginning_of_year.year, "dayOfWeek"=>beginning_of_year.wday}, - "name"=>[ - { - "lang"=>"en", - "text"=>"New Year's Day" - } - ], - "holidayType"=>"public_holiday" - } - day = Enrico::VacationDay.new(rsp) - _(day.date).must_equal Date.today.beginning_of_year - _(day.local_name).must_equal "New Year's Day" - _(day.english_name).must_equal "New Year's Day" - end + it "handles single-language holidays" do + rsp = { + "date"=>{"day"=>4, "month"=>7, "year"=>2020, "dayOfWeek"=>6}, + "name"=>[ + {"lang"=>"en", "text"=>"Independence Day"} + ], + "holidayType"=>"public_holiday" + } + day = Enrico::VacationDay.new(rsp) + _(day.date).must_equal Date.new(2020, 7, 4) + _(day.local_name).must_equal "Independence Day" + _(day.english_name).must_equal "Independence Day" + end + + it "falls back to local name when second language is nil" do + rsp = { + "date"=>{"day"=>25, "month"=>12, "year"=>2020, "dayOfWeek"=>5}, + "name"=>[ + {"lang"=>"fr", "text"=>"Noël"}, + nil + ], + "holidayType"=>"public_holiday" + } + day = Enrico::VacationDay.new(rsp) + _(day.local_name).must_equal "Noël" + _(day.english_name).must_equal "Noël" + end + + it "falls back to local name when second language is empty" do + rsp = { + "date"=>{"day"=>1, "month"=>5, "year"=>2020, "dayOfWeek"=>5}, + "name"=>[ + {"lang"=>"es", "text"=>"Día del Trabajo"}, + {} + ], + "holidayType"=>"public_holiday" + } + day = Enrico::VacationDay.new(rsp) + _(day.local_name).must_equal "Día del Trabajo" + _(day.english_name).must_equal "Día del Trabajo" + end + it "parses dates with string values" do + rsp = { + "date"=>{"day"=>"15", "month"=>"8", "year"=>"2020", "dayOfWeek"=>6}, + "name"=>[ + {"lang"=>"it", "text"=>"Ferragosto"} + ], + "holidayType"=>"public_holiday" + } + day = Enrico::VacationDay.new(rsp) + _(day.date).must_equal Date.new(2020, 8, 15) end end end