add_to_calendar 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +122 -0
- data/Rakefile +10 -0
- data/add_to_calendar.gemspec +36 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/add_to_calendar.rb +181 -0
- data/lib/add_to_calendar/version.rb +3 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1424db1a7b175365602cda45a451d53eabaf14e67058003ef7b024d6984d93bd
|
4
|
+
data.tar.gz: 9e050f1eaf3fb403493000f1487bff404636c5f778b59b72f421caaf5dc00379
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 175b9b699feba0968eb11516e95b84f894bc4a4f7c721d7e65b0af084bd005436a8e6655bf71e50d77fb48ae930cb0ab788ba0cbce4d2c8b23aec1c05fb7e91b
|
7
|
+
data.tar.gz: e98fcbb260cd9ff707d227df4f37113860592af5397932ce2d356e8bd928a3f219827d5e7e48f6e446feb0fdd2349f7e8fa94383b2dc29b13d6088a94e64eb33
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
add_to_calendar (0.1.0)
|
5
|
+
tzinfo (~> 2.0.2)
|
6
|
+
tzinfo-data (~> 1.2020.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
concurrent-ruby (1.1.6)
|
13
|
+
method_source (1.0.0)
|
14
|
+
minitest (5.14.0)
|
15
|
+
pry (0.13.1)
|
16
|
+
coderay (~> 1.1)
|
17
|
+
method_source (~> 1.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
tzinfo (2.0.2)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
tzinfo-data (1.2020.1)
|
22
|
+
tzinfo (>= 1.0.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
add_to_calendar!
|
29
|
+
bundler (~> 2.0)
|
30
|
+
minitest (~> 5.0)
|
31
|
+
pry (~> 0.13.1)
|
32
|
+
rake (~> 12.3.3)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jared Turner
|
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,122 @@
|
|
1
|
+
# AddToCalendar
|
2
|
+
|
3
|
+
A ruby gem to generate 'Add To Calendar' URLs for Google, Apple, Office 365*, Outlook and Yahoo calendars.
|
4
|
+
|
5
|
+
*Office 365 not yet available
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'add_to_calendar'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install add_to_calendar
|
22
|
+
|
23
|
+
## Requirements
|
24
|
+
|
25
|
+
- Ruby 2.0 or higher
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# create new instance, adding your event attributes
|
31
|
+
@cal = AddToCalendar::URLs.new(
|
32
|
+
start_datetime: Time.new(2020,12,12,13,30,00,0),
|
33
|
+
title: "Christmas party!",
|
34
|
+
timezone: 'Europe/London'
|
35
|
+
)
|
36
|
+
|
37
|
+
# access 'add to calendar' URLs
|
38
|
+
@cal.google_url
|
39
|
+
#=> "https://www.google.com/calendar/render?action=TEMPLATE&text=Christmas%20party%21&dates=20201212T133000/20201212T143000&ctz=Europe/London"
|
40
|
+
|
41
|
+
@cal.yahoo_url
|
42
|
+
#=> "https://calendar.yahoo.com/?v=60&view=d&type=20&title=Christmas%20party%21&st=20201212T133000Z&dur=0100"
|
43
|
+
|
44
|
+
# ical provides a data-uri which will download a properly formatted *.ics file (see 'Creating HTML links' section)
|
45
|
+
@cal.ical_url
|
46
|
+
#=> "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20201212T133000Z%0ADTEND=20201212T143000Z%0ASUMMARY=Christmas%20party%21%0AUID=-20201212T133000Z-Christmas%20party%21%0AEND:VEVENT%0AEND:VCALENDAR"
|
47
|
+
|
48
|
+
# apple_url and outlook_url are simply helper methods that call ical_url
|
49
|
+
@cal.apple_url
|
50
|
+
#=> "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20201212T133000Z%0ADTEND=20201212T143000Z%0ASUMMARY=Christmas%20party%21%0AUID=-20201212T133000Z-Christmas%20party%21%0AEND:VEVENT%0AEND:VCALENDAR"
|
51
|
+
|
52
|
+
@cal.outlook_url
|
53
|
+
#=> "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20201212T133000Z%0ADTEND=20201212T143000Z%0ASUMMARY=Christmas%20party%21%0AUID=-20201212T133000Z-Christmas%20party%21%0AEND:VEVENT%0AEND:VCALENDAR"
|
54
|
+
```
|
55
|
+
|
56
|
+
### Creating HTML links
|
57
|
+
|
58
|
+
```erb
|
59
|
+
<!-- Simply pass the url into the href Eg. in ERB -->
|
60
|
+
<a href="<%= @cal.google_url %>">Add to Google Calendar</a>
|
61
|
+
|
62
|
+
<a href="<%= @cal.yahoo_url %>">Add to Yahoo Calendar</a>
|
63
|
+
|
64
|
+
<!-- for ical_url, apple_url and outlook_url you can set the filename like so -->
|
65
|
+
<a download="calendar-event.ics" href="<%= @cal.ical_url %>">Download iCal</a>
|
66
|
+
```
|
67
|
+
|
68
|
+
### Event attributes
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
event_attributes = {
|
72
|
+
start_datetime: Time.new(2020,12,12,9,00,00,0), # required
|
73
|
+
end_datetime: Time.new(2020,12,12,17,00,00,0),
|
74
|
+
title: "Ruby Conference", # required
|
75
|
+
timezone: 'America/New_York', # required
|
76
|
+
location: "20 W 34th St, New York, NY 10001",
|
77
|
+
url: "https://www.ruby-lang.org/en/",
|
78
|
+
description: "Join us to learn all about Ruby.",
|
79
|
+
add_url_to_description: true # defaults to true
|
80
|
+
}
|
81
|
+
|
82
|
+
cal = AddToCalendar::URLs.new(event_attributes)
|
83
|
+
```
|
84
|
+
|
85
|
+
| Attribute | Required? | Class | Notes |
|
86
|
+
| -----------------------|-----------|------------|-------|
|
87
|
+
| start_datetime | Yes | Time | |
|
88
|
+
| end_datetime | No | Time | <ul><li>If not provided, defaults to start_datetime + 1 hour</li><li>Must be > start_datetime</li></ul> |
|
89
|
+
| title | Yes | String | |
|
90
|
+
| timezone | Yes | String | Must be in [tz database format](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) Eg. 'Europe/London', 'America/New_York' |
|
91
|
+
| location | No | String | |
|
92
|
+
| url | No | String | Most providers do not have a native URL field. If you set `url` it will be added to the end of the description field (see `add_url_to_description`) |
|
93
|
+
| description | No | String | Accepts newlines by passing `\n` Eg. `"Join us for fun & drinks\n\nPS. Smart casual"` |
|
94
|
+
| 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 |
|
95
|
+
|
96
|
+
### Timezones and offsets
|
97
|
+
|
98
|
+
- Offset values eg. "2020-05-13 15:31:00 **+05:00**" are ignored. It is only important that you have the correct date and time numbers set. The timezone is set directly using its own attribute `timezone`.
|
99
|
+
- You must set a timezone so that when users add the event to their calendar it shows at their correct local time.
|
100
|
+
- Eg. London event @ `2020-05-13 13:30:00` will save in a New Yorkers calendar as local time `2020-05-13 17:30:00`
|
101
|
+
|
102
|
+
### Browser support
|
103
|
+
|
104
|
+
- 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)).
|
105
|
+
|
106
|
+
### More details
|
107
|
+
|
108
|
+
- Read the [Wiki](https://github.com/jaredlt/add_to_calendar/wiki) for more specific details
|
109
|
+
|
110
|
+
## Development
|
111
|
+
|
112
|
+
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.
|
113
|
+
|
114
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jaredlt/add_to_calendar.
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "add_to_calendar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "add_to_calendar"
|
7
|
+
spec.version = AddToCalendar::VERSION
|
8
|
+
spec.authors = ["Jared Turner"]
|
9
|
+
spec.email = ["jaredlt01@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Generate 'Add To Calendar' URLs for Google, Apple, Office 365, Outlook, Yahoo calendars"
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
+
spec.homepage = "https://github.com/jaredlt/add_to_calendar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "tzinfo", "~> 2.0.2"
|
30
|
+
spec.add_dependency "tzinfo-data", "~> 1.2020.1"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
33
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
34
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.13.1"
|
36
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "add_to_calendar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require "add_to_calendar/version"
|
2
|
+
|
3
|
+
# needed for url_encode method
|
4
|
+
require "erb"
|
5
|
+
include ERB::Util
|
6
|
+
require 'tzinfo'
|
7
|
+
require 'date'
|
8
|
+
# require 'pry'
|
9
|
+
|
10
|
+
|
11
|
+
module AddToCalendar
|
12
|
+
class Error < StandardError; end
|
13
|
+
|
14
|
+
class URLs
|
15
|
+
attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description
|
16
|
+
def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true)
|
17
|
+
@start_datetime = start_datetime
|
18
|
+
@end_datetime = end_datetime
|
19
|
+
@title = title
|
20
|
+
@timezone = TZInfo::Timezone.get(timezone)
|
21
|
+
@location = location
|
22
|
+
@url = url
|
23
|
+
@description = description
|
24
|
+
@add_url_to_description = add_url_to_description
|
25
|
+
|
26
|
+
validate_attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
def google_url
|
30
|
+
# Eg. https://www.google.com/calendar/render?action=TEMPLATE&text=Holly%27s%208th%20Birthday!&dates=20200615T180000/20200615T190000&ctz=Europe/London&details=Join%20us%20to%20celebrate%20with%20lots%20of%20games%20and%20cake!&location=Apartments,%20London&sprop=&sprop=name:
|
31
|
+
calendar_url = "https://www.google.com/calendar/render?action=TEMPLATE"
|
32
|
+
params = {}
|
33
|
+
params[:text] = url_encode(title)
|
34
|
+
if end_datetime
|
35
|
+
params[:dates] = "#{format_date(start_datetime)}/#{format_date(end_datetime)}"
|
36
|
+
else
|
37
|
+
params[:dates] = "#{format_date(start_datetime)}/#{format_date(start_datetime + 60*60)}" # end time is 1 hour later
|
38
|
+
end
|
39
|
+
params[:ctz] = timezone.identifier
|
40
|
+
params[:location] = url_encode(location) if location
|
41
|
+
params[:details] = url_encode(description) if description
|
42
|
+
if add_url_to_description && url
|
43
|
+
if params[:details]
|
44
|
+
params[:details] << url_encode("\n\n#{url}")
|
45
|
+
else
|
46
|
+
params[:details] = url_encode(url)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
params.each do |key, value|
|
51
|
+
calendar_url << "&#{key}=#{value}"
|
52
|
+
end
|
53
|
+
|
54
|
+
return calendar_url
|
55
|
+
end
|
56
|
+
|
57
|
+
# def office_365_url
|
58
|
+
|
59
|
+
# end
|
60
|
+
|
61
|
+
def yahoo_url
|
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
|
63
|
+
calendar_url = "https://calendar.yahoo.com/?v=60&view=d&type=20"
|
64
|
+
params = {}
|
65
|
+
params[:title] = url_encode(title)
|
66
|
+
params[:st] = utc_datetime(start_datetime)
|
67
|
+
if end_datetime
|
68
|
+
seconds = duration_seconds(start_datetime, end_datetime)
|
69
|
+
params[:dur] = seconds_to_hours_minutes(seconds)
|
70
|
+
else
|
71
|
+
params[:dur] = "0100"
|
72
|
+
end
|
73
|
+
params[:desc] = url_encode(description) if description
|
74
|
+
if add_url_to_description && url
|
75
|
+
if params[:desc]
|
76
|
+
params[:desc] << url_encode("\n\n#{url}")
|
77
|
+
else
|
78
|
+
params[:desc] = url_encode(url)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
params[:in_loc] = url_encode(location) if location
|
82
|
+
|
83
|
+
params.each do |key, value|
|
84
|
+
calendar_url << "&#{key}=#{value}"
|
85
|
+
end
|
86
|
+
|
87
|
+
return calendar_url
|
88
|
+
end
|
89
|
+
|
90
|
+
def ical_url
|
91
|
+
# Downloads a *.ics file provided as a data:text href
|
92
|
+
# Eg. data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20200610T123000Z%0ADTEND=20200610T133000Z%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%2C%20The%20Edge%2C%2038%20Smith-Dorrien%20St%2C%20London%2C%20N1%207GU%0AUID=-https%3A%2F%2Fwww.example.com%2Fevent-details%0AEND:VEVENT%0AEND:VCALENDAR
|
93
|
+
calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
|
94
|
+
params = {}
|
95
|
+
params[:DTSTART] = utc_datetime(start_datetime)
|
96
|
+
if end_datetime
|
97
|
+
params[:DTEND] = utc_datetime(end_datetime)
|
98
|
+
else
|
99
|
+
params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
|
100
|
+
end
|
101
|
+
params[:SUMMARY] = url_encode(title)
|
102
|
+
params[:URL] = url_encode(url) if url
|
103
|
+
params[:DESCRIPTION] = url_encode(description) if description
|
104
|
+
if add_url_to_description && url
|
105
|
+
if params[:DESCRIPTION]
|
106
|
+
params[:DESCRIPTION] << "\n\n#{url_encode(url)}"
|
107
|
+
else
|
108
|
+
params[:DESCRIPTION] = url_encode(url)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
params[:LOCATION] = url_encode(location) if location
|
112
|
+
params[:UID] = "-#{url_encode(url)}" if url
|
113
|
+
params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode(title)}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
|
114
|
+
|
115
|
+
new_line = "%0A"
|
116
|
+
params.each do |key, value|
|
117
|
+
calendar_url << "#{new_line}#{key}=#{value}"
|
118
|
+
end
|
119
|
+
|
120
|
+
calendar_url << "%0AEND:VEVENT%0AEND:VCALENDAR"
|
121
|
+
|
122
|
+
return calendar_url
|
123
|
+
end
|
124
|
+
|
125
|
+
def apple_url
|
126
|
+
ical_url
|
127
|
+
end
|
128
|
+
|
129
|
+
def outlook_url
|
130
|
+
ical_url
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
def validate_attributes
|
135
|
+
# msg = "- Object must be a DateTime or Time object."
|
136
|
+
msg = "- Object must be a Time object."
|
137
|
+
raise(ArgumentError, ":start_datetime #{msg} #{start_datetime.class} given") unless start_datetime.kind_of? Time
|
138
|
+
if end_datetime
|
139
|
+
raise(ArgumentError, ":end_datetime #{msg} #{end_datetime.class} given") unless end_datetime.kind_of? Time
|
140
|
+
raise(ArgumentError, ":end_datetime must be greater than :start_datetime") unless end_datetime > start_datetime
|
141
|
+
end
|
142
|
+
|
143
|
+
raise(ArgumentError, ":title must be a string") unless self.title.kind_of? String
|
144
|
+
raise(ArgumentError, ":title must not be blank") if self.title.strip.empty? # strip first, otherwise " ".empty? #=> false
|
145
|
+
|
146
|
+
if location
|
147
|
+
raise(ArgumentError, ":location must be a string") unless self.location.kind_of? String
|
148
|
+
end
|
149
|
+
|
150
|
+
if description
|
151
|
+
raise(ArgumentError, ":description must be a string") unless self.description.kind_of? String
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def utc_datetime(datetime)
|
156
|
+
t = timezone.local_time(
|
157
|
+
datetime.strftime("%Y").to_i,
|
158
|
+
datetime.strftime("%m").to_i,
|
159
|
+
datetime.strftime("%d").to_i,
|
160
|
+
datetime.strftime("%H").to_i,
|
161
|
+
datetime.strftime("%M").to_i,
|
162
|
+
datetime.strftime("%S").to_i
|
163
|
+
).utc
|
164
|
+
|
165
|
+
formatted = t.strftime('%Y%m%dT%H%M%SZ')
|
166
|
+
end
|
167
|
+
|
168
|
+
# Google Calendar format (rename method?)
|
169
|
+
def format_date(start_datetime)
|
170
|
+
start_datetime.strftime('%Y%m%dT%H%M%S')
|
171
|
+
end
|
172
|
+
|
173
|
+
def duration_seconds(start_time, end_time)
|
174
|
+
(start_time.to_i - end_time.to_i).abs
|
175
|
+
end
|
176
|
+
|
177
|
+
def seconds_to_hours_minutes(sec)
|
178
|
+
"%02d%02d" % [sec / 3600, sec / 60 % 60]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: add_to_calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Turner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tzinfo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tzinfo-data
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2020.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2020.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 12.3.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 12.3.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.13.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.13.1
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- jaredlt01@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- add_to_calendar.gemspec
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/add_to_calendar.rb
|
115
|
+
- lib/add_to_calendar/version.rb
|
116
|
+
homepage: https://github.com/jaredlt/add_to_calendar
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata:
|
120
|
+
homepage_uri: https://github.com/jaredlt/add_to_calendar
|
121
|
+
source_code_uri: https://github.com/jaredlt/add_to_calendar
|
122
|
+
changelog_uri: https://github.com/jaredlt/add_to_calendar
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.0.6
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Generate 'Add To Calendar' URLs for Google, Apple, Office 365, Outlook, Yahoo
|
142
|
+
calendars
|
143
|
+
test_files: []
|