gcal-ruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,3 @@
1
+ v0.1.2 added options for events list
1
2
  v0.1.1 added calendar events
2
3
  v0.1.0 first release
data/README.rdoc CHANGED
@@ -7,4 +7,7 @@
7
7
  client = GCal::Client.new(api_key, api_secret, oauth_token, oauth_secret)
8
8
  client.all_calendars # returns all user calendars
9
9
  client.own_calendars # returns user owned calendars
10
- client.events(calendar.id) # returns events in calendar
10
+ client.events(calendar.id) # returns events in calendar
11
+
12
+ # retrieving events with options
13
+ client.events(calendar.id, :start_time => 1.month.ago, :timezone => 'Europe/Moscow')
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('gcal-ruby', '0.1.1') do |p|
6
+ Echoe.new('gcal-ruby', '0.1.2') do |p|
7
7
  p.description = "Ruby library for Google Calendar API."
8
8
  p.url = "http://github.com/23ninja/gcal-ruby"
9
9
  p.author = "Iskander Haziev"
data/gcal-ruby.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gcal-ruby}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [%q{Iskander Haziev}]
9
- s.date = %q{2011-10-05}
9
+ s.date = %q{2011-10-06}
10
10
  s.description = %q{Ruby library for Google Calendar API.}
11
11
  s.email = %q{gvalmon@gmail.com}
12
12
  s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.rdoc}, %q{lib/gcal.rb}, %q{lib/gcal/calendar.rb}, %q{lib/gcal/client.rb}, %q{lib/gcal/event.rb}]
data/lib/gcal/calendar.rb CHANGED
@@ -15,5 +15,32 @@ module GCal
15
15
  def selected?
16
16
  selected
17
17
  end
18
+
19
+ class << self
20
+ def parse(entry)
21
+ parse_time = Time.respond_to?(:parse)
22
+ calendar = self.new
23
+
24
+ # common info
25
+ calendar.id = entry['id'][0].gsub('http://www.google.com/calendar/feeds/default/allcalendars/full/', '')
26
+ calendar.title = entry['title'][0]['content']
27
+ calendar.link = entry['link'][0]['href']
28
+ calendar.access_level = entry['accesslevel'][0]['value']
29
+ calendar.color = entry['color'][0]['value']
30
+ calendar.hidden = entry['hidden'][0]['value'] == 'true'
31
+ calendar.selected = entry['selected'][0]['value'] == 'true'
32
+
33
+ # time info
34
+ calendar.timezone = entry['timezone'][0]['value']
35
+ calendar.updated_at = parse_time ? Time.parse(entry['updated'][0]) : entry['updated'][0]
36
+ calendar.published_at = parse_time ? Time.parse(entry['published'][0]) : entry['published'][0]
37
+
38
+ # author
39
+ author = entry['author'][0]
40
+ calendar.author_name = author['name'] ? author['name'][0] : ''
41
+ calendar.author_email = author['email'] ? author['email'][0] : ''
42
+ calendar
43
+ end
44
+ end
18
45
  end
19
46
  end
data/lib/gcal/client.rb CHANGED
@@ -28,7 +28,7 @@ module GCal
28
28
  xml = call("/default/allcalendars/full")
29
29
  calendars = []
30
30
  xml['entry'].each do |entry|
31
- calendars << parse_calendar(entry)
31
+ calendars << GCal::Calendar.parse(entry)
32
32
  end if xml['entry']
33
33
  calendars
34
34
  end
@@ -37,69 +37,21 @@ module GCal
37
37
  xml = call("/default/owncalendars/full")
38
38
  calendars = []
39
39
  xml['entry'].each do |entry|
40
- calendars << parse_calendar(entry)
40
+ calendars << GCal::Calendar.parse(entry)
41
41
  end if xml['entry']
42
42
  calendars
43
43
  end
44
44
 
45
- def events(calendar_id)
46
- xml = call("/#{calendar_id}/private/full")
45
+ def events(calendar_id, options = {})
46
+ xml = call("/#{calendar_id}/private/full#{GCal::Event.prepare_options(options)}")
47
47
  events = []
48
48
  xml['entry'].each do |entry|
49
- event = GCal::Event.new
50
-
51
- # common info
52
- event.id = entry['id'][0].gsub("http://www.google.com/calendar/feeds/#{calendar_id}/private/full/", '')
53
- event.title = entry['title'][0]['content']
54
- event.link = entry['link'][0]['href']
55
- event.status = entry['eventStatus'][0]['value'].gsub(Event::STATUS_REGEXP, '')
56
- event.where = entry['where'][0]['valueString']
57
- event.who = entry['who'][0]['valueString']
58
-
59
- # time info
60
- time = entry['when'][0]
61
- event.start_time = parse_time? ? Time.parse(time['startTime']) : time['startTime']
62
- event.end_time = parse_time? ? Time.parse(time['endTime']) : time['endTime']
63
- event.updated_at = parse_time? ? Time.parse(entry['updated'][0]) : entry['updated'][0]
64
- event.published_at = parse_time? ? Time.parse(entry['published'][0]) : entry['published'][0]
65
-
66
- # author
67
- author = entry['author'][0]
68
- event.author_name = author['name'] ? author['name'][0] : ''
69
- event.author_email = author['email'] ? author['email'][0] : ''
70
- events << event
49
+ events << GCal::Event.parse(calendar_id, entry)
71
50
  end if xml['entry']
