dyn-rb 1.0.4 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,202 +1,11 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
1
+ Copyright (c) 2014, Dynamic Network Services Inc. All rights reserved.
4
2
 
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
4
 
7
- 1. Definitions.
5
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
6
 
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
7
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
8
 
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
9
+ Neither the name of Dynamic Network Services Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
202
10
 
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -16,4 +16,5 @@
16
16
  # limitations under the License.
17
17
  #
18
18
  require 'dyn/traffic'
19
- require 'dyn/messaging'
19
+ require 'dyn/messaging'
20
+ require 'dyn/version'
@@ -50,7 +50,7 @@ module Dyn
50
50
  @apikey = apikey
51
51
  @rest = Dyn::HttpClient::DefaultClient.new("emailapi.dynect.net", "443", "https")
52
52
  @rest.default_headers = {
53
- 'User-Agent' => 'dyn-rb 1.0.4',
53
+ 'User-Agent' => Dyn::VERSION,
54
54
  'Content-Type' => 'application/x-www-form-urlencoded'
55
55
  }
56
56
  @verbose = verbose
@@ -136,13 +136,8 @@ module Dyn
136
136
  response_body = begin
137
137
  response = block.call
138
138
  response.body
139
- rescue Exception => e
140
- if @verbose
141
- puts "I have #{e.inspect} with #{e.http_code}"
142
- end
143
- e.response
144
139
  end
145
-
140
+
146
141
  response = JSON.parse(response_body || '{}')
147
142
 
148
143
  if (response["response"] && response["response"]["status"] == 200)
@@ -27,8 +27,12 @@ module Dyn
27
27
  @dyn.get("#{resource_path}/count", {starttime:starttime, endtime:endtime})
28
28
  end
29
29
 
30
- def list(starttime, endtime, startindex=0)
31
- @dyn.get("#{resource_path}", {starttime:starttime, endtime:endtime, startindex:startindex})
30
+ def list(starttime, endtime, startindex=0, emailaddress=nil)
31
+ if not emailaddress.nil?
32
+ @dyn.get("#{resource_path}", {starttime:starttime, endtime:endtime, startindex:startindex, emailaddress:emailaddress})
33
+ else
34
+ @dyn.get("#{resource_path}", {starttime:starttime, endtime:endtime, startindex:startindex})
35
+ end
32
36
  end
33
37
 
34
38
  private
@@ -23,8 +23,11 @@ module Dyn
23
23
  @dyn = dyn
24
24
  end
25
25
 
26
- def create(from, to, subject, bodytext, bodyhtml, cc, replyto, xheaders)
27
- @dyn.post("#{resource_path}", {from:from, to:to, subject:subject, bodytext:bodytext, bodyhtml:bodyhtml, cc:cc, replyto:replyto, xheaders:xheaders})
26
+ # TODO: ??? test for valid X-header format??
27
+
28
+ def create(from, to, subject, bodytext, bodyhtml, cc, replyto, xheaders={})
29
+ @dyn.post("#{resource_path}", {from:from, to:to, subject:subject, bodytext:bodytext, bodyhtml:bodyhtml, cc:cc, replyto:replyto}.
30
+ merge(xheaders))
28
31
  end
29
32
 
30
33
  private
@@ -53,7 +53,7 @@ module Dyn
53
53
  @password = password
54
54
  @rest = Dyn::HttpClient::DefaultClient.new("api2.dynect.net", "443", "https")
55
55
  @rest.default_headers = {
56
- 'User-Agent' => 'dyn-rb 1.0.4',
56
+ 'User-Agent' => Dyn::VERSION,
57
57
  'Content-Type' => 'application/json'
58
58
  }
59
59
  @zone = zone
@@ -91,6 +91,11 @@ module Dyn
91
91
  zone.publish
92
92
  end
93
93
 
94
+ # for convenience...
95
+ def discard_change_set
96
+ zone.discard_change_set
97
+ end
98
+
94
99
  ##
95
100
  # Zone attribute setter
96
101
  ##
@@ -194,24 +199,14 @@ module Dyn
194
199
 
195
200
  # Handles making Dynect API requests and formatting the responses properly.
196
201
  def api_request(&block)
