google_client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +92 -0
- data/Rakefile +2 -0
- data/app/controllers/google_client_controller.rb +79 -0
- data/app/views/google_client/show.html.erb +54 -0
- data/config/routes.rb +9 -0
- data/google_client.gemspec +25 -0
- data/lib/google_client.rb +26 -0
- data/lib/google_client/calendar.rb +181 -0
- data/lib/google_client/contact.rb +56 -0
- data/lib/google_client/engine.rb +39 -0
- data/lib/google_client/error.rb +13 -0
- data/lib/google_client/event.rb +135 -0
- data/lib/google_client/format.rb +19 -0
- data/lib/google_client/http_connection.rb +113 -0
- data/lib/google_client/profile.rb +15 -0
- data/lib/google_client/user.rb +130 -0
- data/lib/google_client/version.rb +3 -0
- data/spec/calendar_spec.rb +33 -0
- data/spec/contact_spec.rb +39 -0
- data/spec/event_spec.rb +20 -0
- data/spec/google_client_spec.rb +9 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/user_spec.rb +103 -0
- metadata +133 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'google_client'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
describe GoogleClient::Calendar do
|
6
|
+
let(:user) do
|
7
|
+
GoogleClient::User.new(USER_TOKEN)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:calendar) do
|
11
|
+
GoogleClient::Calendar.new({:user => user, :id => CALENDAR_ID})
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "while initializing" do
|
15
|
+
|
16
|
+
it "should set the OAuth credentials properly" do
|
17
|
+
user.oauth_credentials.should eql(USER_TOKEN)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "while fetching events" do
|
23
|
+
it "should fetch all the calendar events when no param is provided" do
|
24
|
+
pending("need to be developed")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "while deleting a calendar" do
|
29
|
+
it "should delete the calendar when a valid id is set" do
|
30
|
+
pending("need to be developed")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'google_client'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
describe GoogleClient::Contact do
|
6
|
+
|
7
|
+
let(:contact_params) do
|
8
|
+
{
|
9
|
+
:email => "juandebravo@gmail.com",
|
10
|
+
:name => ["Juan de Bravo"],
|
11
|
+
:phone_number => ["+34667788999"]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "while initializing" do
|
16
|
+
it "should set the parameters properly" do
|
17
|
+
contact = GoogleClient::Contact.new(contact_params)
|
18
|
+
contact.should be_instance_of(GoogleClient::Contact)
|
19
|
+
contact.should have_valid_attributes contact_params[:name], contact_params[:email], contact_params[:phone_number]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set the phone_number properly as an Array" do
|
23
|
+
params = contact_params.dup
|
24
|
+
params[:phone_number] = ["+34667788999", "+34667788900"]
|
25
|
+
contact = GoogleClient::Contact.new(contact_params)
|
26
|
+
contact.should be_instance_of(GoogleClient::Contact)
|
27
|
+
contact.should have_valid_attributes contact_params[:name], contact_params[:email], contact_params[:phone_number]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the email properly as an Array" do
|
31
|
+
params = contact_params.dup
|
32
|
+
params[:email] = ["juandebravo@gmail.com", "juandebravo+1@gmail.com"]
|
33
|
+
contact = GoogleClient::Contact.new(params)
|
34
|
+
contact.should be_instance_of(GoogleClient::Contact)
|
35
|
+
contact.should have_valid_attributes params[:name], params[:email], params[:phone_number]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/event_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'google_client'
|
2
|
+
|
3
|
+
describe GoogleClient::Event do
|
4
|
+
describe "when initializing object" do
|
5
|
+
it "should return an Event instance" do
|
6
|
+
GoogleClient::Event.new.should be_instance_of GoogleClient::Event
|
7
|
+
end
|
8
|
+
it "should accept a block to initialize the object" do
|
9
|
+
e = GoogleClient::Event.new do |event|
|
10
|
+
event.title = "Foo"
|
11
|
+
event.description = "Bar"
|
12
|
+
event.location = "Barcelona"
|
13
|
+
end
|
14
|
+
|
15
|
+
e.title.should eql("Foo")
|
16
|
+
e.description.should eql("Bar")
|
17
|
+
e.location.should eql("Barcelona")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
|
2
|
+
CLIENT_ID = "this-should-be-a-valid-client-id"
|
3
|
+
CLIENT_SECRET = "this-should-be-a-valid-client-secret"
|
4
|
+
|
5
|
+
USER_TOKEN = "this-should-be-a-valid-authentication-token"
|
6
|
+
|
7
|
+
CALENDAR_ID = "this-should-be-a-valid-calendar-id"
|
8
|
+
|
9
|
+
NEW_CALENDAR_ID = "this-should-be-a-valid-calendar-id"
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
CONTACT_NAME = "foo bar"
|
14
|
+
CONTACT_ID = "7fb4bd3asbd25633"
|
15
|
+
CONTACT_EMAIL = "foo@gmail.com"
|
16
|
+
CONTACT_PN = "+44 7772 111111"
|
17
|
+
|
18
|
+
RSpec::Matchers.define :have_valid_attributes do |name, email, phone_number|
|
19
|
+
match do |actual|
|
20
|
+
|
21
|
+
actual.name.should eql(name)
|
22
|
+
actual.email.class.should eql(email.class)
|
23
|
+
actual.phone_number.class.should eql(phone_number.class)
|
24
|
+
|
25
|
+
email = Array(email)
|
26
|
+
actual_email = Array(actual.email)
|
27
|
+
email.length.should eql(actual_email.length)
|
28
|
+
email.each do |e|
|
29
|
+
valid_email = actual_email.select{|ae| ae.eql?(e)}
|
30
|
+
valid_email.length.should eql(1)
|
31
|
+
valid_email[0].should eql(e)
|
32
|
+
end
|
33
|
+
|
34
|
+
phone_number = Array(phone_number)
|
35
|
+
actual_phone_number = Array(actual.phone_number)
|
36
|
+
phone_number.length.should eql(actual_phone_number.length)
|
37
|
+
phone_number.each do |p|
|
38
|
+
valid_phone_number = actual_phone_number.select{|ap| ap.eql?(p)}
|
39
|
+
valid_phone_number.length.should eql(1)
|
40
|
+
valid_phone_number[0].should eql(p)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
module GoogleResponseMocks
|
48
|
+
def self.all_calendars
|
49
|
+
"{\"version\":\"1.0\",\"encoding\":\"UTF-8\",\
|
50
|
+
\"feed\":{\
|
51
|
+
\"xmlns\":\"http://www.w3.org/2005/Atom\",\
|
52
|
+
\"xmlns$openSearch\":\"http://a9.com/-/spec/opensearchrss/1.0/\",\"xmlns$gCal\":\"http://schemas.google.com/gCal/2005\",\"xmlns$gd\":\"http://schemas.google.com/g/2005\",\
|
53
|
+
\"id\":{\
|
54
|
+
\"$t\":\"http://www.google.com/calendar/feeds/default/allcalendars/full\"},\
|
55
|
+
\"updated\":{\"$t\":\"2011-10-31T13:51:29.764Z\"},\
|
56
|
+
\"category\":[{\"scheme\":\"http://schemas.google.com/g/2005#kind\",\"term\":\"http://schemas.google.com/gCal/2005#calendarmeta\"}],\
|
57
|
+
\"title\":{\
|
58
|
+
\"$t\":\"foo_bar@gmail.com\'s Calendar List\",\"type\":\"text\"},\
|
59
|
+
\"link\":[{\"rel\":\"alternate\",\"type\":\"text/html\",\"href\":\"https://www.google.com/calendar/render\"},{\"rel\":\"http://schemas.google.com/g/2005#feed\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full\"},{\"rel\":\"http://schemas.google.com/g/2005#post\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full\"},{\"rel\":\"self\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full?alt=json\"}],\
|
60
|
+
\"author\":[{\"name\":{\"$t\":\"foo_bar@gmail.com\"},\"email\":{\"$t\":\"foo_bar@gmail.com\"}}],\
|
61
|
+
\"generator\":{\"$t\":\"Google Calendar\",\"version\":\"1.0\",\"uri\":\"http://www.google.com/calendar\"},\
|
62
|
+
\"openSearch$startIndex\":{\"$t\":1},\
|
63
|
+
\"entry\":[\
|
64
|
+
{\"id\":{\"$t\":\"http://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"},\"published\":{\"$t\":\"2011-10-31T13:51:29.482Z\"},\"updated\":{\"$t\":\"2011-10-20T08:54:48.000Z\"},\"category\":[{\"scheme\":\"http://schemas.google.com/g/2005#kind\",\"term\":\"http://schemas.google.com/gCal/2005#calendarmeta\"}],\"title\":{\"$t\":\"Foo Bar\",\"type\":\"text\"},\"content\":{\"type\":\"application/atom+xml\",\"src\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},\"link\":[{\"rel\":\"alternate\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/gCal/2005#eventFeed\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/acl/2007#accessControlList\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/acl/full\"},{\"rel\":\"self\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"},{\"rel\":\"edit\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"}],\"author\":[{\"name\":{\"$t\":\"foo_bar@gmail.com\"},\"email\":{\"$t\":\"foo_bar@gmail.com\"}}],\"gCal$accesslevel\":{\"value\":\"owner\"},\"gCal$color\":{\"value\":\"#2952A3\"},\"gCal$hidden\":{\"value\":\"false\"},\"gCal$selected\":{\"value\":\"true\"},\"gCal$timezone\":{\"value\":\"Asia/Jerusalem\"},\"gCal$timesCleaned\":{\"value\":0}},\
|
65
|
+
{\"id\":{\"$t\":\"http://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"},\"published\":{\"$t\":\"2011-10-31T13:51:29.482Z\"},\"updated\":{\"$t\":\"2011-10-20T08:54:48.000Z\"},\"category\":[{\"scheme\":\"http://schemas.google.com/g/2005#kind\",\"term\":\"http://schemas.google.com/gCal/2005#calendarmeta\"}],\"title\":{\"$t\":\"Foo Bar\",\"type\":\"text\"},\"content\":{\"type\":\"application/atom+xml\",\"src\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},\"link\":[{\"rel\":\"alternate\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/gCal/2005#eventFeed\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/acl/2007#accessControlList\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/acl/full\"},{\"rel\":\"self\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"},{\"rel\":\"edit\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/allcalendars/full/foo_bar%40gmail.com\"}],\"author\":[{\"name\":{\"$t\":\"foo_bar@gmail.com\"},\"email\":{\"$t\":\"foo_bar@gmail.com\"}}],\"gCal$accesslevel\":{\"value\":\"owner\"},\"gCal$color\":{\"value\":\"#2952A3\"},\"gCal$hidden\":{\"value\":\"false\"},\"gCal$selected\":{\"value\":\"true\"},\"gCal$timezone\":{\"value\":\"Asia/Jerusalem\"},\"gCal$timesCleaned\":{\"value\":0}}\
|
66
|
+
]}}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.one_calendar
|
70
|
+
"{\"version\":\"1.0\",\"encoding\":\"UTF-8\",\"entry\":{\
|
71
|
+
\"xmlns\":\"http://www.w3.org/2005/Atom\",\
|
72
|
+
\"xmlns$gCal\":\"http://schemas.google.com/gCal/2005\",\
|
73
|
+
\"id\":{\
|
74
|
+
\"$t\":\"http://www.google.com/calendar/feeds/default/owncalendars/full/foo_bar%40gmail.com\"},\
|
75
|
+
\"published\":{\"$t\":\"2011-10-31T13:51:30.555Z\"},\"updated\":{\"$t\":\"2011-10-20T08:54:48.000Z\"},\
|
76
|
+
\"category\":[{\"scheme\":\"http://schemas.google.com/g/2005#kind\",\"term\":\"http://schemas.google.com/gCal/2005#calendarmeta\"}],\
|
77
|
+
\"title\":{\"$t\":\"Foo Bar\",\"type\":\"text\"},\
|
78
|
+
\"content\":{\"type\":\"application/atom+xml\",\"src\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},\
|
79
|
+
\"link\":[{\"rel\":\"alternate\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/gCal/2005#eventFeed\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/private/full\"},{\"rel\":\"http://schemas.google.com/acl/2007#accessControlList\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/foo_bar%40gmail.com/acl/full\"},{\"rel\":\"self\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/owncalendars/full/foo_bar%40gmail.com\"},{\"rel\":\"edit\",\"type\":\"application/atom+xml\",\"href\":\"https://www.google.com/calendar/feeds/default/owncalendars/full/foo_bar%40gmail.com\"}],\
|
80
|
+
\"author\":[{\"name\":{\"$t\":\"foo_bar@gmail.com\"},\"email\":{\"$t\":\"foo_bar@gmail.com\"}}],\
|
81
|
+
\"gCal$accesslevel\":{\"value\":\"owner\"},\
|
82
|
+
\"gCal$color\":{\"value\":\"#2952A3\"},\
|
83
|
+
\"gCal$hidden\":{\"value\":\"false\"},\
|
84
|
+
\"gCal$selected\":{\"value\":\"true\"},\
|
85
|
+
\"gCal$timezone\":{\"value\":\"Asia/Jerusalem\"},\
|
86
|
+
\"gCal$timesCleaned\":{\"value\":0}}}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.create_calendar
|
90
|
+
'{"apiVersion":"1.0","data":{"kind":"calendar#calendar","id":"http://www.google.com/calendar/feeds/default/owncalendars/full/'+NEW_CALENDAR_ID+'","created":"2011-10-31T14:33:52.882Z","updated":"1970-01-01T00:00:00.000Z","selfLink":"https://www.google.com/calendar/feeds/default/owncalendars/full/jq9dkvf8rrqkre9lf4k721vgs4%40group.calendar.google.com","canEdit":true}}'
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.one_contact
|
94
|
+
"{\"id\":\{\"$t\":\"http://www.google.com/m8/feeds/contacts/user%40gmail.com/base/7fb4bd3c0bd256bd\"},\
|
95
|
+
\"updated\":{\"$t\":\"2011-09-20T06:55:55.544Z\"},\
|
96
|
+
\"category\":[{\"scheme\":\"http://schemas.google.com/g/2005#kind\",\"term\":\"http://schemas.google.com/contact/2008#contact\"}],\
|
97
|
+
\"title\":{\"type\":\"text\",\"$t\":\"#{CONTACT_NAME}\"},\
|
98
|
+
\"link\":[{\"rel\":\"http://schemas.google.com/contacts/2008/rel#edit-photo\",\"type\":\"image/*\",\
|
99
|
+
\"href\":\"https://www.google.com/m8/feeds/photos/media/user%40gmail.com/7fb4bd3c0bd256bd/1B2M2Y8AsgTpgAmY7PhCfg\"},\
|
100
|
+
{\"rel\":\"self\",\"type\":\"application/atom+xml\",\
|
101
|
+
\"href\":\"https://www.google.com/m8/feeds/contacts/user%40gmail.com/full/#{CONTACT_ID}\"},\
|
102
|
+
{\"rel\":\"edit\",\"type\":\"application/atom+xml\",\
|
103
|
+
\"href\":\"https://www.google.com/m8/feeds/contacts/user%40gmail.com/full/#{CONTACT_ID}/1316501755544001\"}],\
|
104
|
+
\"gd$email\":[{\"rel\":\"http://schemas.google.com/g/2005#mobile\",\"address\":\"#{CONTACT_EMAIL}\"}],\
|
105
|
+
\"gd$phoneNumber\":[{\"rel\":\"http://schemas.google.com/g/2005#mobile\",\"$t\":\"#{CONTACT_PN}\"}],\
|
106
|
+
\"gd$extendedProperty\":[{\"xmlns\":\"\",\"name\":\"GCon\",\"$t\":\"\u003ccc\u003e0\u003c/cc\u003e\"}]}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.all_contacts(contacts=10)
|
110
|
+
"{\"feed\":{\"entry\":[#{Array.new(contacts,one_contact).join(',')}]}}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.refresh_token
|
114
|
+
'{"access_token":"a-valid-new-access-token","token_type":"Bearer","expires_in":3600}'
|
115
|
+
end
|
116
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'google_client'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
describe GoogleClient::User do
|
6
|
+
describe "while initializing" do
|
7
|
+
it "should set the OAuth credentials properly" do
|
8
|
+
GoogleClient::User.new(USER_TOKEN).oauth_credentials.should eql(USER_TOKEN)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "while fetching calendars" do
|
13
|
+
it "should fetch all the user calendars when no calendar_id is provided" do
|
14
|
+
stub_request(:get, "https://www.google.com/calendar/feeds/default/allcalendars/full?alt=json").
|
15
|
+
with(:headers => {"Accept" => "application/json", "Content-Type" => "application/json", :Authorization => "OAuth #{USER_TOKEN}"}).
|
16
|
+
to_return(:status => 200, :body => GoogleResponseMocks.all_calendars, :headers => {})
|
17
|
+
|
18
|
+
calendars = GoogleClient::User.new(USER_TOKEN).calendar
|
19
|
+
calendars.should be_instance_of(Array)
|
20
|
+
calendars.length.should eql(2)
|
21
|
+
calendars.each do |calendar|
|
22
|
+
calendar.should respond_to(:id)
|
23
|
+
calendar.id.should_not be_empty
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fetch a specific calendar when calendar_id is provided" do
|
28
|
+
stub_request(:get, "https://www.google.com/calendar/feeds/default/owncalendars/full/#{CALENDAR_ID}?alt=json").
|
29
|
+
with(:headers => {"Accept" => "application/json", "Content-Type" => "application/json", :Authorization => "OAuth #{USER_TOKEN}"}).
|
30
|
+
to_return(:status => 200, :body => GoogleResponseMocks.one_calendar, :headers => {})
|
31
|
+
calendar = GoogleClient::User.new(USER_TOKEN).calendar(CALENDAR_ID)
|
32
|
+
calendar.should be_instance_of(GoogleClient::Calendar)
|
33
|
+
calendar.should respond_to(:id)
|
34
|
+
calendar.id.should_not be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "while creating calendars" do
|
39
|
+
it "should create a calendar with valid title and details" do
|
40
|
+
stub_request(:post, "https://www.google.com/calendar/feeds/default/owncalendars/full?").
|
41
|
+
with(:body => "{\"data\":{\"title\":\"foo\",\"details\":\"bar\"}}",
|
42
|
+
:headers => {"Accept" => "application/json", "Content-Type" => "application/json", :Authorization => "OAuth #{USER_TOKEN}"}).
|
43
|
+
to_return(:status => 200, :body => GoogleResponseMocks.create_calendar, :headers => {})
|
44
|
+
calendar = GoogleClient::User.new(USER_TOKEN).create_calendar({:title => "foo", :details => "bar"})
|
45
|
+
calendar.should be_instance_of(GoogleClient::Calendar)
|
46
|
+
calendar.id.should eql(NEW_CALENDAR_ID)
|
47
|
+
calendar.title.should eql("foo")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "while fetching contacts" do
|
52
|
+
|
53
|
+
it "should fetch all the user contacts when no filter is provided" do
|
54
|
+
stub_request(:get, "https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000").
|
55
|
+
with(:headers => {"Accept" => "application/json", "Content-Type" => "application/json", :Authorization => "OAuth #{USER_TOKEN}"}).
|
56
|
+
to_return(:status => 200, :body => GoogleResponseMocks.all_contacts(100), :headers => {})
|
57
|
+
|
58
|
+
contacts = GoogleClient::User.new(USER_TOKEN).contacts
|
59
|
+
contacts.should be_instance_of(Array)
|
60
|
+
contacts.length.should eql(100)
|
61
|
+
contacts.each do |contact|
|
62
|
+
contact.should be_instance_of(GoogleClient::Contact)
|
63
|
+
contact.should have_valid_attributes CONTACT_NAME, [CONTACT_EMAIL], [CONTACT_PN]
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "while refreshing auth token" do
|
70
|
+
describe "when credentials are valid" do
|
71
|
+
it "should return a valid access token" do
|
72
|
+
refresh_token = "valid-refresh-token"
|
73
|
+
stub_request(:post, "https://accounts.google.com/o/oauth2/token?").
|
74
|
+
with(:body => "client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}&refresh_token=#{refresh_token}&grant_type=refresh_token",
|
75
|
+
:headers => {"Content-Type" => "application/x-www-form-urlencoded", :Authorization => "OAuth #{USER_TOKEN}"}).
|
76
|
+
to_return(:status => 200, :body => GoogleResponseMocks.refresh_token, :headers => {})
|
77
|
+
user = GoogleClient::User.new(USER_TOKEN)
|
78
|
+
token = user.refresh refresh_token, CLIENT_ID, CLIENT_SECRET
|
79
|
+
token.should be_instance_of(Hash)
|
80
|
+
["access_token", "token_type", "expires_in"].each do |key|
|
81
|
+
token.should have_key key
|
82
|
+
end
|
83
|
+
user.oauth_credentials.should eql USER_TOKEN
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return a valid access token and update the oauth credentials" do
|
87
|
+
refresh_token = "valid-refresh-token"
|
88
|
+
stub_request(:post, "https://accounts.google.com/o/oauth2/token?").
|
89
|
+
with(:body => "client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}&refresh_token=#{refresh_token}&grant_type=refresh_token",
|
90
|
+
:headers => {"Content-Type" => "application/x-www-form-urlencoded", :Authorization => "OAuth #{USER_TOKEN}"}).
|
91
|
+
to_return(:status => 200, :body => GoogleResponseMocks.refresh_token, :headers => {})
|
92
|
+
user = GoogleClient::User.new(USER_TOKEN)
|
93
|
+
token = user.refresh! refresh_token, CLIENT_ID, CLIENT_SECRET
|
94
|
+
token.should be_instance_of(Hash)
|
95
|
+
["access_token", "token_type", "expires_in"].each do |key|
|
96
|
+
token.should have_key key
|
97
|
+
end
|
98
|
+
user.oauth_credentials.should eql "a-valid-new-access-token"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- juandebravo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &2157293120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157293120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: addressable
|
27
|
+
requirement: &2157280100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157280100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2157279480 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2157279480
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2157277600 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2157277600
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: webmock
|
60
|
+
requirement: &2157275880 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2157275880
|
69
|
+
description: This gem is a wrapper on top of the Google API that allows a developer
|
70
|
+
to handle calendars, events, contacts on behalf of the user.
|
71
|
+
email:
|
72
|
+
- juandebravo@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- app/controllers/google_client_controller.rb
|
82
|
+
- app/views/google_client/show.html.erb
|
83
|
+
- config/routes.rb
|
84
|
+
- google_client.gemspec
|
85
|
+
- lib/google_client.rb
|
86
|
+
- lib/google_client/calendar.rb
|
87
|
+
- lib/google_client/contact.rb
|
88
|
+
- lib/google_client/engine.rb
|
89
|
+
- lib/google_client/error.rb
|
90
|
+
- lib/google_client/event.rb
|
91
|
+
- lib/google_client/format.rb
|
92
|
+
- lib/google_client/http_connection.rb
|
93
|
+
- lib/google_client/profile.rb
|
94
|
+
- lib/google_client/user.rb
|
95
|
+
- lib/google_client/version.rb
|
96
|
+
- spec/calendar_spec.rb
|
97
|
+
- spec/contact_spec.rb
|
98
|
+
- spec/event_spec.rb
|
99
|
+
- spec/google_client_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/user_spec.rb
|
102
|
+
homepage: http://www.github.com/juandebravo/google_client
|
103
|
+
licenses: []
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.10
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Ease way to get access to Google API.
|
126
|
+
test_files:
|
127
|
+
- spec/calendar_spec.rb
|
128
|
+
- spec/contact_spec.rb
|
129
|
+
- spec/event_spec.rb
|
130
|
+
- spec/google_client_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- spec/user_spec.rb
|
133
|
+
has_rdoc:
|