cal-invite 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,42 @@
3
3
  # lib/cal_invite/providers/outlook.rb
4
4
  module CalInvite
5
5
  module Providers
6
+ # Microsoft Outlook Live (outlook.live.com) provider for generating calendar event URLs.
7
+ # This provider generates URLs that open the Outlook.com web calendar
8
+ # with a pre-filled event creation form. Supports both all-day and
9
+ # time-specific events.
10
+ #
11
+ # Note: This is for personal Outlook.com accounts. For corporate Office 365,
12
+ # use the {Office365} provider instead.
13
+ #
14
+ # @example Creating a regular event URL
15
+ # event = CalInvite::Event.new(
16
+ # title: "Team Meeting",
17
+ # start_time: Time.now,
18
+ # end_time: Time.now + 3600,
19
+ # description: "Weekly team sync"
20
+ # )
21
+ # outlook = CalInvite::Providers::Outlook.new(event)
22
+ # url = outlook.generate
23
+ #
24
+ # @example Creating an all-day event URL with attendees
25
+ # event = CalInvite::Event.new(
26
+ # title: "Company Holiday",
27
+ # all_day: true,
28
+ # start_time: Date.today,
29
+ # end_time: Date.today + 1,
30
+ # attendees: ["john@example.com", "jane@example.com"],
31
+ # show_attendees: true
32
+ # )
33
+ # url = CalInvite::Providers::Outlook.new(event).generate
34
+ #
35
+ # @see Office365 For corporate Office 365 calendar URLs
6
36
  class Outlook < BaseProvider
37
+ # Generates an Outlook.com calendar URL for the event.
38
+ # Automatically handles both all-day and time-specific events.
39
+ #
40
+ # @return [String] The Outlook.com calendar URL
41
+ # @raise [ArgumentError] If required time fields are missing for non-all-day events
7
42
  def generate
8
43
  if event.all_day
9
44
  generate_all_day_event
@@ -14,6 +49,10 @@ module CalInvite
14
49
 
15
50
  private
16
51
 
52
+ # Generates a URL for an all-day event.
53
+ # Uses simplified date format and sets the allday flag.
54
+ #
55
+ # @return [String] The Outlook.com calendar URL for an all-day event
17
56
  def generate_all_day_event
18
57
  params = {
19
58
  path: '/calendar/0/action/compose',
@@ -21,10 +60,9 @@ module CalInvite
21
60
  allday: 'true'
22
61
  }
23
62
 
24
- # Use current date if no start_time specified
63
+ # Set start and end dates
25
64
  start_date = event.start_time || Time.now
26
- end_date = event.end_time || (start_date + 86400) # Add one day if no end_time
27
-
65
+ end_date = event.end_time || (start_date + 86400)
28
66
  params[:startdt] = format_date(start_date)
29
67
  params[:enddt] = format_date(end_date)
30
68
 
@@ -32,6 +70,11 @@ module CalInvite
32
70
  build_url(params)
33
71
  end
34
72
 
73
+ # Generates a URL for a regular (time-specific) event.
74
+ # Includes specific start and end times in UTC format.
75
+ #
76
+ # @return [String] The Outlook.com calendar URL for a regular event
77
+ # @raise [ArgumentError] If start_time or end_time is missing
35
78
  def generate_single_event
