postal 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/Gemfile +3 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +1 -1
- data/README.md +108 -0
- data/lib/postal.rb +2 -6
- data/lib/postal/content.rb +14 -15
- data/lib/postal/driver.rb +121 -0
- data/lib/postal/mailing.rb +66 -41
- data/lib/postal/member.rb +33 -15
- data/lib/postal/version.rb +3 -0
- data/postal.gemspec +27 -16
- data/test/content_test.rb +2 -2
- data/test/list_test.rb +1 -1
- data/test/mailing_test.rb +1 -1
- data/test/member_test.rb +13 -5
- data/test/test_helper.rb +1 -2
- metadata +49 -52
- data/README.rdoc +0 -108
- data/lib/postal/lmapi/lmapi.rb +0 -1321
- data/lib/postal/lmapi/lmapi_driver.rb +0 -687
- data/lib/postal/lmapi/lmapi_mapping_registry.rb +0 -1237
data/lib/postal/member.rb
CHANGED
@@ -7,9 +7,13 @@ module Postal
|
|
7
7
|
unless args.find { |arg| arg.match(/ListName/) }
|
8
8
|
args << "ListName=#{Postal.options[:list_name]}"
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
begin
|
11
|
+
if soap_members = Postal.driver.selectMembers(args)
|
12
|
+
return parse_members(soap_members)
|
13
|
+
else
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
rescue
|
13
17
|
return nil
|
14
18
|
end
|
15
19
|
end
|
@@ -45,7 +49,7 @@ module Postal
|
|
45
49
|
begin
|
46
50
|
return find_by_filter("EmailAddress=#{email}")
|
47
51
|
# return Postal.driver.getMemberID(Postal::Lmapi::SimpleMemberStruct.new(list_name,member_id,email))
|
48
|
-
rescue SOAP::
|
52
|
+
rescue Savon::SOAP::Fault => soap_fault
|
49
53
|
return nil
|
50
54
|
end
|
51
55
|
end
|
@@ -70,19 +74,28 @@ module Postal
|
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
73
|
-
def parse_members(
|
74
|
-
|
75
|
-
|
76
|
-
member
|
77
|
-
|
77
|
+
def parse_members(return_hash)
|
78
|
+
case return_hash[:item]
|
79
|
+
when Hash
|
80
|
+
member = build_member_from_hash(return_hash[:item])
|
81
|
+
when Array
|
82
|
+
members = return_hash[:item].each do |member|
|
83
|
+
build_member_from_hash(member)
|
84
|
+
end
|
78
85
|
end
|
79
|
-
if
|
80
|
-
return
|
86
|
+
if member
|
87
|
+
return member
|
81
88
|
else
|
82
89
|
return members
|
83
90
|
end
|
84
91
|
end
|
85
92
|
|
93
|
+
def build_member_from_hash(member_hash)
|
94
|
+
demographics = {}
|
95
|
+
member_hash[:demographics][:item].each { |demo| demographics.merge!({ demo[:name].to_sym => demo[:value] }) }
|
96
|
+
Member.new(:email => member_hash[:email_address], :name => member_hash[:full_name], :id => member_hash[:member_id], :list_name => member_hash[:list_name], :demographics => demographics)
|
97
|
+
end
|
98
|
+
|
86
99
|
end
|
87
100
|
|
88
101
|
DEFAULT_ATTRIBUTES = { :id => nil, :email => nil, :name => nil, :list_name => nil, :demographics => {} }
|
@@ -109,7 +122,7 @@ module Postal
|
|
109
122
|
@id = Postal.driver.createSingleMember(@email, @name, list_name)
|
110
123
|
update_attributes(@demographics) unless @demographics.empty?
|
111
124
|
return @id
|
112
|
-
rescue SOAP::
|
125
|
+
rescue Savon::SOAP::Fault
|
113
126
|
return false
|
114
127
|
end
|
115
128
|
end
|
@@ -123,14 +136,19 @@ module Postal
|
|
123
136
|
raise Postal::CouldNotCreateMember, 'Could not create a new member. The most likely cause is that the specified list already contains this email address.'
|
124
137
|
end
|
125
138
|
end
|
139
|
+
|
140
|
+
|
141
|
+
def unsubscribe
|
142
|
+
list_name = @list_name
|
143
|
+
return Postal.driver.unsubscribe(list_name, @id, @email)
|
144
|
+
end
|
126
145
|
|
127
146
|
|
128
147
|
# Update the demographics for a user
|
129
148
|
def update_attributes(attributes={})
|
130
149
|
list_name = @list_name
|
131
|
-
demos = attributes.collect { |key,value|
|
132
|
-
|
133
|
-
return Postal.driver.updateMemberDemographics(member,demos)
|
150
|
+
demos = attributes.collect { |key,value| {'Name' => key, 'Value' => value} }
|
151
|
+
return Postal.driver.updateMemberDemographics(list_name, @id, @email, demos)
|
134
152
|
end
|
135
153
|
|
136
154
|
|
data/postal.gemspec
CHANGED
@@ -1,11 +1,32 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "postal/version"
|
5
4
|
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "postal"
|
7
|
+
s.version = Postal::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['The Active Network']
|
10
|
+
s.email = ['']
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Lyris is an enterprise email service. Postal makes it easy for Ruby to talk to Lyris's API.}
|
13
|
+
s.description = %q{Lyris is an enterprise email service. Postal makes it easy for Ruby to talk to Lyris's API.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "postal"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('savon', '=0.9.7')
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
=begin
|
6
27
|
Gem::Specification.new do |s|
|
7
28
|
s.name = %q{postal}
|
8
|
-
s.version = "0.
|
29
|
+
s.version = "0.3.0"
|
9
30
|
|
10
31
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
32
|
s.authors = ["The Active Network"]
|
@@ -57,16 +78,6 @@ Gem::Specification.new do |s|
|
|
57
78
|
"test/test_helper.rb"
|
58
79
|
]
|
59
80
|
|
60
|
-
if s.respond_to? :specification_version then
|
61
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
-
s.specification_version = 3
|
63
|
-
|
64
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
-
s.add_runtime_dependency(%q<soap4r>, [">= 1.5.8"])
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<soap4r>, [">= 1.5.8"])
|
68
|
-
end
|
69
|
-
else
|
70
|
-
s.add_dependency(%q<soap4r>, [">= 1.5.8"])
|
71
|
-
end
|
72
81
|
end
|
82
|
+
=end
|
83
|
+
|
data/test/content_test.rb
CHANGED
@@ -6,8 +6,8 @@ class ContentTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def setup
|
8
8
|
load_config
|
9
|
-
Postal.options[:list_name] = 'active-casting'
|
10
|
-
Postal.options[:proxy] = "http://localhost:8888/"
|
9
|
+
#Postal.options[:list_name] = 'active-casting'
|
10
|
+
#Postal.options[:proxy] = "http://localhost:8888/"
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_selecting_all_content
|
data/test/list_test.rb
CHANGED
data/test/mailing_test.rb
CHANGED
data/test/member_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require './test_helper'
|
2
2
|
|
3
3
|
class MemberTest < Test::Unit::TestCase
|
4
4
|
|
@@ -12,14 +12,15 @@ class MemberTest < Test::Unit::TestCase
|
|
12
12
|
delete_test_members
|
13
13
|
end
|
14
14
|
|
15
|
+
=begin
|
15
16
|
# members
|
16
17
|
def test_can_create_member
|
17
18
|
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe").save
|
18
19
|
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe").save!
|
19
|
-
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com").save
|
20
|
-
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com").save!
|
20
|
+
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com").save # create member with no name
|
21
|
+
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com").save! # create member with
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
def test_can_create_member_with_explicit_list
|
24
25
|
assert Postal::Member.new(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe", :list_name => @config['list_name']).save
|
25
26
|
end
|
@@ -58,7 +59,14 @@ class MemberTest < Test::Unit::TestCase
|
|
58
59
|
assert Postal::Member.find(new_member.email)
|
59
60
|
assert Postal::Member.find(new_member.email, @config['list_name']) # with explicit list_name
|
60
61
|
end
|
62
|
+
=end
|
63
|
+
|
64
|
+
def test_can_unsubscribe_member
|
65
|
+
new_member = Postal::Member.create(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe")
|
66
|
+
assert new_member.unsubscribe
|
67
|
+
end
|
61
68
|
|
69
|
+
=begin
|
62
70
|
def test_can_find_member_by_filters
|
63
71
|
Postal::Member.create(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe")
|
64
72
|
Postal::Member.create(:email => "john.doe#{rand(1000000)}@anonymous.com", :name => "John Doe 2")
|
@@ -93,5 +101,5 @@ class MemberTest < Test::Unit::TestCase
|
|
93
101
|
assert member.update_attributes(:field_0 => 'Baseball')
|
94
102
|
assert_equal Postal::Member.find(new_member.email).demographics[:field_0], 'Baseball'
|
95
103
|
end
|
96
|
-
|
104
|
+
=end
|
97
105
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
-
# require 'shoulda'
|
4
3
|
|
5
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
|
7
6
|
require 'postal'
|
8
7
|
|
9
8
|
class Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,52 +1,51 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: postal
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- The Active Network
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
date: 2012-02-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: &70139391646780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.7
|
17
22
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version:
|
25
|
-
description: Lyris is an enterprise email service. Postal makes it easy for Ruby to talk to Lyris's API.
|
26
|
-
email: rob.cameron@active.com
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139391646780
|
25
|
+
description: Lyris is an enterprise email service. Postal makes it easy for Ruby to
|
26
|
+
talk to Lyris's API.
|
27
|
+
email:
|
28
|
+
- ''
|
27
29
|
executables: []
|
28
|
-
|
29
30
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
- LICENSE
|
33
|
-
- README.rdoc
|
34
|
-
files:
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
35
33
|
- .document
|
36
34
|
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
37
|
- LICENSE
|
38
|
-
- README.
|
38
|
+
- README.md
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
41
|
- lib/postal.rb
|
42
42
|
- lib/postal/base.rb
|
43
43
|
- lib/postal/content.rb
|
44
|
+
- lib/postal/driver.rb
|
44
45
|
- lib/postal/list.rb
|
45
|
-
- lib/postal/lmapi/lmapi.rb
|
46
|
-
- lib/postal/lmapi/lmapi_driver.rb
|
47
|
-
- lib/postal/lmapi/lmapi_mapping_registry.rb
|
48
46
|
- lib/postal/mailing.rb
|
49
47
|
- lib/postal/member.rb
|
48
|
+
- lib/postal/version.rb
|
50
49
|
- postal.gemspec
|
51
50
|
- test/content_test.rb
|
52
51
|
- test/list_test.rb
|
@@ -56,38 +55,36 @@ files:
|
|
56
55
|
- test/member_test.rb
|
57
56
|
- test/postal_suite.rb
|
58
57
|
- test/test_helper.rb
|
59
|
-
|
60
|
-
homepage: http://github.com/activenetwork/postal
|
58
|
+
homepage: ''
|
61
59
|
licenses: []
|
62
|
-
|
63
60
|
post_install_message:
|
64
|
-
rdoc_options:
|
65
|
-
|
66
|
-
require_paths:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
67
63
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
80
76
|
requirements: []
|
81
|
-
|
82
|
-
|
83
|
-
rubygems_version: 1.3.5
|
77
|
+
rubyforge_project: postal
|
78
|
+
rubygems_version: 1.8.10
|
84
79
|
signing_key:
|
85
80
|
specification_version: 3
|
86
|
-
summary:
|
87
|
-
|
81
|
+
summary: Lyris is an enterprise email service. Postal makes it easy for Ruby to talk
|
82
|
+
to Lyris's API.
|
83
|
+
test_files:
|
88
84
|
- test/content_test.rb
|
89
85
|
- test/list_test.rb
|
90
86
|
- test/lmapiClient.rb
|
87
|
+
- test/lyris_sample.yml
|
91
88
|
- test/mailing_test.rb
|
92
89
|
- test/member_test.rb
|
93
90
|
- test/postal_suite.rb
|
data/README.rdoc
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
== Introduction
|
2
|
-
|
3
|
-
Postal is a gem for working with the Lyris API. "But the Lyris API is just a SOAP service, why
|
4
|
-
don't I use something like Soap4r?" Well you could, but it wouldn't be very pretty. When the
|
5
|
-
interface is created all properties passed to a method are required and always in a certain order.
|
6
|
-
|
7
|
-
Postal does use the Soap4r interface behind the scenes but gives you a simple ActiveRecord-like
|
8
|
-
interface for search and adding records.
|
9
|
-
|
10
|
-
== Installation
|
11
|
-
|
12
|
-
Get the gem:
|
13
|
-
|
14
|
-
gem sources -a http://gems.github.com
|
15
|
-
sudo gem install cannikin-postal
|
16
|
-
|
17
|
-
Then to use just add the require to your script:
|
18
|
-
|
19
|
-
require 'rubygems'
|
20
|
-
require 'postal'
|
21
|
-
|
22
|
-
== Usage
|
23
|
-
|
24
|
-
Postal feels a lot like using ActiveRecord. You create/save new Members, find existing ones, etc.
|
25
|
-
All of the examples below assume you've already set up Postal with your username, password and WSDL
|
26
|
-
endpoint, and optionally the name of the list that all operations should use:
|
27
|
-
|
28
|
-
Postal.options[:wsdl] = 'http://mymailserver.com:82/?wsdl'
|
29
|
-
Postal.options[:username] = 'username'
|
30
|
-
Postal.options[:password] = 'password'
|
31
|
-
Postal.options[:list_name] = 'my-test-list'
|
32
|
-
|
33
|
-
If you don't set your list name in the options you can pass it in with each method call.
|
34
|
-
|
35
|
-
See the /test directory for examples of just about everything you can do with Postal.
|
36
|
-
|
37
|
-
=== Lists
|
38
|
-
|
39
|
-
# find a list based on its name
|
40
|
-
Postal::List.find('my-list-name')
|
41
|
-
|
42
|
-
=== Members
|
43
|
-
|
44
|
-
# add a member to a list (the list saved to Postal.options)
|
45
|
-
new_member = Postal::Member.new(:email => "john.doe@anonymous.com", :name => "John Doe")
|
46
|
-
id = new_member.save
|
47
|
-
# id => 1234567 (the new member_id in Lyris)
|
48
|
-
|
49
|
-
# add a member to a specific list and save in one call (both lines are equivalent)
|
50
|
-
Postal::Member.new(:email => "john.doe@anonymous.com", :name => "John Doe", :list_name => "new-list").save
|
51
|
-
Postal::Member.create(:email => "john.doe@anonymous.com", :name => "John Doe", :list_name => "new-list")
|
52
|
-
|
53
|
-
Postal also has a `save!` method that throws an error if the person can't be saved, rather than just
|
54
|
-
returning false.
|
55
|
-
|
56
|
-
# update a member's demographics
|
57
|
-
new_member = Postal::Member.new(:email => "john.doe@anonymous.com", :name => "John Doe")
|
58
|
-
new_member.save
|
59
|
-
new_member.update_attributes(:field_0 => 'Male')
|
60
|
-
|
61
|
-
# find a member's id based on an email address
|
62
|
-
Postal::Member.find('john.doe@anonymous.com')
|
63
|
-
|
64
|
-
# find a member based on member_id
|
65
|
-
Postal::Member.find(1234567)
|
66
|
-
|
67
|
-
# find a member based on Lyris "filters" (see Lyris API docs for syntax)
|
68
|
-
Postal::Member.find_by_filter('EmailAddress like john.doe%')
|
69
|
-
|
70
|
-
# delete member(s) based on filters
|
71
|
-
Postal::Member.destroy("EmailAddress like john.doe-delete%")
|
72
|
-
|
73
|
-
=== Mailings
|
74
|
-
|
75
|
-
# directly send an email to an array of email addresses
|
76
|
-
mail = Postal::Mailing.new( :to => ['john.doe@anonymous.com','jane.doe@anonymous.com'],
|
77
|
-
:html_message => "<p>Test from Postal at #{Time.now.to_s}</p>",
|
78
|
-
:text_message => 'Test test from Postal at #{Time.now.to_s}',
|
79
|
-
:from => 'Postmaster <postmaster@company.com>',
|
80
|
-
:subject => 'Test from Postal')
|
81
|
-
mail.valid?
|
82
|
-
mail.send
|
83
|
-
|
84
|
-
Mailings require a couple things to be valid, mainly someone to send to, a subject, and
|
85
|
-
the name of a list to send to. `mail.valid?` will return false if any of these do not exist.
|
86
|
-
|
87
|
-
== To Do
|
88
|
-
|
89
|
-
* Implement wrappers for remaining Lyris methods
|
90
|
-
|
91
|
-
== Thanks
|
92
|
-
|
93
|
-
Special thanks to this article: http://markthomas.org/2007/09/12/getting-started-with-soap4r/
|
94
|
-
Mark details how to use Soap4r (for which there is very little documentation in the world) and
|
95
|
-
his example includes talking to Lyris! Postal probably couldn't have happened without his article.
|
96
|
-
|
97
|
-
== Note on Patches/Pull Requests
|
98
|
-
|
99
|
-
* Fork the project.
|
100
|
-
* Make your feature addition or bug fix.
|
101
|
-
* Add tests for it. This is important so I don't break it in a
|
102
|
-
future version unintentionally.
|
103
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
104
|
-
* Send me a pull request. Bonus points for topic branches.
|
105
|
-
|
106
|
-
== Copyright
|
107
|
-
|
108
|
-
Copyright (c) 2009 Rob Cameron. See LICENSE for details.
|