emaildirect 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,6 +1,9 @@
1
+ ## 1.2.0 (Dec. 21st, 2011)
2
+ * Add EmailDirect.disable to disable talking to the EmailDirect server (requires fakeweb gem).
3
+
1
4
  ## 1.1.0 (Dec. 20th, 2011)
2
5
 
3
- * Added EmailDirect::Subscriber#update_custom_field and EmailDirect::Subscriber#update_custom_fields as a way to quickly update one or more custom fields.
6
+ * Add EmailDirect::Subscriber#update_custom_field and EmailDirect::Subscriber#update_custom_fields as a way to quickly update one or more custom fields.
4
7
  * 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
8
  * Authentication is done using a header instead of basic auth so FakeWeb is easier to use.
6
9
 
data/README.md CHANGED
@@ -88,6 +88,11 @@ Results in:
88
88
  Error Code: 101
89
89
  Error Message: Invalid Email Address
90
90
 
91
+ ### Disabling in Development/Test
92
+ A helper method is provided to disable talking to the EmailDirect REST server (requires the [Fakeweb gem](http://fakeweb.rubyforge.org/))
93
+
94
+ EmailDirect.disable
95
+
91
96
  ### Expected input and output
92
97
  The best way of finding out the expected input and output of a particular method in a particular class is to read the [API docs](https://docs.emaildirect.com)
93
98
  and take a look at the code for that function.
data/lib/emaildirect.rb CHANGED
@@ -27,15 +27,21 @@ 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
31
30
  class << self
32
- def api_key=(api_key=nil)
33
- EmailDirect.api_key api_key
31
+ # Just allows callers to do EmailDirect.api_key = "..." rather than EmailDirect::EmailDirect.api_key "..." etc
32
+ def api_key=(api_key)
33
+ EmailDirect.api_key = api_key
34
34
  end
35
35
 
36
36
  def base_uri=(uri)
37
37
  EmailDirect.base_uri uri
38
38
  end
39
+
40
+ # Allows the initializer to turn off actually communicating to the REST service for certain environments
41
+ # Requires fakeweb gem to be installed
42
+ def disable
43
+ FakeWeb.register_uri(:any, %r|#{Regexp.escape(EmailDirect.base_uri)}|, :body => '{"Disabled":true}', :content_type => 'application/json; charset=utf-8')
44
+ end
39
45
  end
40
46
 
41
47
  # Represents a EmailDirect API error and contains specific data about the error.
@@ -67,11 +73,37 @@ module EmailDirect
67
73
  })
68
74
  base_uri @@base_uri
69
75
 
70
- # Sets the API key which will be used to make calls to the EmailDirect API.
71
- def self.api_key(api_key = nil)
72
- return @@api_key unless api_key
73
- @@api_key = api_key
74
- headers 'ApiKey' => @@api_key
76
+ class << self
77
+ # Sets the API key which will be used to make calls to the EmailDirect API.
78
+ def api_key=(api_key)
79
+ return @@api_key unless api_key
80
+ @@api_key = api_key
81
+ headers 'ApiKey' => @@api_key
82
+ end
83
+
84
+ def base_uri; @@base_uri end
85
+
86
+ def get(*args); handle_response super end
87
+ def post(*args); handle_response super end
88
+ def put(*args); handle_response super end
89
+ def delete(*args); handle_response super end
90
+
91
+ def handle_response(response) # :nodoc:
92
+ case response.code
93
+ when 400
94
+ raise BadRequest.new(Hashie::Mash.new response)
95
+ when 401
96
+ raise Unauthorized.new
97
+ when 404
98
+ raise NotFound.new
99
+ when 400...500
100
+ raise ClientError.new response.parsed_response
101
+ when 500...600
102
+ raise ServerError.new
103
+ else
104
+ response
105
+ end
106
+ end
75
107
  end
76
108
 
77
109
  # This call returns an object reflecting the current permissions allowed for the provided API Key
@@ -79,27 +111,5 @@ module EmailDirect
79
111
  response = EmailDirect.get('/Ping')
80
112
  Hashie::Mash.new(response)
81
113
  end
82
-
83
- def self.get(*args); handle_response super end
84
- def self.post(*args); handle_response super end
85
- def self.put(*args); handle_response super end
86
- def self.delete(*args); handle_response super end
87
-
88
- def self.handle_response(response) # :nodoc:
89
- case response.code
90
- when 400
91
- raise BadRequest.new(Hashie::Mash.new response)
92
- when 401
93
- raise Unauthorized.new
94
- when 404
95
- raise NotFound.new
96
- when 400...500
97
- raise ClientError.new response.parsed_response
98
- when 500...600
99
- raise ServerError.new
100
- else
101
- response
102
- end
103
- end
104
114
  end
105
115
  end
@@ -1,3 +1,3 @@
1
1
  module EmailDirect
2
- VERSION = "1.1.0" unless defined?(EmailDirect::VERSION)
2
+ VERSION = "1.2.0" unless defined?(EmailDirect::VERSION)
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emaildirect
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Rust
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-20 00:00:00 -08:00
18
+ date: 2011-12-21 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency