add_to_calendar_links 0.3.5 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09611f4133378a8707615e16cc296be9a6a80e72aa732c81cbb0365db77e9a96'
4
- data.tar.gz: 8bf823a2ed513266665d3e823fa547bfa59e27b3744affdde1ce3498a561992b
3
+ metadata.gz: 7c1fc649c026fad801703de16f4acc9020828623b2cca79bc3b0994d1283b539
4
+ data.tar.gz: 8e982c9be9dae3e653f2db93e09e164ced68ffe4598d9a53881c34a1ea6a7cef
5
5
  SHA512:
6
- metadata.gz: 286fe06c12701edfd41f105ab49223b416fb53ad0ef696aa99d278d9cbcc3ebb0fe0e5880998c4e5799b62fd572740272a38450d99ddabaf79a2d6eccdc39dc1
7
- data.tar.gz: debe4ada97a61847c6174db43d107f150e302f02ef5b555f1bc0c561b666859953eed4728e9def4eda023806947389fecfbd9554f6ef8c8e528eca7779aac2f0
6
+ metadata.gz: 9d3dc98e19a10ef18d984b3e71a4f378ce3e592373e86656b2a09d7aca47616ea2d9f1cc4df56858f3d8fda99092386e1c67fe76b672be38b3e03ecb508f9765
7
+ data.tar.gz: fe8ff7ed31d64ec73ed7af4afa81a3efdb26934f863190903f7b22cba79a954223846a03de81eb01a1694c9c4f836e1d18972a27d9058f602184f5eafb9bc690
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in add_to_calendar.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- add_to_calendar_links (0.3.1)
4
+ add_to_calendar_links (0.3.5)
5
5
  tzinfo (>= 1.1, < 3)
6
6
  tzinfo-data (~> 1.2021)
7
7
 
@@ -12,8 +12,8 @@ module AddToCalendarLinks
12
12
  class Error < StandardError; end
13
13
 
14
14
  class URLs
15
- attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :organizer, :strip_html
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)
15
+ attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :organizer, :strip_html, :sequence, :last_modified, :uid
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, uid:)
17
17
  @start_datetime = start_datetime
18
18
  @end_datetime = end_datetime
19
19
  @title = title
@@ -24,6 +24,9 @@ module AddToCalendarLinks
24
24
  @add_url_to_description = add_url_to_description
25
25
  @organizer = URI.parse(organizer) if organizer
26
26
  @strip_html = strip_html
27
+ @sequence = sequence
28
+ @uid = uid
29
+ @last_modified = last_modified
27
30
  validate_attributes
28
31
  end
29
32
 
@@ -57,25 +60,28 @@ module AddToCalendarLinks
57
60
 
58
61
  def yahoo_url
59
62
  # 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
60
- calendar_url = "https://calendar.yahoo.com/?v=60&view=d&type=20"
63
+ calendar_url = "https://calendar.yahoo.com/?v=60&VIEW=d&TYPE=20"
61
64
  params = {}
62
- params[:title] = url_encode(title)
63
- params[:st] = utc_datetime(start_datetime)
65
+ params[:TITLE] = url_encode(title)
66
+ params[:ST] = utc_datetime(start_datetime)
64
67
  if end_datetime
68
+ # params[:ET] = utc_datetime(end_datetime)
65
69
  seconds = duration_seconds(start_datetime, end_datetime)
66
- params[:dur] = seconds_to_hours_minutes(seconds)
70
+ params[:DUR] = seconds_to_hours_minutes(seconds)
67
71
  else
68
- params[:dur] = "0100"
72
+ # params[:ET] = utc_datetime(start_datetime + 60*60)
73
+ params[:DUR] = "0100"
69
74
  end
70
- params[:desc] = url_encode(description) if description
75
+ params[:DESC] = url_encode(strip_html_tags(description)).truncate(3000) if description
76
+
71
77
  if add_url_to_description && url
72
- if params[:desc]
73
- params[:desc] << url_encode("\n\n#{url}")
78
+ if params[:DESC]
79
+ params[:DESC] << url_encode("\n\n#{url}")
74
80
  else
75
- params[:desc] = url_encode(url)
81
+ params[:DESC] = url_encode(url)
76
82
  end
77
83
  end
78
- params[:in_loc] = url_encode(location) if location
84
+ params[:IN_LOC] = url_encode(location) if location
79
85
 
80
86
  params.each do |key, value|
81
87
  calendar_url << "&#{key}=#{value}"
@@ -94,10 +100,52 @@ module AddToCalendarLinks
94
100
  microsoft("outlook.com")
95
101
  end
96
102
 