36
79
  params = {
37
80
  path: '/calendar/0/action/compose',
@@ -43,21 +86,38 @@ module CalInvite
43
86
 
44
87
  params[:startdt] = format_time(event.start_time)
45
88
  params[:enddt] = format_time(event.end_time)
46
-
47
89
  add_optional_params(params)
48
90
  build_url(params)
49
91
  end
50
92
 
93
+ # Formats a time object as a date string for Outlook.com.
94
+ #
95
+ # @param time [Time] The time to format
96
+ # @return [String] The formatted date (YYYY-MM-DD)
51
97
  def format_date(time)
52
98
  time.strftime('%Y-%m-%d')
53
99
  end
54
100
 
101
+ # Formats a time object as a UTC timestamp for Outlook.com.
102
+ # Outlook.com handles timezone conversion on their end.
103
+ #
104
+ # @param time [Time] The time to format
105
+ # @return [String] The formatted UTC time (YYYY-MM-DDThh:mm:ssZ)
55
106
  def format_time(time)
56
- time.utc.strftime('%Y-%m-%dT%H:%M:%S')
107
+ # Always use UTC format, timezone is handled by the calendar
108
+ time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
57
109
  end
58
110
 
111
+ # Adds optional parameters to the URL parameters hash.
112
+ # Handles description, virtual meeting URL, location, and attendees.
113
+ #
114
+ # @param params [Hash] The parameters hash to update
115
+ # @return [Hash] The updated parameters hash
59
116
  def add_optional_params(params)
60
- params[:body] = url_encode(format_description) if format_description
117
+ description_parts = []
118
+ description_parts << format_description if format_description
119
+ description_parts << "Virtual Meeting URL: #{format_url}" if format_url
120
+ params[:body] = url_encode(description_parts.join("\n\n")) if description_parts.any?
61
121
  params[:location] = url_encode(format_location) if format_location
62
122
 
63
123
  if attendees = attendees_list
@@ -67,6 +127,10 @@ module CalInvite
67
127
  params
68
128
  end
69
129
 
130
+ # Builds the final Outlook.com calendar URL.
131
+ #
132
+ # @param params [Hash] The parameters to include in the URL
133
+ # @return [String] The complete Outlook.com calendar URL
70
134
  def build_url(params)
71
135
  query = params.map { |k, v| "#{k}=#{v}" }.join('&')
72
136
  "https://outlook.live.com/calendar/0/action/compose?#{query}"
@@ -3,9 +3,44 @@
3
3
  # lib/cal_invite/providers/yahoo.rb
4
4
  module CalInvite
5
5
  module Providers
6
+ # Yahoo Calendar provider for generating calendar event URLs.
7
+ # This provider generates URLs that open the Yahoo Calendar with a pre-filled
8
+ # event creation form. Supports all-day events, regular events, and multi-day
9
+ # sessions with proper timezone handling.
10
+ #
11
+ # Note: Yahoo Calendar handles multi-day sessions differently from other providers,
12
+ # generating separate event URLs for each session.
13
+ #
14
+ # @example Creating a regular event URL
15
+ # event = CalInvite::Event.new(
16
+ # title: "Team Meeting",
17
+ # start_time: Time.now,
18
+ # end_time: Time.now + 3600,
19
+ # description: "Weekly team sync",
20
+ # timezone: "America/New_York"
21
+ # )
22
+ # yahoo = CalInvite::Providers::Yahoo.new(event)
23
+ # url = yahoo.generate
24
+ #
25
+ # @example Creating a multi-day event URL
26
+ # event = CalInvite::Event.new(
27
+ # title: "Conference",
28
+ # multi_day_sessions: [
29
+ # { start_time: Time.parse("2024-04-01 09:00"), end_time: Time.parse("2024-04-01 17:00") },
30
+ # { start_time: Time.parse("2024-04-02 09:00"), end_time: Time.parse("2024-04-02 17:00") }
31
+ # ]
32
+ # )
33
+ # urls = CalInvite::Providers::Yahoo.new(event).generate # Returns multiple URLs
6
34
  class Yahoo < BaseProvider
35
+ # Base URL for Yahoo Calendar
7
36
  BASE_URL = "https://calendar.yahoo.com"
8
37
 
38
+ # Generates Yahoo Calendar URL(s) for the event.
39
+ # Handles all event types: all-day, regular, and multi-day sessions.
40
+ #
41
+ # @return [String] A single URL for regular or all-day events, or
42
+ # multiple URLs (separated by newlines) for multi-day sessions
43
+ # @raise [ArgumentError] If required time fields are missing for non-all-day events
9
44
  def generate
10
45
  if event.all_day
11
46
  generate_all_day_event
@@ -18,6 +53,10 @@ module CalInvite
18
53
 
19
54
  private
20
55
 
56
+ # Generates a URL for an all-day event.
57
+ # Uses simplified date format and sets the allday flag.
58
+ #
59
+ # @return [String] The Yahoo Calendar URL for an all-day event
21
60
  def generate_all_day_event
22
61
  start_date = event.start_time || Time.now
23
62
  end_date = event.end_time || (start_date + 86400)
@@ -38,10 +77,19 @@ module CalInvite
38
77
  "#{BASE_URL}/?#{URI.encode_www_form(params)}"
39
78
  end
40
79
 
80
+ # Generates a URL for a regular (time-specific) event.
81
+ # Includes specific start and end times with timezone information.
82
+ #
83
+ # @return [String] The Yahoo Calendar URL for a regular event
84
+ # @raise [ArgumentError] If start_time or end_time is missing
41
85
  def generate_single_event
42
86
  raise ArgumentError, "Start time is required" unless event.start_time
43
87
  raise ArgumentError, "End time is required" unless event.end_time
44
88
 
89
+ description_parts = []
90
+ description_parts << format_description if format_description
91
+ description_parts << "Virtual Meeting URL: #{format_url}" if format_url
92
+
45
93
  params = {
46
94
  v: 60,
47
95
  view: 'd',
@@ -49,7 +97,7 @@ module CalInvite
49
97
  title: event.title,
50
98
  st: format_time(event.start_time),
51
99
  et: format_time(event.end_time),
52
- desc: format_description,
100
+ desc: description_parts.join("\n\n"),
53
101
  in_loc: format_location,
54
102
  crnd: event.timezone
55
103
  }
@@ -57,9 +105,11 @@ module CalInvite
57
105
  "#{BASE_URL}/?#{URI.encode_www_form(params)}"
58
106
  end
59
107
 
108
+ # Generates multiple URLs for multi-day events, one for each session.
109
+ # Yahoo Calendar doesn't support multiple sessions in a single URL.
110
+ #
111
+ # @return [String] Multiple Yahoo Calendar URLs, one per line
60
112
  def generate_multi_day_event
61
- # Yahoo doesn't support multi-day events in a single URL
62
- # Return multiple URLs, one for each session
63
113
  sessions = event.multi_day_sessions.map do |session|
64
114
  params = {
65
115
  v: 60,
@@ -79,12 +129,22 @@ module CalInvite
79
129
  sessions.join("\n")
80
130
  end
81
131
 
132
+ # Formats a time object as a date string for Yahoo Calendar.
133
+ #
134
+ # @param time [Time] The time to format
135
+ # @return [String] The formatted date (YYYYMMDD)
82
136
  def format_date(time)
83
137
  time.strftime("%Y%m%d")
84
138
  end
85
139
 
140
+ # Formats a time object as a UTC timestamp for Yahoo Calendar.
141
+ # Yahoo Calendar accepts timezone separately in the crnd parameter.
142
+ #
143
+ # @param time [Time] The time to format
144
+ # @return [String] The formatted UTC time (YYYYMMDDTHHmmSSZ)
86
145
  def format_time(time)
87
- time.utc.strftime("%Y%m%dT%H%M%S")
146
+ # Always use UTC format for the URL, timezone is passed separately
147
+ time.utc.strftime("%Y%m%dT%H%M%SZ")
88
148
  end
89
149
  end
90
150
  end
@@ -1,17 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'providers/base_provider'
4
+
3
5
  # lib/cal_invite/providers.rb
6
+ # Namespace module for all calendar providers supported by CalInvite.
7
+ # Each provider implements the interface defined by BaseProvider.
8
+ #
9
+ # @see CalInvite::Providers::BaseProvider
4
10
  module CalInvite
5
11
  module Providers
12
+ # List of supported calendar provider symbols
6
13
  SUPPORTED_PROVIDERS = %i[google ical outlook yahoo ics office365].freeze
7
14
 
8
- autoload :BaseProvider, 'cal_invite/providers/base_provider'
9
15
  autoload :Google, 'cal_invite/providers/google'
10
16
  autoload :Ical, 'cal_invite/providers/ical'
11
17
  autoload :Outlook, 'cal_invite/providers/outlook'
12
18
  autoload :Office365, 'cal_invite/providers/office365'
13
19
  autoload :Yahoo, 'cal_invite/providers/yahoo'
20
+ autoload :IcsContent, 'cal_invite/providers/ics_content'
21
+ autoload :IcsDownload, 'cal_invite/providers/ics_content'
14
22
  autoload :Ics, 'cal_invite/providers/ics'
15
-
16
23
  end
17
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CalInvite
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/cal_invite.rb CHANGED
@@ -1,26 +1,65 @@
1
1
  # lib/cal_invite.rb
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
2
4
  require 'securerandom'
3
5
  require 'time'
4
6
  require 'uri'
5
7
 
6
8
  require 'cal_invite/version'
7
9
  require 'cal_invite/configuration'
10
+ require 'cal_invite/caching'
8
11
  require 'cal_invite/event'
9
12
  require 'cal_invite/providers'
10
13
 
14
+ # The main module for the CalInvite gem. This module provides functionality for generating
15
+ # calendar invites across different calendar providers.
16
+ #
17
+ # @example Configure the gem
18
+ # CalInvite.configure do |config|
19
+ # config.timezone = 'America/New_York'
20
+ # config.cache_store = :memory_store
21
+ # end
22
+ #
23
+ # @example Create and generate a calendar URL
24
+ # event = CalInvite::Event.new(
25
+ # title: "Team Meeting",
26
+ # start_time: Time.now,
27
+ # end_time: Time.now + 3600
28
+ # )
29
+ # google_url = event.generate_calendar_url(:google)
30
+ #
11
31
  module CalInvite
12
32
  class Error < StandardError; end
13
33
 
14
34
  class << self
35
+ # Returns the current configuration object.
36
+ # @return [CalInvite::Configuration] The current configuration object
15
37
  attr_accessor :configuration
16
38
 
39
+ # Configures the CalInvite gem through a block.
40
+ #
41
+ # @yield [config] The configuration object to be modified
42
+ # @yieldparam config [CalInvite::Configuration] The configuration object
43
+ # @return [void]
44
+ #
45
+ # @example
46
+ # CalInvite.configure do |config|
47
+ # config.timezone = 'UTC'
48
+ # config.cache_store = :memory_store
49
+ # end
17
50
  def configure
18
51
  self.configuration ||= Configuration.new
19
52
  yield(configuration)
20
53
  end
21
54
 
55
+ # Resets the configuration to default values.
56
+ #
57
+ # @return [void]
22
58
  def reset_configuration!
23
59
  self.configuration = Configuration.new
24
60
  end
61
+
62
+ # Include caching methods at the module level
63
+ include Caching
25
64
  end
26
65
  end
@@ -0,0 +1,13 @@
1
+ # lib/tasks/rdoc.rake
2
+ require 'rdoc/task'
3
+
4
+ RDoc::Task.new do |rdoc|
5
+ rdoc.rdoc_dir = 'doc'
6
+ rdoc.title = 'CalInvite Documentation'
7
+ rdoc.main = 'README.md'
8
+ rdoc.options << '--line-numbers'
9
+ rdoc.options << '--charset' << 'UTF-8'
10
+ rdoc.options << '--markup' << 'markdown'
11
+ rdoc.rdoc_files.include('README.md', 'LICENSE', 'lib/**/*.rb')
12
+ rdoc.rdoc_files.exclude('lib/cal_invite/version.rb')
13
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cal-invite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephane Paquet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-17 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.5'
13
41
  description: CalInvite provides a simple way to generate calendar invite URLs for
14
42
  various providers (Google, Outlook, Yahoo) and ICS files
15
43
  email:
@@ -18,7 +46,10 @@ executables: []
18
46
  extensions: []
19
47
  extra_rdoc_files: []
20
48
  files:
49
+ - ".DS_Store"
50
+ - ".rdoc_options"
21
51
  - ".rubocop.yml"
52
+ - CACHING.md
22
53
  - CHANGELOG.md
23
54
  - CODE_OF_CONDUCT.md
24
55
  - LICENSE.txt
@@ -27,7 +58,10 @@ files:
27
58
  - gemfiles/Gemfile.rails6
28
59
  - gemfiles/Gemfile.rails7
29
60
  - gemfiles/Gemfile.rails8
61
+ - lib/.DS_Store
30
62
  - lib/cal_invite.rb
63
+ - lib/cal_invite/.DS_Store
64
+ - lib/cal_invite/caching.rb
31
65
  - lib/cal_invite/configuration.rb
32
66
  - lib/cal_invite/event.rb
33
67
  - lib/cal_invite/providers.rb
@@ -35,10 +69,12 @@ files:
35
69
  - lib/cal_invite/providers/google.rb
36
70
  - lib/cal_invite/providers/ical.rb
37
71
  - lib/cal_invite/providers/ics.rb
72
+ - lib/cal_invite/providers/ics_content.rb
38
73
  - lib/cal_invite/providers/office365.rb
39
74
  - lib/cal_invite/providers/outlook.rb
40
75
  - lib/cal_invite/providers/yahoo.rb
41
76
  - lib/cal_invite/version.rb
77
+ - lib/tasks/rdoc.rake
42
78
  - sig/cal/invite.rbs
43
79
  homepage: https://github.com/the-pew-inc/cal-invite
44
80
  licenses:
@@ -48,7 +84,21 @@ metadata:
48
84
  source_code_uri: https://github.com/the-pew-inc/cal-invite
49
85
  changelog_uri: https://github.com/the-pew-inc/cal-invite/blob/master/CHANGELOG.md
50
86
  post_install_message:
51
- rdoc_options: []
87
+ rdoc_options:
88
+ - "--title"
89
+ - CalInvite Documentation
90
+ - "--main"
91
+ - README.md
92
+ - "--line-numbers"
93
+ - "--all"
94
+ - "--charset"
95
+ - UTF-8
96
+ - "--markup"
97
+ - markdown
98
+ - "--exclude"
99
+ - "^(test|spec|features)/"
100
+ - "--exclude"
101
+ - lib/cal_invite/version.rb
52
102
  require_paths:
53
103
  - lib
54
104
  required_ruby_version: !ruby/object:Gem::Requirement