oauth-contacts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oauth-contacts.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Joël AZÉMAR joel.azemar@gmail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # OAuth 2.0
2
+
3
+ This gem contains the API acces for grab contacts on Windows Live Id and Google Mail (Gmail).
4
+
5
+ ## Basic Usage
6
+
7
+ ## Supported Flows
8
+
9
+ ## Ruby
10
+
11
+ Tested with the following Ruby versions:
12
+
13
+ - RUBY 1.9.3-p0
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ require "oauth/contacts/version"
2
+ require 'oauth/contacts/base'
3
+ require 'oauth/contacts/oauth2'
4
+ require 'oauth/contacts/google'
5
+ require 'oauth/contacts/live'
6
+
7
+ module Oauth
8
+ module Contacts
9
+ class APIAuthenticationError < StandardError; end
10
+ class TypeNotFound < StandardError; end
11
+
12
+ SUPPORTED_PROVIDERS = ['google', 'live']
13
+
14
+ class << self
15
+
16
+ def supported_providers
17
+ @providers ||= SUPPORTED_PROVIDERS.map(&:to_s).join(', ')
18
+ end
19
+
20
+ def get_provider(provider)
21
+ if !SUPPORTED_PROVIDERS.include?(provider)
22
+ raise Oauth::Contacts::TypeNotFound, "#{provider} is not supported, please use one of the following : #{Oauth::Contacts.supported_providers}"
23
+ end
24
+
25
+ return ("Oauth::Contacts::" + provider.capitalize).constantize.new
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ module Oauth
2
+ module Contacts
3
+ class Base
4
+ attr_reader :consumer, :access_token, :callback_url
5
+
6
+ def initialize
7
+ end
8
+
9
+ def authorize_url
10
+ raise "Not Implemented"
11
+ end
12
+
13
+ def contacts
14
+ raise "Not Implemented"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: UTF-8
2
+ require 'oauth2'
3
+
4
+ # Create or Manage App => https://code.google.com/apis/console#:access
5
+ module Oauth
6
+ module Contacts
7
+ class Google < Oauth::Contacts::OAuth2
8
+
9
+ def initialize
10
+ super
11
+ @callback_url = Settings.oauth.contacts.google.callback_url
12
+
13
+ # GOOGLE
14
+ opts = { key: Settings.oauth.contacts.google.key, secret: Settings.oauth.contacts.google.secret,
15
+ extra: { site: 'https://accounts.google.com',
16
+ authorize_url: '/o/oauth2/auth',
17
+ token_url: '/o/oauth2/token',
18
+ max_redirects: 5,
19
+ raise_errors: true,
20
+ token_method: :post,
21
+ connection_opts: {} # [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
22
+ } }
23
+
24
+ @consumer = ::OAuth2::Client.new(opts[:key], opts[:secret], opts[:extra])
25
+ end
26
+
27
+ def authorize_url
28
+ scopes = Settings.oauth.contacts.google.scopes
29
+
30
+ # http://code.google.com/intl/fr-FR/apis/contacts/docs/3.0/developers_guide.html
31
+ extra_params = { scope: scopes.join(' '),
32
+ redirect_uri: callback_url,
33
+ response_type: 'code',
34
+ access_type: 'offline',
35
+ approval_prompt: 'force',
36
+ state: 'google' }
37
+
38
+ consumer.auth_code.authorize_url( extra_params )
39
+ end
40
+
41
+ def contacts
42
+ token!
43
+
44
+ request = "https://www.google.com/m8/feeds/contacts/default/full?alt=json"
45
+ @contacts = normalize(access_token.get(request, :parse => :json).parsed)
46
+ end
47
+
48
+ class << self
49
+ def slim(contacts) #:nodoc:
50
+ _contacts = { 'contacts' => [] }
51
+
52
+ contacts['feed']['entry'].each do |contact|
53
+ emails, nickname = [], nil
54
+ nickname = contact['title']['$t']
55
+
56
+ contact['gd$email'].each do |email|
57
+ emails << email['address']
58
+ end
59
+ _contacts['contacts'] << { :email => emails.first, :emails => emails, :name => nickname }
60
+ end
61
+ _contacts
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def token!
68
+ if @access_token
69
+ @access_token.refresh! if @access_token.expired?
70
+ else
71
+ @access_token = consumer.auth_code.get_token(code, { redirect_uri: callback_url, parse: :json })
72
+ end
73
+ end
74
+
75
+ def normalize(contacts) #:nodoc:
76
+ _contacts = { 'contacts' => [] }
77
+
78
+ contacts['feed']['entry'].each do |contact|
79
+ emails, nickname = [], nil
80
+ nickname = contact['title']['$t']
81
+
82
+ contact['gd$email'].each do |email|
83
+ emails << email['address']
84
+ end
85
+ _contacts['contacts'] << { :email => emails.first, :emails => emails, :name => nickname }
86
+ end
87
+ _contacts
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+ require 'oauth2'
3
+ require 'multi_json'
4
+
5
+ # Create or Manage App => https://manage.dev.live.com/
6
+ module Oauth
7
+ module Contacts
8
+ class Live < Oauth::Contacts::OAuth2
9
+
10
+ def initialize
11
+ super
12
+ @callback_url = Settings.oauth.contacts.live.callback_url
13
+
14
+ opts = { key: Settings.oauth.contacts.live.key, secret: Settings.oauth.contacts.live.secret,
15
+ extra: { site: 'https://oauth.live.com',
16
+ authorize_url: '/authorize',
17
+ token_url: '/token',
18
+ max_redirects: 5,
19
+ raise_errors: true,
20
+ token_method: :post,
21
+ connection_opts: {} # [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday with
22
+ } }
23
+
24
+ @consumer = ::OAuth2::Client.new(opts[:key], opts[:secret], opts[:extra])
25
+ end
26
+
27
+ def authorize_url
28
+ # Scopes and permissions http://msdn.microsoft.com/en-us/library/hh243646.aspx
29
+ scopes = Settings.oauth.contacts.live.scopes
30
+
31
+ extra_params = { scope: scopes.join(' '),
32
+ redirect_uri: callback_url,
33
+ response_type: 'code',
34
+ state: 'live' }
35
+
36
+ consumer.auth_code.authorize_url( extra_params )
37
+ end
38
+
39
+ # REST API http://msdn.microsoft.com/en-us/library/hh243648.aspx
40
+ def contacts
41
+ token!
42
+
43
+ request = 'https://apis.live.net/v5.0/me/contacts'
44
+ @contacts = normalize(MultiJson.decode(access_token.get(request, parse: :json).body))
45
+ end
46
+
47
+ private
48
+
49
+ def token!
50
+ if @access_token
51
+ @access_token.refresh! if @access_token.expired?
52
+ else
53
+ @access_token = consumer.auth_code.get_token(code, { redirect_uri: callback_url, parse: :json })
54
+ end
55
+ end
56
+
57
+ def normalize(contacts) #:nodoc:
58
+ _contacts = { 'contacts' => [] }
59
+
60
+ contacts['data'].each do |contact|
61
+ _contacts['contacts'] << {
62
+ name: contact['name'],
63
+ email: contact['email_hashes'].first,
64
+ emails: contact['email_hashes'] }
65
+ end
66
+ _contacts
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,19 @@
1
+ module Oauth
2
+ module Contacts
3
+ class OAuth2 < Oauth::Contacts::Base
4
+
5
+ VERSION = 2.0
6
+
7
+ attr_accessor :code
8
+
9
+ def version
10
+ VERSION
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Oauth
2
+ module Contacts
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "oauth/contacts/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "oauth-contacts"
7
+ s.version = Oauth::Contacts::VERSION
8
+ s.authors = ["Joel AZEMAR"]
9
+ s.email = ["joel.azemar@gmail.com"]
10
+ s.homepage = "https://github.com/joel/oauth-contacts"
11
+ s.summary = "Getting mail contacts through OAuth 2.0 for Gmail and Hotmail"
12
+
13
+ s.rubyforge_project = "oauth-contacts"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'oauth2'
21
+ s.add_dependency "rails_config"
22
+ s.add_dependency 'multi_json', '~> 1.0.3'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ # s.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'oauth-contacts'
3
+
4
+ describe Oauth::Contacts::Base do
5
+
6
+ it ""
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'oauth2'
6
+ require "rails_config"
7
+ require 'multi_json'
8
+ require 'oauth-contacts'
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-contacts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joel AZEMAR
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth2
16
+ requirement: &70334006980520 !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: *70334006980520
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails_config
27
+ requirement: &70334006979840 !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: *70334006979840
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_json
38
+ requirement: &70334006978560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.3
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70334006978560
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70334006977620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70334006977620
58
+ description:
59
+ email:
60
+ - joel.azemar@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - lib/oauth-contacts.rb
71
+ - lib/oauth/contacts/base.rb
72
+ - lib/oauth/contacts/google.rb
73
+ - lib/oauth/contacts/live.rb
74
+ - lib/oauth/contacts/oauth2.rb
75
+ - lib/oauth/contacts/version.rb
76
+ - oauth-contacts.gemspec
77
+ - spec/oauth/contacts/base_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: https://github.com/joel/oauth-contacts
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project: oauth-contacts
99
+ rubygems_version: 1.8.10
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Getting mail contacts through OAuth 2.0 for Gmail and Hotmail
103
+ test_files:
104
+ - spec/oauth/contacts/base_spec.rb
105
+ - spec/spec_helper.rb