emaildirect 1.0.1 → 1.1.0

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.
data/HISTORY.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 1.1.0 (Dec. 20th, 2011)
2
+
3
+ * Added EmailDirect::Subscriber#update_custom_field and EmailDirect::Subscriber#update_custom_fields as a way to quickly update one or more custom fields.
4
+ * Custom Fields can now be passed as a regular ruby hash to any of the Subscriber methods and it will be converted to the correct JSON format.
5
+ * Authentication is done using a header instead of basic auth so FakeWeb is easier to use.
6
+
7
+ ## 1.0.0 (Dec. 12th, 2011)
8
+
9
+ * Initial release
data/README.md CHANGED
@@ -7,7 +7,7 @@ A ruby library which implements the complete functionality of the REST (v5) [Ema
7
7
  ### Plain ruby
8
8
  gem install emaildirect
9
9
  require 'emaildirect'
10
- EmailDirect.api_key 'your_api_key'
10
+ EmailDirect.api_key = 'your_api_key'
11
11
 
12
12
  ### Rails integration
13
13
  In your gemfile:
@@ -16,7 +16,7 @@ In your gemfile:
16
16
 
17
17
  In an initializer:
18
18
 
19
- EmailDirect.api_key 'your_api_key'
19
+ EmailDirect.api_key = 'your_api_key'
20
20
 
21
21
  ## Examples
22
22
 
@@ -37,6 +37,20 @@ Results in:
37
37
  sub = EmailDirect::Publication.new(response.publicationID)
38
38
  sub.delete
39
39
 
40
+ ### Updating a subscriber's custom fields
41
+
42
+ A single attribute:
43
+
44
+ EmailDirect::Subscriber.new(email).update_custom_field :FirstName, 'Pat'
45
+
46
+ Multiple attributes:
47
+
48
+ EmailDirect::Subscriber.new(email).update_custom_fields :FirstName => 'Pam', :LastName => 'Sinivas'
49
+
50
+ When creating a subscriber
51
+
52
+ EmailDirect::Subscriber.create(email, :Publications => [1], :CustomFields => { :FirstName => 'Pam', :LastName => 'Sinivas' }
53
+
40
54
  ### ActionMailer integration
41
55
  You can use send your ActionMailer email through Email Direct using their Relay Send functionality by setting up a new delivery method in an initalizer:
42
56
 
data/lib/emaildirect.rb CHANGED
@@ -27,14 +27,14 @@ require 'emaildirect/suppression_list'
27
27
  require 'emaildirect/workflow'
28
28
 
29
29
  module EmailDirect
30
- # Just allows callers to do EmailDirect.api_key "..." rather than EmailDirect::EmailDirect.api_key "..." etc
30
+ # Just allows callers to do EmailDirect.api_key = "..." rather than EmailDirect::EmailDirect.api_key "..." etc
31
31
  class << self
32
- def api_key(api_key=nil)
33
- r = EmailDirect.api_key api_key
32
+ def api_key=(api_key=nil)
33
+ EmailDirect.api_key api_key
34
34
  end
35
35
 
36
- def base_uri(uri)
37
- r = EmailDirect.base_uri uri
36
+ def base_uri=(uri)
37
+ EmailDirect.base_uri uri
38
38
  end
39
39
  end
40
40
 
@@ -62,15 +62,16 @@ module EmailDirect
62
62
  headers({
63
63
  'User-Agent' => "emaildirect-rest-#{VERSION}",
64
64
  'Content-Type' => 'application/json; charset=utf-8',
65
- 'Accept-Encoding' => 'gzip, deflate' })
65
+ 'Accept-Encoding' => 'gzip, deflate',
66
+ 'ApiKey' => @@api_key
67
+ })
66
68
  base_uri @@base_uri
67
- basic_auth 'x', @@api_key
68
69
 
69
70
  # Sets the API key which will be used to make calls to the EmailDirect API.
70
- def self.api_key(api_key=nil)
71
+ def self.api_key(api_key = nil)
71
72
  return @@api_key unless api_key
72
73
  @@api_key = api_key
73
- basic_auth 'x', @@api_key
74
+ headers 'ApiKey' => @@api_key
74
75
  end
75
76
 
76
77
  # This call returns an object reflecting the current permissions allowed for the provided API Key
@@ -27,9 +27,18 @@ module EmailDirect
27
27
 
