postageapp 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +3 -0
  2. data/LICENSE +1 -1
  3. data/README.md +176 -0
  4. data/Rakefile +14 -12
  5. data/VERSION +1 -1
  6. data/generators/postageapp/postageapp_generator.rb +34 -0
  7. data/generators/postageapp/templates/initializer.rb +3 -0
  8. data/generators/postageapp/templates/postageapp_tasks.rake +78 -0
  9. data/lib/generators/postageapp/postageapp_generator.rb +27 -0
  10. data/lib/postageapp.rb +56 -0
  11. data/lib/postageapp/configuration.rb +91 -0
  12. data/lib/postageapp/failed_request.rb +64 -0
  13. data/lib/postageapp/logger.rb +16 -0
  14. data/lib/postageapp/mailer.rb +48 -0
  15. data/lib/postageapp/mailer/mailer_2.rb +92 -0
  16. data/lib/postageapp/mailer/mailer_3.rb +192 -0
  17. data/lib/postageapp/rails.rb +14 -0
  18. data/lib/postageapp/request.rb +87 -0
  19. data/lib/postageapp/response.rb +39 -0
  20. data/lib/postageapp/utils.rb +30 -0
  21. data/lib/postageapp/version.rb +7 -0
  22. data/postageapp.gemspec +61 -7
  23. data/test/configuration_test.rb +66 -0
  24. data/test/failed_request_test.rb +79 -0
  25. data/test/helper.rb +66 -0
  26. data/test/mailer/action_mailer_2/notifier.rb +64 -0
  27. data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +1 -0
  28. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +1 -0
  29. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +1 -0
  30. data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +1 -0
  31. data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +1 -0
  32. data/test/mailer/action_mailer_3/notifier.rb +98 -0
  33. data/test/mailer/action_mailer_3/notifier/with_html_and_text_views.html.erb +1 -0
  34. data/test/mailer/action_mailer_3/notifier/with_html_and_text_views.text.erb +1 -0
  35. data/test/mailer/action_mailer_3/notifier/with_old_api.html.erb +1 -0
  36. data/test/mailer/action_mailer_3/notifier/with_old_api.text.erb +1 -0
  37. data/test/mailer/action_mailer_3/notifier/with_simple_view.erb +1 -0
  38. data/test/mailer/action_mailer_3/notifier/with_text_only_view.text.erb +1 -0
  39. data/test/mailer_2_test.rb +87 -0
  40. data/test/mailer_3_test.rb +104 -0
  41. data/test/mailer_helper_methods_test.rb +24 -0
  42. data/test/postageapp_test.rb +18 -0
  43. data/test/rails_initialization_test.rb +29 -0
  44. data/test/request_integration_test.rb +78 -0
  45. data/test/request_test.rb +81 -0
  46. data/test/response_test.rb +40 -0
  47. metadata +84 -9
  48. data/README.rdoc +0 -17
  49. data/test/test_postageapp.rb +0 -7
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RequestIntegrationTest < Test::Unit::TestCase
4
+
5
+ # Note: Need access to a live PostageApp.com account
6
+ # See helper.rb to set host / api key
7
+ unless false # set to +true+ to run tests
8
+ puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
9
+ def test_nothing ; end
10
+ else
11
+
12
+ def setup
13
+ super
14
+ PostageApp.configure do |config|
15
+ config.secure = false
16
+ config.host = 'api.postageapp.local'
17
+ config.api_key = 'PROJECT_API_KEY'
18
+ end
19
+ end
20
+
21
+ def test_request_get_method_list
22
+ request = PostageApp::Request.new(:get_method_list)
23
+ response = request.send
24
+ assert_equal 'PostageApp::Response', response.class.name
25
+ assert_equal 'ok', response.status
26
+ assert_match /^\w{40}$/, response.uid
27
+ assert_equal nil, response.message
28
+ assert_equal ({
29
+ 'methods' => 'get_account_info, get_message_receipt, get_method_list, get_project_info, send_message'
30
+ }), response.data
31
+ end
32
+
33
+ def test_request_send_message
34
+ request = PostageApp::Request.new(:send_message, {
35
+ :headers => { 'from' => 'sender@test.test',
36
+ 'subject' => 'Test Message'},
37
+ :recipients => 'test@test.test',
38
+ :content => {
39
+ 'text/plain' => 'text content',
40
+ 'text/html' => 'html content'
41
+ }
42
+ })
43
+ response = request.send
44
+ assert_equal 'PostageApp::Response', response.class.name
45
+ assert_equal 'ok', response.status
46
+ assert_match /^\w{40}$/, response.uid
47
+ assert_equal nil, response.message
48
+ assert_match /\d+/, response.data['message']['id'].to_s
49
+
50
+ receipt = PostageApp::Request.new(:get_message_receipt, :uid => response.uid).send
51
+ assert receipt.ok?
52
+
53
+ receipt = PostageApp::Request.new(:get_message_receipt, :uid => 'bogus').send
54
+ assert receipt.not_found?
55
+ end
56
+
57
+ def test_request_non_existant_method
58
+ request = PostageApp::Request.new(:non_existant)
59
+ response = request.send
60
+ assert_equal 'PostageApp::Response', response.class.name
61
+ assert_equal 'internal_server_error', response.status
62
+ assert_match /^\w{40}$/, response.uid
63
+ assert_equal 'No action responded to non_existant. Actions: get_account_info, get_message_receipt, get_method_list, get_project_info, and send_message', response.message
64
+ assert_equal nil, response.data
65
+ end
66
+
67
+ # Testable under ruby 1.9.2 Probably OK in production too... Probably
68
+ # Lunchtime reading: http://ph7spot.com/musings/system-timer
69
+ def test_request_timeout
70
+ PostageApp.configuration.host = 'dead.postageapp.local'
71
+ request = PostageApp::Request.new(:get_method_list)
72
+ response = request.send
73
+ assert_equal 'PostageApp::Response', response.class.name
74
+ assert_equal 'fail', response.status
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class RequestTest < Test::Unit::TestCase
4
+
5
+ def test_method_uid
6
+ request = PostageApp::Request.new(:test_method)
7
+ uid = request.uid
8
+ assert_match /^\w{40}$/, uid
9
+ assert_equal uid, request.uid
10
+ assert_not_equal uid, request.uid(true)
11
+ end
12
+
13
+ def test_method_url
14
+ request = PostageApp::Request.new(:test_method)
15
+ assert_equal 'api.postageapp.com', request.url.host
16
+ assert_equal 443, request.url.port
17
+ assert_equal '/v.1.0/test_method.json', request.url.path
18
+ end
19
+
20
+ def test_method_arguments_to_send
21
+ request = PostageApp::Request.new(:test_method)
22
+ args = request.arguments_to_send
23
+ assert_equal '1234567890abcdef', args['api_key']
24
+ assert_match /^\w{40}$/, args['uid']
25
+
26
+ request.arguments = { 'data' => 'content' }
27
+ args = request.arguments_to_send
28
+ assert_equal '1234567890abcdef', args['api_key']
29
+ assert_match /^\w{40}$/, args['uid']
30
+ assert_equal 'content', args['arguments']['data']
31
+ end
32
+
33
+ def test_uid_is_enforceable
34
+ request = PostageApp::Request.new(:test_method)
35
+ assert_match /^\w{40}$/, request.arguments_to_send['uid']
36
+
37
+ request.uid = 'my_uid'
38
+ assert_equal 'my_uid', request.arguments_to_send['uid']
39
+
40
+ request = PostageApp::Request.new(:test_method, :uid => 'new_uid', :data => 'value')
41
+ assert_equal 'new_uid', request.uid
42
+ assert_equal ({:data => 'value'}), request.arguments
43
+ end
44
+
45
+ def test_send
46
+ mock_successful_send
47
+
48
+ request = PostageApp::Request.new(:send_message, {
49
+ :headers => { 'from' => 'sender@test.test',
50
+ 'subject' => 'Test Message'},
51
+ :recipients => 'test@test.test',
52
+ :content => {
53
+ 'text/plain' => 'text content',
54
+ 'text/html' => 'html content'
55
+ }
56
+ })
57
+ response = request.send
58
+ assert_equal 'ok', response.status
59
+ assert_equal 'sha1hashuid23456789012345678901234567890', response.uid
60
+ assert_equal ({'message' => { 'id' => 999 }}), response.data
61
+ end
62
+
63
+ def test_send_failure
64
+ mock_failed_send
65
+
66
+ request = PostageApp::Request.new(:send_message, {
67
+ :headers => { 'from' => 'sender@test.test',
68
+ 'subject' => 'Test Message'},
69
+ :recipients => 'test@test.test',
70
+ :content => {
71
+ 'text/plain' => 'text content',
72
+ 'text/html' => 'html content'
73
+ }
74
+ })
75
+ response = request.send
76
+ assert_equal 'fail', response.status
77
+ assert_equal nil, response.uid
78
+ assert_equal nil, response.data
79
+ end
80
+
81
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class ResponseTest < Test::Unit::TestCase
4
+
5
+ def test_initialization
6
+ object = stub(:body => {
7
+ 'response' => {
8
+ 'uid' => 'md5_hash_uid',
9
+ 'status' => 'ok',
10
+ 'message' => 'api reply message'
11
+ },
12
+ 'data' => {
13
+ 'key' => 'value'
14
+ }
15
+ }.to_json)
16
+
17
+ response = PostageApp::Response.new(object)
18
+ assert_equal 'md5_hash_uid', response.uid
19
+ assert_equal 'ok', response.status
20
+ assert_equal 'api reply message', response.message
21
+ assert_equal ({'key' => 'value'}), response.data
22
+ assert response.ok?
23
+ end
24
+
25
+ def test_status_check
26
+ response = PostageApp::Response.new(nil)
27
+ assert_equal 'fail', response.status
28
+ assert response.fail?
29
+ assert !response.ok?
30
+ assert !response.really?
31
+
32
+ begin
33
+ response.bad_method
34
+ assert false
35
+ rescue NoMethodError
36
+ assert true
37
+ end
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -3,10 +3,10 @@ name: postageapp
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Oleg Khabarov, The Working Group Inc
@@ -14,10 +14,37 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-10 00:00:00 -04:00
17
+ date: 2010-07-23 00:00:00 -04:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 4
31
+ version: 1.2.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mocha
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 8
45
+ version: 0.9.8
46
+ type: :development
47
+ version_requirements: *id002
21
48
  description: Gem that interfaces with PostageApp.com service to send emails from web apps
22
49
  email: oleg@twg.ca
23
50
  executables: []
@@ -26,18 +53,55 @@ extensions: []
26
53
 
27
54
  extra_rdoc_files:
28
55
  - LICENSE
29
- - README.rdoc
56
+ - README.md
30
57
  files:
31
58
  - .document
32
59
  - .gitignore
33
60
  - LICENSE
34
- - README.rdoc
61
+ - README.md
35
62
  - Rakefile
36
63
  - VERSION
64
+ - generators/postageapp/postageapp_generator.rb
65
+ - generators/postageapp/templates/initializer.rb
66
+ - generators/postageapp/templates/postageapp_tasks.rake
67
+ - lib/generators/postageapp/postageapp_generator.rb
37
68
  - lib/postageapp.rb
69
+ - lib/postageapp/configuration.rb
70
+ - lib/postageapp/failed_request.rb
71
+ - lib/postageapp/logger.rb
72
+ - lib/postageapp/mailer.rb
73
+ - lib/postageapp/mailer/mailer_2.rb
74
+ - lib/postageapp/mailer/mailer_3.rb
75
+ - lib/postageapp/rails.rb
76
+ - lib/postageapp/request.rb
77
+ - lib/postageapp/response.rb
78
+ - lib/postageapp/utils.rb
79
+ - lib/postageapp/version.rb
38
80
  - postageapp.gemspec
