kulesa-contacts 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +51 -0
- data/LICENSE +18 -0
- data/README.markdown +111 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/kulesa-contacts.gemspec +104 -0
- data/lib/contacts.rb +90 -0
- data/lib/contacts/consumer.rb +123 -0
- data/lib/contacts/google.rb +85 -0
- data/lib/contacts/oauth_consumer.rb +71 -0
- data/lib/contacts/railtie.rb +14 -0
- data/lib/contacts/util.rb +24 -0
- data/lib/contacts/version.rb +10 -0
- data/lib/contacts/windows_live.rb +192 -0
- data/lib/contacts/yahoo.rb +89 -0
- data/spec/config/contacts.yml +15 -0
- data/spec/contact_spec.rb +29 -0
- data/spec/feeds/google-many.xml +76 -0
- data/spec/feeds/wl_contacts.xml +29 -0
- data/spec/feeds/yh_contacts.txt +241 -0
- data/spec/gmail/google_spec.rb +54 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/windows_live/windows_live_spec.rb +44 -0
- data/spec/yahoo/yahoo_spec.rb +52 -0
- metadata +213 -0
data/.gitmodules
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem "httparty"
|
3
|
+
gem "hpricot"
|
4
|
+
gem "nokogiri"
|
5
|
+
gem "oauth", "0.4.0"
|
6
|
+
gem "json"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.1.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.1"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem "mocha"
|
14
|
+
gem "fakeweb"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
crack (0.1.8)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
fakeweb (1.3.0)
|
7
|
+
git (1.2.5)
|
8
|
+
hpricot (0.8.4)
|
9
|
+
hpricot (0.8.4-java)
|
10
|
+
httparty (0.7.7)
|
11
|
+
crack (= 0.1.8)
|
12
|
+
jeweler (1.5.2)
|
13
|
+
bundler (~> 1.0.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
json (1.5.1)
|
17
|
+
json (1.5.1-java)
|
18
|
+
mocha (0.9.12)
|
19
|
+
nokogiri (1.4.4)
|
20
|
+
nokogiri (1.4.4-java)
|
21
|
+
weakling (>= 0.0.3)
|
22
|
+
oauth (0.4.0)
|
23
|
+
rake (0.8.7)
|
24
|
+
rcov (0.9.9)
|
25
|
+
rcov (0.9.9-java)
|
26
|
+
rspec (2.1.0)
|
27
|
+
rspec-core (~> 2.1.0)
|
28
|
+
rspec-expectations (~> 2.1.0)
|
29
|
+
rspec-mocks (~> 2.1.0)
|
30
|
+
rspec-core (2.1.0)
|
31
|
+
rspec-expectations (2.1.0)
|
32
|
+
diff-lcs (~> 1.1.2)
|
33
|
+
rspec-mocks (2.1.0)
|
34
|
+
weakling (0.0.4-java)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
java
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
fakeweb
|
43
|
+
hpricot
|
44
|
+
httparty
|
45
|
+
jeweler (~> 1.5.1)
|
46
|
+
json
|
47
|
+
mocha
|
48
|
+
nokogiri
|
49
|
+
oauth (= 0.4.0)
|
50
|
+
rcov
|
51
|
+
rspec (~> 2.1.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Mislav Marohnić
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
## Contacts
|
2
|
+
|
3
|
+
Fetch users' contact lists without asking them to provide their
|
4
|
+
passwords, as painlessly as possible.
|
5
|
+
|
6
|
+
Contacts provides adapters for:
|
7
|
+
|
8
|
+
* Google
|
9
|
+
* Yahoo!
|
10
|
+
* Windows Live
|
11
|
+
|
12
|
+
## Basic usage instructions
|
13
|
+
|
14
|
+
First, register your application with the service providers you
|
15
|
+
require. Instructions below under "Setting up your accounts".
|
16
|
+
|
17
|
+
Now, create a consumer:
|
18
|
+
|
19
|
+
consumer = Contacts::Google.new
|
20
|
+
consumer = Contacts::Yahoo.new
|
21
|
+
consumer = Contacts::WindowsLive.new
|
22
|
+
# OR by parameter:
|
23
|
+
# provider is one of :google, :yahoo, :windows_live
|
24
|
+
consumer = Contacts.new_consumer(provider)
|
25
|
+
|
26
|
+
Now, direct your user to:
|
27
|
+
|
28
|
+
consumer.authentication_url(return_url)
|
29
|
+
|
30
|
+
`return_url` is the page the user will be redirected to by the service
|
31
|
+
once authorization has been granted. You should also persist the
|
32
|
+
consumer object so you can grab the contacts once the user returns:
|
33
|
+
|
34
|
+
session[:consumer] = consumer.serialize
|
35
|
+
|
36
|
+
Now in the request handler of the return_url above:
|
37
|
+
|
38
|
+
consumer = Contacts.deserialize(session[:consumer])
|
39
|
+
if consumer.authorize(params)
|
40
|
+
@contacts = consumer.contacts
|
41
|
+
else
|
42
|
+
# handle error
|
43
|
+
end
|
44
|
+
|
45
|
+
Here, `params` is the hash of request parameters that the user returns
|
46
|
+
with. `consumer.authorize` returns true if the authorization was
|
47
|
+
successful, false otherwise.
|
48
|
+
|
49
|
+
The list of `@contacts` are `Contacts::Contact` objects which have
|
50
|
+
these attributes:
|
51
|
+
|
52
|
+
* name
|
53
|
+
* emails
|
54
|
+
|
55
|
+
## Setting up your accounts
|
56
|
+
|
57
|
+
### Google
|
58
|
+
|
59
|
+
Set up your projects
|
60
|
+
[here](http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html).
|
61
|
+
|
62
|
+
* When redirecting to an unverified domain (e.g., localhost), the
|
63
|
+
user sees a warning when authorizing access.
|
64
|
+
|
65
|
+
What this means:
|
66
|
+
|
67
|
+
* You can use the same consumer key for development as production.
|
68
|
+
|
69
|
+
### Yahoo
|
70
|
+
|
71
|
+
Set up your projects [here](https://developer.apps.yahoo.com/projects)
|
72
|
+
|
73
|
+
* When a project's domain is verified, you must redirect to it.
|
74
|
+
* When a project's domain is not verified, you can redirect anywhere, and the
|
75
|
+
user sees a warning when authorizing access.
|
76
|
+
|
77
|
+
What this means:
|
78
|
+
|
79
|
+
* Set up separate production and development projects.
|
80
|
+
* Verify the domain of your production project. You will only be able to
|
81
|
+
redirect to your production domain when using this key.
|
82
|
+
* Don't verify the domain of your development project. You will be able to
|
83
|
+
redirect to any domain when using this key.
|
84
|
+
|
85
|
+
## Windows Live
|
86
|
+
|
87
|
+
Set up your projects [here](http://msdn.microsoft.com/en-us/library/cc287659.aspx).
|
88
|
+
|
89
|
+
* There is no domain verification step.
|
90
|
+
* The domain cannot be localhost, an IP address, or have a query string.
|
91
|
+
* You must redirect to the project's domain, on any port, and the URL may not
|
92
|
+
have a query string or fragment.
|
93
|
+
* You must specify a privacy policy URL.
|
94
|
+
|
95
|
+
What this means:
|
96
|
+
|
97
|
+
* Set up separate production and development projects.
|
98
|
+
* For development, use a domain like myapp.local.
|
99
|
+
* Map this domain to 127.0.0.1 in /etc/hosts or a local DNS server.
|
100
|
+
* If you want to run your app on a different domain (e.g., localhost:3000),
|
101
|
+
redirect the POST from Windows Live to a GET on the original domain. This
|
102
|
+
ensures the popup window has the same origin as the opener page, in
|
103
|
+
accordance with browser same origin policies.
|
104
|
+
|
105
|
+
## Copyright
|
106
|
+
|
107
|
+
Copyright (c) 2010 [George Ogata](mailto:george.ogata@gmail.com) See
|
108
|
+
LICENSE for details.
|
109
|
+
|
110
|
+
Derived from [Mislav's Contacts](http://github.com/mislav/contacts),
|
111
|
+
Copyright (c) 2009 [Mislav Marohnić](mailto:mislav.marohnic@gmail.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
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 = "kulesa-contacts"
|
16
|
+
gem.homepage = "https://github.com/kulesa/contacts"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "Import users' contacts lists from Google, Yahoo!, and Windows Live."
|
19
|
+
gem.description = "Import users' contacts lists from Google, Yahoo!, and Windows Live."
|
20
|
+
gem.email = "kulesa@gmail.com"
|
21
|
+
gem.authors = ["Mislav Marohnic", "George Odata", "Julian Countu"]
|
22
|
+
end
|
23
|
+
|
24
|
+
Jeweler::RubygemsDotOrgTasks.new
|
25
|
+
|
26
|
+
require 'rspec/core'
|
27
|
+
require 'rspec/core/rake_task'
|
28
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
spec.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "gitnetworkitis #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.6
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kulesa-contacts}
|
8
|
+
s.version = "0.2.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mislav Marohnic", "George Odata", "Julian Countu"]
|
12
|
+
s.date = %q{2011-06-03}
|
13
|
+
s.description = %q{Import users' contacts lists from Google, Yahoo!, and Windows Live.}
|
14
|
+
s.email = %q{kulesa@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitmodules",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"kulesa-contacts.gemspec",
|
28
|
+
"lib/contacts.rb",
|
29
|
+
"lib/contacts/consumer.rb",
|
30
|
+
"lib/contacts/google.rb",
|
31
|
+
"lib/contacts/oauth_consumer.rb",
|
32
|
+
"lib/contacts/railtie.rb",
|
33
|
+
"lib/contacts/util.rb",
|
34
|
+
"lib/contacts/version.rb",
|
35
|
+
"lib/contacts/windows_live.rb",
|
36
|
+
"lib/contacts/yahoo.rb",
|
37
|
+
"spec/config/contacts.yml",
|
38
|
+
"spec/contact_spec.rb",
|
39
|
+
"spec/feeds/google-many.xml",
|
40
|
+
"spec/feeds/wl_contacts.xml",
|
41
|
+
"spec/feeds/yh_contacts.txt",
|
42
|
+
"spec/gmail/google_spec.rb",
|
43
|
+
"spec/rcov.opts",
|
44
|
+
"spec/spec.opts",
|
45
|
+
"spec/spec_helper.rb",
|
46
|
+
"spec/windows_live/windows_live_spec.rb",
|
47
|
+
"spec/yahoo/yahoo_spec.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{https://github.com/kulesa/contacts}
|
50
|
+
s.licenses = ["MIT"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.6.2}
|
53
|
+
s.summary = %q{Import users' contacts lists from Google, Yahoo!, and Windows Live.}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/contact_spec.rb",
|
56
|
+
"spec/gmail/google_spec.rb",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"spec/windows_live/windows_live_spec.rb",
|
59
|
+
"spec/yahoo/yahoo_spec.rb"
|
60
|
+
]
|
61
|
+
|
62
|
+
if s.respond_to? :specification_version then
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
67
|
+
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
|
68
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
69
|
+
s.add_runtime_dependency(%q<oauth>, ["= 0.4.0"])
|
70
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
72
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
74
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
77
|
+
else
|
78
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
79
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
80
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
81
|
+
s.add_dependency(%q<oauth>, ["= 0.4.0"])
|
82
|
+
s.add_dependency(%q<json>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
84
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
85
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
86
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
87
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
88
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
89
|
+
end
|
90
|
+
else
|
91
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
92
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
93
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
94
|
+
s.add_dependency(%q<oauth>, ["= 0.4.0"])
|
95
|
+
s.add_dependency(%q<json>, [">= 0"])
|
96
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
97
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
98
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
99
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
100
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
101
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
data/lib/contacts.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'contacts/version'
|
3
|
+
|
4
|
+
if defined?(Rails)
|
5
|
+
require "contacts/railtie"
|
6
|
+
end
|
7
|
+
|
8
|
+
module Contacts
|
9
|
+
|
10
|
+
Identifier = 'Ruby Contacts v' + VERSION::STRING
|
11
|
+
|
12
|
+
def self.configure(configuration)
|
13
|
+
configuration.each do |key, value|
|
14
|
+
klass =
|
15
|
+
case key.to_s
|
16
|
+
when 'google'
|
17
|
+
Google
|
18
|
+
when 'yahoo'
|
19
|
+
Yahoo
|
20
|
+
when 'windows_live'
|
21
|
+
WindowsLive
|
22
|
+
else
|
23
|
+
raise ArgumentError, "unknown consumer: #{key}"
|
24
|
+
end
|
25
|
+
klass.configure(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Contact
|
30
|
+
attr_reader :name, :username, :emails
|
31
|
+
|
32
|
+
def initialize(emails, name, username = "")
|
33
|
+
@name = name
|
34
|
+
@emails = Array(emails)
|
35
|
+
@username = username
|
36
|
+
end
|
37
|
+
|
38
|
+
def email
|
39
|
+
@emails.first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.deserialize_consumer(name, serialized_data)
|
44
|
+
klass = consumer_class_for(name) and
|
45
|
+
klass.deserialize(serialized_data)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.new(name, *args, &block)
|
49
|
+
klass = consumer_class_for(name) and
|
50
|
+
klass.new(*args, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.consumer_class_for(name)
|
54
|
+
class_name = name.to_s.gsub(/(?:\A|_)(.)/){|s| $1.upcase}
|
55
|
+
class_name.sub!(/Oauth/, 'OAuth')
|
56
|
+
class_name.sub!(/Bbauth/, 'BBAuth')
|
57
|
+
begin
|
58
|
+
klass = const_get(class_name)
|
59
|
+
rescue NameError
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
klass < Consumer ? klass : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.verbose?
|
66
|
+
'irb' == $0
|
67
|
+
end
|
68
|
+
|
69
|
+
class Error < StandardError
|
70
|
+
end
|
71
|
+
|
72
|
+
class TooManyRedirects < Error
|
73
|
+
attr_reader :response, :location
|
74
|
+
|
75
|
+
MAX_REDIRECTS = 2
|
76
|
+
|
77
|
+
def initialize(response)
|
78
|
+
@response = response
|
79
|
+
@location = @response['Location']
|
80
|
+
super "exceeded maximum of #{MAX_REDIRECTS} redirects (Location: #{location})"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
autoload :Util, 'contacts/util'
|
85
|
+
autoload :Consumer, 'contacts/consumer'
|
86
|
+
autoload :OAuthConsumer, 'contacts/oauth_consumer'
|
87
|
+
autoload :Google, 'contacts/google'
|
88
|
+
autoload :Yahoo, 'contacts/yahoo'
|
89
|
+
autoload :WindowsLive, 'contacts/windows_live'
|
90
|
+
end
|