gmail_contatos 0.0.2 → 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/app/controllers/{gmail_contatos/contacts_controller.rb → contacts_controller.rb} +4 -8
- data/config/routes.rb +1 -2
- data/lib/gmail_contatos/engine.rb +1 -0
- data/lib/gmail_contatos/helper.rb +19 -0
- data/lib/gmail_contatos/version.rb +1 -1
- data/lib/gmail_contatos.rb +4 -3
- data/lib/{google.rb → google/contact.rb} +8 -6
- metadata +4 -6
- data/app/helpers/application_helper.rb +0 -7
- data/app/models/gmail_contatos/contact.rb +0 -38
- data/app/views/gmail_contatos/index.html.erb +0 -0
|
@@ -2,24 +2,20 @@
|
|
|
2
2
|
module GmailContatos
|
|
3
3
|
class ContactsController < GmailContatos::ApplicationController
|
|
4
4
|
def new
|
|
5
|
-
|
|
5
|
+
# refatorar para funcionar com qualquer config de rota
|
|
6
|
+
redirect_to Google::Authorization.build_auth_url("http://#{request.env["HTTP_HOST"]}/gmail_contatos/gauthorize")
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def authorize
|
|
9
10
|
token = Google::Authorization.exchange_singular_use_for_session_token(params[:token])
|
|
10
11
|
|
|
11
12
|
unless token == false
|
|
12
|
-
|
|
13
|
+
redirect_to "#{session[:back_url]}?gtoken=#{token}"
|
|
13
14
|
else
|
|
14
15
|
flash[:error] = "Sua tentativa de autenticação com o google falhou."
|
|
16
|
+
# refatorar há um problema aqui, ele redireciona para root_url da aplicação,deve faltar algum include
|
|
15
17
|
redirect_to root_url
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
|
-
|
|
19
|
-
def index
|
|
20
|
-
#render :text=>"aaa"
|
|
21
|
-
@contacts = GmailContatos::Contact.all(params[:token])
|
|
22
|
-
raise @contacts.inspect
|
|
23
|
-
end
|
|
24
20
|
end
|
|
25
21
|
end
|
data/config/routes.rb
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'google/contact'
|
|
2
|
+
module GmailContatos
|
|
3
|
+
module Helper
|
|
4
|
+
include ActionController::UrlFor
|
|
5
|
+
include ActionController
|
|
6
|
+
include Google
|
|
7
|
+
def get_gmail_contatos
|
|
8
|
+
unless params.member?(:gtoken) then
|
|
9
|
+
session[:back_url] = request.url.to_s
|
|
10
|
+
redirect_to "/gmail_contatos/autorizar"
|
|
11
|
+
else
|
|
12
|
+
puts "chamar".inspect
|
|
13
|
+
@gcontatos = Google::Contact.all(params["gtoken"])
|
|
14
|
+
puts "depois".inspect
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/gmail_contatos.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
require "active_support/dependencies"
|
|
2
|
+
require 'gmail_contatos/helper'
|
|
2
3
|
require "gmail_contatos/engine"
|
|
3
4
|
require "google/authorization"
|
|
4
|
-
|
|
5
5
|
module GmailContatos
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
|
7
|
+
include GmailContatos::Helper
|
|
8
|
+
end
|
|
8
9
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'rexml/document'
|
|
1
3
|
module Google
|
|
2
|
-
class Contact
|
|
3
|
-
attr_accessor :
|
|
4
|
+
class Contact
|
|
5
|
+
attr_accessor :nome
|
|
4
6
|
attr_accessor :email
|
|
5
|
-
def initialize(
|
|
6
|
-
@
|
|
7
|
+
def initialize(nome, email)
|
|
8
|
+
@nome = nome
|
|
7
9
|
@email = email
|
|
8
10
|
end
|
|
9
11
|
|
|
@@ -17,8 +19,8 @@ module Google
|
|
|
17
19
|
# in order to retrieve more contacts
|
|
18
20
|
path = "/m8/feeds/contacts/default/base?max-results=10000"
|
|
19
21
|
headers = {'Authorization' => "AuthSub token=#{token}"}
|
|
20
|
-
resp
|
|
21
|
-
|
|
22
|
+
resp = http.get2(path, headers)
|
|
23
|
+
data = resp.body
|
|
22
24
|
# extract the name and email address from the response data
|
|
23
25
|
xml = REXML::Document.new(data)
|
|
24
26
|
contacts = []
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gmail_contatos
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -20,15 +20,13 @@ extra_rdoc_files: []
|
|
|
20
20
|
files:
|
|
21
21
|
- Gemfile
|
|
22
22
|
- Rakefile
|
|
23
|
-
- app/controllers/
|
|
24
|
-
- app/models/gmail_contatos/contact.rb
|
|
25
|
-
- app/views/gmail_contatos/index.html.erb
|
|
26
|
-
- app/helpers/application_helper.rb
|
|
23
|
+
- app/controllers/contacts_controller.rb
|
|
27
24
|
- config/routes.rb
|
|
28
25
|
- lib/gmail_contatos.rb
|
|
29
|
-
- lib/google.rb
|
|
26
|
+
- lib/google/contact.rb
|
|
30
27
|
- lib/google/authorization.rb
|
|
31
28
|
- lib/gmail_contatos/engine.rb
|
|
29
|
+
- lib/gmail_contatos/helper.rb
|
|
32
30
|
- lib/gmail_contatos/version.rb
|
|
33
31
|
homepage: https://github.com/Janderson/gmail_contatos
|
|
34
32
|
licenses: []
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require 'rexml/document'
|
|
3
|
-
module Google
|
|
4
|
-
class GmailContatos::Contact
|
|
5
|
-
attr_accessor :name
|
|
6
|
-
attr_accessor :email
|
|
7
|
-
def initialize(name, email)
|
|
8
|
-
@name = name
|
|
9
|
-
@email = email
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.all(token)
|
|
13
|
-
http = Net::HTTP.new('www.google.com', 80)
|
|
14
|
-
# by default Google returns 50? contacts at a time. Set max-results to very high number
|
|
15
|
-
# in order to retrieve more contacts
|
|
16
|
-
path = "/m8/feeds/contacts/default/base?max-results=10000"
|
|
17
|
-
headers = {'Authorization' => "AuthSub token=#{token}"}
|
|
18
|
-
resp = http.get2(path, headers)
|
|
19
|
-
data = resp.body
|
|
20
|
-
# extract the name and email address from the response data
|
|
21
|
-
xml = REXML::Document.new(data)
|
|
22
|
-
contacts = []
|
|
23
|
-
xml.elements.each('//entry') do |entry|
|
|
24
|
-
name = entry.elements['title'].text
|
|
25
|
-
|
|
26
|
-
gd_email = entry.elements['gd:email']
|
|
27
|
-
email = gd_email.attributes['address'] if gd_email
|
|
28
|
-
person = self.new(name, email)
|
|
29
|
-
contacts << person
|
|
30
|
-
end
|
|
31
|
-
return contacts
|
|
32
|
-
end
|
|
33
|
-
def persisted?
|
|
34
|
-
return false
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
File without changes
|