send_with_us 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb22ce6f21aba1a56300d9053b3dcfd32f6a86e8
4
+ data.tar.gz: c76b1a8d8164876606ad0e557eee35b44feb7f83
5
+ SHA512:
6
+ metadata.gz: 99ec0c8f81778add459db53d53aa9ca44a88f4f68aa2e980eceee9968352dd51f6c19e5361df9873ec3159c4719545d450f2595d78bbe7a6f594ff871c69019f
7
+ data.tar.gz: d1772d7fef1f93635b7e4dbd386bba5194dca363a4f9e2c261cb6e5cee6ded9928d35c71c5ec37631a0e36d6296a411b7fe8139eedbc2826ee8ff8dc3db80852
data/CHANGELOG.md CHANGED
@@ -1,7 +1,7 @@
1
+ 1.0.0 - Updated for v1_0 of SWU api. Added emails endpoint.
1
2
  0.0.4 - Rewritten to be more gem-like
2
3
  - Accepts configuration via a Rails-style initializer
3
4
  - Test coverage
4
5
  0.0.3 - No idea
5
6
  0.0.2 - Full json post body
6
- 0.0.1 - First Version
7
-
7
+ 0.0.1 - First Version
data/README.md CHANGED
@@ -26,7 +26,22 @@ For any Ruby project:
26
26
 
27
27
  begin
28
28
  obj = SendWithUs::Api.new( api_key: 'YOUR API KEY', debug: true )
29
- result = obj.send_with('email_id', 'recipient@testco.com', { company_name: 'TestCo' })
29
+
30
+ # with only required params
31
+ result = obj.send_with(
32
+ 'email_id',
33
+ { address: "user@email.com" },
34
+ { company_name: 'TestCo' })
35
+ puts result
36
+
37
+ # with all optional params
38
+ result = obj.send_with(
39
+ 'email_id',
40
+ { name: 'Matt', address: 'recipient@testco.com' },
41
+ { company_name: 'TestCo' },
42
+ { name: 'Company',
43
+ address: 'company@testco.com',
44
+ reply_to: 'info@testco.com' })
30
45
  puts result
31
46
  rescue Exception => e
32
47
  puts "Error - #{e.class.name}: #{e.message}"
@@ -45,7 +60,7 @@ with the following:
45
60
  In your application code where you want to send an email:
46
61
 
47
62
  begin
48
- result = SendWithUs::Api.new.send_with('email_id', 'recipient@testco.com', { company_name: 'TestCo' })
63
+ result = SendWithUs::Api.new.send_with('email_id', { address: 'recipient@testco.com' }, { company_name: 'TestCo' })
49
64
  puts result
50
65
  rescue Exception => e
51
66
  puts "Error - #{e.class.name}: #{e.message}"
@@ -55,6 +70,6 @@ In your application code where you want to send an email:
55
70
 
56
71
  The following errors may be generated:
57
72
 
58
- SendWithUs::ApiInvalidEndpoint - the target URI is probably incorrect
73
+ SendWithUs::ApiInvalidEndpoint - the target URI is probably incorrect or email_id is invalid
59
74
  SendWithUs::ApiConnectionRefused - the target URI is probably incorrect
60
75
  SendWithUs::ApiUnknownError - an unhandled HTTP error occurred
@@ -20,11 +20,19 @@ module SendWithUs
20
20
  @configuration = SendWithUs::Config.new(settings)
21
21
  end
22
22
 
23
- def send_with(email_id, to, data = {})
24
- payload = { email_id: email_id, email_to: to, email_data: data }.to_json
23
+ def send_with(email_id, to, data = {}, from = {})
24
+ if from.any?
25
+ payload = { email_id: email_id, recipient: to, sender: from, email_data: data }.to_json
26
+ else
27
+ payload = { email_id: email_id, recipient: to, email_data: data }.to_json
28
+ end
25
29
  SendWithUs::ApiRequest.new(@configuration).send_with(payload)
26
30
  end
27
31
 
32
+ def emails()
33
+ SendWithUs::ApiRequest.new(@configuration).get(:emails)
34
+ end
35
+
28
36
  end
29
37
 
30
38
  end
@@ -21,6 +21,30 @@ module SendWithUs
21
21
 
22
22
  @response = http.request(request, payload)
23
23
 
24
+ case @response
25
+ when Net::HTTPNotFound then
26
+ raise SendWithUs::ApiInvalidEndpoint, path
27
+ when Net::HTTPSuccess then
28
+ puts @response.body if @configuration.debug
29
+ @response
30
+ else
31
+ raise SendWithUs::ApiUnknownError
32
+ end
33
+ rescue Errno::ECONNREFUSED
34
+ raise SendWithUs::ApiConnectionRefused
35
+ end
36
+
37
+ def get(endpoint)
38
+ path = request_path(endpoint)
39
+ request = Net::HTTP::Get.new(path, initheader = {'Content-Type' =>'application/json'})
40
+ request.add_field('X-SWU-API-KEY', @configuration.api_key)
41
+
42
+ http = Net::HTTP.new(@configuration.host, @configuration.port)
43
+ http.use_ssl = use_ssl?
44
+ http.set_debug_output($stdout) if @configuration.debug
45
+
46
+ @response = http.request(request)
47
+
24
48
  case @response
25
49
  when Net::HTTPNotFound then
26
50
  raise SendWithUs::ApiInvalidEndpoint, path
@@ -1,7 +1,7 @@
1
1
  module SendWithUs
2
2
  class Config
3
3
  attr_accessor :settings
4
- #attr_writer :url, :api_key, :protocol, :host, :port, :api_verstion, :debug
4
+ #attr_writer :url, :api_key, :protocol, :host, :port, :api_version, :debug
5
5
 
6
6
  DEFAULT_URL = 'https://beta.sendwithus.com'
7
7
 
@@ -14,7 +14,7 @@ module SendWithUs
14
14
  protocol: source.scheme,
15
15
  host: source.host,
16
16
  port: source.port,
17
- api_version: 0,
17
+ api_version: '1_0',
18
18
  debug: true
19
19
  }
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module SendWithUs
2
- VERSION = '0.0.6'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -3,9 +3,9 @@ require_relative '../../test_helper'
3
3
  class TestApiRequest < MiniTest::Unit::TestCase
4
4
 
5
5
  def build_objects
6
- @payload = {}
7
- @config = SendWithUs::Config.new( api_version: 3, api_key: 'TEST_KEY', debug: false )
8
- @request = SendWithUs::ApiRequest.new(@config)
6
+ @payload = {}
7
+ @config = SendWithUs::Config.new( api_version: '1_0', api_key: 'THIS_IS_A_TEST_API_KEY', debug: false )
8
+ @request = SendWithUs::ApiRequest.new(@config)
9
9
  end
10
10
 
11
11
  def test_payload
@@ -32,9 +32,15 @@ class TestApiRequest < MiniTest::Unit::TestCase
32
32
  assert_raises( SendWithUs::ApiConnectionRefused ) { @request.send_with(@payload) }
33
33
  end
34
34
 
35
+ def test_emails
36
+ build_objects
37
+ Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
38
+ assert_instance_of( Net::HTTPSuccess, @request.get(:emails) )
39
+ end
40
+
35
41
  def test_request_path
36
42
  build_objects
37
- assert_equal( true, @request.send(:request_path, :send) == '/api/v3/send' )
43
+ assert_equal( true, @request.send(:request_path, :send) == '/api/v1_0/send' )
38
44
  end
39
45
 
40
46
  end
metadata CHANGED
@@ -1,75 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: send_with_us
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Matt Harris
14
8
  - Chris Cummer
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2013-03-08 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rake
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
33
21
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: shoulda
37
22
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: shoulda
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
47
35
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: mocha
51
36
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mocha
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
61
49
  type: :development
62
- version_requirements: *id003
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
63
56
  description: SendWithUs.com Ruby Client
64
- email:
57
+ email:
65
58
  - us@sendwithus.com
66
59
  executables: []
67
-
68
60
  extensions: []
69
-
70
61
  extra_rdoc_files: []
71
-
72
- files:
62
+ files:
73
63
  - .gitignore
74
64
  - .travis.yml
75
65
  - CHANGELOG.md
@@ -91,38 +81,28 @@ files:
91
81
  - test/test_helper.rb
92
82
  homepage: http://www.sendwithus.com
93
83
  licenses: []
94
-
84
+ metadata: {}
95
85
  post_install_message:
96
86
  rdoc_options: []
97
-
98
- require_paths:
87
+ require_paths:
99
88
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
118
99
  requirements: []
119
-
120
100
  rubyforge_project:
121
- rubygems_version: 1.8.24
101
+ rubygems_version: 2.0.3
122
102
  signing_key:
123
- specification_version: 3
103
+ specification_version: 4
124
104
  summary: SendWithUs.com Ruby Client
125
- test_files:
105
+ test_files:
126
106
  - test/lib/send_with_us/api_request_test.rb
127
107
  - test/lib/send_with_us/api_test.rb
128
108
  - test/lib/send_with_us/config_test.rb