197
- response_body = begin
198
- response = block.call
199
- response.body
200
- rescue Exception => e
201
- if @verbose
202
- puts "I have #{e.inspect} with #{e.http_code}"
203
- end
204
- if e.http_code == 307
205
- e.response.sub!('/REST/','') if e.response =~ /^\/REST\//
206
- get(e.response)
207
- end
208
- e.response
202
+ response = block.call
203
+ if response.status == 307 and response.body =~ /^\/REST\//
204
+ response.body.sub!('/REST/','')
205
+ response = get(response.body)
209
206
  end
210
-
211
- parse_response(JSON.parse(response_body || '{}'))
207
+ parse_response(JSON.parse(response.body || '{}'))
212
208
  end
213
209
 
214
- #
215
210
  def parse_response(response)
216
211
  case response["status"]
217
212
  when "success"
@@ -221,8 +216,10 @@ module Dyn
221
216
  # raise an error and return the job ID in case we want to ask the API what the job's status is
222
217
  error_messages = []
223
218
  error_messages.push( "This session may have a job _still_ running (slowly). Call /REST/Job/#{response["job_id"]} to get its status." )
224
- response["msgs"].each do |error_message|
225
- error_messages << "#{error_message["LVL"]} #{error_message["ERR_CD"]} #{error_message["SOURCE"]} - #{error_message["INFO"]}"
219
+ if response["msgs"]
220
+ response["msgs"].each do |error_message|
221
+ error_messages << "#{error_message["LVL"]} #{error_message["ERR_CD"]} #{error_message["SOURCE"]} - #{error_message["INFO"]}"
222
+ end
226
223
  end
227
224
  raise Dyn::Exceptions::IncompleteRequest.new( "#{error_messages.join("\n")}", response["job_id"] )
228
225
  when "failure"
@@ -33,6 +33,16 @@ module Dyn
33
33
  @dyn.put("Zone/#{@zone}", { "publish" => true })
34
34
  end
35
35
 
36
+ # Discard any pending changes in the session - required if you don't with to persist changes.
37
+ #
38
+ # See: https://help.dynect.net/delete-zone-change-set-api/
39
+ #
40
+ # @param [String] The zone to discard changes for - if one is provided when instantiated, we use that.
41
+ # @return [Hash] The dynect API response
42
+ def discard_change_set
43
+ @dyn.delete("ZoneChanges/#{@zone}")
44
+ end
45
+
36
46
  # Freeze the zone.
37
47
  #
38
48
  # See: https://manage.dynect.net/help/docs/api2/rest/resources/Zone.html
@@ -52,6 +62,16 @@ module Dyn
52
62
  def thaw
53
63
  @dyn.put("Zone/#{@zone}", { "thaw" => true })
54
64
  end
65
+
66
+ # Show pending changes to zone
67
+ #
68
+ # See: https://help.dyn.com/get-zone-changeset-api/
69
+ #
70
+ # @param [String] The zone which we want to see the changes for - if one is provided when instantiated, we use that.
71
+ # @return [Hash] The dynect API response
72
+ def get_change_set
73
+ @dyn.get("ZoneChanges/#{@zone}")
74
+ end
55
75
  end
56
76
  end
57
77
  end
@@ -1,3 +1,3 @@
1
1
  module Dyn
2
- VERSION='1.0.4'
2
+ VERSION='1.0.7'
3
3
  end
