google_calendar 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+
29
+ # For MacOS:
30
+ #
31
+ .DS_Store
32
+
33
+
34
+ # For TextMate
35
+ *.tmproj
36
+ tmtags
37
+
38
+
39
+ # For emacs:
40
+ #*~
41
+ #\#*
42
+ #.\#*
43
+ #
44
+ # For vim:
45
+ #*.swp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ # uncomment this line if your project needs to run something other than `rake`:
7
+ # script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ gem "addressable", ">= 2.2.2"
7
7
  # Gem development dependencies.
8
8
  group :development do
9
9
  gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.1"
12
- gem "rcov", ">= 0"
10
+ gem "bundler", ">= 1.0.0"
13
11
  gem "mocha", ">= 0"
12
+ gem "rake", "> 10"
13
+ gem "rdoc", "> 3"
14
14
  end
data/Gemfile.lock CHANGED
@@ -1,27 +1,38 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.2.2)
5
- git (1.2.5)
6
- jeweler (1.5.1)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- mocha (0.9.10)
11
- rake
12
- nokogiri (1.4.4)
13
- rake (0.8.7)
14
- rcov (0.9.9)
15
- shoulda (2.11.3)
4
+ activesupport (3.2.12)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ addressable (2.3.2)
8
+ bourne (1.1.2)
9
+ mocha (= 0.10.5)
10
+ i18n (0.6.1)
11
+ json (1.7.7)
12
+ metaclass (0.0.1)
13
+ mocha (0.10.5)
14
+ metaclass (~> 0.0.1)
15
+ multi_json (1.6.1)
16
+ nokogiri (1.5.6)
17
+ rake (10.0.3)
18
+ rdoc (3.12.1)
19
+ json (~> 1.4)
20
+ shoulda (3.3.2)
21
+ shoulda-context (~> 1.0.1)
22
+ shoulda-matchers (~> 1.4.1)
23
+ shoulda-context (1.0.2)
24
+ shoulda-matchers (1.4.2)
25
+ activesupport (>= 3.0.0)
26
+ bourne (~> 1.1.2)
16
27
 
17
28
  PLATFORMS
18
29
  ruby
19
30
 
20
31
  DEPENDENCIES
21
32
  addressable (>= 2.2.2)
22
- bundler (~> 1.0.0)
23
- jeweler (~> 1.5.1)
33
+ bundler (>= 1.0.0)
24
34
  mocha
25
35
  nokogiri (>= 1.4.4)
26
- rcov
36
+ rake (> 10)
37
+ rdoc (> 3)
27
38
  shoulda
