add_to_calendar_links 0.3.4 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/lib/add_to_calendar_links.rb +71 -25
- data/lib/add_to_calendar_links/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2497b47a154707baecaf96e5a06c8bf247a3a4927bac368fe9102d64ab53c139
|
4
|
+
data.tar.gz: 03d063b6c2083d55d09e7ba710616d5de6337dbf8ba4f0e16c133147ea190607
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 045fb5416365467b8b557c981d27a754826750a0efce2d2dbc00ab348b5bdba7e4e37449611fdc828772be5c13bd639b8f78d045ac937f14981345c0d589d9e4
|
7
|
+
data.tar.gz: c64b76d1d4fa90e10c3e0227e413064330b9adbcf2d0e38a09360a110310fef2a85ae015ff0d723a1e79dae63fd8cb8374d43167db490fa783204e0941ee3386
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,14 +7,13 @@ include ERB::Util
|
|
7
7
|
require 'tzinfo'
|
8
8
|
require 'date'
|
9
9
|
require 'uri'
|
10
|
-
require 'byebug'
|
11
10
|
|
12
11
|
module AddToCalendarLinks
|
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, :organizer, :strip_html
|
17
|
-
def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, organizer: nil, strip_html: false)
|
15
|
+
attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :organizer, :strip_html, :sequence, :last_modified
|
16
|
+
def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, organizer: nil, strip_html: false, sequence: nil, last_modified: Time.now.utc)
|
18
17
|
@start_datetime = start_datetime
|
19
18
|
@end_datetime = end_datetime
|
20
19
|
@title = title
|
@@ -25,6 +24,8 @@ module AddToCalendarLinks
|
|
25
24
|
@add_url_to_description = add_url_to_description
|
26
25
|
@organizer = URI.parse(organizer) if organizer
|
27
26
|
@strip_html = strip_html
|
27
|
+
@sequence = sequence
|
28
|
+
@last_modified = last_modified
|
28
29
|
validate_attributes
|
29
30
|
end
|
30
31
|
|
@@ -58,25 +59,28 @@ module AddToCalendarLinks
|
|
58
59
|
|
59
60
|
def yahoo_url
|
60
61
|
# Eg. https://calendar.yahoo.com/?v=60&view=d&type=20&title=Holly%27s%208th%20Birthday!&st=20200615T170000Z&dur=0100&desc=Join%20us%20to%20celebrate%20with%20lots%20of%20games%20and%20cake!&in_loc=7%20Apartments,%20London
|
61
|
-
calendar_url = "https://calendar.yahoo.com/?v=60&
|
62
|
+
calendar_url = "https://calendar.yahoo.com/?v=60&VIEW=d&TYPE=20"
|
62
63
|
params = {}
|
63
|
-
params[:
|
64
|
-
params[:
|
64
|
+
params[:TITLE] = url_encode(title)
|
65
|
+
params[:ST] = utc_datetime(start_datetime)
|
65
66
|
if end_datetime
|
67
|
+
# params[:ET] = utc_datetime(end_datetime)
|
66
68
|
seconds = duration_seconds(start_datetime, end_datetime)
|
67
|
-
params[:
|
69
|
+
params[:DUR] = seconds_to_hours_minutes(seconds)
|
68
70
|
else
|
69
|
-
params[:
|
71
|
+
# params[:ET] = utc_datetime(start_datetime + 60*60)
|
72
|
+
params[:DUR] = "0100"
|
70
73
|
end
|
71
|
-
params[:
|
74
|
+
params[:DESC] = url_encode(strip_html_tags(description)).truncate(3000) if description
|
75
|
+
|
72
76
|
if add_url_to_description && url
|
73
|
-
if params[:
|
74
|
-
params[:
|
77
|
+
if params[:DESC]
|
78
|
+
params[:DESC] << url_encode("\n\n#{url}")
|
75
79
|
else
|
76
|
-
params[:
|
80
|
+
params[:DESC] = url_encode(url)
|
77
81
|
end
|
78
82
|
end
|
79
|
-
params[:
|
83
|
+
params[:IN_LOC] = url_encode(location) if location
|
80
84
|
|
81
85
|
params.each do |key, value|
|
82
86
|
calendar_url << "&#{key}=#{value}"
|
@@ -95,10 +99,48 @@ module AddToCalendarLinks
|
|
95
99
|
microsoft("outlook.com")
|
96
100
|
end
|
97
101
|
|
102
|
+
def ical_file
|
103
|
+
calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:REQUEST\nBEGIN:VEVENT"
|
104
|
+
|
105
|
+
params = {}
|
106
|
+
params[:DTSTART] = utc_datetime(start_datetime)
|
107
|
+
if end_datetime
|
108
|
+
params[:DTEND] = utc_datetime(end_datetime)
|
109
|
+
else
|
110
|
+
params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
|
111
|
+
end
|
112
|
+
params[:SUMMARY] = strip_html_tags(title) #ical doesnt support html so remove all markup. Optional for other formats
|
113
|
+
params[:URL] = url if url
|
114
|
+
params[:DESCRIPTION] = strip_html_tags(description).strip if description
|
115
|
+
if add_url_to_description && url
|
116
|
+
if params[:DESCRIPTION]
|
117
|
+
params[:DESCRIPTION] << "\\n\\n#{url}"
|
118
|
+
else
|
119
|
+
params[:DESCRIPTION] = url
|
120
|
+
end
|
121
|
+
end
|
122
|
+
params[:LOCATION] = strip_html_tags(location) if location
|
123
|
+
params[:UID] = "-#{url}" if url
|
124
|
+
params[:UID] = "-#{utc_datetime(start_datetime)}-#{title}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
|
125
|
+
params[:ORGANIZER] = organizer if organizer
|
126
|
+
params[:SEQUENCE] = sequence if sequence
|
127
|
+
params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
|
128
|
+
params[:METHOD] = "REQUEST"
|
129
|
+
|
130
|
+
params.each do |key, value|
|
131
|
+
calendar_url << "\n#{key}:#{value}"
|
132
|
+
end
|
133
|
+
|
134
|
+
calendar_url << "\nEND:VEVENT\nEND:VCALENDAR"
|
135
|
+
|
136
|
+
return calendar_url
|
137
|
+
end
|
138
|
+
|
98
139
|
def ical_url
|
99
140
|
# Downloads a *.ics file provided as a data-uri
|
100
141
|
# Eg. "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART:20200512T123000Z%0ADTEND:20200512T160000Z%0ASUMMARY:Holly%27s%208th%20Birthday%21%0AURL:https%3A%2F%2Fwww.example.com%2Fevent-details%0ADESCRIPTION:Come%20join%20us%20for%20lots%20of%20fun%20%26%20cake%21\\n\\nhttps%3A%2F%2Fwww.example.com%2Fevent-details%0ALOCATION:Flat%204%5C%2C%20The%20Edge%5C%2C%2038%20Smith-Dorrien%20St%5C%2C%20London%5C%2C%20N1%207GU%0AUID:-https%3A%2F%2Fwww.example.com%2Fevent-details%0AEND:VEVENT%0AEND:VCALENDAR"
|
101
|
-
calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
|
142
|
+
calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0AMETHOD:REQUEST%0ABEGIN:VEVENT"
|
143
|
+
|
102
144
|
params = {}
|
103
145
|
params[:DTSTART] = utc_datetime(start_datetime)
|
104
146
|
if end_datetime
|
@@ -108,7 +150,7 @@ module AddToCalendarLinks
|
|
108
150
|
end
|
109
151
|
params[:SUMMARY] = url_encode_ical(title, strip_html: true) #ical doesnt support html so remove all markup. Optional for other formats
|
110
152
|
params[:URL] = url_encode(url) if url
|
111
|
-
params[:DESCRIPTION] = url_encode_ical(description,
|
153
|
+
params[:DESCRIPTION] = url_encode_ical(strip_html_tags(description, line_break_seperator: "\n")) if description
|
112
154
|
if add_url_to_description && url
|
113
155
|
if params[:DESCRIPTION]
|
114
156
|
params[:DESCRIPTION] << "\\n\\n#{url_encode(url)}"
|
@@ -119,7 +161,9 @@ module AddToCalendarLinks
|
|
119
161
|
params[:LOCATION] = url_encode_ical(location) if location
|
120
162
|
params[:UID] = "-#{url_encode(url)}" if url
|
121
163
|
params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode_ical(title)}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
|
122
|
-
params[:
|
164
|
+
params[:ORGANIZER] = organizer if organizer
|
165
|
+
params[:SEQUENCE] = sequence if sequence
|
166
|
+
params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
|
123
167
|
|
124
168
|
new_line = "%0A"
|
125
169
|
params.each do |key, value|
|
@@ -254,13 +298,7 @@ module AddToCalendarLinks
|
|
254
298
|
def url_encode_ical(s, strip_html: @strip_html)
|
255
299
|
# per https://tools.ietf.org/html/rfc5545#section-3.3.11
|
256
300
|
string = s.dup # don't modify original input
|
257
|
-
|
258
301
|
if strip_html
|
259
|
-
string.gsub!("<br>", "\n")
|
260
|
-
string.gsub!("<p>", "\n")
|
261
|
-
string.gsub!("</p>", "\n\n")
|
262
|
-
string.gsub!("&", "and")
|
263
|
-
string.gsub!(" ", " ")
|
264
302
|
string = strip_html_tags(string)
|
265
303
|
end
|
266
304
|
string.gsub!("\\", "\\\\\\") # \ >> \\ --yes, really: https://stackoverflow.com/questions/6209480/how-to-replace-backslash-with-double-backslash
|
@@ -271,11 +309,19 @@ module AddToCalendarLinks
|
|
271
309
|
else
|
272
310
|
url_encode(e)
|
273
311
|
end
|
274
|
-
}.join("
|
312
|
+
}.compact.join("\\n").gsub(/(\\n){2,}/, "\\n\\n").strip
|
275
313
|
end
|
276
314
|
|
277
|
-
def strip_html_tags(description)
|
278
|
-
description.dup
|
315
|
+
def strip_html_tags(description, line_break_seperator: "\\n")
|
316
|
+
string = description.dup
|
317
|
+
string.gsub!("<br>", line_break_seperator)
|
318
|
+
string.gsub!("<p>", line_break_seperator)
|
319
|
+
string.gsub!("</p>", line_break_seperator)
|
320
|
+
string.gsub!("&", "and")
|
321
|
+
string.gsub!(" ", " ")
|
322
|
+
string.gsub!(/<\/?[^>]*>/, "")
|
323
|
+
string.gsub!(/(\\n){2,}/, "\\n\\n")
|
324
|
+
string.strip
|
279
325
|
end
|
280
326
|
end
|
281
327
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: add_to_calendar_links
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Turner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-03-
|
12
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tzinfo
|