@@ -0,0 +1,3 @@
1
+ module Dyn
2
+ VERSION='1.0.4'
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "accounts()" do
6
+
7
+ start_index = 40
8
+ username = "some-user-name"
9
+ xheader1 = "a"
10
+ xheader2 = "b"
11
+ xheader3 = "c"
12
+ xheader4 = "d"
13
+
14
+ subject {
15
+ dyn = Dyn::Messaging::Client.new(@DEFAULT_API_KEY)
16
+ dyn.accounts
17
+ }
18
+
19
+ it "should list results with the default startindex" do
20
+ stub = stub_request(:get, "#{@API_BASE_PATH}/accounts?apikey=#{@DEFAULT_API_KEY}&startindex=0")
21
+ subject.send(:list)
22
+ expect(stub).to have_been_requested
23
+ end
24
+
25
+ it "should list results with a specified start index" do
26
+ stub = stub_request(:get, "#{@API_BASE_PATH}/accounts?apikey=#{@DEFAULT_API_KEY}&startindex=#{start_index}")
27
+ subject.send(:list, start_index)
28
+ expect(stub).to have_been_requested
29
+ end
30
+
31
+ it "should create account" do
32
+ account_data = {"username" => "a", "password" => "b", "companyname" =>"c", "phone" =>"d", "address" =>"e", "city" =>"f", "state" =>"g", "zipcode" =>"h", "country" =>"i", "timezone" =>"j", "bounceurl" =>"k", "spamurl" =>"l", "unsubscribeurl" =>"m", "tracelinks" =>"n", "trackunsubscribes" =>"o", "generatenewapikey" => "p"}
33
+
34
+ stub = stub_request(:post, "#{@API_BASE_PATH}/accounts")
35
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}"}.merge(account_data))
36
+
37
+ subject.send(:create, account_data['username'], account_data['password'], account_data['companyname'], account_data['phone'], account_data['address'], account_data['city'], account_data['state'], account_data['zipcode'], account_data['country'], account_data['timezone'], account_data['bounceurl'], account_data['spamurl'], account_data['unsubscribeurl'], account_data['tracelinks'], account_data['trackunsubscribes'], account_data['generatenewapikey'])
38
+
39
+ expect(stub).to have_been_requested
40
+ end
41
+
42
+ it "should destroy account with the given email address" do
43
+ stub = stub_request(:post, "#{@API_BASE_PATH}/accounts/delete")
44
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "username"=>username})
45
+
46
+ subject.send(:destroy, username)
47
+
48
+ expect(stub).to have_been_requested
49
+ end
50
+
51
+ it "should list xheaders" do
52
+ stub = stub_request(:get, "#{@API_BASE_PATH}/accounts/xheaders?apikey=#{@DEFAULT_API_KEY}")
53
+ subject.send(:list_xheaders)
54
+ expect(stub).to have_been_requested
55
+ end
56
+
57
+ it "should update xheaders" do
58
+ stub = stub_request(:post, "#{@API_BASE_PATH}/accounts/xheaders")
59
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "xheader1"=>xheader1, "xheader2"=>xheader2, "xheader3"=>xheader3, "xheader4"=>xheader4})
60
+
61
+ subject.send(:update_xheaders, xheader1, xheader2, xheader3, xheader4)
62
+
63
+ expect(stub).to have_been_requested
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "bounces()" do
6
+
7
+ subject { @dyn.bounces }
8
+ it_should_behave_like "a collection", "reports/bounces"
9
+
10
+ it "should list results for a specific receiver email address" do
11
+ start_time = 1
12
+ end_time = 2
13
+ start_index = 40
14
+ email_address = "abc@domain.com"
15
+
16
+ stub = stub_request(:get, "#{@API_BASE_PATH}/reports/bounces?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}&startindex=#{start_index}&emailaddress=#{email_address}")
17
+ subject.send(:list, start_time, end_time, start_index, email_address)
18
+ expect(stub).to have_been_requested
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "clicks()" do
6
+ subject { @dyn.clicks }
7
+ it_should_behave_like "a collection", "reports/clicks"
8
+ it_should_behave_like "a unique collection", "reports/clicks"
9
+ end
10
+
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "complaints()" do
6
+ subject { @dyn.complaints }
7
+ it_should_behave_like "a collection", "reports/complaints"
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "delivery()" do
6
+ subject { @dyn.delivery }
7
+ it_should_behave_like "a collection", "reports/delivered"
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "issues()" do
6
+ subject { @dyn.issues }
7
+ it_should_behave_like "a collection", "reports/issues"
8
+ end
9
+
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "opens()" do
6
+ subject { @dyn.opens }
7
+ it_should_behave_like "a collection", "reports/opens"
8
+ it_should_behave_like "a unique collection", "reports/opens"
9
+ end
10
+
11
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "recipients()" do
6
+ emailaddress = "abc@foobar.com"
7
+
8
+ subject { @dyn.recipients }
9
+
10
+ it "should retrieve the status of an email address" do
11
+
12
+ stub = stub_request(:get, "#{@API_BASE_PATH}/recipients/status?apikey=#{@DEFAULT_API_KEY}&emailaddress=#{emailaddress}")
13
+
14
+ subject.send(:status, emailaddress)
15
+
16
+ expect(stub).to have_been_requested
17
+ end
18
+
19
+ it "should activate an email address" do
20
+ stub = stub_request(:post, "#{@API_BASE_PATH}/recipients/activate")
21
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress})
22
+
23
+ subject.send(:activate, emailaddress)
24
+
25
+ expect(stub).to have_been_requested
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "send_mail()" do
6
+
7
+ subject { @dyn.send_mail }
8
+
9
+ headers = {
10
+ 'xheader1' => 'value1',
11
+ 'xheader2' => 'value2'
12
+ }
13
+
14
+ it "should send an email" do
15
+ stub = stub_request(:post, "#{@API_BASE_PATH}/send")
16
+ .with(:body => {"apikey" => "#{@DEFAULT_API_KEY}", "from" => "a", "to" => "b", "subject" => "c", "bodytext" => "d", "bodyhtml" => "e", "cc" => "f", "replyto" => "g"}.merge(headers))
17
+
18
+ subject.send(:create, "a", "b", "c", "d", "e", "f", "g", headers)
19
+
20
+ expect(stub).to have_been_requested
21
+ end
22
+
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "recipients()" do
6
+
7
+ start_index = 40
8
+ emailaddress = "my-sender@foobar.com"
9
+ seeding = 1
10
+ dkim = "[identifier]._domainkey.[senderdomain]"
11
+
12
+ subject { @dyn.senders }
13
+
14
+ it "should list results with the default startindex" do
15
+ stub = stub_request(:get, "#{@API_BASE_PATH}/senders?apikey=#{@DEFAULT_API_KEY}&startindex=0")
16
+ subject.send(:list)
17
+ expect(stub).to have_been_requested
18
+ end
19
+
20
+ it "should list results with a specified start index" do
21
+ stub = stub_request(:get, "#{@API_BASE_PATH}/senders?apikey=#{@DEFAULT_API_KEY}&startindex=#{start_index}")
22
+ subject.send(:list, start_index)
23
+ expect(stub).to have_been_requested
24
+ end
25
+
26
+ it "should create sender with default seeding" do
27
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders")
28
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress, "seeding" => "0"})
29
+
30
+ subject.send(:create, emailaddress)
31
+
32
+ expect(stub).to have_been_requested
33
+ end
34
+
35
+ it "should create sender with specified seeding" do
36
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders")
37
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress, "seeding" => "#{seeding}"})
38
+
39
+ subject.send(:create, emailaddress, seeding)
40
+
41
+ expect(stub).to have_been_requested
42
+ end
43
+
44
+ it "should update sender with default seeding" do
45
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders")
46
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress, "seeding" => "0"})
47
+
48
+ subject.send(:update, emailaddress)
49
+
50
+ expect(stub).to have_been_requested
51
+ end
52
+
53
+ it "should update sender with specified seeding" do
54
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders")
55
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress, "seeding" => "#{seeding}"})
56
+
57
+ subject.send(:update, emailaddress, seeding)
58
+
59
+ expect(stub).to have_been_requested
60
+ end
61
+
62
+ it "should destroy sender with the given email address" do
63
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders/delete")
64
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress})
65
+
66
+ subject.send(:destroy, emailaddress)
67
+
68
+ expect(stub).to have_been_requested
69
+ end
70
+
71
+ it "should get details" do
72
+ stub = stub_request(:get, "#{@API_BASE_PATH}/senders/details?apikey=#{@DEFAULT_API_KEY}&emailaddress=#{emailaddress}")
73
+ subject.send(:details, emailaddress)
74
+ expect(stub).to have_been_requested
75
+ end
76
+
77
+ it "should get status" do
78
+ stub = stub_request(:get, "#{@API_BASE_PATH}/senders/status?apikey=#{@DEFAULT_API_KEY}&emailaddress=#{emailaddress}")
79
+ subject.send(:status, emailaddress)
80
+ expect(stub).to have_been_requested
81
+ end
82
+
83
+ it "should set the dkim for the given email address" do
84
+ stub = stub_request(:post, "#{@API_BASE_PATH}/senders/dkim")
85
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress, "dkim"=>dkim})
86
+
87
+ subject.send(:dkim, emailaddress, dkim)
88
+
89
+ expect(stub).to have_been_requested
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "sent()" do
6
+ subject { @dyn.sent_mail }
7
+ it_should_behave_like "a collection", "reports/sent"
8
+ end
9
+
10
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dyn::Messaging::Client do
4
+
5
+ describe "suppressions()" do
6
+
7
+ subject { @dyn.suppressions }
8
+
9
+ start_date = 1
10
+ end_date = 2
11
+ start_index = 40
12
+ emailaddress = "abc@foobar.com"
13
+
14
+ it "should be countable" do
15
+ stub = stub_request(:get, "#{@API_BASE_PATH}/suppressions/count?apikey=#{@DEFAULT_API_KEY}&startdate=#{start_date}&enddate=#{end_date}")
16
+
17
+ subject.send(:count, start_date, end_date)
18
+
19
+ expect(stub).to have_been_requested
20
+ end
21
+
22
+ it "should list results for a date range with the default startindex" do
23
+ stub = stub_request(:get, "#{@API_BASE_PATH}/suppressions?apikey=#{@DEFAULT_API_KEY}&startdate=#{start_date}&enddate=#{end_date}&startindex=0")
24
+
25
+ subject.send(:list,start_date, end_date)
26
+
27
+ expect(stub).to have_been_requested
28
+ end
29
+
30
+ it "should list results for a date range with a specified start index" do
31
+ stub = stub_request(:get, "#{@API_BASE_PATH}/suppressions?apikey=#{@DEFAULT_API_KEY}&startdate=#{start_date}&enddate=#{end_date}&startindex=#{start_index}")
32
+
33
+ subject.send(:list, start_date, end_date, start_index)
34
+
35
+ expect(stub).to have_been_requested
36
+ end
37
+
38
+ it "should create a new suppression list entry" do
39
+ stub = stub_request(:post, "#{@API_BASE_PATH}/suppressions")
40
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress})
41
+
42
+ subject.send(:create, emailaddress)
43
+
44
+ expect(stub).to have_been_requested
45
+ end
46
+
47
+ it "should activates an email address on the suppression list" do
48
+ stub = stub_request(:post, "#{@API_BASE_PATH}/suppressions/activate")
49
+ .with(:body => {"apikey"=>"#{@DEFAULT_API_KEY}", "emailaddress"=>emailaddress})
50
+
51
+ subject.send(:activate, emailaddress)
52
+
53
+ expect(stub).to have_been_requested
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "bundler"
4
+ Bundler.setup
5
+
6
+ require "spec_helper"
7
+ require "rspec"
8
+ require "webmock/rspec"
9
+
10
+ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/dyn-rb.rb"))
11
+
12
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+
16
+ config.expect_with :rspec do |c|
17
+ c.syntax = :expect
18
+ end
19
+
20
+ config.before(:all) do
21
+ @DEFAULT_API_KEY = 1
22
+ @API_BASE_PATH = 'https://emailapi.dynect.net/rest/json'
23
+
24
+ @dyn = Dyn::Messaging::Client.new(@DEFAULT_API_KEY)
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ shared_examples "a collection" do |call_path|
2
+ start_time = 1
3
+ end_time = 2
4
+ start_index = 40
5
+
6
+ it "should be countable" do
7
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}/count?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}")
8
+ subject.send(:count, start_time, end_time)
9
+ expect(stub).to have_been_requested
10
+ end
11
+
12
+ it "should list results for a date range with the default startindex" do
13
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}&startindex=0")
14
+ subject.send(:list, start_time, end_time)
15
+ expect(stub).to have_been_requested
16
+ end
17
+
18
+ it "should list results for a date range with a specified start index" do
19
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}&startindex=#{start_index}")
20
+ subject.send(:list, start_time, end_time, start_index)
21
+ expect(stub).to have_been_requested
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ shared_examples "a unique collection" do |call_path|
2
+ start_time = 1
3
+ end_time = 2
4
+ start_index = 40
5
+
6
+ it "should be countable" do
7
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}/count/unique?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}")
8
+ subject.send(:unique_count, start_time, end_time)
9
+ expect(stub).to have_been_requested
10
+ end
11
+
12
+ it "should list results for a date range with the default startindex" do
13
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}/unique?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}&startindex=0")
14
+ subject.send(:unique, start_time, end_time)
15
+ expect(stub).to have_been_requested
16
+ end
17
+
18
+ it "should list results for a date range with a specified start index" do
19
+ stub = stub_request(:get, "#{@API_BASE_PATH}/#{call_path}/unique?apikey=#{@DEFAULT_API_KEY}&starttime=#{start_time}&endtime=#{end_time}&startindex=#{start_index}")
20
+ subject.send(:unique, start_time, end_time, start_index)
21
+ expect(stub).to have_been_requested
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,19 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyn-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.7
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
- - Sunny Gleason
8
- - Dani Dewitt
9
- - Adam Sarenski
10
- - Adam Jacob
11
- - Ranjib Dey
8
+ - Dyn Inc
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
- date: 2014-07-14 00:00:00.000000000 Z
16
- dependencies: []
12
+ date: 2015-04-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fuubar
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
17
62
  description: Dyn Ruby SDK
