google_calendar 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -10
- data/.travis.yml +1 -1
- data/Gemfile +2 -12
- data/Gemfile.lock +81 -24
- data/Guardfile +7 -0
- data/README.rdoc +60 -8
- data/VERSION +1 -1
- data/google_calendar.gemspec +19 -29
- data/lib/google/calendar.rb +149 -118
- data/lib/google/connection.rb +114 -79
- data/lib/google/errors.rb +2 -1
- data/lib/google/event.rb +191 -94
- data/lib/google_calendar.rb +5 -5
- data/readme_code.rb +72 -0
- data/test/helper.rb +12 -5
- data/test/mocks/401.json +15 -0
- data/test/mocks/403.json +12 -0
- data/test/mocks/404.json +13 -0
- data/test/mocks/create_event.json +31 -0
- data/test/mocks/create_quickadd_event.json +30 -0
- data/test/mocks/empty_events.json +12 -0
- data/test/mocks/events.json +117 -0
- data/test/mocks/find_event_by_id.json +31 -0
- data/test/mocks/login_with_auth_code_fail.json +4 -0
- data/test/mocks/login_with_auth_code_success.json +6 -0
- data/test/mocks/login_with_refresh_token_success.json +5 -0
- data/test/mocks/query_events.json +44 -0
- data/test/mocks/repeating_events.json +48 -0
- data/test/mocks/successful_login.json +6 -0
- data/test/test_google_calendar.rb +167 -139
- metadata +167 -53
- data/lib/google/net/https.rb +0 -19
- data/test/mocks/create_event.xml +0 -31
- data/test/mocks/create_quickadd_event.xml +0 -31
- data/test/mocks/events.xml +0 -119
- data/test/mocks/find_event_by_id.xml +0 -33
- data/test/mocks/list_calendars.xml +0 -89
- data/test/mocks/query_events.xml +0 -55
- data/test/mocks/successful_login.txt +0 -3
data/lib/google_calendar.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Google
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
require 'google/errors'
|
3
|
+
require 'google/calendar'
|
4
|
+
require 'google/connection'
|
5
|
+
require 'google/event'
|
6
|
+
end
|
data/readme_code.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Uncomment the LOAD_PATH lines if you want to run against the
|
3
|
+
# local version of the gem.
|
4
|
+
#
|
5
|
+
# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
6
|
+
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
#
|
9
|
+
# Comment out the require lines out if you want to run against
|
10
|
+
# the local version of the gem.
|
11
|
+
#
|
12
|
+
require 'rubygems'
|
13
|
+
require 'google_calendar'
|
14
|
+
|
15
|
+
YOUR_CLIENT_ID = ""
|
16
|
+
YOUR_SECRET = ""
|
17
|
+
YOUR_CALENDAR_ID = ""
|
18
|
+
|
19
|
+
# Create an instance of the calendar.
|
20
|
+
cal = Google::Calendar.new(:client_id => YOUR_CLIENT_ID,
|
21
|
+
:client_secret => YOUR_SECRET,
|
22
|
+
:calendar => YOUR_CALENDAR_ID,
|
23
|
+
:redirect_url => "urn:ietf:wg:oauth:2.0:oob" # this is what Google uses for 'applications'
|
24
|
+
)
|
25
|
+
|
26
|
+
puts "Do you already have a refresh token? (y/n)"
|
27
|
+
has_token = $stdin.gets.chomp
|
28
|
+
|
29
|
+
if has_token.downcase != 'y'
|
30
|
+
|
31
|
+
# A user needs to approve access in order to work with their calendars.
|
32
|
+
puts "Visit the following web page in your browser and approve access."
|
33
|
+
puts cal.authorize_url
|
34
|
+
puts "\nCopy the code that Google returned and paste it here:"
|
35
|
+
|
36
|
+
# Pass the ONE TIME USE access code here to login and get a refresh token that you can use for access from now on.
|
37
|
+
refresh_token = cal.login_with_auth_code( $stdin.gets.chomp )
|
38
|
+
|
39
|
+
puts "\nMake sure you SAVE YOUR REFRESH TOKEN so you don't have to prompt the user to approve access again."
|
40
|
+
puts "your refresh token is:\n\t#{refresh_token}\n"
|
41
|
+
puts "Press return to continue"
|
42
|
+
$stdin.gets.chomp
|
43
|
+
|
44
|
+
else
|
45
|
+
puts "Enter your refresh token"
|
46
|
+
refresh_token = $stdin.gets.chomp
|
47
|
+
cal.login_with_refresh_token(refresh_token)
|
48
|
+
|
49
|
+
# Note: You can also pass your refresh_token to the constructor and it will login at that time.
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
event = cal.create_event do |e|
|
54
|
+
e.title = 'A Cool Event'
|
55
|
+
e.start_time = Time.now
|
56
|
+
e.end_time = Time.now + (60 * 60) # seconds * min
|
57
|
+
end
|
58
|
+
|
59
|
+
puts event
|
60
|
+
|
61
|
+
event = cal.find_or_create_event_by_id(event.id) do |e|
|
62
|
+
e.title = 'An Updated Cool Event'
|
63
|
+
e.end_time = Time.now + (60 * 60 * 2) # seconds * min * hours
|
64
|
+
end
|
65
|
+
|
66
|
+
puts event
|
67
|
+
|
68
|
+
# All events
|
69
|
+
puts cal.events
|
70
|
+
|
71
|
+
# Query events
|
72
|
+
puts cal.find_events('your search string')
|
data/test/helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'bundler'
|
3
6
|
begin
|
@@ -7,15 +10,19 @@ rescue Bundler::BundlerError => e
|
|
7
10
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
11
|
exit e.status_code
|
9
12
|
end
|
10
|
-
|
11
|
-
require
|
13
|
+
|
14
|
+
require "minitest/autorun"
|
15
|
+
require 'minitest/reporters'
|
16
|
+
require 'shoulda/context'
|
12
17
|
require 'mocha/setup'
|
18
|
+
require 'faraday'
|
13
19
|
|
14
20
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
22
|
require 'google_calendar'
|
17
|
-
require 'google/net/https'
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
25
|
+
|
26
|
+
class Minitest::Test
|
27
|
+
@@mock_path = File.expand_path(File.join(File.dirname(__FILE__), 'mocks'))
|
21
28
|
end
|
data/test/mocks/401.json
ADDED
data/test/mocks/403.json
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
error: {
|
2
|
+
errors: [
|
3
|
+
{
|
4
|
+
"domain": "global",
|
5
|
+
"reason": "appNotInstalled",
|
6
|
+
"message": "The authenticated user has not installed the app with client id clientId"
|
7
|
+
}
|
8
|
+
],
|
9
|
+
"code": 403,
|
10
|
+
"message": "The authenticated user has not installed the app with client id clientId"
|
11
|
+
}
|
12
|
+
}
|
data/test/mocks/404.json
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"status": "confirmed",
|
3
|
+
"kind": "calendar#event",
|
4
|
+
"end": {
|
5
|
+
"dateTime": "2014-11-16T21:17:31-08:00"
|
6
|
+
},
|
7
|
+
"description": "A New Event",
|
8
|
+
"created": "2014-11-17T03:19:37.000Z",
|
9
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
10
|
+
"reminders": {
|
11
|
+
"useDefault": true
|
12
|
+
},
|
13
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=aslkjhdfasod89f7aspdfghsdlkfghsdlkjghsdfgposdr7gpsdorigh",
|
14
|
+
"sequence": 0,
|
15
|
+
"updated": "2014-11-17T03:19:37.944Z",
|
16
|
+
"summary": "New Event",
|
17
|
+
"start": {
|
18
|
+
"dateTime": "2014-11-16T20:17:31-08:00"
|
19
|
+
},
|
20
|
+
"etag": "\"123456728900000\"",
|
21
|
+
"organizer": {
|
22
|
+
"self": true,
|
23
|
+
"displayName": "Some Person",
|
24
|
+
"email": "klei8jnelo09nflqehnvfzipgs@group.calendar.google.com"
|
25
|
+
},
|
26
|
+
"creator": {
|
27
|
+
"displayName": "Some Person",
|
28
|
+
"email": "some.person@gmail.com"
|
29
|
+
},
|
30
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
31
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"status": "confirmed",
|
3
|
+
"kind": "calendar#event",
|
4
|
+
"end": {
|
5
|
+
"dateTime": "2014-11-16T22:21:24-08:00"
|
6
|
+
},
|
7
|
+
"created": "2014-11-17T05:21:24.000Z",
|
8
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
9
|
+
"reminders": {
|
10
|
+
"useDefault": true
|
11
|
+
},
|
12
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=cHBtNzMybzBqOWpuZDI0M25zZWx1ZjllYjQgZ3FlYjBpNnY3MzdrZnU1bWQwZjNldWtqbGdAZw",
|
13
|
+
"sequence": 0,
|
14
|
+
"updated": "2014-11-17T05:21:24.614Z",
|
15
|
+
"summary": "Test Event",
|
16
|
+
"start": {
|
17
|
+
"dateTime": "2014-11-16T21:21:24-08:00"
|
18
|
+
},
|
19
|
+
"etag": "\"2832403369228000\"",
|
20
|
+
"organizer": {
|
21
|
+
"self": true,
|
22
|
+
"displayName": "Some Person",
|
23
|
+
"email": "klei8jnelo09nflqehnvfzipgs@group.calendar.google.com"
|
24
|
+
},
|
25
|
+
"creator": {
|
26
|
+
"displayName": "Some Person",
|
27
|
+
"email": "some.person@gmail.com"
|
28
|
+
},
|
29
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
30
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"kind": "calendar#events",
|
3
|
+
"defaultReminders": [],
|
4
|
+
"description": "My Personal Events Calendar",
|
5
|
+
"items": [],
|
6
|
+
"updated": "2014-11-15T22:32:46.965Z",
|
7
|
+
"summary": "My Events Calendar",
|
8
|
+
"etag": "\"1234567890123000\"",
|
9
|
+
"nextSyncToken": "AKi8uge987ECEIjyiZnV_cECGAU=",
|
10
|
+
"timeZone": "America/Los_Angeles",
|
11
|
+
"accessRole": "owner"
|
12
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
{
|
2
|
+
"nextPageToken": "CkkKO183NTM0Mmdobzc0cDNhYmE0ODUyajZiOWs2bDBqMmJhMTZsMjNjYmExOHAyajhoOXA3NG80YWRoaDZrGAEggICA7NHLrqgTGg0IABIAGIjyiZnV_cEC",
|
3
|
+
"kind": "calendar#events",
|
4
|
+
"defaultReminders": [],
|
5
|
+
"description": "My Personal Events Calenda",
|
6
|
+
"items": [
|
7
|
+
{
|
8
|
+
"status": "confirmed",
|
9
|
+
"kind": "calendar#event",
|
10
|
+
"end": {
|
11
|
+
"timeZone": "America/Los_Angeles",
|
12
|
+
"dateTime": "2011-10-03T10:30:00-07:00"
|
13
|
+
},
|
14
|
+
"created": "2011-04-04T23:52:57.000Z",
|
15
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
16
|
+
"reminders": {
|
17
|
+
"useDefault": true
|
18
|
+
},
|
19
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=HikHg9bQzIk2dWtpdTRwM3Zpazd0cHMwcjRfMjAxMTEwMDNUMTYzMDAwWiBncWViMGk2djczN2tmdTVtZDBmM2V1a2psZ0Bn",
|
20
|
+
"sequence": 2,
|
21
|
+
"updated": "2012-01-09T19:39:49.000Z",
|
22
|
+
"summary": "Staff Meeting",
|
23
|
+
"recurrence": [
|
24
|
+
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20120109T075959Z;BYDAY=MO"
|
25
|
+
],
|
26
|
+
"start": {
|
27
|
+
"timeZone": "America/Los_Angeles",
|
28
|
+
"dateTime": "2011-10-03T09:30:00-07:00"
|
29
|
+
},
|
30
|
+
"etag": "\"2652275978000000\"",
|
31
|
+
"organizer": {
|
32
|
+
"self": true,
|
33
|
+
"displayName": "Some Person",
|
34
|
+
"email": "klei8jnelo09nflqehnvfzipgs@group.calendar.google.com"
|
35
|
+
},
|
36
|
+
"creator": {
|
37
|
+
"displayName": "Some Person",
|
38
|
+
"email": "some.person@gmail.com"
|
39
|
+
},
|
40
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"status": "confirmed",
|
44
|
+
"kind": "calendar#event",
|
45
|
+
"end": {
|
46
|
+
"timeZone": "America/Los_Angeles",
|
47
|
+
"dateTime": "2011-10-03T11:00:00-07:00"
|
48
|
+
},
|
49
|
+
"created": "2010-06-01T03:53:00.000Z",
|
50
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
51
|
+
"reminders": {
|
52
|
+
"useDefault": true
|
53
|
+
},
|
54
|
+
"htmlLink": "https://www.google.com/calendar/event?eidi1wegp0jHmAFucjlhMXY0c2RqMjBpYXNlNmNfMjAxMTEwMDNUMTczMDAwWiBncWViMGk2djczN2tmdTVtZDBmM2V1a2psZ0Bn",
|
55
|
+
"sequence": 2,
|
56
|
+
"updated": "2012-01-13T18:24:01.000Z",
|
57
|
+
"summary": "Skype Meeting",
|
58
|
+
"recurrence": [
|
59
|
+
"RRULE:FREQ=WEEKLY;UNTIL=20120109T183000Z"
|
60
|
+
],
|
61
|
+
"start": {
|
62
|
+
"timeZone": "America/Los_Angeles",
|
63
|
+
"dateTime": "2011-10-03T10:30:00-07:00"
|
64
|
+
},
|
65
|
+
"etag": "\"2652958082000000\"",
|
66
|
+
"organizer": {
|
67
|
+
"self": true,
|
68
|
+
"displayName": "Some Person",
|
69
|
+
"email": "some.person@gmail.com"
|
70
|
+
},
|
71
|
+
"creator": {
|
72
|
+
"displayName": "Some Person",
|
73
|
+
"email": "some.person@gmail.com"
|
74
|
+
},
|
75
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"status": "confirmed",
|
79
|
+
"kind": "calendar#event",
|
80
|
+
"end": {
|
81
|
+
"timeZone": "America/Los_Angeles",
|
82
|
+
"dateTime": "2012-01-09T10:15:00-08:00"
|
83
|
+
},
|
84
|
+
"created": "2012-01-09T19:39:50.000Z",
|
85
|
+
"reminders": {
|
86
|
+
"useDefault": true
|
87
|
+
},
|
88
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=uIf5JKmaPdhvNzRwM2FiYTQ4NTJqNmI5azZsMGoyYmExNmwyM2NiYTE4cDJqOGg5cDc0bzRhZGhoNmtfMjAxMjAxMDlUMTcxNTAwWiBncWViMGk2djczN2tmdTVtZDBmM2V1a2psZ0Bn",
|
89
|
+
"sequence": 3,
|
90
|
+
"updated": "2012-01-23T17:38:31.000Z",
|
91
|
+
"summary": "Sales Staff Meeting",
|
92
|
+
"recurrence": [
|
93
|
+
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20120123T171459Z;BYDAY=MO"
|
94
|
+
],
|
95
|
+
"start": {
|
96
|
+
"timeZone": "America/Los_Angeles",
|
97
|
+
"dateTime": "2012-01-09T09:15:00-08:00"
|
98
|
+
},
|
99
|
+
"etag": "\"2654680622000000\"",
|
100
|
+
"organizer": {
|
101
|
+
"self": true,
|
102
|
+
"displayName": "Some Person",
|
103
|
+
"email": "some.person@gmail.com"
|
104
|
+
},
|
105
|
+
"creator": {
|
106
|
+
"displayName": "Some Person",
|
107
|
+
"email": "some.person@gmail.com"
|
108
|
+
},
|
109
|
+
"id": "_75342gho74p3aba4852j6b9k6l0j2ba16l23cba18p2j8h9p74o4adhh6k"
|
110
|
+
}
|
111
|
+
],
|
112
|
+
"updated": "2014-11-15T22:32:46.965Z",
|
113
|
+
"summary": "My Events Calendar",
|
114
|
+
"etag": "\"1234567890123000\"",
|
115
|
+
"timeZone": "America/Los_Angeles",
|
116
|
+
"accessRole": "owner"
|
117
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"status": "confirmed",
|
3
|
+
"kind": "calendar#event",
|
4
|
+
"end": {
|
5
|
+
"dateTime": "2008-09-24T11:00:00-07:00"
|
6
|
+
},
|
7
|
+
"description": "Test Event",
|
8
|
+
"created": "2008-09-18T21:17:11.000Z",
|
9
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
10
|
+
"reminders": {
|
11
|
+
"useDefault": true
|
12
|
+
},
|
13
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=hJo0SgXn9qMwOHJjYWJpNnBhNTQ5dHRqbGsgZ3FlYjBpNnY3MzdrZnU1bWQwZjNldWtqbGdAZw",
|
14
|
+
"sequence": 1,
|
15
|
+
"updated": "2008-10-24T23:08:09.010Z",
|
16
|
+
"summary": "This is a test event",
|
17
|
+
"start": {
|
18
|
+
"dateTime": "2008-09-24T10:30:00-07:00"
|
19
|
+
},
|
20
|
+
"etag": "\"2449779378020000\"",
|
21
|
+
"organizer": {
|
22
|
+
"self": true,
|
23
|
+
"displayName": "Some Person",
|
24
|
+
"email": "some.person@gmail.com"
|
25
|
+
},
|
26
|
+
"creator": {
|
27
|
+
"displayName": "Some Person",
|
28
|
+
"email": "some.person@gmail.com"
|
29
|
+
},
|
30
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
31
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"kind": "calendar#events",
|
3
|
+
"defaultReminders": [],
|
4
|
+
"description": "My Personal Events Calendar",
|
5
|
+
"items": [
|
6
|
+
{
|
7
|
+
"status": "confirmed",
|
8
|
+
"kind": "calendar#event",
|
9
|
+
"end": {
|
10
|
+
"dateTime": "2008-09-24T11:00:00-07:00"
|
11
|
+
},
|
12
|
+
"description": "My Test Event",
|
13
|
+
"created": "2008-09-18T21:17:11.000Z",
|
14
|
+
"iCalUID": "fhru34kt6ikmr20knd2456l08n@google.com",
|
15
|
+
"reminders": {
|
16
|
+
"useDefault": true
|
17
|
+
},
|
18
|
+
"htmlLink": "https://www.google.com/calendar/event?eid=dDAwam5wcWMwOHJjYWJpNnBhNTQ5dHRqbGsgZ3FlYjBpNnY3MzdrZnU1bWQwZjNldWtqbGdAZw",
|
19
|
+
"sequence": 1,
|
20
|
+
"updated": "2008-10-24T23:08:09.010Z",
|
21
|
+
"summary": "Test Event",
|
22
|
+
"start": {
|
23
|
+
"dateTime": "2008-09-24T10:30:00-07:00"
|
24
|
+
},
|
25
|
+
"etag": "\"2449779378020000\"",
|
26
|
+
"organizer": {
|
27
|
+
"self": true,
|
28
|
+
"displayName": "Some Person",
|
29
|
+
"email": "some.person@gmail.com"
|
30
|
+
},
|
31
|
+
"creator": {
|
32
|
+
"displayName": "Some Person",
|
33
|
+
"email": "some.person@gmail.com"
|
34
|
+
},
|
35
|
+
"id": "fhru34kt6ikmr20knd2456l08n"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"updated": "2014-11-15T22:32:46.965Z",
|
39
|
+
"summary": "My Events Calendar",
|
40
|
+
"etag": "\"1234567890123000\"",
|
41
|
+
"nextSyncToken": "AKi8uge987ECEIjyiZnV_cECGAU=",
|
42
|
+
"timeZone": "America/Los_Angeles",
|
43
|
+
"accessRole": "owner"
|
44
|
+
}
|