add_to_calendar 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +25 -0
- data/Gemfile.lock +8 -8
- data/README.md +11 -4
- data/add_to_calendar.gemspec +1 -1
- data/lib/add_to_calendar/version.rb +1 -1
- data/lib/add_to_calendar.rb +81 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 066bd5d8dca47c52812bd31e3025bebc8dc2cb26a0401565b069d9b14cce5b6f
|
4
|
+
data.tar.gz: ed67f1f5d08cb1a318948a4c4315aa9aa23dcebda93a03899e715fe60deb0f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0bdd471038f1e8deaadab3382de66287df61abf6f747a9a4567a5ed231776e38d683b57ed429a2865364d29f435ffd6d3c7cfd1499c7ac5290b785af1b0ce0b
|
7
|
+
data.tar.gz: d5cb5db508ceb12c74b68e492b36393bd46c0ec4c844854bf90346ddec0a9338e0961b864f0d682f8c78b150aa6c79b85c6b26cb1952e52fbf1610c9213c894d
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Ruby Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rake test
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
add_to_calendar (0.
|
4
|
+
add_to_calendar (0.5.0)
|
5
5
|
tzinfo (>= 1.1, < 3)
|
6
6
|
tzinfo-data (~> 1.2020)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
coderay (1.1.
|
12
|
-
concurrent-ruby (1.
|
11
|
+
coderay (1.1.3)
|
12
|
+
concurrent-ruby (1.3.3)
|
13
13
|
method_source (1.0.0)
|
14
14
|
minitest (5.18.0)
|
15
|
-
pry (0.
|
15
|
+
pry (0.14.2)
|
16
16
|
coderay (~> 1.1)
|
17
17
|
method_source (~> 1.0)
|
18
18
|
rake (13.0.1)
|
19
19
|
timecop (0.9.6)
|
20
|
-
tzinfo (2.0.
|
20
|
+
tzinfo (2.0.6)
|
21
21
|
concurrent-ruby (~> 1.0)
|
22
|
-
tzinfo-data (1.
|
22
|
+
tzinfo-data (1.2024.1)
|
23
23
|
tzinfo (>= 1.0.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
@@ -29,9 +29,9 @@ DEPENDENCIES
|
|
29
29
|
add_to_calendar!
|
30
30
|
bundler (~> 2.0)
|
31
31
|
minitest (~> 5.0)
|
32
|
-
pry (~> 0.
|
32
|
+
pry (~> 0.14)
|
33
33
|
rake (~> 13.0.1)
|
34
34
|
timecop (~> 0.9)
|
35
35
|
|
36
36
|
BUNDLED WITH
|
37
|
-
2.
|
37
|
+
2.3.9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AddToCalendar
|
2
2
|
|
3
|
-
A ruby gem to generate 'Add To Calendar' URLs for Android, Apple, Google, Office 365, Outlook, Outlook.com and Yahoo calendars.
|
3
|
+
A ruby gem to generate 'Add To Calendar' URLs for Android, Apple, Google, Hey, Office 365, Outlook, Outlook.com and Yahoo calendars.
|
4
4
|
|
5
5
|
If this gem brings you some value feel free to buy me a coffee :) [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/P5P71PK9T)
|
6
6
|
|
@@ -41,6 +41,9 @@ Or install it yourself as:
|
|
41
41
|
@cal.yahoo_url
|
42
42
|
#=> "https://calendar.yahoo.com/?v=60&view=d&type=20&title=Christmas%20party%21&st=20201212T133000Z&dur=0100"
|
43
43
|
|
44
|
+
@cal.hey_url
|
45
|
+
#=> "https://app.hey.com/calendar/ical_events/new?ical_source=BEGIN%3AVCALENDAR%0AVERSION%3A2.0%0APRODID%3A-//AddToCalendar//RubyGem//EN%0ABEGIN%3AVEVENT%0ASUMMARY%3AHolly%27s%209th%20birthday%21%0ADTSTAMP%3A20240913T151029Z%0ADTSTART%3A20240906T123000Z%0ADTEND%3A20240906T133000Z%0AUID%3A-20240906T123000Z-Holly%27s%209th%20birthday%21%0AEND%3AVEVENT%0AEND%3AVCALENDAR"
|
46
|
+
|
44
47
|
@cal.office365_url
|
45
48
|
#=> "https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Christmas%20party%21&startdt=2020-12-12T13:30:00Z&enddt=2020-12-12T14:30:00Z"
|
46
49
|
|
@@ -78,8 +81,12 @@ event_attributes = {
|
|
78
81
|
location: "20 W 34th St, New York, NY 10001",
|
79
82
|
url: "https://www.ruby-lang.org/en/",
|
80
83
|
description: "Join us to learn all about Ruby.",
|
81
|
-
add_url_to_description: true # defaults to true
|
82
|
-
all_day: true # defaults to false
|
84
|
+
add_url_to_description: true, # defaults to true
|
85
|
+
all_day: true, # defaults to false
|
86
|
+
organizer: {
|
87
|
+
name: "First Last",
|
88
|
+
email: "email@example.com"
|
89
|
+
}
|
83
90
|
}
|
84
91
|
|
85
92
|
cal = AddToCalendar::URLs.new(**event_attributes)
|
@@ -96,6 +103,7 @@ cal = AddToCalendar::URLs.new(**event_attributes)
|
|
96
103
|
| description | No | String | Accepts newlines by passing `\n` Eg. `"Join us for fun & drinks\n\nPS. Smart casual"` |
|
97
104
|
| add_url_to_description | No | true/false | Defaults to `true`. Set `add_url_to_description: false` to stop the URL from being added to the description |
|
98
105
|
| all_day | No | true/false | <ul><li>Defaults to `false`.</li><li>When set to `true` the times will be ignored.</li><li>If no end_datetime provided it will be a single day event.</li><li>When providing end_datetime, use the final day of the event (eg. 1 day event start: 2023-05-01, end: 2023-05-01; 3 day event start: 2023-05-01, end: 2023-05-03).</li><li>Some calendars require you to specify the _day after_ as the end date which feels counterintuitive, this Gem takes care of that for you.</li></ul> |
|
106
|
+
| organizer | No | Hash | <ul><li>Only supported by ical</li><li>If used you must provide both `name` and `email`</li><li>Must be in format `{ name: "First Last", email: "email@example.com" }`</li></ul> |
|
99
107
|
|
100
108
|
### Timezones and offsets
|
101
109
|
|
@@ -107,7 +115,6 @@ cal = AddToCalendar::URLs.new(**event_attributes)
|
|
107
115
|
|
108
116
|
- IE11 and lower will not work for `ical_url`, `apple_url` and `outlook_url` (IE does not properly support [data-uri links](https://caniuse.com/#feat=datauri). See [#16](https://github.com/jaredlt/add_to_calendar/issues/16)).
|
109
117
|
- IE11 will also not work with `Yahoo`, but this is because Yahoo is deprecating IE 11 support and only offers a simplified interface which does not work with the add event URL.
|
110
|
-
- `Office 365` and `Outlook.com` do not work on mobile. This seems to be an issue on Microsoft's side. Their mobile web interface does not support the 'create event' URLs and the links do not open the apps if you have them installed.
|
111
118
|
|
112
119
|
### More details
|
113
120
|
|
data/add_to_calendar.gemspec
CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "bundler", "~> 2.0"
|
35
35
|
spec.add_development_dependency "rake", "~> 13.0.1"
|
36
36
|
spec.add_development_dependency "minitest", "~> 5.0"
|
37
|
-
spec.add_development_dependency "pry", "~> 0.
|
37
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
38
38
|
spec.add_development_dependency "timecop", "~> 0.9"
|
39
39
|
end
|
data/lib/add_to_calendar.rb
CHANGED
@@ -8,13 +8,12 @@ require 'tzinfo'
|
|
8
8
|
require 'date'
|
9
9
|
# require 'pry'
|
10
10
|
|
11
|
-
|
12
11
|
module AddToCalendar
|
13
12
|
class Error < StandardError; end
|
14
13
|
|
15
14
|
class URLs
|
16
|
-
attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :all_day
|
17
|
-
def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, all_day: false)
|
15
|
+
attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :all_day, :organizer
|
16
|
+
def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, all_day: false, organizer: nil)
|
18
17
|
@start_datetime = start_datetime
|
19
18
|
@end_datetime = end_datetime
|
20
19
|
@title = title
|
@@ -24,6 +23,7 @@ module AddToCalendar
|
|
24
23
|
@description = description
|
25
24
|
@add_url_to_description = add_url_to_description
|
26
25
|
@all_day = all_day
|
26
|
+
@organizer = organizer
|
27
27
|
|
28
28
|
validate_attributes
|
29
29
|
end
|
@@ -92,6 +92,59 @@ module AddToCalendar
|
|
92
92
|
return calendar_url
|
93
93
|
end
|
94
94
|
|
95
|
+
def hey_url
|
96
|
+
calendar_url = "https://app.hey.com/calendar/ical_events/new?ical_source=BEGIN%3AVCALENDAR%0AVERSION%3A2.0%0APRODID%3A-//AddToCalendar//RubyGem//EN%0ABEGIN%3AVEVENT"
|
97
|
+
|
98
|
+
params = {}
|
99
|
+
params[:SUMMARY] = url_encode(title)
|
100
|
+
params[:DTSTAMP] = Time.now.strftime("%Y%m%dT%H%M%SZ")
|
101
|
+
|
102
|
+
if all_day
|
103
|
+
one_day = 1 * 24 * 60 * 60
|
104
|
+
params["DTSTART%3BVALUE=DATE"] = format_date(start_datetime)
|
105
|
+
if end_datetime
|
106
|
+
params["DTEND%3BVALUE=DATE"] = format_date(end_datetime + one_day)
|
107
|
+
else
|
108
|
+
params["DTEND%3BVALUE=DATE"] = format_date(start_datetime + one_day)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
params[:DTSTART] = utc_datetime(start_datetime)
|
112
|
+
if end_datetime
|
113
|
+
params[:DTEND] = utc_datetime(end_datetime)
|
114
|
+
else
|
115
|
+
params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
params[:URL] = url_encode(url) if url
|
120
|
+
params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode(title)}"
|
121
|
+
params[:DESCRIPTION] = url_encode_hey(description) if description
|
122
|
+
if add_url_to_description && url
|
123
|
+
if params[:DESCRIPTION]
|
124
|
+
params[:DESCRIPTION] << "\n\n#{url_encode(url)}"
|
125
|
+
else
|
126
|
+
params[:DESCRIPTION] = url_encode(url)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
if organizer
|
130
|
+
params[:ORGANIZER] = url_encode("CN=\"#{organizer[:name]}\"%3Amailto%3A#{organizer[:email]}")
|
131
|
+
end
|
132
|
+
params[:LOCATION] = url_encode(location) if location
|
133
|
+
|
134
|
+
new_line = "%0A"
|
135
|
+
params.each do |key, value|
|
136
|
+
if key == :ORGANIZER
|
137
|
+
calendar_url << "#{new_line}#{key}%3B#{value}"
|
138
|
+
else
|
139
|
+
calendar_url << "#{new_line}#{key}%3A#{value}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
calendar_url << "%0AEND%3AVEVENT%0AEND%3AVCALENDAR"
|
144
|
+
|
145
|
+
return calendar_url
|
146
|
+
end
|
147
|
+
|
95
148
|
def office365_url
|
96
149
|
# Eg. https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Holly%27s%208th%20Birthday%21&startdt=2020-05-12T12:30:00Z&enddt=2020-05-12T16:00:00Z&body=Come%20join%20us%20for%20lots%20of%20fun%20%26%20cake%21%0A%0Ahttps%3A%2F%2Fwww.example.com%2Fevent-details&location=Flat%204%2C%20The%20Edge%2C%2038%20Smith-Dorrien%20St%2C%20London%2C%20N1%207GU
|
97
150
|
microsoft("office365")
|
@@ -126,6 +179,9 @@ module AddToCalendar
|
|
126
179
|
end
|
127
180
|
end
|
128
181
|
params[:SUMMARY] = url_encode_ical(title)
|
182
|
+
if organizer
|
183
|
+
params[:ORGANIZER] = url_encode_ical("CN=\"#{organizer[:name]}\":mailto:#{organizer[:email]}")
|
184
|
+
end
|
129
185
|
params[:URL] = url_encode(url) if url
|
130
186
|
params[:DESCRIPTION] = url_encode_ical(description) if description
|
131
187
|
if add_url_to_description && url
|
@@ -141,7 +197,11 @@ module AddToCalendar
|
|
141
197
|
|
142
198
|
new_line = "%0A"
|
143
199
|
params.each do |key, value|
|
144
|
-
|
200
|
+
if key == :ORGANIZER
|
201
|
+
calendar_url << "#{new_line}#{key};#{value}"
|
202
|
+
else
|
203
|
+
calendar_url << "#{new_line}#{key}:#{value}"
|
204
|
+
end
|
145
205
|
end
|
146
206
|
|
147
207
|
calendar_url << "%0AEND:VEVENT%0AEND:VCALENDAR"
|
@@ -181,6 +241,12 @@ module AddToCalendar
|
|
181
241
|
if description
|
182
242
|
raise(ArgumentError, ":description must be a string") unless self.description.kind_of? String
|
183
243
|
end
|
244
|
+
|
245
|
+
if organizer
|
246
|
+
unless self.organizer.is_a?(Hash) && self.organizer[:name].is_a?(String) && self.organizer[:email].is_a?(String)
|
247
|
+
raise(ArgumentError, ":organizer must be a Hash of format { name: \"First Last\", email: \"email@example.com\" }")
|
248
|
+
end
|
249
|
+
end
|
184
250
|
end
|
185
251
|
|
186
252
|
def microsoft(service)
|
@@ -313,6 +379,17 @@ module AddToCalendar
|
|
313
379
|
}.join("\\n")
|
314
380
|
end
|
315
381
|
|
382
|
+
def url_encode_hey(s)
|
383
|
+
string = s.dup # don't modify original input
|
384
|
+
string.split("\n").map { |e|
|
385
|
+
if e.empty?
|
386
|
+
e
|
387
|
+
else
|
388
|
+
url_encode(e)
|
389
|
+
end
|
390
|
+
}.join("\n")
|
391
|
+
end
|
392
|
+
|
316
393
|
def yahoo_param(key)
|
317
394
|
if key == :in_loc
|
318
395
|
key.to_s
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: add_to_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
95
|
+
version: '0.14'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.
|
102
|
+
version: '0.14'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: timecop
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,7 @@ extensions: []
|
|
122
122
|
extra_rdoc_files: []
|
123
123
|
files:
|
124
124
|
- ".github/FUNDING.yml"
|
125
|
+
- ".github/workflows/tests.yml"
|
125
126
|
- ".gitignore"
|
126
127
|
- ".travis.yml"
|
127
128
|
- Gemfile
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
- !ruby/object:Gem::Version
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
160
|
+
rubygems_version: 3.5.6
|
160
161
|
signing_key:
|
161
162
|
specification_version: 4
|
162
163
|
summary: Generate 'Add To Calendar' URLs for Android, Apple, Google, Office 365, Outlook,
|