18
63
  email: concierge@dyn.com
19
64
  executables: []
@@ -49,28 +94,45 @@ files:
49
94
  - lib/dyn/traffic/zone.rb
50
95
  - lib/dyn/traffic.rb
51
96
  - lib/dyn/version.rb
97
+ - lib/dyn/version.rb~
52
98
  - lib/dyn-rb.rb
99
+ - spec/messaging/accounts_spec.rb
100
+ - spec/messaging/bounces_spec.rb
101
+ - spec/messaging/clicks_spec.rb
102
+ - spec/messaging/complaints_spec.rb
103
+ - spec/messaging/delivery_spec.rb
104
+ - spec/messaging/issues_spec.rb
105
+ - spec/messaging/opens_spec.rb
106
+ - spec/messaging/recipients_spec.rb
107
+ - spec/messaging/send_mail_spec.rb
108
+ - spec/messaging/senders_spec.rb
109
+ - spec/messaging/sent_mail_spec.rb
110
+ - spec/messaging/suppressions_spec.rb
111
+ - spec/spec_helper.rb
112
+ - spec/support/a_collection_resource.rb
113
+ - spec/support/a_collection_resource_with_uniqueness.rb
53
114
  homepage: http://github.com/dyninc/dyn-rb
54
115
  licenses: []
