gcal-ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,2 @@
1
+ v0.1.1 added calendar events
1
2
  v0.1.0 first release
data/Manifest CHANGED
@@ -7,3 +7,4 @@ init.rb
7
7
  lib/gcal.rb
8
8
  lib/gcal/calendar.rb
9
9
  lib/gcal/client.rb
10
+ lib/gcal/event.rb
data/README.rdoc CHANGED
@@ -6,4 +6,5 @@
6
6
 
7
7
  client = GCal::Client.new(api_key, api_secret, oauth_token, oauth_secret)
8
8
  client.all_calendars # returns all user calendars
9
- client.all_calendars # returns user owned calendars
9
+ client.own_calendars # returns user owned calendars
10
+ client.events(calendar.id) # returns events in calendar
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.0') do |p|
6
+ Echoe.new('gcal-ruby', '0.1.1') 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,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gcal-ruby}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
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
9
  s.date = %q{2011-10-05}
10
10
  s.description = %q{Ruby library for Google Calendar API.}
11
11
  s.email = %q{gvalmon@gmail.com}
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}]
13
- s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{init.rb}, %q{lib/gcal.rb}, %q{lib/gcal/calendar.rb}, %q{lib/gcal/client.rb}, %q{gcal-ruby.gemspec}]
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}]
13
+ s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{init.rb}, %q{lib/gcal.rb}, %q{lib/gcal/calendar.rb}, %q{lib/gcal/client.rb}, %q{lib/gcal/event.rb}, %q{gcal-ruby.gemspec}]
14
14
  s.homepage = %q{http://github.com/23ninja/gcal-ruby}
15
15
  s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Gcal-ruby}, %q{--main}, %q{README.rdoc}]
16
16
  s.require_paths = [%q{lib}]
data/lib/gcal/calendar.rb CHANGED
@@ -1,5 +1,19 @@
1
1
  module GCal
2
2
  class Calendar
3
- attr_accessor :id, :title
3
+ attr_accessor :id, :title, :link, :author_name, :author_email,
4
+ :access_level, :color, :hidden, :selected, :timezone,
5
+ :updated_at, :published_at
6
+
7
+ def hidden?
8
+ hidden
9
+ end
10
+
11
+ def visible
12
+ !hidden?
13
+ end
14
+
15
+ def selected?
16
+ selected
17
+ end
4
18
  end
5
19
  end
data/lib/gcal/client.rb CHANGED
@@ -4,7 +4,7 @@ require 'xmlsimple'
4
4
  module GCal
5
5
  class Client
6
6
  BASE_URL = 'https://www.google.com'
7
- API_URL = "#{BASE_URL}/calendar/feeds/default"
7
+ API_URL = "#{BASE_URL}/calendar/feeds"
8
8
 
9
9
  def initialize(api_key = nil, api_secret = nil, token = nil, secret = nil)
10
10
  @api_key, @api_secret = api_key, api_secret
@@ -25,30 +25,82 @@ module GCal
25
25
  end
26
26
 
27
27
  def all_calendars
28
- xml = call("/allcalendars/full")
28
+ xml = call("/default/allcalendars/full")
29
29
  calendars = []
30
30
  xml['entry'].each do |entry|
31
- calendar = GCal::Calendar.new
32
- calendar.id = entry['id'][0]
33
- calendar.title = entry['title'][0]['content']
34
- calendars << calendar
31
+ calendars << parse_calendar(entry)
35
32
  end if xml['entry']
36
33
  calendars
37
34
  end
38
35
 
39
36
  def own_calendars
40
- xml = call("/owncalendars/full")
37
+ xml = call("/default/owncalendars/full")
41
38
  calendars = []
42
39
  xml['entry'].each do |entry|
43
- calendar = GCal::Calendar.new
44
- calendar.id = entry['id'][0]
45
- calendar.title = entry['title'][0]['content']
46
- calendars << calendar
40
+ calendars << parse_calendar(entry)
47
41
  end if xml['entry']
48
42
  calendars
49
43
  end
50
44
 
45
+ def events(calendar_id)
46
+ xml = call("/#{calendar_id}/private/full")
47
+ events = []
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
71
+ end if xml['entry']
72
+ events
73
+ end
74
+
51
75
  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
+
52
104
  def protected_api_call?
53
105
  !@api_key.nil?
54
106
  end
data/lib/gcal/event.rb ADDED
@@ -0,0 +1,11 @@
1
+ module GCal
2
+ class Event
3
+ STATUS_REGEXP = /http\:\/\/schemas\.google\.com\/g\/[0-9]+\#event\./
4
+ attr_accessor :id, :title, :link, :author_name, :author_email,
5
+ :updated_at, :published_at, :status, :where, :who, :start_time, :end_time
6
+
7
+ def confirmed?
8
+ status == 'confirmed'
9
+ end
10
+ end
11
+ end
data/lib/gcal.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module GCal
2
2
  require 'gcal/client'
3
3
  require 'gcal/calendar'
4
+ require 'gcal/event'
4
5
  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.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &2153447540 !ruby/object:Gem::Requirement
16
+ requirement: &2165484340 !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: *2153447540
24
+ version_requirements: *2165484340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: typhoeus
27
- requirement: &2153446140 !ruby/object:Gem::Requirement
27
+ requirement: &2165483340 !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: *2153446140
35
+ version_requirements: *2165483340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: xml-simple
38
- requirement: &2153445040 !ruby/object:Gem::Requirement
38
+ requirement: &2165482160 !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: *2153445040
46
+ version_requirements: *2165482160
47
47
  description: Ruby library for Google Calendar API.
48
48
  email: gvalmon@gmail.com
49
49
  executables: []
@@ -55,6 +55,7 @@ extra_rdoc_files:
55
55
  - lib/gcal.rb
56
56
  - lib/gcal/calendar.rb
57
57
  - lib/gcal/client.rb
58
+ - lib/gcal/event.rb
58
59
  files:
59
60
  - CHANGELOG
60
61
  - LICENSE
@@ -65,6 +66,7 @@ files:
65
66
  - lib/gcal.rb
66
67
  - lib/gcal/calendar.rb
67
68
  - lib/gcal/client.rb
69
+ - lib/gcal/event.rb
68
70
  - gcal-ruby.gemspec
69
71
  homepage: http://github.com/23ninja/gcal-ruby
70
72
  licenses: []