send_with_us 1.0.5 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4af3e368512e19608207ecc65ef6a8e6cd8deb0b
4
- data.tar.gz: f1f2ac7ebb7d14164f768dab256669fe5e1822da
3
+ metadata.gz: 1e1ccb915c665ef78694fb507017fde34ae43b83
4
+ data.tar.gz: 4f6b82c1110f7284652f71dcfa0eeb5957bd67b9
5
5
  SHA512:
6
- metadata.gz: 5071d2e5c5c453c26802b024483e61ce3dd93a03410c8eddacf7bfa493eed1fe42c4f814386c3bc5ec3e872ba20800162e4442e1f8fab6d89ee860f19bf1ed2b
7
- data.tar.gz: b5088e7f4267e46867e29bd12acc7b7583bfa159736c697caa16bf2091fa2cddaaf951e074604a195036c957c9b687c3465f8e181a869ab70bec03c0f38923ab
6
+ metadata.gz: 0187466927694f4dc3ee0aaabfe0f67fd7bf11fae095a857ea77af5cb6f9ca114240ab435477e4d5c1816093bfc51bd8532cc8d908470e39d90c596e1bfc5670
7
+ data.tar.gz: b3b1ce4aee881938c37ec44aaf1b5211509c22f9a5aa44cc11631e9f0a966c952750b871bff2c249043521a09be4e62c38f8f7e78eda6fa511458c3308c69cc0
data/README.md CHANGED
@@ -34,37 +34,50 @@ begin
34
34
  # only required params
35
35
  result = obj.send_with(
36
36
  'EMAIL_ID',
37
- { address: "user@email.com" })
37
+ { address: "user@example.com" })
38
38
  puts result
39
39
 
40
40
  # with all optional params
41
41
  result = obj.send_with(
42
42
  'email_id',
43
- { name: 'Matt', address: 'recipient@testco.com' },
43
+ { name: 'Matt', address: 'recipient@example.com' },
44
44
  { company_name: 'TestCo' },
45
45
  { name: 'Company',
46
- address: 'company@testco.com',
47
- reply_to: 'info@testco.com' })
46
+ address: 'company@example.com',
47
+ reply_to: 'info@example.com' })
48
48
  puts result
49
49
 
50
50
  # full cc/bcc support
51
51
  result = obj.send_with(
52
52
  'email_id',
53
- { name: 'Matt', address: 'recipient@testco.com' },
53
+ { name: 'Matt', address: 'recipient@example.com' },
54
54
  { company_name: 'TestCo' },
55
55
  { name: 'Company',
56
- address: 'company@testco.com',
57
- reply_to: 'info@testco.com' },
56
+ address: 'company@example.com',
57
+ reply_to: 'info@example.com' },
58
58
  [
59
59
  { name: 'CC',
60
- address: 'cc@testco.com' }
60
+ address: 'cc@example.com' }
61
61
  ],
62
62
  [
63
63
  { name: 'BCC',
64
- address: 'bcc@testco.com' },
64
+ address: 'bcc@example.com' },
65
65
  { name: 'BCC2',
66
- address: 'bcc2@test.com' }
66
+ address: 'bcc2@example.com' }
67
67
  ])
68
+
69
+ # Attachment support
70
+ result = obj.send_with(
71
+ 'email_id',
72
+ { name: 'Matt', address: 'recipient@example.com' },
73
+ { company_name: 'TestCo' },
74
+ { name: 'Company',
75
+ address: 'company@example.com',
76
+ reply_to: 'info@example.com' },
77
+ [],
78
+ [],
79
+ ['path/to/file.txt'])
80
+
68
81
  puts result
69
82
  rescue => e
70
83
  puts "Error - #{e.class.name}: #{e.message}"
@@ -87,7 +100,7 @@ In your application code where you want to send an email:
87
100
 
88
101
  ```ruby
89
102
  begin
90
- result = SendWithUs::Api.new.send_with('email_id', { address: 'recipient@testco.com' }, { company_name: 'TestCo' })
103
+ result = SendWithUs::Api.new.send_with('email_id', { address: 'recipient@example.com' }, { company_name: 'TestCo' })
91
104
  puts result
92
105
  rescue => e
93
106
  puts "Error - #{e.class.name}: #{e.message}"
@@ -29,7 +29,7 @@ module SendWithUs
29
29
  raise SendWithUs::ApiNilEmailId, 'email_id cannot be nil'
30
30
  end
31
31
 
32
- payload = { email_id: email_id, recipient: to,
32
+ payload = { email_id: email_id, recipient: to,
33
33
  email_data: data }
34
34
 
35
35
  if from.any?
@@ -53,7 +53,7 @@ module SendWithUs
53
53
  end
54
54
 
55
55
  payload = payload.to_json
56
- SendWithUs::ApiRequest.new(@configuration).send_with(payload)
56
+ SendWithUs::ApiRequest.new(@configuration).post(:send, payload)
57
57
  end
58
58
 
59
59
  def drips_unsubscribe(email_address)
@@ -64,14 +64,25 @@ module SendWithUs
64
64
 
65
65
  payload = { email_address: email_address }
66
66
  payload = payload.to_json
67
-
68
- SendWithUs::ApiRequest.new(@configuration).drips_unsubscribe(payload)
67
+
68
+ SendWithUs::ApiRequest.new(@configuration).post(:'drips/unsubscribe', payload)
69
69
  end
70
70
 
71
71
  def emails()
72
72
  SendWithUs::ApiRequest.new(@configuration).get(:emails)
73
73
  end
74
74
 
75
+ def create_template(name, subject, html, text)
76
+ payload = {
77
+ name: name,
78
+ subject: subject,
79
+ html: html,
80
+ text: text
81
+ }.to_json
82
+
83
+ SendWithUs::ApiRequest.new(@configuration).post(:emails, payload)
84
+ end
85
+
75
86
  end
76
87
 
77
88
  end
@@ -12,93 +12,12 @@ module SendWithUs
12
12
  @configuration = configuration
13
13
  end
14
14
 
15
- def send_with(payload)
16
-
17
- path = request_path(:send)
18
- request = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'})
19
- request.add_field('X-SWU-API-KEY', @configuration.api_key)
20
- request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)
21
-
22
- http = Net::HTTP.new(@configuration.host, @configuration.port)
23
- http.use_ssl = use_ssl?
24
- http.set_debug_output($stdout) if @configuration.debug
25
-
26
- @response = http.request(request, payload)
27
-
28
- case @response
29
- when Net::HTTPNotFound then
30
- raise SendWithUs::ApiInvalidEndpoint, path
31
- when Net::HTTPForbidden then
32
- raise SendWithUs::ApiInvalidKey, 'Invalid api key: ' + @configuration.api_key
33
- when Net::HTTPBadRequest then
34
- raise SendWithUs::ApiBadRequest, @response.body
35
- when Net::HTTPSuccess then
36
- puts @response.body if @configuration.debug
37
- @response
38
- else
39
- raise SendWithUs::ApiUnknownError, 'An unknown error has occurred'
40
- end
41
- rescue Errno::ECONNREFUSED
42
- raise SendWithUs::ApiConnectionRefused, 'The connection was refused'
43
- end
44
-
45
- def drips_unsubscribe(payload)
46
-
47
- path = request_path(:'drips/unsubscribe')
48
- request = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'})
49
- request.add_field('X-SWU-API-KEY', @configuration.api_key)
50
- request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)
51
-
52
- http = Net::HTTP.new(@configuration.host, @configuration.port)
53
- http.use_ssl = use_ssl?
54
- http.set_debug_output($stdout) if @configuration.debug
55
-
56
- @response = http.request(request, payload)
57
-
58
- case @response
59
- when Net::HTTPNotFound then
60
- raise SendWithUs::ApiInvalidEndpoint, path
61
- when Net::HTTPForbidden then
62
- raise SendWithUs::ApiInvalidKey, 'Invalid api key: ' + @configuration.api_key
63
- when Net::HTTPBadRequest then
64
- raise SendWithUs::ApiBadRequest, @response.body
65
- when Net::HTTPSuccess then
66
- puts @response.body if @configuration.debug
67
- @response
68
- else
69
- raise SendWithUs::ApiUnknownError, 'An unknown error has occurred'
70
- end
71
- rescue Errno::ECONNREFUSED
72
- raise SendWithUs::ApiConnectionRefused, 'The connection was refused'
15
+ def post(endpoint, payload)
16
+ request(Net::HTTP::Post, request_path(endpoint), payload)
73
17
  end
74
18
 
75
19
  def get(endpoint)
76
- path = request_path(endpoint)
77
- request = Net::HTTP::Get.new(path, initheader = {'Content-Type' =>'application/json'})
78
- request.add_field('X-SWU-API-KEY', @configuration.api_key)
79
- request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)
80
-
81
- http = Net::HTTP.new(@configuration.host, @configuration.port)
82
- http.use_ssl = use_ssl?
83
- http.set_debug_output($stdout) if @configuration.debug
84
-
85
- @response = http.request(request)
86
-
87
- case @response
88
- when Net::HTTPNotFound then
89
- raise SendWithUs::ApiInvalidEndpoint, path
90
- when Net::HTTPForbidden then
91
- raise SendWithUs::ApiInvalidKey, 'Invalid api key: ' + @configuration.api_key
92
- when Net::HTTPBadRequest then
93
- raise SendWithUs::ApiBadRequest, @response.body
94
- when Net::HTTPSuccess
95
- puts @response.body if @configuration.debug
96
- @response
97
- else
98
- raise SendWithUs::ApiUnknownError, 'An unknown error has occurred'
99
- end
100
- rescue Errno::ECONNREFUSED
101
- raise SendWithUs::ApiConnectionRefused, 'The connection was refused'
20
+ request(Net::HTTP::Get, request_path(endpoint))
102
21
  end
103
22
 
104
23
  private
@@ -111,5 +30,32 @@ module SendWithUs
111
30
  @configuration.protocol == 'https'
112
31
  end
113
32
 
33
+ def request(method_klass, path, payload=nil)
34
+ request = method_klass.new(path, initheader = {'Content-Type' =>'application/json'})
35
+ request.add_field('X-SWU-API-KEY', @configuration.api_key)
36
+ request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)
37
+
38
+ http = Net::HTTP.new(@configuration.host, @configuration.port)
39
+ http.use_ssl = use_ssl?
40
+ http.set_debug_output($stdout) if @configuration.debug
41
+
42
+ @response = http.request(request, payload)
43
+
44
+ case @response
45
+ when Net::HTTPNotFound then
46
+ raise SendWithUs::ApiInvalidEndpoint, path
47
+ when Net::HTTPForbidden then
48
+ raise SendWithUs::ApiInvalidKey, 'Invalid api key: ' + @configuration.api_key
49
+ when Net::HTTPBadRequest then
50
+ raise SendWithUs::ApiBadRequest, @response.body
51
+ when Net::HTTPSuccess
52
+ puts @response.body if @configuration.debug
53
+ @response
54
+ else
55
+ raise SendWithUs::ApiUnknownError, 'An unknown error has occurred'
56
+ end
57
+ rescue Errno::ECONNREFUSED
58
+ raise SendWithUs::ApiConnectionRefused, 'The connection was refused'
59
+ end
114
60
  end
115
61
  end
@@ -1,3 +1,3 @@
1
1
  module SendWithUs
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -4,6 +4,7 @@ class TestApiRequest < MiniTest::Unit::TestCase
4
4
 
5
5
  def build_objects
6
6
  @payload = {}
7
+ @api = SendWithUs::Api.new( api_key: 'THIS_IS_A_TEST_API_KEY', debug: false)
7
8
  @config = SendWithUs::Config.new( api_version: '1_0', api_key: 'THIS_IS_A_TEST_API_KEY', debug: false )
8
9
  @request = SendWithUs::ApiRequest.new(@config)
9
10
  end
@@ -11,31 +12,46 @@ class TestApiRequest < MiniTest::Unit::TestCase
11
12
  def test_payload
12
13
  build_objects
13
14
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
14
- assert_instance_of( Net::HTTPSuccess, @request.send_with(@payload) )
15
+ assert_instance_of( Net::HTTPSuccess, @request.post(:send, @payload) )
16
+ end
17
+
18
+ def test_attachment
19
+ build_objects
20
+ email_id = 'test_fixture_1'
21
+ result = @api.send_with(
22
+ email_id,
23
+ {name: 'Ruby Unit Test', address: 'matt@example.com'},
24
+ {name: 'sendwithus', address: 'matt@example.com'},
25
+ {},
26
+ [],
27
+ [],
28
+ ['README.md']
29
+ )
30
+ assert_instance_of( Net::HTTPOK, result )
15
31
  end
16
32
 
17
33
  def test_unsubscribe
18
34
  build_objects
19
35
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
20
- assert_instance_of( Net::HTTPSuccess, @request.drips_unsubscribe(@payload) )
36
+ assert_instance_of( Net::HTTPSuccess, @request.post(:'drips/unsubscribe', @payload) )
21
37
  end
22
38
 
23
39
  def test_send_with_not_found_exception
24
40
  build_objects
25
41
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPNotFound.new(1.0, 404, "OK"))
26
- assert_raises( SendWithUs::ApiInvalidEndpoint ) { @request.send_with(@payload) }
42
+ assert_raises( SendWithUs::ApiInvalidEndpoint ) { @request.post(:send, @payload) }
27
43
  end
28
44
 
29
45
  def test_send_with_unknown_exception
30
46
  build_objects
31
47
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPNotAcceptable.new(1.0, 406, "OK"))
32
- assert_raises( SendWithUs::ApiUnknownError ) { @request.send_with(@payload) }
48
+ assert_raises( SendWithUs::ApiUnknownError ) { @request.post(:send, @payload) }
33
49
  end
34
50
 
35
51
  def test_send_with_connection_refused
36
52
  build_objects
37
53
  Net::HTTP.any_instance.stubs(:request).raises(Errno::ECONNREFUSED.new)
38
- assert_raises( SendWithUs::ApiConnectionRefused ) { @request.send_with(@payload) }
54
+ assert_raises( SendWithUs::ApiConnectionRefused ) { @request.post(:send, @payload) }
39
55
  end
40
56
 
41
57
  def test_emails
@@ -48,5 +64,4 @@ class TestApiRequest < MiniTest::Unit::TestCase
48
64
  build_objects
49
65
  assert_equal( true, @request.send(:request_path, :send) == '/api/v1_0/send' )
50
66
  end
51
-
52
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send_with_us
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Harris
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-07 00:00:00.000000000 Z
13
+ date: 2014-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.0.6
103
+ rubygems_version: 2.0.14
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: SendWithUs.com Ruby Client