cal-invite 0.1.1
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +19 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +111 -0
- data/Rakefile +12 -0
- data/gemfiles/Gemfile.rails6 +16 -0
- data/gemfiles/Gemfile.rails7 +16 -0
- data/gemfiles/Gemfile.rails8 +16 -0
- data/lib/cal_invite/configuration.rb +13 -0
- data/lib/cal_invite/event.rb +49 -0
- data/lib/cal_invite/providers/base_provider.rb +44 -0
- data/lib/cal_invite/providers/google.rb +66 -0
- data/lib/cal_invite/providers/ical.rb +69 -0
- data/lib/cal_invite/providers/ics.rb +89 -0
- data/lib/cal_invite/providers/outlook.rb +65 -0
- data/lib/cal_invite/providers/yahoo.rb +66 -0
- data/lib/cal_invite/providers.rb +15 -0
- data/lib/cal_invite/version.rb +5 -0
- data/lib/cal_invite.rb +22 -0
- data/sig/cal/invite.rbs +4 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87266e97a53aac81a619ae283a7c14c05f67140e96f6d57bc8aca97789c232f4
|
4
|
+
data.tar.gz: c169424e6171d5f814b41ef6d8154c790efdd1a9693244db1b93265f940dbe6c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0fd39a7fa410f1c3212015f3bf4276cbee1473fe2b5f887aef9bcbc1d43ca1da9af1dfb9f72dec990ae25c7e0af33b260778981fd01a795cba3658fafced1fc4
|
7
|
+
data.tar.gz: 5743ca62b4e8f7062e748ba717e29b5e68909e812a526575dc65b06f17b95d69aec3c7458cb1481c39e6f986b0c594a0ec2a8f390f54d0d78e7909dd21ef4517
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.1] - 2024-12-17
|
4
|
+
|
5
|
+
Fixing a bug in the gemspec file
|
6
|
+
|
7
|
+
## [0.1.0] - 2024-12-17
|
8
|
+
|
9
|
+
First public release of the Calendar Invite gem
|
10
|
+
|
11
|
+
Support the calendar invites for the following calendars:
|
12
|
+
|
13
|
+
- Microsoft Outlook
|
14
|
+
- Google Calendar
|
15
|
+
- Yahoo Calendar
|
16
|
+
|
17
|
+
Support Apple iCal
|
18
|
+
|
19
|
+
Support other calendars via .ics
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Stephane Paquet
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# CalInvite
|
2
|
+
|
3
|
+
A Ruby gem for generating calendar invitations across multiple calendar platforms with caching and webhook support.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/cal-invite)
|
6
|
+
[](https://github.com/yourusername/cal-invite/actions)
|
7
|
+
|
8
|
+
## Compatibility
|
9
|
+
|
10
|
+
- Ruby >= 3.0.0
|
11
|
+
- Rails 6.0, 6.1, 7.0, 7.1, 8.0
|
12
|
+
|
13
|
+
## Supported Calendar Platforms
|
14
|
+
|
15
|
+
Direct Integration:
|
16
|
+
- Apple iCal
|
17
|
+
- Microsoft Outlook
|
18
|
+
- Google Calendar
|
19
|
+
- Yahoo Calendar
|
20
|
+
- Standard .ics file generation
|
21
|
+
|
22
|
+
Any calendar application that supports the iCalendar (.ics) standard should work, including but not limited to:
|
23
|
+
- ProtonCalendar
|
24
|
+
- FastMail Calendar
|
25
|
+
- Thunderbird Calendar
|
26
|
+
- Zoho Calendar
|
27
|
+
- Microsoft Teams Calendar
|
28
|
+
- Zoom Calendar Integration
|
29
|
+
- Office 365 Calendar
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'cal-invite'
|
37
|
+
```
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
```bash
|
41
|
+
$ bundle install
|
42
|
+
```
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
```bash
|
46
|
+
$ gem install cal-invite
|
47
|
+
```
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
### Basic Event Creation
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# Single day event
|
55
|
+
event = CalInvite::Event.new(
|
56
|
+
title: "Team Meeting",
|
57
|
+
start_time: Time.current,
|
58
|
+
end_time: Time.current + 2.hours,
|
59
|
+
description: "Weekly team sync",
|
60
|
+
location: "Conference Room A",
|
61
|
+
url: "https://zoom.us/j/123456789",
|
62
|
+
attendees: ["person@example.com"],
|
63
|
+
show_attendees: true,
|
64
|
+
timezone: "America/New_York",
|
65
|
+
notes: "Please bring your laptop"
|
66
|
+
)
|
67
|
+
|
68
|
+
# Multi-day event
|
69
|
+
event = CalInvite::Event.new(
|
70
|
+
title: "Training Workshop",
|
71
|
+
multi_day_sessions: [
|
72
|
+
{
|
73
|
+
start_time: Time.parse("2024-03-01 08:00:00 UTC"),
|
74
|
+
end_time: Time.parse("2024-03-01 17:00:00 UTC")
|
75
|
+
},
|
76
|
+
{
|
77
|
+
start_time: Time.parse("2024-03-02 09:00:00 UTC"),
|
78
|
+
end_time: Time.parse("2024-03-02 13:00:00 UTC")
|
79
|
+
}
|
80
|
+
],
|
81
|
+
description: "Advanced Ruby Training",
|
82
|
+
location: "Training Center",
|
83
|
+
url: "https://zoom.us/j/123456789",
|
84
|
+
timezone: "America/New_York",
|
85
|
+
notes: "Bring your own laptop"
|
86
|
+
)
|
87
|
+
|
88
|
+
ical_url = event.calendar_url(:ical)
|
89
|
+
google_url = event.calendar_url(:google)
|
90
|
+
outlook_url = event.calendar_url(:outlook)
|
91
|
+
yahoo_url = event.calendar_url(:yahoo)
|
92
|
+
ics_content = event.calendar_url(:ics)
|
93
|
+
```
|
94
|
+
|
95
|
+
## Development
|
96
|
+
|
97
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
|
+
|
99
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cal-invite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cal-invite/blob/master/CODE_OF_CONDUCT.md).
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
108
|
+
|
109
|
+
## Code of Conduct
|
110
|
+
|
111
|
+
Everyone interacting in the Cal::Invite project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cal-invite/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
group :development, :test do
|
5
|
+
gem "bundler"
|
6
|
+
gem "rails", "~> 6.0.0"
|
7
|
+
gem "actionview", "~> 6.0.0"
|
8
|
+
gem "activesupport", "~> 6.0.0"
|
9
|
+
gem "activemodel", "~> 6.0.0"
|
10
|
+
gem "minitest"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "tzinfo"
|
13
|
+
gem "uri"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem "simplecov", require: false, group: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
group :development, :test do
|
5
|
+
gem "bundler"
|
6
|
+
gem "rails", "~> 7.0.0"
|
7
|
+
gem "actionview", "~> 7.0.0"
|
8
|
+
gem "activesupport", "~> 7.0.0"
|
9
|
+
gem "activemodel", "~> 7.0.0"
|
10
|
+
gem "minitest"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "tzinfo"
|
13
|
+
gem "uri"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem "simplecov", require: false, group: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
group :development, :test do
|
5
|
+
gem "bundler"
|
6
|
+
gem "rails", "~> 8.0.0"
|
7
|
+
gem "actionview", "~> 8.0.0"
|
8
|
+
gem "activesupport", "~> 8.0.0"
|
9
|
+
gem "activemodel", "~> 8.0.0"
|
10
|
+
gem "minitest"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "tzinfo"
|
13
|
+
gem "uri"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem "simplecov", require: false, group: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# lib/cal_invite/configuration.rb
|
2
|
+
module CalInvites
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :cache_store, :cache_prefix, :webhook_secret, :timezone
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@cache_store = :memory_store
|
8
|
+
@cache_prefix = 'cal_invite'
|
9
|
+
@webhook_secret = nil
|
10
|
+
@timezone = 'UTC'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/event.rb
|
4
|
+
module CalInvite
|
5
|
+
class Event
|
6
|
+
attr_accessor :title,
|
7
|
+
:start_time,
|
8
|
+
:end_time,
|
9
|
+
:description,
|
10
|
+
:location,
|
11
|
+
:url,
|
12
|
+
:attendees,
|
13
|
+
:timezone,
|
14
|
+
:show_attendees,
|
15
|
+
:notes,
|
16
|
+
:multi_day_sessions
|
17
|
+
|
18
|
+
def initialize(attributes = {})
|
19
|
+
@show_attendees = attributes.delete(:show_attendees) || false
|
20
|
+
@timezone = attributes.delete(:timezone) || 'UTC'
|
21
|
+
@multi_day_sessions = attributes.delete(:multi_day_sessions) || []
|
22
|
+
|
23
|
+
attributes.each do |key, value|
|
24
|
+
send("#{key}=", value) if respond_to?("#{key}=")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def calendar_url(provider)
|
29
|
+
provider_class = CalInvite::Providers.const_get(provider.to_s.camelize)
|
30
|
+
generator = provider_class.new(self)
|
31
|
+
generator.generate
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convert a UTC time to event's timezone
|
35
|
+
def localize_time(time)
|
36
|
+
return time unless time
|
37
|
+
time.in_time_zone(timezone)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get all event sessions (including multi-day)
|
41
|
+
def sessions
|
42
|
+
return [@start_time, @end_time] if multi_day_sessions.empty?
|
43
|
+
|
44
|
+
multi_day_sessions.map do |session|
|
45
|
+
[session[:start_time], session[:end_time]]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/base_provider.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class BaseProvider
|
7
|
+
attr_reader :event
|
8
|
+
|
9
|
+
def initialize(event)
|
10
|
+
@event = event
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate
|
14
|
+
raise NotImplementedError, "#{self.class} must implement #generate"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def url_encode(str)
|
20
|
+
URI.encode_www_form_component(str.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_description
|
24
|
+
parts = []
|
25
|
+
parts << event.description if event.description
|
26
|
+
parts << "Notes: #{event.notes}" if event.notes
|
27
|
+
parts << "URL: #{event.url}" if event.url
|
28
|
+
parts.join("\n\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_location
|
32
|
+
return event.url if event.url && !event.location
|
33
|
+
return event.location if event.location && !event.url
|
34
|
+
return "#{event.location}\n#{event.url}" if event.location && event.url
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def attendees_list
|
39
|
+
return [] unless event.show_attendees && event.attendees&.any?
|
40
|
+
event.attendees
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/google.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class Google < BaseProvider
|
7
|
+
BASE_URL = "https://calendar.google.com/calendar/render"
|
8
|
+
|
9
|
+
def generate
|
10
|
+
if event.multi_day_sessions.any?
|
11
|
+
generate_multi_day_event
|
12
|
+
else
|
13
|
+
generate_single_event
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def generate_single_event
|
20
|
+
params = {
|
21
|
+
action: "TEMPLATE",
|
22
|
+
text: event.title,
|
23
|
+
dates: format_dates(event.start_time, event.end_time),
|
24
|
+
details: format_description,
|
25
|
+
location: format_location,
|
26
|
+
ctz: event.timezone
|
27
|
+
}
|
28
|
+
|
29
|
+
if attendees_list.any?
|
30
|
+
params[:add] = attendees_list.join(',')
|
31
|
+
end
|
32
|
+
|
33
|
+
"#{BASE_URL}?#{URI.encode_www_form(params)}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_multi_day_event
|
37
|
+
# For multi-day events, Google Calendar supports recurring events
|
38
|
+
sessions = event.multi_day_sessions.map do |session|
|
39
|
+
format_dates(session[:start_time], session[:end_time])
|
40
|
+
end
|
41
|
+
|
42
|
+
params = {
|
43
|
+
action: "TEMPLATE",
|
44
|
+
text: event.title,
|
45
|
+
dates: sessions.join(','),
|
46
|
+
details: format_description,
|
47
|
+
location: format_location,
|
48
|
+
ctz: event.timezone
|
49
|
+
}
|
50
|
+
|
51
|
+
if attendees_list.any?
|
52
|
+
params[:add] = attendees_list.join(',')
|
53
|
+
end
|
54
|
+
|
55
|
+
"#{BASE_URL}?#{URI.encode_www_form(params)}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def format_dates(start_time, end_time)
|
59
|
+
start_time = event.localize_time(start_time)
|
60
|
+
end_time = event.localize_time(end_time)
|
61
|
+
|
62
|
+
"#{start_time.strftime('%Y%m%dT%H%M%S')}/#{end_time.strftime('%Y%m%dT%H%M%S')}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/ical.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class Ical < BaseProvider
|
7
|
+
def generate
|
8
|
+
[
|
9
|
+
"BEGIN:VCALENDAR",
|
10
|
+
"VERSION:2.0",
|
11
|
+
"PRODID:-//CalInvite//EN",
|
12
|
+
generate_events,
|
13
|
+
"END:VCALENDAR"
|
14
|
+
].flatten.join("\r\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def generate_events
|
20
|
+
if event.multi_day_sessions.any?
|
21
|
+
event.multi_day_sessions.map { |session| generate_vevent(session[:start_time], session[:end_time]) }
|
22
|
+
else
|
23
|
+
[generate_vevent(event.start_time, event.end_time)]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_vevent(start_time, end_time)
|
28
|
+
vevent = [
|
29
|
+
"BEGIN:VEVENT",
|
30
|
+
"UID:#{generate_uid}",
|
31
|
+
"DTSTAMP:#{format_time(Time.now)}",
|
32
|
+
"DTSTART;TZID=#{event.timezone}:#{format_time(start_time)}",
|
33
|
+
"DTEND;TZID=#{event.timezone}:#{format_time(end_time)}",
|
34
|
+
"SUMMARY:#{event.title}",
|
35
|
+
"DESCRIPTION:#{format_description}",
|
36
|
+
]
|
37
|
+
|
38
|
+
if format_location
|
39
|
+
vevent << "LOCATION:#{format_location}"
|
40
|
+
end
|
41
|
+
|
42
|
+
if event.url
|
43
|
+
vevent << "URL:#{event.url}"
|
44
|
+
end
|
45
|
+
|
46
|
+
if attendees_list.any?
|
47
|
+
attendees_list.each do |attendee|
|
48
|
+
vevent << "ATTENDEE;RSVP=TRUE:mailto:#{attendee}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
vevent << "END:VEVENT"
|
53
|
+
vevent
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_uid
|
57
|
+
"#{Time.now.to_i}-#{SecureRandom.hex(8)}@cal-invite"
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_time(time)
|
61
|
+
event.localize_time(time).strftime("%Y%m%dT%H%M%S")
|
62
|
+
end
|
63
|
+
|
64
|
+
def escape_text(text)
|
65
|
+
text.to_s.gsub(/[,;\\]/) { |match| "\\#{match}" }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/ics.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class Ics < BaseProvider
|
7
|
+
def generate
|
8
|
+
calendar_lines = [
|
9
|
+
"BEGIN:VCALENDAR",
|
10
|
+
"VERSION:2.0",
|
11
|
+
"PRODID:-//CalInvite//EN",
|
12
|
+
"CALSCALE:GREGORIAN",
|
13
|
+
"METHOD:PUBLISH"
|
14
|
+
]
|
15
|
+
|
16
|
+
# Add events (either single or multiple sessions)
|
17
|
+
if event.multi_day_sessions.any?
|
18
|
+
event.multi_day_sessions.each do |session|
|
19
|
+
calendar_lines.concat(generate_vevent(session[:start_time], session[:end_time]))
|
20
|
+
end
|
21
|
+
else
|
22
|
+
calendar_lines.concat(generate_vevent(event.start_time, event.end_time))
|
23
|
+
end
|
24
|
+
|
25
|
+
calendar_lines << "END:VCALENDAR"
|
26
|
+
calendar_lines.join("\r\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_vevent(start_time, end_time)
|
32
|
+
vevent = [
|
33
|
+
"BEGIN:VEVENT",
|
34
|
+
"UID:#{generate_uid}",
|
35
|
+
"DTSTAMP:#{format_timestamp(Time.now)}",
|
36
|
+
"DTSTART;TZID=#{event.timezone}:#{format_local_timestamp(start_time)}",
|
37
|
+
"DTEND;TZID=#{event.timezone}:#{format_local_timestamp(end_time)}",
|
38
|
+
"SUMMARY:#{escape_text(event.title)}"
|
39
|
+
]
|
40
|
+
|
41
|
+
# Add description (including notes if present)
|
42
|
+
if desc = format_description
|
43
|
+
vevent << "DESCRIPTION:#{escape_text(desc)}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add location and/or URL
|
47
|
+
if event.location
|
48
|
+
vevent << "LOCATION:#{escape_text(event.location)}"
|
49
|
+
end
|
50
|
+
|
51
|
+
if event.url
|
52
|
+
vevent << "URL:#{escape_text(event.url)}"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Add attendees if showing is enabled
|
56
|
+
if attendees_list.any?
|
57
|
+
attendees_list.each do |attendee|
|
58
|
+
vevent << "ATTENDEE;RSVP=TRUE:mailto:#{attendee}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
vevent << "END:VEVENT"
|
63
|
+
vevent
|
64
|
+
end
|
65
|
+
|
66
|
+
def format_timestamp(time)
|
67
|
+
time.utc.strftime("%Y%m%dT%H%M%SZ")
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_local_timestamp(time)
|
71
|
+
event.localize_time(time).strftime("%Y%m%dT%H%M%S")
|
72
|
+
end
|
73
|
+
|
74
|
+
def generate_uid
|
75
|
+
"#{Time.now.to_i}-#{SecureRandom.hex(8)}@cal-invite"
|
76
|
+
end
|
77
|
+
|
78
|
+
def escape_text(text)
|
79
|
+
return '' if text.nil?
|
80
|
+
|
81
|
+
text.to_s
|
82
|
+
.gsub('\\', '\\\\')
|
83
|
+
.gsub("\n", '\\n')
|
84
|
+
.gsub(',', '\\,')
|
85
|
+
.gsub(';', '\\;')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/outlook.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class Outlook < BaseProvider
|
7
|
+
BASE_URL = "https://outlook.live.com/calendar/0/deeplink/compose"
|
8
|
+
|
9
|
+
def generate
|
10
|
+
if event.multi_day_sessions.any?
|
11
|
+
generate_multi_day_event
|
12
|
+
else
|
13
|
+
generate_single_event
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def generate_single_event
|
20
|
+
params = {
|
21
|
+
subject: event.title,
|
22
|
+
startdt: format_time(event.start_time),
|
23
|
+
enddt: format_time(event.end_time),
|
24
|
+
body: format_description,
|
25
|
+
location: format_location,
|
26
|
+
path: '/calendar/action/compose',
|
27
|
+
rru: 'addevent'
|
28
|
+
}
|
29
|
+
|
30
|
+
if attendees_list.any?
|
31
|
+
params[:to] = attendees_list.join(';')
|
32
|
+
end
|
33
|
+
|
34
|
+
"#{BASE_URL}?#{URI.encode_www_form(params)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_multi_day_event
|
38
|
+
# For Outlook, we create separate events for each session
|
39
|
+
sessions = event.multi_day_sessions.map do |session|
|
40
|
+
params = {
|
41
|
+
subject: event.title,
|
42
|
+
startdt: format_time(session[:start_time]),
|
43
|
+
enddt: format_time(session[:end_time]),
|
44
|
+
body: format_description,
|
45
|
+
location: format_location,
|
46
|
+
path: '/calendar/action/compose',
|
47
|
+
rru: 'addevent'
|
48
|
+
}
|
49
|
+
|
50
|
+
if attendees_list.any?
|
51
|
+
params[:to] = attendees_list.join(';')
|
52
|
+
end
|
53
|
+
|
54
|
+
"#{BASE_URL}?#{URI.encode_www_form(params)}"
|
55
|
+
end
|
56
|
+
|
57
|
+
sessions.join("\n")
|
58
|
+
end
|
59
|
+
|
60
|
+
def format_time(time)
|
61
|
+
event.localize_time(time).strftime("%Y-%m-%dT%H:%M:%S")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers/yahoo.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
class Yahoo < BaseProvider
|
7
|
+
BASE_URL = "https://calendar.yahoo.com"
|
8
|
+
|
9
|
+
def generate
|
10
|
+
if event.multi_day_sessions.any?
|
11
|
+
generate_multi_day_event
|
12
|
+
else
|
13
|
+
generate_single_event
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def generate_single_event
|
20
|
+
params = {
|
21
|
+
v: 60,
|
22
|
+
view: 'd',
|
23
|
+
type: 20,
|
24
|
+
title: event.title,
|
25
|
+
st: format_start_time(event.start_time),
|
26
|
+
et: format_end_time(event.end_time),
|
27
|
+
desc: format_description,
|
28
|
+
in_loc: format_location,
|
29
|
+
crnd: event.timezone
|
30
|
+
}
|
31
|
+
|
32
|
+
"#{BASE_URL}/?#{URI.encode_www_form(params)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_multi_day_event
|
36
|
+
# Yahoo doesn't support multi-day events in a single URL
|
37
|
+
# Return multiple URLs, one for each session
|
38
|
+
sessions = event.multi_day_sessions.map do |session|
|
39
|
+
params = {
|
40
|
+
v: 60,
|
41
|
+
view: 'd',
|
42
|
+
type: 20,
|
43
|
+
title: event.title,
|
44
|
+
st: format_start_time(session[:start_time]),
|
45
|
+
et: format_end_time(session[:end_time]),
|
46
|
+
desc: format_description,
|
47
|
+
in_loc: format_location,
|
48
|
+
crnd: event.timezone
|
49
|
+
}
|
50
|
+
|
51
|
+
"#{BASE_URL}/?#{URI.encode_www_form(params)}"
|
52
|
+
end
|
53
|
+
|
54
|
+
sessions.join("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def format_start_time(time)
|
58
|
+
event.localize_time(time).strftime("%Y%m%dT%H%M%S")
|
59
|
+
end
|
60
|
+
|
61
|
+
def format_end_time(time)
|
62
|
+
event.localize_time(time).strftime("%Y%m%dT%H%M%S")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/providers.rb
|
4
|
+
module CalInvite
|
5
|
+
module Providers
|
6
|
+
SUPPORTED_PROVIDERS = %i[google ical outlook yahoo ics].freeze
|
7
|
+
|
8
|
+
autoload :BaseProvider, 'cal_invite/providers/base_provider'
|
9
|
+
autoload :Google, 'cal_invite/providers/google'
|
10
|
+
autoload :Ical, 'cal_invite/providers/ical'
|
11
|
+
autoload :Outlook, 'cal_invite/providers/outlook'
|
12
|
+
autoload :Yahoo, 'cal_invite/providers/yahoo'
|
13
|
+
autoload :Ics, 'cal_invite/providers/ics'
|
14
|
+
end
|
15
|
+
end
|
data/lib/cal_invite.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# lib/cal_invite.rb
|
2
|
+
require 'cal_invite/version'
|
3
|
+
require 'cal_invite/configuration'
|
4
|
+
require 'cal_invite/event'
|
5
|
+
require 'cal_invite/providers'
|
6
|
+
|
7
|
+
module CalInvite
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
def configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_configuration!
|
19
|
+
self.configuration = Configuration.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/sig/cal/invite.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cal-invite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephane Paquet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: CalInvite is a gem to generate calendar invitations and provides an easu
|
14
|
+
way to generate .ics files or link to quickly save an event date/time into the major
|
15
|
+
calendards such as Google Calendar, Microsoft Outlook, Apple Calendar and many more.
|
16
|
+
email:
|
17
|
+
- 176050+spaquet@users.noreply.github.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- gemfiles/Gemfile.rails6
|
29
|
+
- gemfiles/Gemfile.rails7
|
30
|
+
- gemfiles/Gemfile.rails8
|
31
|
+
- lib/cal_invite.rb
|
32
|
+
- lib/cal_invite/configuration.rb
|
33
|
+
- lib/cal_invite/event.rb
|
34
|
+
- lib/cal_invite/providers.rb
|
35
|
+
- lib/cal_invite/providers/base_provider.rb
|
36
|
+
- lib/cal_invite/providers/google.rb
|
37
|
+
- lib/cal_invite/providers/ical.rb
|
38
|
+
- lib/cal_invite/providers/ics.rb
|
39
|
+
- lib/cal_invite/providers/outlook.rb
|
40
|
+
- lib/cal_invite/providers/yahoo.rb
|
41
|
+
- lib/cal_invite/version.rb
|
42
|
+
- sig/cal/invite.rbs
|
43
|
+
homepage: https://github.com/the-pew-inc/cal-invite
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
homepage_uri: https://github.com/the-pew-inc/cal-invite
|
48
|
+
source_code_uri: https://github.com/the-pew-inc/cal-invite
|
49
|
+
changelog_uri: https://github.com/the-pew-inc/cal-invite/blob/master/CHANGELOG.md
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 3.0.0
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.5.22
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: CalInvite is a gem to generate calendar invitations.
|
69
|
+
test_files: []
|