cloudsponge 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in my.gemspec
4
+ gemspec
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cloudsponge (0.9.7)
5
+ json (>= 1.6.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ columnize (0.3.0)
11
+ json (1.6.1)
12
+ linecache (0.43)
13
+ ruby-debug (0.10.3)
14
+ columnize (>= 0.1)
15
+ ruby-debug-base (~> 0.10.3.0)
16
+ ruby-debug-base (0.10.3)
17
+ linecache (>= 0.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (>= 1.0.0)
24
+ cloudsponge!
25
+ json (>= 1.6.1)
26
+ ruby-debug (>= 0.10.3)
@@ -0,0 +1,10 @@
1
+ ===
2
+ 0.9.7 / 2011-09-19
3
+
4
+ * Added options to initialize and begin_import signatures
5
+ * Added import_id to initialize signature
6
+
7
+ === 0.9.2 / 2010-04-20
8
+
9
+ * Created Gem version of basic library functionality
10
+
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
File without changes
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/cloudsponge/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "cloudsponge"
6
+ s.version = Cloudsponge::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Graeme Rouse"]
9
+ s.email = ["graeme@cloudsponge.com"]
10
+ s.homepage = "http://rubygems.org/gems/cloudsponge"
11
+ s.summary = "CloudSponge integration library for Ruby"
12
+ s.description = "CloudSponge is the tool that you need to go viral. Create an account at http://www.cloudsponge.com and integrate with this library. In a few lines of code you'll have access to your users' contact lists."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "cloudsponge"
16
+
17
+ s.add_development_dependency "bundler", ">= 1.0.0"
18
+ s.add_development_dependency "ruby-debug", ">= 0.10.3"
19
+ s.add_dependency "json", ">=1.6.1"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
23
+ s.require_path = 'lib'
24
+ end
@@ -3,7 +3,3 @@ require File.expand_path(File.dirname(__FILE__) + '/cloudsponge/contact')
3
3
  require File.expand_path(File.dirname(__FILE__) + '/cloudsponge/event')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/cloudsponge/cs_exception')
5
5
  require File.expand_path(File.dirname(__FILE__) + '/cloudsponge/utility')
6
-
7
- module Cloudsponge
8
- VERSION = '0.9.6'
9
- end
@@ -1,25 +1,40 @@
1
1
  module Cloudsponge
2
2
 
3
3
  class Contact
4
- attr_accessor :first_name, :last_name, :emails, :phones
4
+ attr_accessor :first_name, :last_name, :emails, :phones, :addresses
5
5
 
6
6
  def self.from_array(list)
7
7
  list.map { |contact_data| Contact.new(contact_data) }.compact
8
8
  end
9
9
 
10
10
  def initialize(contact_data)
11
+ super()
11
12
  # get the basic data
12
13
  self.first_name = contact_data['first_name']
13
14
  self.last_name = contact_data['last_name']
15
+
14
16
  # get the phone numbers
15
17
  self.phones = []
16
18
  contact_data['phone'] && contact_data['phone'].each do |phone|
17
19
  self.add_array_value(self.phones, phone['number'], phone['type'])
18
20
  end
21
+
19
22
  self.emails = []
20
23
  contact_data['email'] && contact_data['email'].each do |email|
21
24
  self.add_array_value(self.emails, email['address'], email['type'])
22
25
  end
26
+
27
+ @addresses = contact_data['addresses'] && contact_data['addresses'].inject([]) do |memo, address|
28
+ memo << {
29
+ :type => address['type'],
30
+ :street => address["street"],
31
+ :city => address["city"],
32
+ :region => address["region"],
33
+ :country => address["country"],
34
+ :postal_code => address["postal_code"],
35
+ :formatted => address["formatted"]}
36
+ end || []
37
+
23
38
  self
24
39
  end
25
40
 
@@ -34,6 +49,10 @@ module Cloudsponge
34
49
  def phone
35
50
  Contact.get_first_value(self.phones)
36
51
  end
52
+
53
+ def address
54
+ Contact.get_first_value(self.addresses)
55
+ end
37
56
 
38
57
  def add_array_value(collection, value, type = nil)
39
58
  collection << {:value => value, :type => type}
@@ -19,8 +19,8 @@ module Cloudsponge
19
19
  class ContactImporter
20
20
  attr_accessor :key, :password, :import_id
21
21
 
22
- def initialize(key = nil, password = nil)
23
- @key, @password = [key, password]
22
+ def initialize(key = nil, password = nil, import_id = nil, opts = {})
23
+ @key, @password, @import_id, @options = [key, password, import_id, opts]
24
24
  end
25
25
 
26
26
  # guesses the most appropriate invocation for begin_import_xxx()
@@ -30,10 +30,11 @@ module Cloudsponge
30
30
  # :consent_url => nil | <consent_url>,
31
31
  # :applet_tag => nil | <applet_tag>
32
32
  # ]
33
- def begin_import(source_name, username = nil, password = nil, user_id = '', redirect_url = nil)
33
+ def begin_import(source_name, username = nil, password = nil, user_id = '', redirect_url = nil, opts = {})
34
34
  id = nil
35
35
  consent_url = nil
36
36
  applet_tag = nil
37
+ @options.update(opts)
37
38
 
38
39
  # look at the given service and decide how which begin function to invoke.
39
40
  unless username.nil? || username.empty?
@@ -104,7 +105,7 @@ module Cloudsponge
104
105
  # throws an exception if an invalid service is invoked.
105
106
  def begin_import_consent(source_name, user_id = nil, redirect_url = nil)
106
107
  # we need to pass in all params to the call
107
- params = {:service => source_name, :user_id => user_id, :redirect_url => redirect_url}.reject{ |k,v| v.nil? || v.empty? }
108
+ params = {:service => source_name, :user_id => user_id, :redirect_url => redirect_url, :include => @options["include"]}.reject{ |_,v| v.nil? || v.empty? }
108
109
 
109
110
  # get and decode the response into an associated array
110
111
  # Throws an exception if there was a problem at the server
@@ -116,7 +117,7 @@ module Cloudsponge
116
117
  # throws an exception if an invalid service is invoked.
117
118
  def begin_import_applet(source_name, user_id = nil)
118
119
  # we need to pass in all params to the call
119
- params = {:service => source_name, :user_id => user_id}
120
+ params = {:service => source_name, :user_id => user_id, :include => @options["include"]}.reject{ |_,v| v.nil? || v.empty? }
120
121
 
121
122
  # get and decode the response into an associated array
122
123
  # Throws an exception if there was a problem at the server
@@ -128,7 +129,7 @@ module Cloudsponge
128
129
  # throws an exception if an invalid service is invoked.
129
130
  def begin_import_username_password(source_name, username, password, user_id)
130
131
  # we need to pass in all params to the call
131
- params = {:service => source_name, :user_id => user_id, :username => username, :password => password}
132
+ params = {:service => source_name, :user_id => user_id, :username => username, :password => password, :include => @options["include"]}.reject{ |_,v| v.nil? || v.empty? }
132
133
 
133
134
  # get and decode the response into an associated array
134
135
  # Throws an exception if there was a problem at the server
@@ -151,12 +152,39 @@ module Cloudsponge
151
152
 
152
153
  def create_applet_tag(id, url)
153
154
  <<-EOS
154
- <APPLET archive="#{url}" code="ContactsApplet" id="Contact_Importer" width="0" height="0">
155
- <PARAM name="cookieValue" value="document.cookie"/>
156
- <PARAM name="importId" value="#{id}"/>
157
- Your browser does not support Java which is required for this utility to operate correctly.
158
- </APPLET>
155
+ <!--[if !IE]> Firefox and others will use outer object -->
156
+ <object classid="java:ContactsApplet" type="application/x-java-applet" archive="#{url}" height="1" width="1" >
157
+ <!-- Konqueror browser needs the following param -->
158
+ <param name="archive" value="#{url}" />
159
+ <param name="cookieValue" value="document.cookie"/>
160
+ <param name="importId" value="#{id}"/>
161
+ <!--<![endif]-->
162
+ <!-- MSIE (Microsoft Internet Explorer) will use inner object -->
163
+ <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
164
+ codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
165
+ height="0" width="0" >
166
+ <param name="code" value="ContactsApplet" />
167
+ <param name="archive" value="#{url}" />
168
+ <param name="cookieValue" value="document.cookie"/>
169
+ <param name="importId" value="#{id}"/> <strong>
170
+ This browser does not have a Java Plug-in.
171
+ <br />
172
+ <a href="http://java.sun.com/products/plugin/downloads/index.html">
173
+ Get the latest Java Plug-in here.
174
+ </a>
175
+ </strong>
176
+ </object>
177
+ <!--[if !IE]> close outer object -->
178
+ </object>
179
+ <!--<![endif]-->
159
180
  EOS
181
+ # <<-EOS
182
+ # <APPLET archive="#{url}" code="ContactsApplet" id="Contact_Importer" width="0" height="0">
183
+ # <PARAM name="cookieValue" value="document.cookie"/>
184
+ # <PARAM name="importId" value="#{id}"/>
185
+ # Your browser does not support Java which is required for this utility to operate correctly.
186
+ # </APPLET>
187
+ # EOS
160
188
  end
161
189
 
162
190
  def generate_poll_url(path, import_id)
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module Cloudsponge
2
+ VERSION = "0.9.7"
3
+ end
File without changes
@@ -1,5 +1,4 @@
1
- require "test/unit"
2
- require File.dirname(__FILE__) + "/../lib/cloudsponge"
1
+ require 'test/test_helper'
3
2
 
4
3
  class TestContactImporter < Test::Unit::TestCase
5
4
  def test_version_exists
@@ -10,25 +9,31 @@ class TestContactImporter < Test::Unit::TestCase
10
9
  DOMAIN_PASSWORD = "Your Domain Password"
11
10
 
12
11
  def test_u_p_import
13
- contacts = nil
14
12
  importer = Cloudsponge::ContactImporter.new(DOMAIN_KEY, DOMAIN_PASSWORD)
15
- importer.begin_import('AOL', 'username', 'password')
16
- loop do
17
- events = importer.get_events
18
- break unless events.select{ |e| e.is_error? }.empty?
19
- unless events.select{ |e| e.is_complete? }.empty?
20
- contacts = importer.get_contacts
21
- break
22
- end
23
- end
13
+ importer.begin_import('AOL', 'u', 'p')
14
+ contacts = events_wait(importer)
24
15
  assert contacts
25
16
  end
26
-
17
+
27
18
  def test_auth_import
28
- contacts = nil
29
19
  importer = Cloudsponge::ContactImporter.new(DOMAIN_KEY, DOMAIN_PASSWORD)
30
20
  resp = importer.begin_import('YAHOO')
31
21
  puts "Navigate to #{resp[:consent_url]} and complete the authentication process."
22
+ contacts = events_wait(importer)
23
+ assert contacts
24
+ end
25
+
26
+ def test_contacts_with_mailing_addresses
27
+ importer = Cloudsponge::ContactImporter.new(DOMAIN_KEY, DOMAIN_PASSWORD, nil, {"include" => "mailing_address"})
28
+ importer.begin_import('AOL', 'u', 'p')
29
+ contacts = events_wait(importer)
30
+ assert contacts[0].detect{ |contact| contact.addresses }
31
+ end
32
+
33
+ private
34
+
35
+ def events_wait(importer)
36
+ contacts = nil
32
37
  loop do
33
38
  events = importer.get_events
34
39
  break unless events.select{ |e| e.is_error? }.empty?
@@ -36,7 +41,8 @@ class TestContactImporter < Test::Unit::TestCase
36
41
  contacts = importer.get_contacts
37
42
  break
38
43
  end
44
+ sleep 1
39
45
  end
40
- assert contacts
46
+ contacts
41
47
  end
42
48
  end
File without changes
@@ -0,0 +1,5 @@
1
+ require "test/unit"
2
+ require "cloudsponge"
3
+ require 'rubygems'
4
+ require 'ruby-debug'
5
+
File without changes
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudsponge
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 53
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 9
8
- - 6
9
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Graeme Rouse
@@ -14,38 +15,90 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-04 00:00:00 -07:00
18
+ date: 2011-09-19 00:00:00 -07:00
18
19
  default_executable:
19
- dependencies: []
20
-
21
- description: " Usage:\n contacts = nil\n importer = Cloudsponge::ContactImporter.new(DOMAIN_KEY, DOMAIN_PASSWORD)\n importer.begin_import('YAHOO')\n loop do\n events = importer.get_events\n break unless events.select{ |e| e.is_error? }.empty?\n unless events.select{ |e| e.is_completed? }.empty?\n contacts = importer.get_contacts\n break\n end\n end\n"
22
- email: graeme@cloudsponge.com
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: ruby-debug
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 49
46
+ segments:
47
+ - 0
48
+ - 10
49
+ - 3
50
+ version: 0.10.3
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 13
62
+ segments:
63
+ - 1
64
+ - 6
65
+ - 1
66
+ version: 1.6.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: CloudSponge is the tool that you need to go viral. Create an account at http://www.cloudsponge.com and integrate with this library. In a few lines of code you'll have access to your users' contact lists.
70
+ email:
71
+ - graeme@cloudsponge.com
23
72
  executables: []
24
73
 
25
74
  extensions: []
26
75
 
27
- extra_rdoc_files:
28
- - README
29
- - HISTORY
30
- - TODO
76
+ extra_rdoc_files: []
77
+
31
78
  files:
32
- - HISTORY
33
- - lib/cloudsponge/contact.rb
34
- - lib/cloudsponge/contact_importer.rb
35
- - lib/cloudsponge/cs_exception.rb
36
- - lib/cloudsponge/event.rb
37
- - lib/cloudsponge/utility.rb
38
- - lib/cloudsponge.rb
39
- - Manifest.txt
40
- - Rakefile
41
- - README
42
- - test/test_contact.rb
43
- - test/test_contact_importer.rb
44
- - test/test_cs_exception.rb
45
- - test/test_utility.rb
46
- - TODO
79
+ - cloudsponge/.gitignore
80
+ - cloudsponge/Gemfile
81
+ - cloudsponge/Gemfile.lock
82
+ - cloudsponge/HISTORY
83
+ - cloudsponge/Manifest.txt
84
+ - cloudsponge/README
85
+ - cloudsponge/Rakefile
86
+ - cloudsponge/TODO
87
+ - cloudsponge/cloudsponge.gemspec
88
+ - cloudsponge/lib/cloudsponge.rb
89
+ - cloudsponge/lib/cloudsponge/contact.rb
90
+ - cloudsponge/lib/cloudsponge/contact_importer.rb
91
+ - cloudsponge/lib/cloudsponge/cs_exception.rb
92
+ - cloudsponge/lib/cloudsponge/event.rb
93
+ - cloudsponge/lib/cloudsponge/utility.rb
94
+ - cloudsponge/lib/cloudsponge/version.rb
95
+ - cloudsponge/test/test_contact.rb
96
+ - cloudsponge/test/test_contact_importer.rb
97
+ - cloudsponge/test/test_cs_exception.rb
98
+ - cloudsponge/test/test_helper.rb
99
+ - cloudsponge/test/test_utility.rb
47
100
  has_rdoc: true
48
- homepage: http://www.cloudsponge.com
101
+ homepage: http://rubygems.org/gems/cloudsponge
49
102
  licenses: []
50
103
 
51
104
  post_install_message:
@@ -54,25 +107,31 @@ rdoc_options: []
54
107
  require_paths:
55
108
  - lib
56
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
57
111
  requirements:
58
112
  - - ">="
59
113
  - !ruby/object:Gem::Version
114
+ hash: 3
60
115
  segments:
61
116
  - 0
62
117
  version: "0"
63
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
64
120
  requirements:
65
121
  - - ">="
66
122
  - !ruby/object:Gem::Version
123
+ hash: 23
67
124
  segments:
68
- - 0
69
- version: "0"
125
+ - 1
126
+ - 3
127
+ - 6
128
+ version: 1.3.6
70
129
  requirements: []
71
130
 
72
- rubyforge_project:
73
- rubygems_version: 1.3.6
131
+ rubyforge_project: cloudsponge
132
+ rubygems_version: 1.3.7
74
133
  signing_key:
75
134
  specification_version: 3
76
- summary: A library wrapper for Cloudsponge.com's API
135
+ summary: CloudSponge integration library for Ruby
77
136
  test_files: []
78
137
 
data/HISTORY DELETED
@@ -1,4 +0,0 @@
1
- === 0.9.2 / 2010-04-20
2
-
3
- * Created Gem version of basic library functionality
4
-
data/Rakefile DELETED
@@ -1,44 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- require 'rake'
5
- require 'rake/gempackagetask'
6
- require 'lib/cloudsponge'
7
-
8
- PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile|\.nfs\./)
9
-
10
- spec = Gem::Specification.new do |s|
11
- s.name = 'cloudsponge'
12
- s.version = Cloudsponge::VERSION
13
- s.author = "Graeme Rouse"
14
- s.email = "graeme@cloudsponge.com"
15
- s.homepage = "http://www.cloudsponge.com"
16
- s.platform = Gem::Platform::RUBY
17
- s.summary = "A library wrapper for Cloudsponge.com's API"
18
- s.description = <<-EOF
19
- Usage:
20
- contacts = nil
21
- importer = Cloudsponge::ContactImporter.new(DOMAIN_KEY, DOMAIN_PASSWORD)
22
- importer.begin_import('YAHOO')
23
- loop do
24
- events = importer.get_events
25
- break unless events.select{ |e| e.is_error? }.empty?
26
- unless events.select{ |e| e.is_completed? }.empty?
27
- contacts = importer.get_contacts
28
- break
29
- end
30
- end
31
- EOF
32
-
33
- #s.files = FileList["{test,lib}/**/*"].exclude("rdoc").to_a
34
- s.files = PKG_FILES
35
- # s.files = PKG_FILES
36
- s.require_path = "lib"
37
- s.has_rdoc = true
38
- s.extra_rdoc_files = ["README", "HISTORY", "TODO"]
39
- end
40
-
41
-
42
- Rake::GemPackageTask.new(spec) do |pkg|
43
- pkg.need_tar = true
44
- end