55
- metadata: {}
56
116
  post_install_message:
57
117
  rdoc_options: []
58
118
  require_paths:
59
119
  - lib
60
120
  required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
61
122
  requirements:
62
- - - '>='
123
+ - - ! '>='
63
124
  - !ruby/object:Gem::Version
64
125
  version: '0'
65
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
66
128
  requirements:
67
- - - '>='
129
+ - - ! '>='
68
130
  - !ruby/object:Gem::Version
69
131
  version: '0'
70
132
  requirements: []
71
133
  rubyforge_project:
72
- rubygems_version: 2.0.14
134
+ rubygems_version: 1.8.23.2
73
135
  signing_key:
74
- specification_version: 4
136
+ specification_version: 3
75
137
  summary: Dyn Ruby SDK
76
138
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a622d2577af3d41ddbc424ad6418f909a35f149b
4
- data.tar.gz: d26db9e36da5467858a35f556ea6a3619b6b4e4d
5
- SHA512:
6
- metadata.gz: 61d7833421ef55ca40c0dae29f34d42652c445424ba4de65f9227f40c590e0fef3c75809ae428b55393188cbb94883b2fdb01606afb95207bd626b14820c59c7
7
- data.tar.gz: 246ce276c2f99435f48ba94933489cfac10aee8b8adb87451fc73b03f56c597433e9c366ae2001043a369838640eee356e2713ae0d226cebba3060bbd5297e0e