relevant-google-calendar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ GoogleCalendar widget for Relevant
@@ -0,0 +1,70 @@
1
+ require "relevant/widget"
2
+ require 'gcal4ruby'
3
+
4
+ module Relevant
5
+ class GoogleCalendar
6
+ Version = "0.0.1"
7
+ include Relevant::Widget
8
+
9
+ available_options :title => :string, :username => :string, :password => :password, :calendar => :string, :search => :string
10
+
11
+ refresh_every 10.minutes
12
+
13
+ template_format :haml
14
+ template %q[
15
+ %h2= options[:title].present? ? options[:title] : calendar.title
16
+ .google-calendar
17
+ - (Date.today..6.days.from_now.to_date).each do |date|
18
+ - events_for_day = events_happening_on(date)
19
+ - if events_for_day.any?
20
+ %h4
21
+ %span.day= date.day
22
+ = date.to_s(:long_ordinal)
23
+ %ul.google-calendar-events
24
+ - events_for_day.each do |event|
25
+ %li= event.title
26
+ :css
27
+ .google-calendar h4 {
28
+ padding-bottom: 0.3em;
29
+ border-bottom: 1px solid #454545;
30
+ }
31
+ .google-calendar span.day {
32
+ display: inline-block;
33
+ padding: 0.2em 0;
34
+ width: 1.5em;
35
+ color: #f0f0f0;
36
+ border: 2px solid #555;
37
+ border-top-width: 4px;
38
+ font-size: 1.3em;
39
+ font-weight: bold;
40
+ text-align: center
41
+ }
42
+ .google-calendar ul.google-calendar-events {
43
+ margin-left: 2em;
44
+ }
45
+ ]
46
+
47
+ def gcal
48
+ return @gcal if defined?(@gcal)
49
+
50
+ @gcal = GCal4Ruby::Service.new
51
+ @gcal.authenticate(options[:username], options[:password])
52
+ @gcal
53
+ end
54
+
55
+ def calendar
56
+ @calendar ||= GCal4Ruby::Calendar.find(gcal, :title => options[:calendar]).first
57
+ end
58
+
59
+ def events
60
+ event_options = {'calendar' => calendar.id, 'start-min' => Date.today.beginning_of_day.utc.xmlschema, 'start-max' => 6.days.from_now.end_of_day.utc.xmlschema}
61
+ @events ||= GCal4Ruby::Event.find(gcal, options[:search], event_options)
62
+ end
63
+
64
+ def events_happening_on(date)
65
+ events.select {|event| event.start_time.to_date <= date && (event.end_time - 1.minute).to_date >= date}
66
+ end
67
+ end
68
+ end
69
+
70
+ Relevant.register Relevant::GoogleCalendar
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Relevant::GoogleCalendar do
4
+
5
+ let(:widget) {Relevant::GoogleCalendar.setup(:username => 'foo', :password => 'bob', :calendar => 'My Calendar', :search => 'widget')}
6
+
7
+ before do
8
+ widget.stubs(:gcal).returns(stub('gcal'))
9
+ end
10
+
11
+ context '#calendar' do
12
+ it 'finds the calendar using the Google Api' do
13
+ GCal4Ruby::Calendar.expects(:find).with(widget.gcal, :title => 'My Calendar').returns([stub('calendar')])
14
+ widget.calendar
15
+ end
16
+ end
17
+
18
+ context '#events' do
19
+ it 'calls out to the Google Calendar api' do
20
+ widget.stubs(:calendar).returns(stub('calendar', :id => 123))
21
+ expected_options = {
22
+ 'calendar' => 123,
23
+ 'start-min' => Date.today.beginning_of_day.utc.xmlschema,
24
+ 'start-max' => 6.days.from_now.end_of_day.utc.xmlschema
25
+ }
26
+ GCal4Ruby::Event.expects(:find).with(widget.gcal, 'widget', expected_options).returns([])
27
+ widget.events
28
+ end
29
+ end
30
+
31
+ context '#events_happening_on' do
32
+ it 'returns all events happening on a given day' do
33
+ monday_event = stub('event', :start_time => Time.parse('27/09/2010'), :end_time => Time.parse('28/09/2010'))
34
+ wednesday_event = stub('event', :start_time => Time.parse('29/09/2010'), :end_time => Time.parse('30/09/2010'))
35
+ all_week_event = stub('event', :start_time => Time.parse('27/09/2010'), :end_time => Time.parse('02/10/2010'))
36
+ widget.stubs(:events).returns([monday_event, wednesday_event, all_week_event])
37
+
38
+ events = widget.events_happening_on(Date.parse('29/09/2010'))
39
+ events.should == [wednesday_event, all_week_event]
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+
3
+ $LOAD_PATH.unshift "../lib"
4
+ require "relevant/google_calendar"
5
+ require 'active_support/all'
6
+
7
+ RSpec.configure do |config|
8
+ config.color_enabled = true
9
+ config.mock_with :mocha
10
+
11
+ config.formatter = :progress
12
+ config.color_enabled = true
13
+ config.filter_run :focused => true
14
+ config.run_all_when_everything_filtered = true
15
+ config.alias_example_to :fit, :focused => true
16
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relevant-google-calendar
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jared Pace
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-29 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: relevant-widget
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 0
31
+ - 6
32
+ version: 0.0.6
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: gcal4ruby
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 5
46
+ - 5
47
+ version: 0.5.5
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 2
60
+ - 0
61
+ - 0
62
+ - beta
63
+ - 22
64
+ version: 2.0.0.beta.22
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: Show upcoming events
68
+ email: opensource@thinkrelevance.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - README.md
75
+ files:
76
+ - lib/relevant/google_calendar.rb
77
+ - spec/relevant/google_calendar_spec.rb
78
+ - spec/spec_helper.rb
79
+ - README.md
80
+ has_rdoc: true
81
+ homepage: http://github.com/relevance/relevant-google-calendar
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.7
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: GoogleCalendar widget for Relevant
112
+ test_files:
113
+ - spec/relevant/google_calendar_spec.rb
114
+ - spec/spec_helper.rb