constant_contact 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,8 +65,9 @@ module ConstantContact
65
65
  prefix_options, query_options = split_options(options[:params])
66
66
  path = collection_path(prefix_options, query_options)
67
67
  result = connection.get(path, headers)
68
- case result.class.name
69
- when 'Hash': instantiate_collection( [ result ], prefix_options )
68
+ case result
69
+ when Hash
70
+ instantiate_collection( [ result ], prefix_options )
70
71
  else
71
72
  instantiate_collection( (result || []), prefix_options )
72
73
  end
@@ -80,15 +81,15 @@ module ConstantContact
80
81
  def method_missing(method_symbol, *arguments) #:nodoc:
81
82
  method_name = method_symbol.to_s
82
83
 
83
- case method_name.last
84
+ case method_name[-1,1]
84
85
  when "="
85
- attributes[method_name.first(-1).camelize] = arguments.first
86
+ attributes[method_name.chop.camelize] = arguments.first
86
87
  when "?"
87
- attributes[method_name.first(-1).camelize]
88
+ attributes[method_name.chop.camelize]
88
89
  else
89
90
  attributes.has_key?(method_name.camelize) ? attributes[method_name.camelize] : super
90
91
  end
91
- end
92
+ end
92
93
 
93
94
  # Caching accessor for the the id integer
94
95
  def int_id
@@ -138,9 +139,9 @@ module ConstantContact
138
139
  <content type=\"application/vnd.ctct+xml\">
139
140
  #{self.to_xml}
140
141
  </content>
141
- </entry>"
142
+ </entry>"
142
143
  end
143
-
144
+
144
145
  # TODO: Move this out to a lib
145
146
  def html_encode(txt)
146
147
  mapping = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
@@ -71,7 +71,29 @@ module ConstantContact
71
71
  def self.find_by_email(email_address)
72
72
  find :first, {:params => {:email => email_address.downcase}}
73
73
  end
74
-
74
+
75
+ # Needed a lot of custom work here because of the way ActiveResource turns
76
+ # arrays into query strings.
77
+ # ActiveResource would do: email[]=<email 1>&email[]=<email 2>
78
+ # But we need: email=<email 1>&email=<email 2>
79
+ def self.find_all_by_emails(emails)
80
+ raise ArgumentError, "Expected an array of emails, got a(n) #{emails.class.name}" unless emails.is_a? Array
81
+ return [] if email_addresses.empty?
82
+
83
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
84
+ query_string = emails.map{|e| "email=#{CGI.escape(e.to_s.downcase)}"}.join('&')
85
+
86
+ path = "/ws/customers/#{self.user}/#{collection_name}?#{query_string}"
87
+ result = connection.get(path, headers)
88
+
89
+ case result
90
+ when Hash
91
+ instantiate_collection( [ result ], {} )
92
+ else
93
+ instantiate_collection( (result || []), {} )
94
+ end
95
+ end
96
+
75
97
  protected
76
98
  def validate
77
99
  # errors.add(:opt_in_source, 'must be either ACTION_BY_CONTACT or ACTION_BY_CUSTOMER') unless ['ACTION_BY_CONTACT','ACTION_BY_CUSTOMER'].include?(attributes['OptInSource'])
@@ -27,10 +27,12 @@ module ActiveResource
27
27
 
28
28
  def from_atom_data(xml)
29
29
  if is_collection?(xml)
30
- return content_from_collection(xml)
30
+ result = content_from_collection(xml)
31
31
  else
32
- return content_from_single_record(xml)
32
+ result = content_from_single_record(xml)
33
33
  end
34
+ result.delete('xmlns')
35
+ return result
34
36
  end
35
37
 
36
38
  def no_content?(xml)
@@ -1,3 +1,3 @@
1
1
  module ConstantContact
2
- Version = '1.0.0'.freeze
2
+ Version = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constant_contact
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Case
14
14
  - Ed Hickey
15
15
  - Nathan Hyde
16
+ - Idris Mokhtarzada
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2010-09-02 00:00:00 -04:00
21
+ date: 2010-09-17 00:00:00 -04:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency