constant_contact 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
1
  directory = File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  require 'active_resource'
4
- require 'action_pack'
5
4
  require 'builder'
6
5
  require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
7
6
  require File.join(directory, 'constant_contact', 'formats')
@@ -17,40 +17,47 @@ module ActiveResource
17
17
  end
18
18
 
19
19
  def decode(xml)
20
- if xml =~ /\<atom\:/
21
- xml.gsub!( /\<atom\:/, '<' )
22
- xml.gsub!( /\<\/atom\:/, '</' )
20
+ xml.gsub!( /\<(\/?)atom\:/, '<\1' ) # the "events" feeds have "atom:" in front of tags, for some reason
21
+ doc = REXML::Document.new(xml)
22
+ return [] if no_content?(doc)
23
+ result = Hash.from_xml(from_atom_data(doc))
24
+
25
+ if is_collection?(doc)
26
+ list = result['records']
27
+
28
+ next_link = REXML::XPath.first(doc, "/feed/link[@rel='next']")
29
+ if next_link
30
+ next_path = next_link.attribute('href').value
31
+ next_page = ::ConstantContact::Base.connection.get(next_path)
32
+ list.concat(next_page)
33
+ end
34
+
35
+ list
36
+ else
37
+ result.values.first
23
38
  end
24
- return [] if no_content?(xml)
25
- result = Hash.from_xml(from_atom_data(xml))
26
- is_collection?(xml) ? result['records'] : result.values.first
27
39
  end
28
40
 
29
41
 
30
42
  private
31
43
 
32
- def from_atom_data(xml)
33
- if is_collection?(xml)
34
- result = content_from_collection(xml)
44
+ def from_atom_data(doc)
45
+ if is_collection?(doc)
46
+ content_from_collection(doc)
35
47
  else
36
- result = content_from_single_record(xml)
48
+ content_from_single_record(doc)
37
49
  end
38
- result.delete('xmlns')
39
- return result
40
50
  end
41
51
 
42
- def no_content?(xml)
43
- doc = REXML::Document.new(xml)
52
+ def no_content?(doc)
44
53
  REXML::XPath.match(doc,'//content').size == 0
45
54
  end
46
55
 
47
- def is_collection?(xml)
48
- doc = REXML::Document.new(xml)
56
+ def is_collection?(doc)
49
57
  REXML::XPath.match(doc,'//content').size > 1
50
58
  end
51
59
 
52
- def content_from_single_record(xml)
53
- doc = REXML::Document.new(xml)
60
+ def content_from_single_record(doc)
54
61
  str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
55
62
  REXML::XPath.each(doc, '//content') do |e|
56
63
  content = e.children[1]
@@ -59,19 +66,17 @@ module ActiveResource
59
66
  str
60
67
  end
61
68
 
62
- def content_from_collection(xml)
63
- doc = REXML::Document.new(xml)
69
+ def content_from_collection(doc)
64
70
  str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><records type=\"array\">"
65
71
  REXML::XPath.each(doc, '//content') do |e|
66
72
  content = e.children[1]
67
73
  str << content.to_s
68
74
  end
69
- str << "</records>"
75
+ str << "</records>"
70
76
  str
71
77
  end
72
78
 
73
- def content_from_member(xml)
74
- doc = REXML::Document.new(xml)
79
+ def content_from_member(doc)
75
80
  str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
76
81
  REXML::XPath.each(doc, '//content') do |e|
77
82
  content = e.children[1].children
@@ -1,3 +1,3 @@
1
1
  module ConstantContact
2
- Version = '1.2.1'.freeze
2
+ Version = '1.2.2'.freeze
3
3
  end
@@ -34,7 +34,7 @@ class Activity < Test::Unit::TestCase
34
34
 
35
35
  context 'format' do
36
36
  should 'be html encoded' do
37
- assert_equal ActiveResource::Formats[:html_encoded], ConstantContact::Activity.connection.format
37
+ assert_equal ActiveResource::Formats[:html_encoded], ConstantContact::Activity.format
38
38
  end
39
39
  end