28
28
  def create(email, options = {})
29
29
  options.merge! :EmailAddress => email
30
+ self.convert_custom_fields options
30
31
  response = EmailDirect.post '/Subscribers', :body => options.to_json
31
32
  Hashie::Mash.new(response)
32
33
  end
34
+
35
+ protected
36
+
37
+ def convert_custom_fields(options)
38
+ if options.has_key?(:CustomFields) && options[:CustomFields].is_a?(Hash)
39
+ options[:CustomFields] = options[:CustomFields].map { |k, v| { :FieldName => k, :Value => v } }
40
+ end
41
+ end
33
42
  end
34
43
 
35
44
  attr_reader :email
@@ -55,10 +64,19 @@ module EmailDirect
55
64
 
56
65
  def update(options)
57
66
  options.merge! :EmailAddress => email
67
+ self.class.convert_custom_fields options
58
68
  response = EmailDirect.put uri_for, :body => options.to_json
59
69
  Hashie::Mash.new(response)
60
70
  end
61
71
 
72
+ def update_custom_field(attribute, value)
73
+ self.class.create email, :CustomFields => [ { :FieldName => attribute, :Value => value } ]
74
+ end
75
+
76
+ def update_custom_fields(attributes)
77
+ self.class.create email, :CustomFields => attributes
78
+ end
79
+
62
80
  def delete
63
81
  response = EmailDirect.delete uri_for, {}
64
82
  Hashie::Mash.new(response)
@@ -1,3 +1,3 @@
1
1
  module EmailDirect
2
- VERSION = "1.0.1" unless defined?(EmailDirect::VERSION)
2
+ VERSION = "1.1.0" unless defined?(EmailDirect::VERSION)
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emaildirect
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
- - 0
8
8
  - 1
9
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jason Rust
@@ -14,45 +15,51 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-12-13 00:00:00 -08:00
18
+ date: 2011-12-20 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
22
25
  requirements:
23
26
  - - ">="
24
27
  - !ruby/object:Gem::Version
28
+ hash: 3
25
29
  segments:
26
30
  - 0
27
31
  version: "0"
28
- name: json
29
- prerelease: false
30
- requirement: *id001
31
32
  type: :runtime
33
+ name: json
34
+ version_requirements: *id001
32
35
  - !ruby/object:Gem::Dependency
33
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
34
39
  requirements:
35
40
  - - ">="
36
41
  - !ruby/object:Gem::Version
42
+ hash: 3
37
43
  segments:
38
44
  - 0
39
45
  version: "0"
40
- name: hashie
41
- prerelease: false
42
- requirement: *id002
43
46
  type: :runtime
47
+ name: hashie
48
+ version_requirements: *id002
44
49
  - !ruby/object:Gem::Dependency
45
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
46
53
  requirements:
47
54
  - - ">="
48
55
  - !ruby/object:Gem::Version
56
+ hash: 3
49
57
  segments:
50
58
  - 0
51
59
  version: "0"
52
- name: httparty
53
- prerelease: false
54
- requirement: *id003
55
60
  type: :runtime
61
+ name: httparty
62
+ version_requirements: *id003
56
63
  description: Implements the complete functionality of the email direct REST API.
57
64
  email:
58
65
  - rustyparts@gmail.com
@@ -66,6 +73,7 @@ files:
66
73
  - .gitignore
67
74
  - Gemfile
68
75
  - Gemfile.lock
76
+ - HISTORY.md
69
77
  - LICENSE
70
78
  - README.md
71
79
  - Rakefile
@@ -103,16 +111,20 @@ rdoc_options: []
103
111
  require_paths:
104
112
  - lib
105
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
106
115
  requirements:
107
116
  - - ">="
108
117
  - !ruby/object:Gem::Version
118
+ hash: 3
109
119
  segments:
110
120
  - 0
111
121
  version: "0"
112
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
113
124
  requirements:
114
125
  - - ">="
115
126
  - !ruby/object:Gem::Version
127
+ hash: 23
116
128
  segments:
117
129
  - 1
118
130
  - 3
@@ -121,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
133
  requirements: []
122
134
 
123
135
  rubyforge_project:
124
- rubygems_version: 1.3.6
136
+ rubygems_version: 1.4.2
125
137
  signing_key:
126
138
  specification_version: 3
127
139
  summary: A library which implements the complete functionality of of the emaildirect REST API (v5).