knock-knock 0.1.1 → 0.1.2

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.
@@ -1,3 +1,8 @@
1
+ == 0.1.2 2008-12-07
2
+
3
+ * Bug fix
4
+ * Fixing a problem with namespaces
5
+
1
6
  == 0.1.1 2008-12-07
2
7
 
3
8
  * Bug fix
@@ -1,6 +1,6 @@
1
1
  = KnockKnock
2
2
 
3
- KnockKnock was made for turn login with Google Authentication API more easy.
3
+ KnockKnock was made to turn login with Google Authentication API easier.
4
4
 
5
5
  == Features
6
6
  * Singleton class for connection with Google.
@@ -25,7 +25,7 @@ KnockKnock was made for turn login with Google Authentication API more easy.
25
25
 
26
26
  (The MIT License)
27
27
 
28
- Copyright (c) 2008 Bruno Azisaka Maciel
28
+ Copyright (c) 2008 Bubble[http://bubble.com.br]
29
29
 
30
30
  Permission is hereby granted, free of charge, to any person obtaining
31
31
  a copy of this software and associated documentation files (the
@@ -3,66 +3,71 @@ require 'uri'
3
3
  require 'net/http'
4
4
  require 'net/https'
5
5
 
6
- # This class make the connection between Ruby and Google.
7
- # It's a Singleton class, turning the management of the connection more easy. Just one connection will be created during all your script.
8
- class Bubble::KnockKnock::Connection
9
- include Singleton
6
+ module Bubble
7
+ module KnockKnock
8
+
9
+ # This class make the connection between Ruby and Google.
10
+ # It's a Singleton class, turning the management of the connection easier. Just one connection will be created during all your script.
11
+ class Connection
12
+ include Singleton
10
13
 
11
- attr_accessor :email, :service
12
- attr_reader :password, :auth
14
+ attr_accessor :email, :service
15
+ attr_reader :password, :auth
13
16
 
14
- # This method create the connection. First of all it set up the environment for make the connection and after it stablish the connection with Google
15
- # The service should be (i.e.):
16
- # * [cp] Google Mail Contact Book
17
- # * [analytics] Google Analytics
18
- #
19
- # === Example
20
- # require 'rubygems'
21
- # require 'knock_knock'
22
- #
23
- # Bubble::KnockKnock::Connection.connect('email@gmail.com', 'password', 'cp')
24
- def connect(email, password, service)
25
- @email = email
26
- @password = password
27
- @service = service
17
+ # This method creates the connection. First of all it set up the environment to make the connection and after it stablish the connection with Google
18
+ # The service should be (i.e.):
19
+ # * [cp] Google Mail Contact Book
20
+ # * [analytics] Google Analytics
21
+ #
22
+ # === Example
23
+ # require 'rubygems'
24
+ # require 'knock_knock'
25
+ #
26
+ # Bubble::KnockKnock::Connection.connect('email@gmail.com', 'password', 'cp')
27
+ def connect(email, password, service)
28
+ @email = email
29
+ @password = password
30
+ @service = service
28
31
 
29
- setup
30
- stablish
31
- end
32
+ setup
33
+ stablish
34
+ end
32
35
 
33
- # Retrieve the Auth Token required for authentications on all Google Services.
34
- def auth
35
- @auth
36
- end
36
+ # Retrieve the Auth Token required for authentications on all Google Services.
37
+ def auth
38
+ @auth
39
+ end
37
40
 
38
- protected
41
+ protected
39
42
 
40
- # It gives the correct values to attributes and variables required for make the connection.
41
- def setup
42
- @uri = URI.parse('https://www.google.com/accounts/ClientLogin')
43
+ # It gives the correct values to attributes and variables required to make the connection.
44
+ def setup
45
+ @uri = URI.parse('https://www.google.com/accounts/ClientLogin')
43
46
 
44
- @query = { 'accountType' => 'GOOGLE',
45
- 'Email' => @email,
46
- 'Passwd' => @password,
47
- 'service' => @service,
48
- 'source' => Bubble::KnockKnock::APP_NAME }
47
+ @query = { 'accountType' => 'GOOGLE',
48
+ 'Email' => @email,
49
+ 'Passwd' => @password,
50
+ 'service' => @service,
51
+ 'source' => Bubble::KnockKnock::APP_NAME }
49
52
 
50
- @http = Net::HTTP.new(@uri.host, 443)
51
- @http.use_ssl = true
52
- end
53
+ @http = Net::HTTP.new(@uri.host, 443)
54
+ @http.use_ssl = true
55
+ end
53
56
 
54
- # Makes the connection with Google. If the login and password are wrong an BadLogin exception occours.
55
- def stablish
56
- response, body = @http.post(@uri.path, @query.to_uri)
57
+ # Makes the connection with Google. If the login and password are wrong a BadLogin exception occurs.
58
+ def stablish
59
+ response, body = @http.post(@uri.path, @query.to_uri)
57
60
 
58
- case response.code.to_i
59
- when 403; raise BadLogin
60
- else; parse(body)
61
- end
62
- end
61
+ case response.code.to_i
62
+ when 403; raise BadLogin
63
+ else; parse(body)
64
+ end
65
+ end
63
66
 
64
- # Gives the Auth Token from authentication request.
65
- def parse(body)
66
- @auth = body.match(/Auth=(.*)/)[1]
67
+ # Gives the Auth Token from authentication request.
68
+ def parse(body)
69
+ @auth = body.match(/Auth=(.*)/)[1]
70
+ end
71
+ end
67
72
  end
68
73
  end
@@ -1,4 +1,10 @@
1
- # For login errors
2
- class Bubble::KnockKnock::BadLogin < Exception; end
3
- # For requests to Google services without a connection
4
- class Bubble::KnockKnock::UnstablishedConnection < Exception; end
1
+ module Bubble
2
+ module KnockKnock
3
+
4
+ # For login errors
5
+ class BadLogin < Exception; end
6
+ # For requests to Google services without a connection
7
+ class UnstablishedConnection < Exception; end
8
+
9
+ end
10
+ end
@@ -1,11 +1,15 @@
1
- # A collection of util methods for KnockKnock gem
2
- module Bubble::KnockKnock::Hash
1
+ module Bubble
2
+ module KnockKnock
3
+ # A collection of util methods for KnockKnock gem
4
+ module Bubble::KnockKnock::Hash
3
5
 
4
- # Transforms the hash into to a string which will be used to transmit data with the requests.
5
- def to_uri
6
- self.map { |k,v| "#{k}=#{v}"}.join('&')
7
- end
6
+ # Transforms the hash into a string which will be used to transmit data with the requests.
7
+ def to_uri
8
+ self.map { |k,v| "#{k}=#{v}"}.join('&')
9
+ end
8
10
 
11
+ end
12
+ end
9
13
  end
10
14
 
11
15
  class Hash
@@ -1,34 +1,38 @@
1
- # This class gives you a easy way to request informations from Google.
2
- class Bubble::KnockKnock::Request
3
- attr_reader :header
1
+ module Bubble
2
+ module KnockKnock
3
+ # This class gives you an easy way to request informations from Google.
4
+ class Request
5
+ attr_reader :header
4
6
 
5
- # Finds the Singleton Connection and creates the header structure to requesting informations.
6
- def initialize
7
- raise UnstablishedConnection if Connection.instance.auth.nil?
7
+ # Finds the Singleton Connection and creates the header structure to requesting informations.
8
+ def initialize
9
+ raise Bubble::KnockKnock::UnstablishedConnection if Bubble::KnockKnock::Connection.instance.auth.nil?
8
10
 
9
- connection = Connection.instance
10
- @header = {'Cookie' => "Name=#{connection.auth};Auth=#{connection.auth};Domain=.google.com;Path=/;Expires=160000000000",
11
- 'Content-length' => '0',
12
- 'Authorization' => "GoogleLogin auth=#{connection.auth}" }
13
- end
11
+ connection = Bubble::KnockKnock::Connection.instance
12
+ @header = {'Cookie' => "Name=#{connection.auth};Auth=#{connection.auth};Domain=.google.com;Path=/;Expires=160000000000",
13
+ 'Content-length' => '0',
14
+ 'Authorization' => "GoogleLogin auth=#{connection.auth}" }
15
+ end
14
16
 
15
- # Get the data from any Google Service.
16
- # You just need to indicate the URI of the API and the attributes must be sent with the request.
17
- # The content of the response will be returned if all occour as well.
18
- # === Example
19
- # You must to be connected. Take a look in Connection for more information.
20
- #
21
- # Request.get('http://www.google.com/m8/feeds/contacts/email%40gmail.com/full')
22
- def self.get(uri, query=nil)
23
- @request = self.new
17
+ # Get the data from any Google Service.
18
+ # You just need to indicate the URI of the API and the attributes must that be sent with the request.
19
+ # The response's content will be returned if all occur as well.
20
+ # === Example
21
+ # You must to be connected. Take a look in Connection for more information.
22
+ #
23
+ # Request.get('http://www.google.com/m8/feeds/contacts/email%40gmail.com/full')
24
+ def self.get(uri, query=nil)
25
+ @request = self.new
24
26
 
25
- uri = URI.parse(uri)
27
+ uri = URI.parse(uri)
26
28
 
27
- http = Net::HTTP.new(uri.host, 443)
28
- http.use_ssl = true
29
+ http = Net::HTTP.new(uri.host, 443)
30
+ http.use_ssl = true
29
31
 
30
- response, body = http.get("#{uri.path}?#{query}", @request.header)
32
+ response, body = http.get("#{uri.path}?#{query}", @request.header)
31
33
 
32
- body
34
+ body
35
+ end
36
+ end
33
37
  end
34
38
  end
@@ -7,9 +7,9 @@ require 'active_support'
7
7
  # A project developed by Bubble[http://bubble.com.br]
8
8
  module Bubble
9
9
 
10
- # For more information take a look on README
10
+ # For more information take a look at the README
11
11
  module KnockKnock
12
- VERSION = '0.1.1'
12
+ VERSION = '0.1.2'
13
13
  APP_NAME = 'KnockKnock Ruby Gem'
14
14
  end
15
15
  end
@@ -1,14 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestKnockKnock < Test::Unit::TestCase # :nodoc:
4
- include Bubble::KnockKnock
5
-
6
4
  def setup
7
- @kk = Connection.instance
5
+ @kk = Bubble::KnockKnock::Connection.instance
8
6
  end
9
7
 
10
8
  def test_stablish_connection
11
- assert_raise(BadLogin) { @kk.connect('test@gmail.com', 'password', 'xapi') }
9
+ assert_raise(Bubble::KnockKnock::BadLogin) { @kk.connect('test@gmail.com', 'password', 'xapi') }
12
10
 
13
11
  authenticate
14
12
  assert @kk.auth
@@ -17,9 +15,9 @@ class TestKnockKnock < Test::Unit::TestCase # :nodoc:
17
15
  def test_retrieving_data
18
16
  authenticate
19
17
 
20
- assert body = Request.get("http://www.google.com/m8/feeds/contacts/bubble.testing%40gmail.com/full")
18
+ assert body = Bubble::KnockKnock::Request.get("http://www.google.com/m8/feeds/contacts/bubble.testing%40gmail.com/full")
21
19
  assert_match(/^<\?xml.*/, body)
22
- assert_equal(@kk.auth, Connection.instance.auth)
20
+ assert_equal(@kk.auth, Bubble::KnockKnock::Connection.instance.auth)
23
21
  end
24
22
 
25
23
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knock-knock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Azisaka Maciel
@@ -71,7 +71,7 @@ files:
71
71
  - test/test_helper.rb
72
72
  - test/test_knock_knock.rb
73
73
  has_rdoc: true
74
- homepage: KnockKnock was made for turn login with Google Authentication API more easy.
74
+ homepage: KnockKnock was made to turn login with Google Authentication API easier.
75
75
  post_install_message:
76
76
  rdoc_options:
77
77
  - --main