40
40
 
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class FiftyTest < Test::Unit::TestCase
4
+
5
+ context 'find more than 50' do
6
+ setup do
7
+ ConstantContact::Base.api_key = "fc2113f8-9336-4886-9b04-61aa5092d428"
8
+ # ConstantContact::Base.user = "dtjohnsospam"
9
+ # ConstantContact::Base.password = "qwerty7"
10
+ ConstantContact::Base.user = "ChiefExperts"
11
+ ConstantContact::Base.password = "danbcr1234"
12
+ end
13
+
14
+ should 'return more than 50 members of list' do
15
+ FakeWeb.allow_net_connect = true
16
+ # lists = ConstantContact::List.find(:all, :params => { :list_id => 3 })
17
+ # lists.each do |list|
18
+ # next unless list.respond_to? :SortOrder
19
+ members = ConstantContact::Member.find(:all, :params => { :list_id => 3 })
20
+ assert members.size > 50
21
+ # assert_equal list.contact_count.to_i, members.size
22
+ # end
23
+ end
24
+
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constant_contact
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Case
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-10-29 00:00:00 -04:00
21
+ date: 2010-11-04 00:00:00 -04:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -36,34 +36,34 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: actionpack
39
+ name: builder
40
40
  prerelease: false
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ">="
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
- hash: 3
46
+ hash: 15
47
47
  segments:
48
- - 0
49
- version: "0"
48
+ - 2
49
+ - 1
50
+ - 2
51
+ version: 2.1.2
50
52
  type: :runtime
51
53
  version_requirements: *id002
52
54
  - !ruby/object:Gem::Dependency
53
- name: builder
55
+ name: activesupport
54
56
  prerelease: false
55
57
  requirement: &id003 !ruby/object:Gem::Requirement
56
58
  none: false
57
59
  requirements:
58
- - - ~>
60
+ - - ">="
59
61
  - !ruby/object:Gem::Version
60
- hash: 15
62
+ hash: 3
61
63
  segments:
62
- - 2
63
- - 1
64
- - 2
65
- version: 2.1.2
66
- type: :runtime
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
67
  version_requirements: *id003
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: shoulda
@@ -152,10 +152,13 @@ files:
152
152
  - lib/constant_contact/member.rb
153
153
  - lib/constant_contact/version.rb
154
154
  - lib/constant_contact.rb
155
+ - MIT-LICENSE
156
+ - README.md
155
157
  - test/constant_contact/activity_test.rb
156
158
  - test/constant_contact/atom_format_test.rb
157
159
  - test/constant_contact/base_test.rb
158
160
  - test/constant_contact/contact_test.rb
161
+ - test/constant_contact/fifty_test.rb
159
162
  - test/constant_contact/list_test.rb
160
163
  - test/constant_contact/member_test.rb
161
164
  - test/constant_contact_test.rb
@@ -172,8 +175,6 @@ files:
172
175
  - test/fixtures/single_contact_by_id.xml
173
176
  - test/fixtures/single_contact_by_id_with_no_contactlists.xml
174
177
  - test/test_helper.rb
175
- - MIT-LICENSE
176
- - README.md
177
178
  has_rdoc: true
178
179
  homepage: http://github.com/idris/constant_contact
179
180
  licenses: []
@@ -210,5 +211,25 @@ rubygems_version: 1.3.7
210
211
  signing_key:
211
212
  specification_version: 3
212
213
  summary: ActiveResource wrapper for the Constant Contact API.
213
- test_files: []
214
-
214
+ test_files:
215
+ - test/constant_contact/activity_test.rb
216
+ - test/constant_contact/atom_format_test.rb
217
+ - test/constant_contact/base_test.rb
218
+ - test/constant_contact/contact_test.rb
219
+ - test/constant_contact/fifty_test.rb
220
+ - test/constant_contact/list_test.rb
221
+ - test/constant_contact/member_test.rb
222
+ - test/constant_contact_test.rb
223
+ - test/fixtures/all_contacts.xml
224
+ - test/fixtures/contactlistscollection.xml
225
+ - test/fixtures/contactlistsindividuallist.xml
226
+ - test/fixtures/memberscollection.xml
227
+ - test/fixtures/multiple_contacts_by_emails.xml
228
+ - test/fixtures/new_list.xml
229
+ - test/fixtures/nocontent.xml
230
+ - test/fixtures/senteventscollection.xml
231
+ - test/fixtures/service_document.xml
232
+ - test/fixtures/single_contact_by_email.xml
233
+ - test/fixtures/single_contact_by_id.xml
234
+ - test/fixtures/single_contact_by_id_with_no_contactlists.xml
235
+ - test/test_helper.rb