72
51
  events
73
52
  end
74
53
 
75
54
  protected
76
- def parse_calendar(entry)
77
- calendar = GCal::Calendar.new
78
-
79
- # common info
80
- calendar.id = entry['id'][0].gsub('http://www.google.com/calendar/feeds/default/allcalendars/full/', '')
81
- calendar.title = entry['title'][0]['content']
82
- calendar.link = entry['link'][0]['href']
83
- calendar.access_level = entry['accesslevel'][0]['value']
84
- calendar.color = entry['color'][0]['value']
85
- calendar.hidden = entry['hidden'][0]['value'] == 'true'
86
- calendar.selected = entry['selected'][0]['value'] == 'true'
87
-
88
- # time info
89
- calendar.timezone = entry['timezone'][0]['value']
90
- calendar.updated_at = parse_time? ? Time.parse(entry['updated'][0]) : entry['updated'][0]
91
- calendar.published_at = parse_time? ? Time.parse(entry['published'][0]) : entry['published'][0]
92
-
93
- # author
94
- author = entry['author'][0]
95
- calendar.author_name = author['name'] ? author['name'][0] : ''
96
- calendar.author_email = author['email'] ? author['email'][0] : ''
97
- calendar
98
- end
99
-
100
- def parse_time?
101
- Time.respond_to?(:parse)
102
- end
103
55
 
104
56
  def protected_api_call?
105
57
  !@api_key.nil?
data/lib/gcal/event.rb CHANGED
@@ -7,5 +7,52 @@ module GCal
7
7
  def confirmed?
8
8
  status == 'confirmed'
9
9
  end
10
+
11
+ class << self
12
+ def parse(calendar_id, entry)
13
+ parse_time = Time.respond_to?(:parse)
14
+ event = self.new
15
+
16
+ # common info
17
+ event.id = entry['id'][0].gsub("http://www.google.com/calendar/feeds/#{calendar_id}/private/full/", '')
18
+ event.title = entry['title'][0]['content']
19
+ event.link = entry['link'][0]['href']
20
+ event.status = entry['eventStatus'][0]['value'].gsub(Event::STATUS_REGEXP, '')
21
+ event.where = entry['where'][0]['valueString']
22
+ event.who = entry['who'][0]['valueString']
23
+
24
+ # time info
25
+ time = entry['when'][0]
26
+ event.start_time = parse_time ? Time.parse(time['startTime']) : time['startTime']
27
+ event.end_time = parse_time ? Time.parse(time['endTime']) : time['endTime']
28
+ event.updated_at = parse_time ? Time.parse(entry['updated'][0]) : entry['updated'][0]
29
+ event.published_at = parse_time ? Time.parse(entry['published'][0]) : entry['published'][0]
30
+
31
+ # author
32
+ author = entry['author'][0]
33
+ event.author_name = author['name'] ? author['name'][0] : ''
34
+ event.author_email = author['email'] ? author['email'][0] : ''
35
+ event
36
+ end
37
+
38
+ def prepare_options(options)
39
+ options.symbolize_keys! if Hash.respond_to?(:symbolize_keys!)
40
+ prepared_options = {}
41
+ if options[:start_time]
42
+ prepared_options['start-min'] = options[:start_time].strftime("%Y-%m-%dT%H:%M:%S")
43
+ end
44
+ if options[:end_time]
45
+ prepared_options['start-max'] = options[:end_time].strftime("%Y-%m-%dT%H:%M:%S")
46
+ end
47
+ if options[:timezone]
48
+ prepared_options['ctz'] = options[:timezone].gsub(' ', '_')
49
+ end
50
+ if prepared_options.size > 0
51
+ "?" + prepared_options.map{|k, v| "#{k}=#{v}" }.join('&')
52
+ else
53
+ ''
54
+ end
55
+ end
56
+ end
10
57
  end
11
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcal-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-05 00:00:00.000000000Z
12
+ date: 2011-10-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &2165484340 !ruby/object:Gem::Requirement
16
+ requirement: &2165531020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2165484340
24
+ version_requirements: *2165531020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: typhoeus
27
- requirement: &2165483340 !ruby/object:Gem::Requirement
27
+ requirement: &2165530020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2165483340
35
+ version_requirements: *2165530020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: xml-simple
38
- requirement: &2165482160 !ruby/object:Gem::Requirement
38
+ requirement: &2165528780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2165482160
46
+ version_requirements: *2165528780
47
47
  description: Ruby library for Google Calendar API.
48
48
  email: gvalmon@gmail.com
49
49
  executables: []