add_to_calendar_links 0.3.2 → 0.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/lib/add_to_calendar_links.rb +74 -22
- 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: ff19e9aa3a6c509b5469cd27ff8f0b01cc82f07141cd0ed67e34f5eb43bfa65e
|
4
|
+
data.tar.gz: 94432081f0b675201b9aada3180aa03b4ddd28b6f22a74712510686c6c3e9faf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4489eeed48856d3ecb2a34bef48d25eb31cedb38096f8e5bc77337099401729a054402f63456163ac42641b73a53290f13329241b63fe3737121632df88450
|
7
|
+
data.tar.gz: 48777ad3226a53f48e5bfc46d9e81df16d82f1dd40600dac72313a9d48a7198ec647ff2ada13a4502dac022a5c1c9e0314d7134182bbd8bf9c206a52a0a02908
|
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 'pry'
|
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\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[:LASTMODIFIED] = 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
142
|
calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%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,10 @@ 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[:LASTMODIFIED] = format_date_google(last_modified) if last_modified
|
167
|
+
params[:METHOD] = "REQUEST"
|
123
168
|
|
124
169
|
new_line = "%0A"
|
125
170
|
params.each do |key, value|
|
@@ -254,11 +299,10 @@ module AddToCalendarLinks
|
|
254
299
|
def url_encode_ical(s, strip_html: @strip_html)
|
255
300
|
# per https://tools.ietf.org/html/rfc5545#section-3.3.11
|
256
301
|
string = s.dup # don't modify original input
|
257
|
-
|
258
|
-
|
302
|
+
if strip_html
|
303
|
+
string = strip_html_tags(string)
|
304
|
+
end
|
259
305
|
string.gsub!("\\", "\\\\\\") # \ >> \\ --yes, really: https://stackoverflow.com/questions/6209480/how-to-replace-backslash-with-double-backslash
|
260
|
-
string.gsub!(",", "\\,")
|
261
|
-
string.gsub!(";", "\\;")
|
262
306
|
string.gsub!("\r\n", "\n") # so can handle all newlines the same
|
263
307
|
string.split("\n").map { |e|
|
264
308
|
if e.empty?
|
@@ -266,11 +310,19 @@ module AddToCalendarLinks
|
|
266
310
|
else
|
267
311
|
url_encode(e)
|
268
312
|
end
|
269
|
-
}.join("\\n")
|
313
|
+
}.compact.join("\\n").gsub(/(\\n){2,}/, "\\n\\n").strip
|
270
314
|
end
|
271
315
|
|
272
|
-
def strip_html_tags(description)
|
273
|
-
description.dup
|
316
|
+
def strip_html_tags(description, line_break_seperator: "\\n")
|
317
|
+
string = description.dup
|
318
|
+
string.gsub!("<br>", line_break_seperator)
|
319
|
+
string.gsub!("<p>", line_break_seperator)
|
320
|
+
string.gsub!("</p>", line_break_seperator)
|
321
|
+
string.gsub!("&", "and")
|
322
|
+
string.gsub!(" ", " ")
|
323
|
+
string.gsub!(/<\/?[^>]*>/, "")
|
324
|
+
string.gsub!(/(\\n){2,}/, "\\n\\n")
|
325
|
+
string.strip
|
274
326
|
end
|
275
327
|
end
|
276
328
|
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'
|
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
|