omnigroupcontacts 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +39 -0
  5. data/README.md +132 -0
  6. data/Rakefile +7 -0
  7. data/lib/omnigroupcontacts.rb +19 -0
  8. data/lib/omnigroupcontacts/authorization/oauth1.rb +122 -0
  9. data/lib/omnigroupcontacts/authorization/oauth2.rb +87 -0
  10. data/lib/omnigroupcontacts/builder.rb +30 -0
  11. data/lib/omnigroupcontacts/http_utils.rb +101 -0
  12. data/lib/omnigroupcontacts/importer.rb +5 -0
  13. data/lib/omnigroupcontacts/importer/gmailgroup.rb +238 -0
  14. data/lib/omnigroupcontacts/integration_test.rb +36 -0
  15. data/lib/omnigroupcontacts/middleware/base_oauth.rb +120 -0
  16. data/lib/omnigroupcontacts/middleware/oauth1.rb +70 -0
  17. data/lib/omnigroupcontacts/middleware/oauth2.rb +80 -0
  18. data/lib/omnigroupcontacts/parse_utils.rb +56 -0
  19. data/omnigroupcontacts-0.3.10.gem +0 -0
  20. data/omnigroupcontacts-0.3.8.gem +0 -0
  21. data/omnigroupcontacts-0.3.9.gem +0 -0
  22. data/omnigroupcontacts.gemspec +25 -0
  23. data/spec/omnicontacts/authorization/oauth1_spec.rb +82 -0
  24. data/spec/omnicontacts/authorization/oauth2_spec.rb +92 -0
  25. data/spec/omnicontacts/http_utils_spec.rb +79 -0
  26. data/spec/omnicontacts/importer/facebook_spec.rb +120 -0
  27. data/spec/omnicontacts/importer/gmail_spec.rb +194 -0
  28. data/spec/omnicontacts/importer/hotmail_spec.rb +106 -0
  29. data/spec/omnicontacts/importer/linkedin_spec.rb +67 -0
  30. data/spec/omnicontacts/importer/yahoo_spec.rb +124 -0
  31. data/spec/omnicontacts/integration_test_spec.rb +51 -0
  32. data/spec/omnicontacts/middleware/base_oauth_spec.rb +53 -0
  33. data/spec/omnicontacts/middleware/oauth1_spec.rb +78 -0
  34. data/spec/omnicontacts/middleware/oauth2_spec.rb +67 -0
  35. data/spec/omnicontacts/parse_utils_spec.rb +53 -0
  36. data/spec/spec_helper.rb +12 -0
  37. metadata +37 -2
