ical2gcal 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,7 +6,8 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  gem 'ri_cal'
9
- gem 'gcal4ruby'
9
+ gem 'gcalapi'
10
+ gem 'simple-rss'
10
11
  gem 'pit'
11
12
 
12
13
  group :development do
data/README.rdoc CHANGED
@@ -5,28 +5,28 @@ sync ics(es) to google calendar
5
5
  == Benefits
6
6
 
7
7
  * Solve the PROBLEM that Android's calendar program cannot reference webcal !
8
- * Complete sync calendar from .ics to google calendar ( also deleting )
8
+ * Complete sync calendar from .ics to google calendar ( also deleting events )
9
9
 
10
10
  == Requirements
11
11
 
12
12
  * PC :-)
13
13
  * Ruby ( tested with CRuby 1.8.7 )
14
- * RiCal
15
- * GCal4ruby
16
- * Pit
17
- * Googlecl ( made with Python )
14
+ * ri_cal http://ri-cal.rubyforge.org/
15
+ * gcalapi http://gcalapi.rubyforge.org/
16
+ * simple-rss http://simple-rss.rubyforge.org/
17
+ * pit http://coderepos.org/share/browser/lang/ruby/pit
18
18
 
19
19
  == How to use
20
20
 
21
- 1. Install Ruby and gems.
22
- 2. Install Googlecl from http://code.google.com/p/googlecl/
21
+ 1. Install Ruby
22
+ 2. `gem install ical2gcal`
23
23
  3. Setup Your Google account info using Pit
24
24
  4. Prepare calendar that you like to import to
25
- 5. Here we go !
25
+ 5. type `ical2gcal --help`
26
26
 
27
27
  == How to config pit
28
28
 
29
- 1. SET ENVIRONMENT VARIABLE **EDITOR**
29
+ 1. SET ENVIRONMENT VARIABLE *EDITOR*
30
30
  2. type
31
31
 
32
32
  pit set google
@@ -35,7 +35,7 @@ ex)
35
35
 
36
36
  username: `google account'
37
37
  password: PASSWORD
38
- calendar:
38
+ calendar: ( optional below )
39
39
  name: `calendar name above'
40
40
 
41
41
  == Contributing to ical2gcal
data/Rakefile CHANGED
@@ -26,7 +26,8 @@ Jeweler::Tasks.new do |gem|
26
26
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
27
27
 
28
28
  gem.add_runtime_dependency 'ri_cal'
29
- gem.add_runtime_dependency 'gcal4ruby'
29
+ gem.add_runtime_dependency 'gcalapi'
30
+ gem.add_runtime_dependency 'simple-rss'
30
31
  gem.add_runtime_dependency 'pit'
31
32
 
32
33
  # gem.add_development_dependency 'rspec', '> 1.2.3'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
data/ical2gcal.gemspec CHANGED
@@ -5,12 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ical2gcal}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["wtnabe"]
12
- s.date = %q{2011-04-28}
13
- s.default_executable = %q{ical2gcal}
12
+ s.date = %q{2011-04-30}
14
13
  s.description = %q{You can sync local and remote ics file(s) to google calendar}
15
14
  s.email = %q{wtnabe@gmail.com}
16
15
  s.executables = ["ical2gcal"]
@@ -28,7 +27,7 @@ Gem::Specification.new do |s|
28
27
  "VERSION",
29
28
  "bin/ical2gcal",
30
29
  "ical2gcal.gemspec",
31
- "lib/google_calendar.rb",
30
+ "lib/google.rb",
32
31
  "lib/ical2gcal.rb",
33
32
  "lib/ics.rb",
34
33
  "lib/ics/events.rb",
@@ -42,7 +41,7 @@ Gem::Specification.new do |s|
42
41
  s.homepage = %q{http://github.com/wtnabe/ical2gcal}
43
42
  s.licenses = ["two-clause BSD"]
44
43
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.5.0}
44
+ s.rubygems_version = %q{1.7.2}
46
45
  s.summary = %q{sync ics(es) to google calendar}
