gcal_button 1.0.0

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.
Files changed (2) hide show
  1. data/lib/gcal_button.rb +67 -0
  2. metadata +45 -0
@@ -0,0 +1,67 @@
1
+ require 'date'
2
+
3
+ class GcalButton
4
+ GCAL_TIME_FORMAT = "%Y%m%dT%H%M%SZ"
5
+ GCAL_DATE_FORMAT = "%Y%m%d"
6
+
7
+ BASE_URL = "http://www.google.com/calendar/event"
8
+ IMAGE_URLS = {
9
+ default: "http://www.google.com/calendar/images/ext/gc_button1.gif",
10
+ remind_me: "http://www.google.com/calendar/images/ext/gc_button2.gif",
11
+ add_to: "http://www.google.com/calendar/images/ext/gc_button6.gif",
12
+ large: "http://www.google.com/calendar/images/ext/gc_button6.gif"
13
+ }
14
+
15
+ def initialize(title, start_time, end_time, sprops={})
16
+ @title = title
17
+ @start_time = start_time
18
+ @end_time = end_time
19
+ @sprops = sprops
20
+ end
21
+
22
+ def url
23
+ "#{BASE_URL}?#{query_params}"
24
+ end
25
+
26
+ def image_url(type=:default)
27
+ IMAGE_URLS[type]
28
+ end
29
+
30
+ private
31
+ def sprops
32
+ @sprops.collect do |key,val|
33
+ ["sprop", "#{key}:#{val}"]
34
+ end
35
+ end
36
+
37
+ def dates
38
+ "#{formatted_time(@start_time)}/#{formatted_time(@end_time)}"
39
+ end
40
+
41
+ def formatted_time(time)
42
+ if time.class == Date
43
+ time.strftime(GCAL_DATE_FORMAT)
44
+ else
45
+ time.strftime(GCAL_TIME_FORMAT)
46
+ end
47
+ end
48
+
49
+ def query_params
50
+ params = {
51
+ action: "TEMPLATE",
52
+ dates: dates,
53
+ text: @title
54
+ }
55
+
56
+ params = params.to_a + sprops
57
+
58
+ params.collect do |key, value|
59
+ to_query(key, value)
60
+ end.sort * '&'
61
+ end
62
+
63
+ def to_query(key, value)
64
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
65
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gcal_button
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Anderson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-31 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Generate Google Calendar Button URLs
15
+ email: adamandersonis@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/gcal_button.rb
21
+ homepage: http://github.com/scudco/gcal_button
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.10
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Google Calendar Button
45
+ test_files: []