81
+ - test/configuration_test.rb
82
+ - test/failed_request_test.rb
39
83
  - test/helper.rb
40
- - test/test_postageapp.rb
84
+ - test/mailer/action_mailer_2/notifier.rb
85
+ - test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb
86
+ - test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb
87
+ - test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb
88
+ - test/mailer/action_mailer_2/notifier/with_simple_view.erb
89
+ - test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb
90
+ - test/mailer/action_mailer_3/notifier.rb
91
+ - test/mailer/action_mailer_3/notifier/with_html_and_text_views.html.erb
92
+ - test/mailer/action_mailer_3/notifier/with_html_and_text_views.text.erb
93
+ - test/mailer/action_mailer_3/notifier/with_old_api.html.erb
94
+ - test/mailer/action_mailer_3/notifier/with_old_api.text.erb
95
+ - test/mailer/action_mailer_3/notifier/with_simple_view.erb
96
+ - test/mailer/action_mailer_3/notifier/with_text_only_view.text.erb
97
+ - test/mailer_2_test.rb
98
+ - test/mailer_3_test.rb
99
+ - test/mailer_helper_methods_test.rb
100
+ - test/postageapp_test.rb
101
+ - test/rails_initialization_test.rb
102
+ - test/request_integration_test.rb
103
+ - test/request_test.rb
104
+ - test/response_test.rb
41
105
  has_rdoc: true
42
106
  homepage: http://github.com/theworkinggroup/postageapp-gem
43
107
  licenses: []
@@ -69,5 +133,16 @@ signing_key:
69
133
  specification_version: 3
70
134
  summary: Easier way to send email from web apps
71
135
  test_files:
136
+ - test/configuration_test.rb
137
+ - test/failed_request_test.rb
72
138
  - test/helper.rb
73
- - test/test_postageapp.rb
139
+ - test/mailer/action_mailer_2/notifier.rb
140
+ - test/mailer/action_mailer_3/notifier.rb
141
+ - test/mailer_2_test.rb
142
+ - test/mailer_3_test.rb
143
+ - test/mailer_helper_methods_test.rb
144
+ - test/postageapp_test.rb
145
+ - test/rails_initialization_test.rb
146
+ - test/request_integration_test.rb
147
+ - test/request_test.rb
148
+ - test/response_test.rb
@@ -1,17 +0,0 @@
1
- = postageapp
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Oleg. See LICENSE for details.
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestPostageapp < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end