47
46
  s.test_files = [
48
47
  "spec/ics/events_spec.rb",
@@ -55,37 +54,43 @@ Gem::Specification.new do |s|
55
54
 
56
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
56
  s.add_runtime_dependency(%q<ri_cal>, [">= 0"])
58
- s.add_runtime_dependency(%q<gcal4ruby>, [">= 0"])
57
+ s.add_runtime_dependency(%q<gcalapi>, [">= 0"])
58
+ s.add_runtime_dependency(%q<simple-rss>, [">= 0"])
59
59
  s.add_runtime_dependency(%q<pit>, [">= 0"])
60
60
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
61
61
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
62
62
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
63
63
  s.add_development_dependency(%q<rcov>, [">= 0"])
64
64
  s.add_runtime_dependency(%q<ri_cal>, [">= 0"])
65
- s.add_runtime_dependency(%q<gcal4ruby>, [">= 0"])
65
+ s.add_runtime_dependency(%q<gcalapi>, [">= 0"])
66
+ s.add_runtime_dependency(%q<simple-rss>, [">= 0"])
66
67
  s.add_runtime_dependency(%q<pit>, [">= 0"])
67
68
  else
68
69
  s.add_dependency(%q<ri_cal>, [">= 0"])
69
- s.add_dependency(%q<gcal4ruby>, [">= 0"])
70
+ s.add_dependency(%q<gcalapi>, [">= 0"])
71
+ s.add_dependency(%q<simple-rss>, [">= 0"])
70
72
  s.add_dependency(%q<pit>, [">= 0"])
71
73
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
72
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
75
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
74
76
  s.add_dependency(%q<rcov>, [">= 0"])
75
77
  s.add_dependency(%q<ri_cal>, [">= 0"])
76
- s.add_dependency(%q<gcal4ruby>, [">= 0"])
78
+ s.add_dependency(%q<gcalapi>, [">= 0"])
79
+ s.add_dependency(%q<simple-rss>, [">= 0"])
77
80
  s.add_dependency(%q<pit>, [">= 0"])
78
81
  end
79
82
  else
80
83
  s.add_dependency(%q<ri_cal>, [">= 0"])
81
- s.add_dependency(%q<gcal4ruby>, [">= 0"])
84
+ s.add_dependency(%q<gcalapi>, [">= 0"])
85
+ s.add_dependency(%q<simple-rss>, [">= 0"])
82
86
  s.add_dependency(%q<pit>, [">= 0"])
83
87
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
84
88
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
85
89
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
86
90
  s.add_dependency(%q<rcov>, [">= 0"])
87
91
  s.add_dependency(%q<ri_cal>, [">= 0"])
88
- s.add_dependency(%q<gcal4ruby>, [">= 0"])
92
+ s.add_dependency(%q<gcalapi>, [">= 0"])
93
+ s.add_dependency(%q<simple-rss>, [">= 0"])
89
94
  s.add_dependency(%q<pit>, [">= 0"])
90
95
  end
91
96
  end
data/lib/google.rb ADDED
@@ -0,0 +1,81 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+ require 'gcalapi'
4
+ require 'simple-rss'
5
+
6
+ module Ical2gcal
7
+ class Google
8
+
9
+ def initialize( opts )
10
+ @service = nil
11
+ @opts = {
12
+ 'username' => nil,
13
+ 'password' => nil,
14
+ 'calendar' => nil
15
+ }.merge( opts )
16
+ @calendar = nil
17
+ @events = nil
18
+ end
19
+
20
+ #
21
+ # [return] GoogleCalendar::Service
22
+ #
23
+ def service
24
+ if ( !@service and @opts )
25
+ @service = GoogleCalendar::Service.new( @opts['username'],
26
+ @opts['password'] )
27
+ end
28
+
29
+ @service
30
+ end
31
+
32
+ #
33
+ # [return] Array
34
+ #
35
+ def calendars
36
+ SimpleRSS.parse( service.calendars.body ).entries
37
+ end
38
+
39
+ #
40
+ # [return] GoogleCalendar::Calendar
41
+ #
42
+ def calendar
43
+ if ( !@calendar )
44
+ cal = calendars.find { |c|
45
+ c.title == calendar_name
46
+ }
47
+ @calendar = GoogleCalendar::Calendar.new( @service, cal[:link] )
48
+ end
49
+
50
+ @calendar
51
+ end
52
+
53
+ #
54
+ # [return] String
55
+ #
56
+ def calendar_name
57
+ @opts['calendar']['name']
58
+ end
59
+
60
+ def create_event( event )
61
+ e = calendar.create_event
62
+ e.title = event.summary
63
+ e.desc = event.description
64
+ e.where = event.location
65
+ e.st = Time.parse(event.start_time.to_s.sub(/\+.*/, ''))
66
+ e.allday = e.st.hour == 0 and e.st.min == 0 and not event.respond_to? :end_time
67
+ e.en = if event.respond_to? :end_time
68
+ Time.parse(event.end_time.to_s.sub(/\+.*/, ''))
69
+ else
70
+ Time.parse(event.start_time.to_s.sub(/\+.*/, ''))
71
+ end
72
+ e.save!
73
+ end
74
+
75
+ def remove_all_events
76
+ calendar.events.each { |e|
77
+ e.destroy!
78
+ }
79
+ end
80
+ end
81
+ end
data/lib/ical2gcal.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems' unless defined? ::Gem
2
2
  require File.dirname( __FILE__ ) + '/ics'
3
- require File.dirname( __FILE__ ) + '/google_calendar'
3
+ require File.dirname( __FILE__ ) + '/google'
4
4
 
5
5
  require 'optparse'
6
6
  require 'pit'
@@ -19,19 +19,18 @@ module Ical2gcal
19
19
 
20
20
  opts = ::Pit.get('google')
21
21
  opts.merge!( {'calendar' => {'name' => @target}} ) if @target
22
- if ( Ical2gcal::GoogleCalendar.authenticated? )
23
- g = Ical2gcal::GoogleCalendar.new( opts )
24
- g.remove_all_events
25
- calendars.each { |c|
26
- Ical2gcal::Ics::Events.new( c ).each { |e|
27
- g.create_event( e )
28
- }
22
+ g = Ical2gcal::Google.new( opts )
23
+ g.remove_all_events
24
+ calendars.each { |c|
25
+ Ical2gcal::Ics::Events.new( c ).each { |e|
26
+ g.create_event( e )
29
27
  }
30
- else
31
- puts "Your `google' command is not authorized. Please type `google calendar list' and get auth."
32
- end
28
+ }
33
29
  end
34
30
 
31
+ #
32
+ # [return] Array
33
+ #
35
34
  def calendars
36
35
  if ( @ics )
37
36
  @calendars = @ics
@@ -44,6 +43,9 @@ module Ical2gcal
44
43
  @calendars
45
44
  end
46
45
 
46
+ #
47
+ # [return] OptionParser
48
+ #
47
49
  def opts
48
50
  OptionParser.new do |opt|
49
51
  opt.on( '-c', '--calendar-name NAME' ) { |c|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ical2gcal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - wtnabe
@@ -15,13 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-28 00:00:00 +09:00
19
- default_executable: ical2gcal
18
+ date: 2011-04-30 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
24
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
22
  none: false
26
23
  requirements:
27
24
  - - ">="
@@ -31,11 +28,11 @@ dependencies:
31
28
  - 0
32
29
  version: "0"
33
30
  name: ri_cal
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
31
  prerelease: false
37
32
  type: :runtime
38
- requirement: &id002 !ruby/object:Gem::Requirement
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
36
  none: false
40
37
  requirements:
41
38
  - - ">="
@@ -44,12 +41,26 @@ dependencies:
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
47
- name: gcal4ruby
48
- version_requirements: *id002
44
+ name: gcalapi
45
+ prerelease: false
46
+ type: :runtime
47
+ requirement: *id002
49
48
  - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: simple-rss
50
59
  prerelease: false
51
60
  type: :runtime
52
- requirement: &id003 !ruby/object:Gem::Requirement
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
53
64
  none: false
54
65
  requirements:
55
66
  - - ">="
@@ -59,11 +70,11 @@ dependencies:
59
70
  - 0
60
71
  version: "0"
61
72
  name: pit
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
73
  prerelease: false
65
- type: :development
66
- requirement: &id004 !ruby/object:Gem::Requirement
74
+ type: :runtime
75
+ requirement: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
67
78
  none: false
68
79
  requirements:
69
80
  - - ~>
@@ -75,11 +86,11 @@ dependencies:
75
86
  - 0
76
87
  version: 2.3.0
77
88
  name: rspec
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
89
  prerelease: false
81
90
  type: :development
82
- requirement: &id005 !ruby/object:Gem::Requirement
91
+ requirement: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ version_requirements: &id006 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ~>
@@ -91,11 +102,11 @@ dependencies:
91
102
  - 0
92
103
  version: 1.0.0
93
104
  name: bundler
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
105
  prerelease: false
97
106
  type: :development
98
- requirement: &id006 !ruby/object:Gem::Requirement
107
+ requirement: *id006
108
+ - !ruby/object:Gem::Dependency
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
99
110
  none: false
100
111
  requirements:
101
112
  - - ~>
@@ -107,11 +118,11 @@ dependencies:
107
118
  - 2
108
119
  version: 1.5.2
109
120
  name: jeweler
110
- version_requirements: *id006
111
- - !ruby/object:Gem::Dependency
112
121
  prerelease: false
113
122
  type: :development
114
- requirement: &id007 !ruby/object:Gem::Requirement
123
+ requirement: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
115
126
  none: false
116
127
  requirements:
117
128
  - - ">="
@@ -121,11 +132,11 @@ dependencies:
121
132
  - 0
122
133
  version: "0"
123
134
  name: rcov
124
- version_requirements: *id007
125
- - !ruby/object:Gem::Dependency
126
135
  prerelease: false
127
- type: :runtime
128
- requirement: &id008 !ruby/object:Gem::Requirement
136
+ type: :development
137
+ requirement: *id008
138
+ - !ruby/object:Gem::Dependency
139
+ version_requirements: &id009 !ruby/object:Gem::Requirement
129
140
  none: false
130
141
  requirements:
131
142
  - - ">="
@@ -135,11 +146,11 @@ dependencies:
135
146
  - 0
136
147
  version: "0"
137
148
  name: ri_cal
138
- version_requirements: *id008
139
- - !ruby/object:Gem::Dependency
140
149
  prerelease: false
141
150
  type: :runtime
142
- requirement: &id009 !ruby/object:Gem::Requirement
151
+ requirement: *id009
152
+ - !ruby/object:Gem::Dependency
153
+ version_requirements: &id010 !ruby/object:Gem::Requirement
143
154
  none: false
144
155
  requirements:
145
156
  - - ">="
@@ -148,12 +159,26 @@ dependencies:
148
159
  segments:
149
160
  - 0
150
161
  version: "0"
151
- name: gcal4ruby
152
- version_requirements: *id009
162
+ name: gcalapi
163
+ prerelease: false
164
+ type: :runtime
165
+ requirement: *id010
153
166
  - !ruby/object:Gem::Dependency
167
+ version_requirements: &id011 !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ name: simple-rss
154
177
  prerelease: false
155
178
  type: :runtime
156
- requirement: &id010 !ruby/object:Gem::Requirement
179
+ requirement: *id011
180
+ - !ruby/object:Gem::Dependency
181
+ version_requirements: &id012 !ruby/object:Gem::Requirement
157
182
  none: false
158
183
  requirements:
159
184
  - - ">="
@@ -163,7 +188,9 @@ dependencies:
163
188
  - 0
164
189
  version: "0"
165
190
  name: pit
166
- version_requirements: *id010
191
+ prerelease: false
192
+ type: :runtime
193
+ requirement: *id012
167
194
  description: You can sync local and remote ics file(s) to google calendar
168
195
  email: wtnabe@gmail.com
169
196
  executables:
@@ -183,7 +210,7 @@ files:
183
210
  - VERSION
184
211
  - bin/ical2gcal
185
212
  - ical2gcal.gemspec
186
- - lib/google_calendar.rb
213
+ - lib/google.rb
187
214
  - lib/ical2gcal.rb
188
215
  - lib/ics.rb
189
216
  - lib/ics/events.rb
@@ -193,7 +220,6 @@ files:
193
220
  - spec/spec_helper.rb
194
221
  - spec/support/ics_list.txt
195
222
  - spec/support/japanese_holidays.ics
196
- has_rdoc: true
197
223
  homepage: http://github.com/wtnabe/ical2gcal
198
224
  licenses:
199
225
  - two-clause BSD
@@ -223,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
249
  requirements: []
224
250
 
225
251
  rubyforge_project:
226
- rubygems_version: 1.5.0
252
+ rubygems_version: 1.7.2
227
253
  signing_key:
228
254
  specification_version: 3
229
255
  summary: sync ics(es) to google calendar
@@ -1,110 +0,0 @@
1
- # -*- mode: ruby; coding: utf-8 -*-
2
-
3
- require 'pty'
4
- require 'expect'
5
- require 'gcal4ruby'
6
-
7
- module Ical2gcal
8
- class GoogleCalendar
9
- include GCal4Ruby
10
-
11
- class GoogleclNotAuthenticated < StandardError; end
12
-
13
- def initialize( opts )
14
- @service = nil
15
- @opts = {
16
- 'username' => nil,
17
- 'password' => nil,
18
- 'calendar' => nil
19
- }.merge( opts )
20
- @calendar = nil
21
- @events = nil
22
- end
23
-
24
- def service
25
- if ( !@service and @opts )
26
- @service = Service.new
27
- @service.authenticate( @opts['username'], @opts['password'] )
28
- end
29
-
30
- @service
31
- end
32
-
33
- def calendar
34
- if ( !@calendar )
35
- @calendar = Calendar.find( service, :title => calendar_name ).first
36
- end
37
-
38
- @calendar
39
- end
40
-
41
- def calendar_name
42
- @opts['calendar']['name']
43
- end
44
-
45
- def create_event( event )
46
- begin
47
- e = Event.new( service )
48
- e.calendar = calendar
49
- e.title = event.summary
50
- e.start_time = Time.parse(event.start_time.to_s.sub(/\+.*/, ''))
51
- e.all_day = e.start_time.hour == 0 and e.start_time.min == 0 and not event.respond_to? :end_time
52
- e.end_time = if event.respond_to? :end_time
53
- Time.parse(event.end_time.to_s.sub(/\+.*/, ''))
54
- else
55
- Time.parse(event.start_time.to_s.sub(/\+.*/, ''))
56
- end
57
- e.save
58
- rescue
59
- ;
60
- end
61
- end
62
-
63
- def remove_all_events
64
- if ( events.size )
65
- PTY.spawn( "google calendar delete --cal '#{calendar_name}' --title '.*'" ) { |r, w|
66
- w.sync = true
67
-
68
- events.each { |e|
69
- r.expect( /Are you SURE.*\?.*\(y\/N\)/iu, 5 ) {
70
- w.puts 'y'
71
- }
72
- }
73
- }
74
- end
75
- end
76
-
77
- def events
78
- if ( !@events )
79
- @events = []
80
- list_below = false
81
-
82
- `google calendar list --cal '#{calendar_name}' --title '.*'`.lines.each { |line|
83
- if ( line.chomp == "[#{calendar_name}]" )
84
- list_below = true
85
- next
86
- end
87
- if ( list_below )
88
- @events << line.chomp
89
- end
90
- }
91
- end
92
-
93
- @events
94
- end
95
-
96
- def self.authenticated?
97
- begin
98
- PTY.spawn( 'google calendar list' ) { |r, w|
99
- r.expect( /(?:user|pass)/, 3 ) { |s|
100
- raise GoogleclNotAuthenticated if ( s and s[0] =~ /(?:user|pass)/ )
101
- }
102
- }
103
- rescue GoogleclNotAuthenticated
104
- false
105
- else
106
- true
107
- end
108
- end
109
- end
110
- end