103
+ def ical_file
104
+ calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:REQUEST\nBEGIN:VEVENT"
105
+
106
+ params = {}
107
+ params[:DTSTART] = utc_datetime(start_datetime)
108
+ if end_datetime
109
+ params[:DTEND] = utc_datetime(end_datetime)
110
+ else
111
+ params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
112
+ end
113
+ params[:SUMMARY] = strip_html_tags(title) #ical doesnt support html so remove all markup. Optional for other formats
114
+ params[:URL] = url if url
115
+ params[:DESCRIPTION] = strip_html_tags(description).strip if description
116
+ if add_url_to_description && url
117
+ if params[:DESCRIPTION]
118
+ params[:DESCRIPTION] << "\\n\\n#{url}"
119
+ else
120
+ params[:DESCRIPTION] = url
121
+ end
122
+ end
123
+ params[:LOCATION] = strip_html_tags(location) if location
124
+ if uid
125
+ params[:UID] = uid
126
+ else
127
+ params[:UID] = "-#{urlc}" if url
128
+ params[:UID] = "-#{utc_datetime(start_datetime)}-#{title}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
129
+ end
130
+ params[:ORGANIZER] = organizer if organizer
131
+ params[:SEQUENCE] = sequence if sequence
132
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
133
+ params[:METHOD] = "REQUEST"
134
+
135
+ params.each do |key, value|
136
+ calendar_url << "\n#{key}:#{value}"
137
+ end
138
+
139
+ calendar_url << "\nEND:VEVENT\nEND:VCALENDAR"
140
+
141
+ return calendar_url
142
+ end
143
+
97
144
  def ical_url
98
145
  # Downloads a *.ics file provided as a data-uri
99
146
  # 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"
100
- calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
147
+ calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0AMETHOD:REQUEST%0ABEGIN:VEVENT"
148
+
101
149
  params = {}
102
150
  params[:DTSTART] = utc_datetime(start_datetime)
103
151
  if end_datetime
@@ -107,7 +155,7 @@ module AddToCalendarLinks
107
155
  end
108
156
  params[:SUMMARY] = url_encode_ical(title, strip_html: true) #ical doesnt support html so remove all markup. Optional for other formats
109
157
  params[:URL] = url_encode(url) if url
110
- params[:DESCRIPTION] = url_encode_ical(description, strip_html: true) if description
158
+ params[:DESCRIPTION] = url_encode_ical(strip_html_tags(description, line_break_seperator: "\n")) if description
111
159
  if add_url_to_description && url
112
160
  if params[:DESCRIPTION]
113
161
  params[:DESCRIPTION] << "\\n\\n#{url_encode(url)}"
@@ -116,9 +164,15 @@ module AddToCalendarLinks
116
164
  end
117
165
  end
118
166
  params[:LOCATION] = url_encode_ical(location) if location
119
- params[:UID] = "-#{url_encode(url)}" if url
120
- 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
121
- params[:organizer] = organizer if organizer
167
+ if uid
168
+ params[:UID] = uid
169
+ else
170
+ params[:UID] = "-#{url_encode(url)}" if url
171
+ 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
172
+ end
173
+ params[:ORGANIZER] = organizer if organizer
174
+ params[:SEQUENCE] = sequence if sequence
175
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
122
176
 
123
177
  new_line = "%0A"
124
178
  params.each do |key, value|
@@ -253,13 +307,7 @@ module AddToCalendarLinks
253
307
  def url_encode_ical(s, strip_html: @strip_html)
254
308
  # per https://tools.ietf.org/html/rfc5545#section-3.3.11
255
309
  string = s.dup # don't modify original input
256
-
257
310
  if strip_html
258
- string.gsub!("<br>", "\n")
259
- string.gsub!("<p>", "\n")
260
- string.gsub!("</p>", "\n\n")
261
- string.gsub!("&amp;", "and")
262
- string.gsub!("&nbsp;", " ")
263
311
  string = strip_html_tags(string)
264
312
  end
265
313
  string.gsub!("\\", "\\\\\\") # \ >> \\ --yes, really: https://stackoverflow.com/questions/6209480/how-to-replace-backslash-with-double-backslash
@@ -270,11 +318,19 @@ module AddToCalendarLinks
270
318
  else
271
319
  url_encode(e)
272
320
  end
273
- }.join("\n")
321
+ }.compact.join("\\n").gsub(/(\\n){2,}/, "\\n\\n").strip
274
322
  end
275
323
 
276
- def strip_html_tags(description)
277
- description.dup.gsub(/<\/?[^>]*>/, "")
324
+ def strip_html_tags(description, line_break_seperator: "\\n")
325
+ string = description.dup
326
+ string.gsub!("<br>", line_break_seperator)
327
+ string.gsub!("<p>", line_break_seperator)
328
+ string.gsub!("</p>", line_break_seperator)
329
+ string.gsub!("&amp;", "and")
330
+ string.gsub!("&nbsp;", " ")
331
+ string.gsub!(/<\/?[^>]*>/, "")
332
+ string.gsub!(/(\\n){2,}/, "\\n\\n")
333
+ string.strip
278
334
  end
279
335
  end
280
336
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AddToCalendarLinks
4
- VERSION = '0.3.5'
4
+ VERSION = '0.4.3'
5
5
  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.3.5
4
+ version: 0.4.3
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-22 00:00:00.000000000 Z
12
+ date: 2021-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo