concerto_calendar 0.0.8 → 0.0.9

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
  SHA1:
3
- metadata.gz: 6f6683b4f897e8fa6fa0999aa95ac77e68dd2ce1
4
- data.tar.gz: fe10b87be48822f02d725cf4baf283cfe57f8f68
3
+ metadata.gz: f27f79afdd123d8326d30877b9584096ae939940
4
+ data.tar.gz: b254c5dcb6429a10601d85d15e483f7dcba7baba
5
5
  SHA512:
6
- metadata.gz: e14a69cb8541b92799c72d37227c62ce2190b82ea880df223d5e62538a7d8f3057fde90af96931d9e9876171c564be8de7c71b0ece005c7d0af097f5ac2f1bca
7
- data.tar.gz: a928c6dbab3786c9fb901aadad9c7b246c45933f09b3f5262d0811f8b15f615f746c8e8cd6eb010725042aca3184f68d2e142a95eb8e41827360d3c7e61c2de8
6
+ metadata.gz: dabec14dac2742d42119d3ff44d34a3cb3c0dd340174c440004e78ceaa6ecb8acaf934f502c25bf3a64c0df5b3d1070ff0176ef1cd30f135bb66d40eb21fb7b1
7
+ data.tar.gz: 9eb2b0a119295a372549d2e8f320c5d20e6821bcbc06ad4ba20aa3e4731d20373363d8357f43355bae1a6c0220ebf8942b5b034d38ad0832a7ab32c628aa2475
@@ -49,6 +49,7 @@ class Calendar < DynamicContent
49
49
  self.config['day_format'] ||= '%A %b %e'
50
50
  self.config['time_format'] ||= '%l:%M %P'
51
51
  self.config['max_results'] ||= 10
52
+ self.config['days_ahead'] ||= 7
52
53
  end
53
54
 
54
55
  def build_content
@@ -90,67 +91,37 @@ class Calendar < DynamicContent
90
91
  calendar_id = self.config['calendar_id']
91
92
  calendar_source = self.config['calendar_source']
92
93
  start_date = self.config['start_date'].strip.empty? ? Clock.time.beginning_of_day.iso8601 : self.config['start_date'].to_time.beginning_of_day.iso8601
94
+ # end_date is not used by the google api, as the resulting behavior is unexpected
93
95
  end_date = self.config['end_date'].strip.empty? ? (start_date.to_time.beginning_of_day + self.config['days_ahead'].to_i.days).end_of_day.iso8601 : self.config['end_date'].to_time.beginning_of_day.iso8601
94
96
 
95
97
  case calendar_source
96
98
  when 'google'
97
99
  if !client_key.empty?
98
100
  # ---------------------------------- google calendar api v3 via client api
99
- require 'google/api_client'
101
+ require 'google/apis/calendar_v3'
100
102
 
101
- client = Google::APIClient.new
102
- client.authorization = nil
103
+ client = Google::Apis::CalendarV3::CalendarService.new
103
104
  client.key = client_key
104
105
 
105
- cal = client.discovered_api('calendar', 'v3')
106
-
107
- params = {}
108
- params['calendarId'] = calendar_id
109
- params['maxResults'] = self.config['max_results'] if !params['max_results'].blank?
110
- params['singleEvents'] = true
111
- params['orderBy'] = 'startTime'
112
- params['fields'] = "description,items(description,end,endTimeUnspecified,location,organizer/displayName,source/title,start,status,summary,updated),summary,timeZone,updated"
113
- params['timeMin'] = start_date
114
- params['timeMax'] = end_date
115
-
116
- tmp = client.execute(:api_method => cal.events.list, :parameters => params)
106
+ begin
107
+ tmp = client.list_events(calendar_id,
108
+ max_results: self.config['max_results'],
109
+ single_events: true,
110
+ order_by: 'startTime',
111
+ time_min: start_date)
117
112
 
118
113
  # convert to common data structure
119
- result.error_message = tmp.error_message if tmp.error?
120
- if !result.error?
121
- result.name = tmp.data.summary
122
- tmp.data.items.each do |item|
123
- result.add_item(item.summary, item.description, item.location, item.start.dateTime, item.end.dateTime)
124
- end
125
- end
126
- else
127
- # ---------------------------------- public calendar via plain http
128
- require 'net/http'
129
- url = "http://www.google.com/calendar/feeds/#{calendar_id}/public/full?alt=json"
130
- params = {}
131
- params['max-results'] = self.config['max_results'] if !params['max_results'].blank?
132
- params['singleevents'] = true
133
- params['orderby'] = 'starttime'
134
- params['start-min'] = start_date
135
- params['start-max'] = end_date
136
- url += params.collect { |k,v| "&#{k}=#{v}" }.join()
137
-
138
- tmp = nil
139
- begin
140
- json_data = Net::HTTP.get_response(URI.parse(url)).body
141
- tmp = JSON.load(json_data)
114
+ #result.error_message = tmp.error_message if tmp.error?
142
115
  rescue => e
143
- result.error_message = e.message
116
+ result.error_message = e.message
144
117
  end
145
-
146
- # convert to common data structure
147
118
  if !result.error?
148
- result.name = tmp["feed"]["title"]["$t"]
149
- tmp["feed"]["entry"].each do |item|
150
- location = item["gd$where"].first["valueString"]
151
- start_time = item["gd$when"].first["startTime"].to_time
152
- end_time = item["gd$when"].first["endTime"].to_time
153
- result.add_item(item["title"]["$t"], item["content"]["$t"], location, start_time, end_time)
119
+ result.name = tmp.summary
120
+ tmp.items.each do |item|
121
+ # All-day events aren't parsed as DateTime. Make it so.
122
+ starttime = item.start.date_time || Date.parse(item.start.date)
123
+ endtime = item.end.date_time || Date.parse(item.end.date)
124
+ result.add_item(item.summary, item.description, item.location, starttime, endtime)
154
125
  end
155
126
  end
156
127
  end
@@ -174,12 +145,23 @@ class Calendar < DynamicContent
174
145
  title = item.summary
175
146
  description = item.description
176
147
  location = item.location
177
- item_start_time = item.dtstart.to_time unless item.dtstart.nil?
178
- item_end_time = item.dtend.to_time unless item.dtend.nil?
148
+ # behave a little differently depending on whether or not our iCal has a timezone defined
149
+ # this behavior is somewhat lazy/sloppy in that we're assuming the existence of a defined timezone means
150
+ # that times are local ('correct'), whereas the absence of a timezone means the data is
151
+ # likely in UTC/Zulu time
152
+ if calendars.first.has_timezone?
153
+ item_start_time = item.dtstart.to_datetime unless item.dtstart.nil?
154
+ item_end_time = item.dtend.to_datetime unless item.dtend.nil?
155
+ else
156
+ item_start_time = Time.zone.parse(item.dtstart.to_s).to_datetime unless item.dtstart.nil?
157
+ item_end_time = Time.zone.parse(item.dtend.to_s).to_datetime unless item.dtend.nil?
158
+ end
159
+ item_end_time = nil if item_end_time == item_start_time
179
160
  # make sure the item's start date is within the specified range
180
161
  if item_start_time >= start_date && item_start_time < end_date
181
162
  result.add_item(title, description, location, item_start_time, item_end_time)
182
163
  end
164
+
183
165
  end
184
166
  result.items.sort! { |a, b| a.start_time <=> b.start_time }
185
167
  result.items = result.items[0..(max_results -1)]
@@ -200,7 +182,7 @@ class Calendar < DynamicContent
200
182
  html = []
201
183
  html << "<h1>#{item.name}</h1>"
202
184
  html << "<h2>#{item.start_time.strftime(day_format)}</h2>"
203
- html << (end_time.nil? ? "<div class=\"cal-time\">#{start_time}</div>" : "<div class=\"cal-time\">#{start_time} - #{end_time}</div>") unless start_time == end_time
185
+ html << (end_time.nil? || start_time == end_time ? "<div class=\"cal-time\">#{start_time}</div>" : "<div class=\"cal-time\">#{start_time} - #{end_time}</div>")
204
186
  html << "<div class=\"cal-location\">#{item.location}</div>"
205
187
  html << "<p>#{item.description}</p>"
206
188
  return html.join("")
@@ -225,7 +207,9 @@ class Calendar < DynamicContent
225
207
  start_time = item.start_time.strftime(time_format)
226
208
  end_time = item.end_time.strftime(time_format) unless item.end_time.nil?
227
209
 
228
- html << (end_time.nil? ? "<dt>#{start_time}</dt>" : "<dt>#{start_time} - #{end_time}</dt>") unless start_time == end_time
210
+ html << (end_time.nil? || start_time == end_time ? "<dt>#{start_time}</dt>" : "<dt>#{start_time} - #{end_time}</dt>")
211
+ # if the item we're evaluating isn't a DateTime, it's a full-day event
212
+ html << (item.start_time.is_a?(DateTime) ? "" : "<dt>Time N/A</dt>")
229
213
  html << "<dd>#{item.name}</dd>"
230
214
  last_date = item.start_time.to_date
231
215
  end
@@ -1,3 +1,3 @@
1
1
  module ConcertoCalendar
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerto_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marvin Frederickson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: google-api-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: icalendar
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.4.5
132
+ rubygems_version: 2.5.2
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Calendar Content for Concerto 2.