data/README.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/northworld/google_calendar.png?branch=master)](https://travis-ci.org/northworld/google_calendar)
2
+
3
+ [![Code Climate](https://codeclimate.com/github/northworld/google_calendar.png)](https://codeclimate.com/github/northworld/google_calendar)
4
+
1
5
  = Google Calendar
2
6
 
3
7
  A fast lightweight and minimalist wrapper around the google calendar api.
data/Rakefile CHANGED
@@ -9,19 +9,6 @@ rescue Bundler::BundlerError => e
9
9
  end
10
10
  require 'rake'
11
11
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "google_calendar"
16
- gem.homepage = "http://github.com/northworld/google_calendar"
17
- gem.license = "MIT"
18
- gem.summary = %Q{A lightweight google calendar API wrapper}
19
- gem.description = %Q{A minimal wrapper around the google calendar API, which uses nokogiri for fast parsing.}
20
- gem.email = "steve.zich@gmail.com"
21
- gem.authors = ["Steve Zich"]
22
- end
23
- Jeweler::RubygemsDotOrgTasks.new
24
-
25
12
  require 'rake/testtask'
26
13
  Rake::TestTask.new(:test) do |test|
27
14
  test.libs << 'lib' << 'test'
@@ -29,16 +16,9 @@ Rake::TestTask.new(:test) do |test|
29
16
  test.verbose = true
30
17
  end
31
18
 
32
- require 'rcov/rcovtask'
33
- Rcov::RcovTask.new do |test|
34
- test.libs << 'test'
35
- test.pattern = 'test/**/test_*.rb'
36
- test.verbose = true
37
- end
38
-
39
19
  task :default => :test
40
20
 
41
- require 'rake/rdoctask'
21
+ require 'rdoc/task'
42
22
  Rake::RDocTask.new do |rdoc|
43
23
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
@@ -1,55 +1,31 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "google_calendar"
8
- s.version = "0.2.8"
5
+ s.version = "0.2.9"
6
+ s.date = "2013-02-15"
9
7
 
10
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+
11
10
  s.authors = ["Steve Zich"]
12
- s.date = "2013-01-10"
13
- s.description = "A minimal wrapper around the google calendar API, which uses nokogiri for fast parsing."
14
11
  s.email = "steve.zich@gmail.com"
12
+
13
+ s.summary = "A lightweight google calendar API wrapper"
14
+ s.description = "A minimal wrapper around the google calendar API, which uses nokogiri for fast parsing."
15
+ s.homepage = "http://github.com/northworld/google_calendar"
16
+ s.licenses = ["MIT"]
17
+
15
18
  s.extra_rdoc_files = [
16
19
  "LICENSE.txt",
17
20
  "README.rdoc"
18
21
  ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "google_calendar.gemspec",
28
- "lib/google/calendar.rb",
29
- "lib/google/connection.rb",
30
- "lib/google/errors.rb",
31
- "lib/google/event.rb",
32
- "lib/google/net/https.rb",
33
- "lib/google_calendar.rb",
34
- "test/helper.rb",
35
- "test/mocks/create_event.xml",
36
- "test/mocks/create_quickadd_event.xml",
37
- "test/mocks/events.xml",
38
- "test/mocks/find_event_by_id.xml",
39
- "test/mocks/list_calendars.xml",
40
- "test/mocks/query_events.xml",
41
- "test/mocks/successful_login.txt",
42
- "test/test_google_calendar.rb"
43
- ]
44
- s.homepage = "http://github.com/northworld/google_calendar"
45
- s.licenses = ["MIT"]
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+
46
26
  s.require_paths = ["lib"]
47
27
  s.rubygems_version = "1.8.24"
48
- s.summary = "A lightweight google calendar API wrapper"
49
- s.test_files = [
50
- "test/helper.rb",
51
- "test/test_google_calendar.rb"
52
- ]
28
+
53
29
 
54
30
  if s.respond_to? :specification_version then
55
31
  s.specification_version = 3
@@ -58,26 +34,20 @@ Gem::Specification.new do |s|
58
34
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
59
35
  s.add_runtime_dependency(%q<addressable>, [">= 2.2.2"])
60
36
  s.add_development_dependency(%q<shoulda>, [">= 0"])
61
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
62
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
63
- s.add_development_dependency(%q<rcov>, [">= 0"])
37
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
64
38
  s.add_development_dependency(%q<mocha>, [">= 0"])
65
39
  else
66
40
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
67
41
  s.add_dependency(%q<addressable>, [">= 2.2.2"])
68
42
  s.add_dependency(%q<shoulda>, [">= 0"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
71
- s.add_dependency(%q<rcov>, [">= 0"])
43
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
72
44
  s.add_dependency(%q<mocha>, [">= 0"])
73
45
  end
74
46
  else
75
47
  s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
76
48
  s.add_dependency(%q<addressable>, [">= 2.2.2"])
77
49
  s.add_dependency(%q<shoulda>, [">= 0"])
78
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
80
- s.add_dependency(%q<rcov>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
81
51
  s.add_dependency(%q<mocha>, [">= 0"])
82
52
  end
83
53
  end
@@ -49,36 +49,61 @@ module Google
49
49
  set_session_if_necessary(uri)
50
50
 
51
51
  http = (uri.scheme == 'https' ? Net::HTTPS.new(uri.host, uri.inferred_port) : Net::HTTP.new(uri.host, uri.inferred_port))
52
+ response = http.request(build_request(uri, method, content))
52
53
 
54
+ # recurse if necessary.
55
+ if response.kind_of? Net::HTTPRedirection
56
+ response = send(Addressable::URI.parse(response['location']), method, content, redirect_count - 1)
57
+ end
58
+
59
+ check_for_errors(response)
60
+
61
+ return response
62
+ end
63
+
64
+ protected
65
+
66
+ # Check to see if we are using a session and extract it's values if required.
67
+ #
68
+ def set_session_if_necessary(uri) #:nodoc:
69
+ # only extract the session if we don't already have one.
70
+ @session_id = uri.query_values['gsessionid'] if @session_id == nil && uri.query
71
+
72
+ if @session_id
73
+ uri.query ||= ''
74
+ uri.query_values = uri.query_values.merge({'gsessionid' => @session_id})
75
+ end
76
+ end
77
+
78
+ # Construct the appropriate request object.
79
+ #
80
+ def build_request(uri, method, content) #:nodoc
53
81
  case method
54
82
  when :delete
55
- # puts "in delete: #{uri.to_s}"
56
83
  request = Net::HTTP::Delete.new(uri.to_s, @update_header)
84
+
57
85
  when :get
58
- # puts "in get: #{uri.to_s}"
59
86
  request = Net::HTTP::Get.new(uri.to_s, @headers)
87
+
60
88
  when :post_form
61
- # puts "in post_form: #{uri.to_s}"
62
89
  request = Net::HTTP::Post.new(uri.to_s, @headers)
63
90
  request.set_form_data(content)
91
+
64
92
  when :post
65
- # puts "in post: #{uri.to_s}\n#{content}"
66
93
  request = Net::HTTP::Post.new(uri.to_s, @headers)
67
94
  request.body = content
95
+
68
96
  when :put
69
- # puts "in put: #{uri.to_s}\n#{content}"
70
97
  request = Net::HTTP::Put.new(uri.to_s, @update_header)
71
98
  request.body = content
72
- end
99
+ end # case
73
100
 
74
- response = http.request(request)
75
-
76
- # recurse if necessary.
77
- if response.kind_of? Net::HTTPRedirection
78
- response = send(Addressable::URI.parse(response['location']), method, content, redirect_count - 1)
79
- end
101
+ return request
102
+ end
80
103
 
81
- # Raise the appropiate error if necessary.
104
+ # Check for common HTTP Errors and raise the appropriate response.
105
+ #
106
+ def check_for_errors(response) #:nodoc
82
107
  if response.kind_of? Net::HTTPForbidden
83
108
  raise HTTPAuthorizationFailed, response.body
84
109
 
@@ -88,20 +113,6 @@ module Google
88
113
  elsif response.kind_of? Net::HTTPNotFound
89
114
  raise HTTPNotFound, response.body
90
115
  end
91
-
92
- return response
93
- end
94
-
95
- protected
96
-
97
- def set_session_if_necessary(uri) #:nodoc:
98
- # only extract the session if we don't already have one.
99
- @session_id = uri.query_values['gsessionid'] if @session_id == nil && uri.query
100
-
101
- if @session_id
102
- uri.query ||= ''
103
- uri.query_values = uri.query_values.merge({'gsessionid' => @session_id})
104
- end
105
116
  end
106
117
 
107
118
  end
data/lib/google/event.rb CHANGED
@@ -3,7 +3,7 @@ require 'time'
3
3
 
4
4
  module Google
5
5
 
6
- # Represents a google Event.
6
+ # Represents a Google Event.
7
7
  #
8
8
  # === Attributes
9
9
  #
@@ -50,8 +50,7 @@ module Google
50
50
  # Sets the start time of the Event. Must be a Time object or a parsable string representation of a time.
51
51
  #
52
52
  def start_time=(time)
53
- raise ArgumentError, "Start Time must be either Time or String" unless (time.is_a?(String) || time.is_a?(Time))
54
- @start_time = (time.is_a? String) ? Time.parse(time) : time.dup.utc
53
+ @start_time = parse_time(time)
55
54
  end
56
55
 
57
56
  # Get the start_time of the event.
@@ -75,6 +74,7 @@ module Google
75
74
  # Sets the end time of the Event. Must be a Time object or a parsable string representation of a time.
76
75
  #
77
76
  def end_time=(time)
77
+ @end_time = parse_time(time)
78
78
  raise ArgumentError, "End Time must be either Time or String" unless (time.is_a?(String) || time.is_a?(Time))
79
79
  @end_time = (time.is_a? String) ? Time.parse(time) : time.dup.utc
80
80
  end
@@ -83,7 +83,7 @@ module Google
83
83
  #
84
84
  def all_day?
85
85
  time = Time.parse(@start_time)
86
- duration % (24 * 60 * 60) == 0 && time == Time.new(time.year,time.month,time.day)
86
+ duration % (24 * 60 * 60) == 0 && time == Time.local(time.year,time.month,time.day)
87
87
  end
88
88
 
89
89
  def all_day=(time)
@@ -163,27 +163,17 @@ module Google
163
163
  # Create a new event from a google 'entry' xml block.
164
164
  #
165
165
  def self.new_from_xml(xml, calendar) #:nodoc:
166
- id = xml.at_xpath("gCal:uid")['value'].split('@').first
167
- title = xml.at_xpath("xmlns:title").content
168
- content = xml.at_xpath("xmlns:content").content
169
- where = xml.at_xpath("gd:where")['valueString']
170
- start_time = xml.at_xpath("gd:when")['startTime']
171
- end_time = xml.at_xpath("gd:when")['endTime']
172
- transparency = xml.at_xpath("gd:transparency")['value'].split('.').last
173
- quickadd = xml.at_xpath("gCal:quickadd") ? xml.at_xpath("gCal:quickadd")['quickadd'] : nil
174
- html_link = xml.at_xpath('//xmlns:link[@title="alternate" and @rel="alternate" and @type="text/html"]')['href']
175
-
176
- Event.new(:id => id,
177
- :title => title,
178
- :content => content,
179
- :where => where,
180
- :start_time => start_time,
181
- :end_time => end_time,
182
- :calendar => calendar,
183
- :raw_xml => xml,
184
- :transparency => transparency,
185
- :quickadd => quickadd,
186
- :html_link => html_link)
166
+ Event.new(:id => xml.at_xpath("gCal:uid")['value'].split('@').first,
167
+ :calendar => calendar,
168
+ :raw_xml => xml,
169
+ :title => xml.at_xpath("xmlns:title").content,
170
+ :content => xml.at_xpath("xmlns:content").content,
171
+ :where => xml.at_xpath("gd:where")['valueString'],
172
+ :start_time => xml.at_xpath("gd:when")['startTime'],
173
+ :end_time => xml.at_xpath("gd:when")['endTime'],
174
+ :transparency => xml.at_xpath("gd:transparency")['value'].split('.').last,
175
+ :quickadd => (xml.at_xpath("gCal:quickadd") ? (xml.at_xpath("gCal:quickadd")['quickadd']) : nil),
176
+ :html_link => xml.at_xpath('//xmlns:link[@title="alternate" and @rel="alternate" and @type="text/html"]')['href'])
187
177
  end
188
178
 
189
179
  # Set the ID after google assigns it (only necessary when we are creating a new event)
@@ -197,5 +187,12 @@ module Google
197
187
  @raw_xml = xml
198
188
  end
199
189
 
190
+ # A utility method used centralize time parsing.
191
+ #
192
+ def parse_time(time) #:nodoc
193
+ raise ArgumentError, "Start Time must be either Time or String" unless (time.is_a?(String) || time.is_a?(Time))
194
+ (time.is_a? String) ? Time.parse(time) : time.dup.utc
195
+ end
196
+
200
197
  end
201
198
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -61,44 +61,12 @@ dependencies:
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bundler
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 1.0.0
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 1.0.0
78
- - !ruby/object:Gem::Dependency
79
- name: jeweler
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: 1.5.1
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 1.5.1
94
- - !ruby/object:Gem::Dependency
95
- name: rcov
96
64
  requirement: !ruby/object:Gem::Requirement
97
65
  none: false
98
66
  requirements:
99
67
  - - ! '>='
100
68
  - !ruby/object:Gem::Version
101
- version: '0'
69
+ version: 1.0.0
102
70
  type: :development
103
71
  prerelease: false
104
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +74,7 @@ dependencies:
106
74
  requirements:
107
75
  - - ! '>='
108
76
  - !ruby/object:Gem::Version
109
- version: '0'
77
+ version: 1.0.0
110
78
  - !ruby/object:Gem::Dependency
111
79
  name: mocha
112
80
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +101,8 @@ extra_rdoc_files:
133
101
  - README.rdoc
134
102
  files:
135
103
  - .document
104
+ - .gitignore
105
+ - .travis.yml
136
106
  - Gemfile
137
107
  - Gemfile.lock
138
108
  - LICENSE.txt
@@ -168,9 +138,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
138
  - - ! '>='
169
139
  - !ruby/object:Gem::Version
170
140
  version: '0'
171
- segments:
172
- - 0
173
- hash: 2763887538730031791
174
141
  required_rubygems_version: !ruby/object:Gem::Requirement
175
142
  none: false
176
143
  requirements:
@@ -185,4 +152,11 @@ specification_version: 3
185
152
  summary: A lightweight google calendar API wrapper
186
153
  test_files:
187
154
  - test/helper.rb
155
+ - test/mocks/create_event.xml
156
+ - test/mocks/create_quickadd_event.xml
157
+ - test/mocks/events.xml
158
+ - test/mocks/find_event_by_id.xml
159
+ - test/mocks/list_calendars.xml
160
+ - test/mocks/query_events.xml
161
+ - test/mocks/successful_login.txt
188
162
  - test/test_google_calendar.rb