@@ -0,0 +1,120 @@
1
+ require "spec_helper"
2
+ require "omnigroupcontacts/importer/facebook"
3
+
4
+ describe OmniGroupContacts::Importer::Facebook do
5
+
6
+ let(:facebook) { OmniGroupContacts::Importer::Facebook.new({}, "client_id", "client_secret") }
7
+
8
+ let(:self_response) {
9
+ '{
10
+ "first_name":"Chris",
11
+ "last_name":"Johnson",
12
+ "name":"Chris Johnson",
13
+ "id":"543216789",
14
+ "gender":"male",
15
+ "birthday":"06/21/1982",
16
+ "significant_other":{"id": "243435322"},
17
+ "relationship_status": "Married",
18
+ "picture":{"data":{"url":"http://profile.ak.fbcdn.net/hprofile-ak-snc6/186364_543216789_2089044200_q.jpg","is_silhouette":false}},
19
+ "email": "chrisjohnson@gmail.com"
20
+ }'
21
+ }
22
+
23
+ let(:spouse_response) {
24
+ '{
25
+ "first_name":"Mary",
26
+ "last_name":"Johnson",
27
+ "name":"Mary Johnson",
28
+ "id":"243435322",
29
+ "gender":"female",
30
+ "birthday":"01/21",
31
+ "picture":{"data":{"url":"http://profile.ak.fbcdn.net/hprofile-ak-snc6/186364_243435322_2089044200_q.jpg","is_silhouette":false}}
32
+ }'
33
+ }
34
+
35
+ let(:contacts_as_json) {
36
+ '{"data":[
37
+ {
38
+ "first_name":"John",
39
+ "last_name":"Smith",
40
+ "name":"John Smith",
41
+ "id":"608061886",
42
+ "gender":"male",
43
+ "birthday":"06/21",
44
+ "relationship":"cousin",
45
+ "picture":{"data":{"url":"http://profile.ak.fbcdn.net/hprofile-ak-snc6/186364_608061886_2089044200_q.jpg","is_silhouette":false}}
46
+ }
47
+ ]
48
+ }' }
49
+
50
+ describe "fetch_contacts_using_access_token" do
51
+ let(:token) { "token" }
52
+ let(:token_type) { "token_type" }
53
+
54
+ before(:each) do
55
+ facebook.instance_variable_set(:@env, {})
56
+ end
57
+
58
+ it "should request the contacts by providing the token in the url" do
59
+ facebook.should_receive(:https_get) do |host, self_path, params, headers|
60
+ params[:access_token].should eq(token)
61
+ params[:fields].should eq('first_name,last_name,name,id,gender,birthday,picture,relationship_status,significant_other,email')
62
+ self_response
63
+ end
64
+ facebook.should_receive(:https_get) do |host, spouse_path, params, headers|
65
+ params[:access_token].should eq(token)
66
+ params[:fields].should eq('first_name,last_name,name,id,gender,birthday,picture')
67
+ spouse_response
68
+ end
69
+ facebook.should_receive(:https_get) do |host, path, params, headers|
70
+ params[:access_token].should eq(token)
71
+ params[:fields].should eq('first_name,last_name,name,id,gender,birthday,picture,relationship')
72
+ contacts_as_json
73
+ end.exactly(1).times
74
+ facebook.should_receive(:https_get) do |host, path, params, headers|
75
+ params[:access_token].should eq(token)
76
+ params[:fields].should eq('first_name,last_name,name,id,gender,birthday,picture')
77
+ contacts_as_json
78
+ end.exactly(1).times
79
+
80
+ facebook.fetch_contacts_using_access_token token, token_type
81
+ end
82
+
83
+ it "should correctly parse id, name,email,gender, birthday, profile picture and relation" do
84
+ 1.times { facebook.should_receive(:https_get).and_return(self_response) }
85
+ 1.times { facebook.should_receive(:https_get) }
86
+ 2.times { facebook.should_receive(:https_get).and_return(contacts_as_json) }
87
+ result = facebook.fetch_contacts_using_access_token token, token_type
88
+ result.size.should be(1)
89
+ result.first[:id].should eq('608061886')
90
+ result.first[:first_name].should eq('John')
91
+ result.first[:last_name].should eq('Smith')
92
+ result.first[:name].should eq('John Smith')
93
+ result.first[:email].should be_nil
94
+ result.first[:gender].should eq('male')
95
+ result.first[:birthday].should eq({:day=>21, :month=>06, :year=>nil})
96
+ result.first[:profile_picture].should eq('https://graph.facebook.com/608061886/picture')
97
+ result.first[:relation].should eq('cousin')
98
+ end
99
+
100
+ it "should correctly parse and set logged in user information" do
101
+ 1.times { facebook.should_receive(:https_get).and_return(self_response) }
102
+ 1.times { facebook.should_receive(:https_get) }
103
+ 2.times { facebook.should_receive(:https_get).and_return(contacts_as_json) }
104
+
105
+ facebook.fetch_contacts_using_access_token token, token_type
106
+
107
+ user = facebook.instance_variable_get(:@env)["omnigroupcontacts.user"]
108
+ user.should_not be_nil
109
+ user[:id].should eq("543216789")
110
+ user[:first_name].should eq("Chris")
111
+ user[:last_name].should eq("Johnson")
112
+ user[:name].should eq("Chris Johnson")
113
+ user[:email].should eq("chrisjohnson@gmail.com")
114
+ user[:gender].should eq("male")
115
+ user[:birthday].should eq({:day=>21, :month=>06, :year=>1982})
116
+ user[:profile_picture].should eq("https://graph.facebook.com/543216789/picture")
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,194 @@
1
+ require "spec_helper"
2
+ require "omnigroupcontacts/importer/gmail"
3
+
4
+ describe OmniGroupContacts::Importer::Gmail do
5
+
6
+ let(:gmail) { OmniGroupContacts::Importer::Gmail.new({}, "client_id", "client_secret") }
7
+
8
+ let(:gmail_with_scope_args) { OmniGroupContacts::Importer::Gmail.new({}, "client_id", "client_secret", {scope: "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/contacts.readonly"}) }
9
+
10
+ let(:self_response) {
11
+ '{
12
+ "id":"16482944006464829443",
13
+ "email":"chrisjohnson@gmail.com",
14
+ "name":"Chris Johnson",
15
+ "given_name":"Chris",
16
+ "family_name":"Johnson",
17
+ "picture":"https://lh3.googleusercontent.com/-b8aFbTBM/AAAAAAI/IWA/vsek/photo.jpg",
18
+ "gender":"male",
19
+ "birthday":"1982-06-21"
20
+ }'
21
+ }
22
+
23
+ let(:contacts_as_json) {
24
+ '{"version":"1.0","encoding":"UTF-8",
25
+ "feed":{
26
+ "xmlns":"http://www.w3.org/2005/Atom",
27
+ "xmlns$openSearch":"http://a9.com/-/spec/opensearch/1.1/",
28
+ "xmlns$gContact":"http://schemas.google.com/contact/2008",
29
+ "xmlns$batch":"http://schemas.google.com/gdata/batch",
30
+ "xmlns$gd":"http://schemas.google.com/g/2005",
31
+ "gd$etag":"W/\"C0YHRno7fSt7I2A9WhBSQ0Q.\"",
32
+
33
+ "id":{"$t":"logged_in_user@gmail.com"},
34
+ "updated":{"$t":"2013-02-20T20:12:17.405Z"},
35
+ "category":[{
36
+ "scheme":"http://schemas.google.com/g/2005#kind",
37
+ "term":"http://schemas.google.com/contact/2008#contact"
38
+ }],
39
+
40
+ "title":{"$t":"Users\'s Contacts"},
41
+ "link":[
42
+ {"rel":"alternate","type":"text/html","href":"http://www.google.com/"},
43
+ {"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full"},
44
+ {"rel":"http://schemas.google.com/g/2005#post","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full"},
45
+ {"rel":"http://schemas.google.com/g/2005#batch","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/batch"},
46
+ {"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full?alt\u003djson\u0026max-results\u003d1"},
47
+ {"rel":"next","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full?alt\u003djson\u0026start-index\u003d2\u0026max-results\u003d1"}
48
+ ],
49
+ "author":[{"name":{"$t":"Edward"},"email":{"$t":"logged_in_user@gmail.com"}}],
50
+ "generator":{"version":"1.0","uri":"http://www.google.com/m8/feeds","$t":"Contacts"},
51
+ "openSearch$totalResults":{"$t":"1007"},
52
+ "openSearch$startIndex":{"$t":"1"},
53
+ "openSearch$itemsPerPage":{"$t":"1"},
54
+ "entry":[
55
+ {
56
+ "gd$etag":"\"R3oyfDVSLyt7I2A9WhBTSEULRA0.\"",
57
+ "id":{"$t":"http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1"},
58
+ "updated":{"$t":"2013-02-14T22:36:36.494Z"},
59
+ "app$edited":{"xmlns$app":"http://www.w3.org/2007/app","$t":"2013-02-14T22:36:36.494Z"},
60
+ "category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/contact/2008#contact"}],
61
+ "title":{"$t":"Edward Bennet"},
62
+ "link":[
63
+ {"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*","href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/1"},
64
+ {"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"},
65
+ {"rel":"edit","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"}
66
+ ],
67
+ "gd$name":{
68
+ "gd$fullName":{"$t":"Edward Bennet"},
69
+ "gd$givenName":{"$t":"Edward"},
70
+ "gd$familyName":{"$t":"Bennet"}
71
+ },
72
+ "gd$organization":[{"rel":"http://schemas.google.com/g/2005#other","gd$orgName":{"$t":"Google"},"gd$orgTitle":{"$t":"Master Developer"}}],
73
+ "gContact$birthday":{"when":"1954-07-02"},
74
+ "gContact$relation":{"rel":"father"},
75
+ "gContact$gender":{"value":"male"},
76
+ "gContact$event":[{"rel":"anniversary","gd$when":{"startTime":"1983-04-21"}},{"label":"New Job","gd$when":{"startTime":"2014-12-01"}}],
77
+ "gd$email":[{"rel":"http://schemas.google.com/g/2005#other","address":"bennet@gmail.com","primary":"true"}],
78
+ "gContact$groupMembershipInfo":[{"deleted":"false","href":"http://www.google.com/m8/feeds/groups/logged_in_user%40gmail.com/base/6"}],
79
+ "gd$structuredPostalAddress":[{"rel":"http://schemas.google.com/g/2005#home","gd$formattedAddress":{"$t":"1313 Trashview Court\nApt. 13\nNowheresville, OK 66666"},"gd$street":{"$t":"1313 Trashview Court\nApt. 13"},"gd$postcode":{"$t":"66666"},"gd$country":{"code":"VA","$t":"Valoran"},"gd$city":{"$t":"Nowheresville"},"gd$region":{"$t":"OK"}}],
80
+ "gd$phoneNumber":[{"rel":"http://schemas.google.com/g/2005#mobile","uri":"tel:+34-653-15-76-88","$t":"653157688"}]
81
+ },
82
+ {
83
+ "gd$etag":"\"R3oyfDVSLyt7I2A9WhBTSEULRA0.\"",
84
+ "id":{"$t":"http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1"},
85
+ "updated":{"$t":"2013-02-15T22:36:36.494Z"},
86
+ "app$edited":{"xmlns$app":"http://www.w3.org/2007/app","$t":"2013-02-15T22:36:36.494Z"},
87
+ "category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/contact/2008#contact"}],
88
+ "title":{"$t":"Emilia Fox"},
89
+ "link":[
90
+ {"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*","href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/1"},
91
+ {"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"},
92
+ {"rel":"edit","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"}
93
+ ],
94
+ "gd$name":{
95
+ "gd$fullName":{"$t":"Emilia Fox"},
96
+ "gd$givenName":{"$t":"Emilia"},
97
+ "gd$familyName":{"$t":"Fox"}
98
+ },
99
+ "gContact$birthday":{"when":"1974-02-10"},
100
+ "gContact$relation":[{"rel":"spouse"}],
101
+ "gContact$gender":{"value":"female"},
102
+ "gd$email":[{"rel":"http://schemas.google.com/g/2005#other","address":"emilia.fox@gmail.com","primary":"true"}],
103
+ "gContact$groupMembershipInfo":[{"deleted":"false","href":"http://www.google.com/m8/feeds/groups/logged_in_user%40gmail.com/base/6"}]
104
+ }]
105
+ }
106
+ }'
107
+ }
108
+
109
+ describe "fetch_contacts_using_access_token" do
110
+ let(:token) { "token" }
111
+ let(:token_type) { "token_type" }
112
+
113
+ before(:each) do
114
+ gmail.instance_variable_set(:@env, {})
115
+ gmail_with_scope_args.instance_variable_set(:@env, {})
116
+ end
117
+
118
+ it "should request the contacts by specifying version and code in the http headers" do
119
+ gmail.should_receive(:https_get) do |host, path, params, headers|
120
+ headers["GData-Version"].should eq("3.0")
121
+ headers["Authorization"].should eq("#{token_type} #{token}")
122
+ self_response
123
+ end
124
+ gmail.should_receive(:https_get) do |host, path, params, headers|
125
+ headers["GData-Version"].should eq("3.0")
126
+ headers["Authorization"].should eq("#{token_type} #{token}")
127
+ contacts_as_json
128
+ end
129
+ gmail.fetch_contacts_using_access_token token, token_type
130
+
131
+ gmail.scope.should eq "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
132
+ gmail_with_scope_args.scope.should eq "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/contacts.readonly"
133
+ end
134
+
135
+ it "should correctly parse id, name, email, gender, birthday, profile picture and relation for 1st contact" do
136
+ gmail.should_receive(:https_get)
137
+ gmail.should_receive(:https_get).and_return(contacts_as_json)
138
+ result = gmail.fetch_contacts_using_access_token token, token_type
139
+
140
+ result.size.should be(2)
141
+ result.first[:id].should eq('http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1')
142
+ result.first[:first_name].should eq('Edward')
143
+ result.first[:last_name].should eq('Bennet')
144
+ result.first[:name].should eq("Edward Bennet")
145
+ result.first[:email].should eq("bennet@gmail.com")
146
+ result.first[:gender].should eq("male")
147
+ result.first[:birthday].should eq({:day=>02, :month=>07, :year=>1954})
148
+ result.first[:relation].should eq('father')
149
+ result.first[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/bennet")
150
+ result.first[:dates][0][:name].should eq("anniversary")
151
+ end
152
+
153
+ it "should correctly parse id, name, email, gender, birthday, profile picture, snailmail address, phone and relation for 2nd contact" do
154
+ gmail.should_receive(:https_get)
155
+ gmail.should_receive(:https_get).and_return(contacts_as_json)
156
+ result = gmail.fetch_contacts_using_access_token token, token_type
157
+ result.size.should be(2)
158
+ result.last[:id].should eq('http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1')
159
+ result.last[:first_name].should eq('Emilia')
160
+ result.last[:last_name].should eq('Fox')
161
+ result.last[:name].should eq("Emilia Fox")
162
+ result.last[:email].should eq("emilia.fox@gmail.com")
163
+ result.last[:gender].should eq("female")
164
+ result.last[:birthday].should eq({:day=>10, :month=>02, :year=>1974})
165
+ result.last[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/emilia.fox")
166
+ result.last[:relation].should eq('spouse')
167
+ result.first[:address_1].should eq('1313 Trashview Court')
168
+ result.first[:address_2].should eq('Apt. 13')
169
+ result.first[:city].should eq('Nowheresville')
170
+ result.first[:region].should eq('OK')
171
+ result.first[:country].should eq('VA')
172
+ result.first[:postcode].should eq('66666')
173
+ result.first[:phone_number].should eq('653157688')
174
+ end
175
+
176
+ it "should correctly parse and set logged in user information" do
177
+ gmail.should_receive(:https_get).and_return(self_response)
178
+ gmail.should_receive(:https_get).and_return(contacts_as_json)
179
+
180
+ gmail.fetch_contacts_using_access_token token, token_type
181
+
182
+ user = gmail.instance_variable_get(:@env)["omnigroupcontacts.user"]
183
+ user.should_not be_nil
184
+ user[:id].should eq("16482944006464829443")
185
+ user[:first_name].should eq("Chris")
186
+ user[:last_name].should eq("Johnson")
187
+ user[:name].should eq("Chris Johnson")
188
+ user[:email].should eq("chrisjohnson@gmail.com")
189
+ user[:gender].should eq("male")
190
+ user[:birthday].should eq({:day=>21, :month=>06, :year=>1982})
191
+ user[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/16482944006464829443")
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,106 @@
1
+ require "spec_helper"
2
+ require "omnigroupcontacts/importer/hotmail"
3
+
4
+ describe OmniGroupContacts::Importer::Hotmail do
5
+
6
+ let(:permissions) { "perm1, perm2" }
7
+ let(:hotmail) { OmniGroupContacts::Importer::Hotmail.new({}, "client_id", "client_secret", {:permissions => permissions}) }
8
+
9
+ let(:self_response) {
10
+ '{
11
+ "id": "4502de12390223d0",
12
+ "name": "Chris Johnson",
13
+ "first_name": "Chris",
14
+ "last_name": "Johnson",
15
+ "birth_day": 21,
16
+ "birth_month": 6,
17
+ "birth_year": 1982,
18
+ "gender": null,
19
+ "emails": {"preferred":"chrisjohnson@gmail.com", "account":"chrisjohn@gmail.com", "personal":null, "business":null}
20
+ }'
21
+ }
22
+
23
+ let(:contacts_as_json) {
24
+ '{
25
+ "data": [
26
+ {
27
+ "id": "contact.7fac34bb000000000000000000000000",
28
+ "first_name": "John",
29
+ "last_name": "Smith",
30
+ "name": "John Smith",
31
+ "gender": null,
32
+ "user_id": "123456",
33
+ "is_friend": false,
34
+ "is_favorite": false,
35
+ "birth_day": 5,
36
+ "birth_month": 6,
37
+ "birth_year":1952,
38
+ "email_hashes":["1234567890"]
39
+ }
40
+ ]}'
41
+ }
42
+
43
+ describe "fetch_contacts_using_access_token" do
44
+
45
+ let(:token) { "token" }
46
+ let(:token_type) { "token_type" }
47
+
48
+ before(:each) do
49
+ hotmail.instance_variable_set(:@env, {"HTTP_HOST" => "http://example.com"})
50
+ end
51
+
52
+ it "should request the contacts by providing the token in the url" do
53
+ hotmail.should_receive(:https_get) do |host, path, params, headers|
54
+ params[:access_token].should eq(token)
55
+ self_response
56
+ end
57
+
58
+ hotmail.should_receive(:https_get) do |host, path, params, headers|
59
+ params[:access_token].should eq(token)
60
+ contacts_as_json
61
+ end
62
+ hotmail.fetch_contacts_using_access_token token, token_type
63
+ end
64
+
65
+ it "should set requested permissions in the authorization url" do
66
+ hotmail.authorization_url.should match(/scope=#{Regexp.quote(CGI.escape(permissions))}/)
67
+ end
68
+
69
+ it "should correctly parse id, name, email, gender, birthday, profile picture, relation and email hashes" do
70
+ hotmail.should_receive(:https_get).and_return(self_response)
71
+ hotmail.should_receive(:https_get).and_return(contacts_as_json)
72
+ result = hotmail.fetch_contacts_using_access_token token, token_type
73
+
74
+ result.size.should be(1)
75
+ result.first[:id].should eq('123456')
76
+ result.first[:first_name].should eq("John")
77
+ result.first[:last_name].should eq('Smith')
78
+ result.first[:name].should eq("John Smith")
79
+ result.first[:email].should be_nil
80
+ result.first[:gender].should be_nil
81
+ result.first[:birthday].should eq({:day=>5, :month=>6, :year=>1952})
82
+ result.first[:profile_picture].should eq('https://apis.live.net/v5.0/123456/picture')
83
+ result.first[:relation].should be_nil
84
+ result.first[:email_hashes].should eq(["1234567890"])
85
+ end
86
+
87
+ it "should correctly parse and set logged in user information" do
88
+ hotmail.should_receive(:https_get).and_return(self_response)
89
+ hotmail.should_receive(:https_get).and_return(contacts_as_json)
90
+
91
+ hotmail.fetch_contacts_using_access_token token, token_type
92
+
93
+ user = hotmail.instance_variable_get(:@env)["omnigroupcontacts.user"]
94
+ user.should_not be_nil
95
+ user[:id].should eq('4502de12390223d0')
96
+ user[:first_name].should eq('Chris')
97
+ user[:last_name].should eq('Johnson')
98
+ user[:name].should eq('Chris Johnson')
99
+ user[:gender].should be_nil
100
+ user[:birthday].should eq({:day=>21, :month=>06, :year=>1982})
101
+ user[:email].should eq('chrisjohn@gmail.com')
102
+ user[:profile_picture].should eq('https://apis.live.net/v5.0/4502de12390223d0/picture')
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+ require "omnigroupcontacts/importer/linkedin"
3
+
4
+ describe OmniGroupContacts::Importer::Linkedin do
5
+
6
+ let(:linkedin) { OmniGroupContacts::Importer::Linkedin.new({}, "client_id", "client_secret", state: "ipsaeumeaque") }
7
+
8
+ let(:contacts_as_json) do
9
+ "{
10
+ \n \"_total\": 2,
11
+ \n \"values\": [
12
+ \n {
13
+ \n \"firstName\": \"Adolf\",
14
+ \n \"id\": \"k71S5q6MKe\",
15
+ \n \"lastName\": \"Witting\",
16
+ \n \"pictureUrl\": \"https://media.licdn.com/mpr/mprx/0_mLnj-7szw130pFRLB8Op7-p1Sxoyv53U3B47Scp1Sxoyv53U3B47Scp1Sxoyv53U3B47Sc\"\n
17
+ },
18
+ \n {
19
+ \n \"firstName\": \"Emmet\",
20
+ \n \"id\": \"ms5r3lI3J2\",
21
+ \n \"lastName\": \"Little\",
22
+ \n \"pictureUrl\": \"https://media.licdn.com/mpr/mprx/0_iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6\"\n
23
+ }
24
+ ]\n
25
+ }"
26
+ end
27
+
28
+ describe "fetch_contacts_using_access_token" do
29
+ let(:token) { "token" }
30
+ let(:token_type) { nil }
31
+
32
+ before(:each) do
33
+ linkedin.instance_variable_set(:@env, {})
34
+ end
35
+
36
+ it "should request the contacts by specifying code in the http headers" do
37
+ linkedin.should_receive(:https_get) do |host, path, params, headers|
38
+ headers["Authorization"].should eq("Bearer #{token}")
39
+ contacts_as_json
40
+ end
41
+ linkedin.fetch_contacts_using_access_token token, token_type
42
+ end
43
+
44
+ it "should correctly parse id, name, and profile picture for 1st contact" do
45
+ linkedin.should_receive(:https_get).and_return(contacts_as_json)
46
+ result = linkedin.fetch_contacts_using_access_token token, token_type
47
+
48
+ result.size.should be(2)
49
+ result.first[:id].should eq('k71S5q6MKe')
50
+ result.first[:first_name].should eq('Adolf')
51
+ result.first[:last_name].should eq('Witting')
52
+ result.first[:name].should eq("Adolf Witting")
53
+ result.first[:profile_picture].should eq("https://media.licdn.com/mpr/mprx/0_mLnj-7szw130pFRLB8Op7-p1Sxoyv53U3B47Scp1Sxoyv53U3B47Scp1Sxoyv53U3B47Sc")
54
+ end
55
+
56
+ it "should correctly parse id, name, and profile picture for 2nd contact" do
57
+ linkedin.should_receive(:https_get).and_return(contacts_as_json)
58
+ result = linkedin.fetch_contacts_using_access_token token, token_type
59
+ result.size.should be(2)
60
+ result.last[:id].should eq('ms5r3lI3J2')
61
+ result.last[:first_name].should eq('Emmet')
62
+ result.last[:last_name].should eq('Little')
63
+ result.last[:name].should eq("Emmet Little")
64
+ result.last[:profile_picture].should eq("https://media.licdn.com/mpr/mprx/0_iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6iH9m158zCdISt1X6")
65
+ end
66
+ end
67
+ end