infusionsoft 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.md +0 -2
  6. data/README.md +17 -21
  7. data/Rakefile +12 -2
  8. data/infusionsoft.gemspec +2 -2
  9. data/lib/infusionsoft/client.rb +2 -0
  10. data/lib/infusionsoft/client/contact.rb +15 -5
  11. data/lib/infusionsoft/client/email.rb +1 -1
  12. data/lib/infusionsoft/client/funnel.rb +18 -0
  13. data/lib/infusionsoft/client/invoice.rb +1 -1
  14. data/lib/infusionsoft/connection.rb +1 -1
  15. data/lib/infusionsoft/request.rb +1 -0
  16. data/lib/infusionsoft/version.rb +1 -1
  17. data/test/client/contact_test.rb +79 -0
  18. data/test/client/data_test.rb +102 -0
  19. data/test/client/email_test.rb +89 -0
  20. data/test/exceptions_test.rb +131 -0
  21. data/test/test_helper.rb +47 -0
  22. data/test/vcr_cassettes/add_to_group.yml +49 -0
  23. data/test/vcr_cassettes/contact_add.yml +93 -0
  24. data/test/vcr_cassettes/contact_add_dup_check_no_dup.yml +93 -0
  25. data/test/vcr_cassettes/contact_add_dup_check_with_dup.yml +186 -0
  26. data/test/vcr_cassettes/contact_load.yml +49 -0
  27. data/test/vcr_cassettes/contact_merge.yml +49 -0
  28. data/test/vcr_cassettes/contact_update.yml +95 -0
  29. data/test/vcr_cassettes/data_add.yml +49 -0
  30. data/test/vcr_cassettes/data_add_custom_field.yml +49 -0
  31. data/test/vcr_cassettes/data_auth_user_failure.yml +50 -0
  32. data/test/vcr_cassettes/data_auth_user_success.yml +49 -0
  33. data/test/vcr_cassettes/data_delete.yml +49 -0
  34. data/test/vcr_cassettes/data_find_by_field.yml +51 -0
  35. data/test/vcr_cassettes/data_get_app_setting.yml +50 -0
  36. data/test/vcr_cassettes/data_load.yml +51 -0
  37. data/test/vcr_cassettes/data_query.yml +51 -0
  38. data/test/vcr_cassettes/data_query_order_by.yml +51 -0
  39. data/test/vcr_cassettes/data_update.yml +96 -0
  40. data/test/vcr_cassettes/data_update_custom_field.yml +49 -0
  41. data/test/vcr_cassettes/email_add.yml +50 -0
  42. data/test/vcr_cassettes/email_attach.yml +50 -0
  43. data/test/vcr_cassettes/email_get_available_merge_fields.yml +52 -0
  44. data/test/vcr_cassettes/email_get_opt_status.yml +50 -0
  45. data/test/vcr_cassettes/email_get_template.yml +118 -0
  46. data/test/vcr_cassettes/email_optin.yml +50 -0
  47. data/test/vcr_cassettes/email_optout.yml +50 -0
  48. data/test/vcr_cassettes/email_send.yml +50 -0
  49. data/test/vcr_cassettes/email_send_template.yml +50 -0
  50. data/test/vcr_cassettes/email_update_template.yml +50 -0
  51. data/test/vcr_cassettes/find_by_email.yml +49 -0
  52. data/test/vcr_cassettes/remove_from_group.yml +49 -0
  53. metadata +50 -17
  54. data/test/api_infusion_test.rb +0 -8
  55. data/test/test_exceptions.rb +0 -113
@@ -0,0 +1,89 @@
1
+ require_relative('../test_helper')
2
+
3
+ class EmailTest < Test::Unit::TestCase
4
+
5
+ def test_email_add
6
+ VCR.use_cassette('email_add') do
7
+ result = Infusionsoft.email_add('Test Via API', 'test,api', 'noreply@test.com',
8
+ 'test@test.com', 'test2@test.com', 'test3@test.com',
9
+ 'Test Subject', 'Text Body', '<p> HTML body',
10
+ 'Multipart', 'Contact')
11
+ assert_instance_of Fixnum, result
12
+ end
13
+ end
14
+
15
+ def test_email_attach
16
+ VCR.use_cassette('email_attach') do
17
+ result = Infusionsoft.email_attach(304, 'The Dude', 'the_dude@lebowski.com',
18
+ 'hagglundized@gmail.com', 'hagglundized+cc@gmail.com',
19
+ 'hagglundized+bcc@gmail.com', 'Multipart', 'Question',
20
+ "<em>Where's the money?</em>", "Where's the money?",
21
+ 'Test Header', DateTime.now.to_s, DateTime.now.to_s)
22
+ assert_true result
23
+ end
24
+ end
25
+
26
+ def test_email_get_available_merge_fields
27
+ VCR.use_cassette('email_get_available_merge_fields') do
28
+ result = Infusionsoft.email_get_available_merge_fields('Contact')
29
+ assert_instance_of Array, result
30
+ end
31
+ end
32
+
33
+ def test_email_get_template
34
+ VCR.use_cassette('email_get_template') do
35
+ result = Infusionsoft.email_get_template(3649)
36
+ assert_instance_of Hash, result
37
+ end
38
+ end
39
+
40
+ def test_email_get_opt_status
41
+ VCR.use_cassette('email_get_opt_status') do
42
+ result = Infusionsoft.email_get_opt_status('hagglundized@gmail.com')
43
+ assert_instance_of Fixnum, result
44
+ end
45
+ end
46
+
47
+ def test_email_optin
48
+ VCR.use_cassette('email_optin') do
49
+ result = Infusionsoft.email_optin('hagglundized@gmail.com', 'because i said so')
50
+ assert_true [true, false].include? result
51
+ end
52
+ end
53
+
54
+ def test_email_optout
55
+ VCR.use_cassette('email_optout') do
56
+ result = Infusionsoft.email_optout('boutthat@ction.boss', 'because i said so')
57
+ assert_true [true, false].include? result
58
+ end
59
+ end
60
+
61
+ def test_email_send
62
+ VCR.use_cassette('email_send') do
63
+ result = Infusionsoft.email_send([304], 'the_dude@lebowski.com',
64
+ 'hagglundized@gmail.com', 'hagglundized+cc@gmail.com',
65
+ 'hagglundized+bcc@gmail.com', 'Multipart', 'Question',
66
+ "<em>Where's the money?</em>", "Where's the money?")
67
+ assert_true [true, false].include? result
68
+ end
69
+ end
70
+
71
+ def test_email_send_template
72
+ VCR.use_cassette('email_send_template') do
73
+ result = Infusionsoft.email_send_template([304], '3649')
74
+ assert_true [true, false].include? result
75
+ end
76
+ end
77
+
78
+ def test_email_update_template
79
+ VCR.use_cassette('email_update_template') do
80
+ result = Infusionsoft.email_update_template(3649, 'Testingness Testagram', '', '',
81
+ 'hagglundized@gmail.com',
82
+ 'hagglundized+cc@gmail.com',
83
+ 'hagglundized+bcc@gmail.com',
84
+ 'Testingness Testagrams', 'Stuff',
85
+ '<em>Stuff</em>', 'Multipart', 'Contact')
86
+ assert_true [true, false].include? result
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,131 @@
1
+ require_relative('test_helper')
2
+
3
+ class ExceptionsTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @test_exc_msg = 'Some error message'
8
+ end
9
+
10
+ def test_should_raise_invalid_config
11
+ stub_client_call(1)
12
+ assert_raise_kind_of Infusionsoft::InvalidConfigError do
13
+ run_exceptional_data_query
14
+ end
15
+ end
16
+
17
+ def test_should_raise_invalid_key
18
+ stub_client_call(2)
19
+ assert_raise_kind_of Infusionsoft::InvalidKeyError do
20
+ run_exceptional_data_query
21
+ end
22
+ end
23
+
24
+ def test_should_raise_unexpected_error
25
+ stub_client_call(3)
26
+ assert_raise_kind_of Infusionsoft::UnexpectedError do
27
+ run_exceptional_data_query
28
+ end
29
+ end
30
+
31
+ def test_should_raise_database_error
32
+ stub_client_call(4)
33
+ assert_raise_kind_of Infusionsoft::DatabaseError do
34
+ run_exceptional_data_query
35
+ end
36
+ end
37
+
38
+ def test_should_raise_record_not_found
39
+ stub_client_call(5)
40
+ assert_raise_kind_of Infusionsoft::RecordNotFoundError do
41
+ run_exceptional_data_query
42
+ end
43
+ end
44
+
45
+ def test_should_raise_loading_error
46
+ stub_client_call(6)
47
+ assert_raise_kind_of Infusionsoft::LoadingError do
48
+ run_exceptional_data_query
49
+ end
50
+ end
51
+
52
+ def test_should_raise_no_table_access
53
+ stub_client_call(7)
54
+ assert_raise_kind_of Infusionsoft::NoTableAccessError do
55
+ run_exceptional_data_query
56
+ end
57
+ end
58
+
59
+ def test_should_raise_no_field_access
60
+ stub_client_call(8)
61
+ assert_raise_kind_of Infusionsoft::NoFieldAccessError do
62
+ run_exceptional_data_query
63
+ end
64
+ end
65
+
66
+ def test_should_raise_no_table_found
67
+ stub_client_call(9)
68
+ assert_raise_kind_of Infusionsoft::NoTableFoundError do
69
+ run_exceptional_data_query
70
+ end
71
+ end
72
+
73
+ def test_should_raise_no_field_found
74
+ stub_client_call(10)
75
+ assert_raise_kind_of Infusionsoft::NoFieldFoundError do
76
+ run_exceptional_data_query
77
+ end
78
+ end
79
+
80
+ def test_should_raise_no_fields_error
81
+ stub_client_call(11)
82
+ assert_raise_kind_of Infusionsoft::NoFieldsError do
83
+ run_exceptional_data_query
84
+ end
85
+ end
86
+
87
+ def test_should_raise_invalid_parameter_error
88
+ stub_client_call(12)
89
+ assert_raise_kind_of Infusionsoft::InvalidParameterError do
90
+ run_exceptional_data_query
91
+ end
92
+ end
93
+
94
+ def test_should_raise_failed_login_attempt
95
+ stub_client_call(13)
96
+ assert_raise_kind_of Infusionsoft::FailedLoginAttemptError do
97
+ run_exceptional_data_query
98
+ end
99
+ end
100
+
101
+ def test_should_raise_no_access_error
102
+ stub_client_call(14)
103
+ assert_raise_kind_of Infusionsoft::NoAccessError do
104
+ run_exceptional_data_query
105
+ end
106
+ end
107
+
108
+ def test_should_raise_failed_login_attempt_password_expired
109
+ stub_client_call(15)
110
+ assert_raise_kind_of Infusionsoft::FailedLoginAttemptPasswordExpiredError do
111
+ run_exceptional_data_query
112
+ end
113
+ end
114
+
115
+ def test_should_raise_infusionapierror_when_fault_code_unknown
116
+ stub_client_call(42)
117
+ assert_raise_kind_of InfusionAPIError do
118
+ run_exceptional_data_query
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def stub_client_call(exception_num)
125
+ XMLRPC::Client.any_instance.stubs(:call).raises(XMLRPC::FaultException.new(exception_num, @test_exc_msg))
126
+ end
127
+
128
+ def run_exceptional_data_query
129
+ Infusionsoft.data_query(:Contact, 1, 0, {}, [:BlahdyDah])
130
+ end
131
+ end
@@ -0,0 +1,47 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'simplecov'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/vendor/'
11
+ add_filter '/.bundle/'
12
+ add_filter '/test'
13
+ add_group 'Clients', 'lib/infusionsoft/client'
14
+ end
15
+
16
+ require 'test/unit'
17
+ require 'infusionsoft'
18
+
19
+ require 'vcr'
20
+ require 'webmock/test_unit'
21
+ require 'mocha/test_unit'
22
+
23
+ WebMock.disable_net_connect!(allow_localhost: true)
24
+
25
+ VCR.configure do |c|
26
+ c.cassette_library_dir = 'test/vcr_cassettes'
27
+ c.hook_into :webmock
28
+ c.default_cassette_options = { record: :once, match_requests_on: [:method] }
29
+ end
30
+
31
+ class Test::Unit::TestCase
32
+ class TestLogger
33
+ def info(msg); end
34
+ def warn(msg); end
35
+ def error(msg); end
36
+ def debug(msg); end
37
+ def fatal(msg); end
38
+ end
39
+
40
+ def setup
41
+ Infusionsoft.configure do |config|
42
+ config.api_url = 'test.infusionsoft.com'
43
+ config.api_key = 'not_a_real_key'
44
+ config.api_logger = TestLogger.new
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://test.infusionsoft.com/api/xmlrpc
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" ?><methodCall><methodName>ContactService.addToGroup</methodName><params><param><value><string>not_a_real_key</string></value></param><param><value><i4>3794</i4></value></param><param><value><i4>382</i4></value></param></params></methodCall>
10
+ headers:
11
+ User-Agent:
12
+ - Infusionsoft-1.1.8 (RubyGem)
13
+ Content-Type:
14
+ - text/xml; charset=utf-8
15
+ Content-Length:
16
+ - '279'
17
+ Connection:
18
+ - keep-alive
19
+ Accept-Encoding:
20
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
21
+ Accept:
22
+ - "*/*"
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Server:
29
+ - Apache-Coyote/1.1
30
+ Pragma:
31
+ - no-cache
32
+ Cache-Control:
33
+ - no-cache, no-store
34
+ Expires:
35
+ - Sat, 30 May 2015 19:30:00 GMT
36
+ Content-Type:
37
+ - text/xml;charset=UTF-8
38
+ Content-Length:
39
+ - '138'
40
+ Date:
41
+ - Sat, 30 May 2015 07:29:59 GMT
42
+ Set-Cookie:
43
+ - app-lb=2466578442.20480.0000; path=/
44
+ body:
45
+ encoding: UTF-8
46
+ string: <?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><boolean>1</boolean></value></param></params></methodResponse>
47
+ http_version:
48
+ recorded_at: Sat, 30 May 2015 07:30:00 GMT
49
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://test.infusionsoft.com/api/xmlrpc
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" ?><methodCall><methodName>ContactService.add</methodName><params><param><value><string>not_a_real_key</string></value></param><param><value><struct><member><name>Email</name><value><string>test@tester.com</string></value></member><member><name>FirstName</name><value><string>Severus</string></value></member><member><name>LastName</name><value><string>Snape</string></value></member></struct></value></param></params></methodCall>
10
+ headers:
11
+ User-Agent:
12
+ - Infusionsoft-1.1.8 (RubyGem)
13
+ Content-Type:
14
+ - text/xml; charset=utf-8
15
+ Content-Length:
16
+ - '469'
17
+ Connection:
18
+ - keep-alive
19
+ Accept-Encoding:
20
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
21
+ Accept:
22
+ - "*/*"
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Server:
29
+ - Apache-Coyote/1.1
30
+ Pragma:
31
+ - no-cache
32
+ Cache-Control:
33
+ - no-cache, no-store
34
+ Expires:
35
+ - Thu, 09 Apr 2015 19:14:00 GMT
36
+ Content-Type:
37
+ - text/xml;charset=UTF-8
38
+ Content-Length:
39
+ - '131'
40
+ Date:
41
+ - Thu, 09 Apr 2015 07:14:00 GMT
42
+ Set-Cookie:
43
+ - app-lb=2466578442.20480.0000; path=/
44
+ body:
45
+ encoding: UTF-8
46
+ string: <?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><i4>3602</i4></value></param></params></methodResponse>
47
+ http_version:
48
+ recorded_at: Thu, 09 Apr 2015 07:14:00 GMT
49
+ - request:
50
+ method: post
51
+ uri: https://test.infusionsoft.com/api/xmlrpc
52
+ body:
53
+ encoding: UTF-8
54
+ string: |
55
+ <?xml version="1.0" ?><methodCall><methodName>APIEmailService.optIn</methodName><params><param><value><string>not_a_real_key</string></value></param><param><value><string>testing@test.com</string></value></param><param><value><string>requested information</string></value></param></params></methodCall>
56
+ headers:
57
+ User-Agent:
58
+ - Infusionsoft-1.1.8 (RubyGem)
59
+ Content-Type:
60
+ - text/xml; charset=utf-8
61
+ Content-Length:
62
+ - '321'
63
+ Connection:
64
+ - keep-alive
65
+ Accept:
66
+ - "*/*"
67
+ response:
68
+ status:
69
+ code: 200
70
+ message: OK
71
+ headers:
72
+ Server:
73
+ - Apache-Coyote/1.1
74
+ Pragma:
75
+ - no-cache
76
+ Cache-Control:
77
+ - no-cache, no-store
78
+ Expires:
79
+ - Fri, 31 Jul 2015 11:55:20 GMT
80
+ Content-Type:
81
+ - text/xml;charset=UTF-8
82
+ Content-Length:
83
+ - '138'
84
+ Date:
85
+ - Thu, 30 Jul 2015 23:55:20 GMT
86
+ Set-Cookie:
87
+ - app-lb=2466578442.20480.0000; path=/
88
+ body:
89
+ encoding: US-ASCII
90
+ string: <?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><boolean>1</boolean></value></param></params></methodResponse>
91
+ http_version:
92
+ recorded_at: Thu, 30 Jul 2015 23:55:21 GMT
93
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://test.infusionsoft.com/api/xmlrpc
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" ?><methodCall><methodName>ContactService.addWithDupCheck</methodName><params><param><value><string>not_a_real_key</string></value></param><param><value><struct><member><name>Email</name><value><string>new@tester.com</string></value></member><member><name>FirstName</name><value><string>Albus</string></value></member><member><name>LastName</name><value><string>Dumbledore</string></value></member><member><name>Company</name><value><string>Hogwarts</string></value></member></struct></value></param><param><value><string>EmailAndNameAndCompany</string></value></param></params></methodCall>
10
+ headers:
11
+ User-Agent:
12
+ - Infusionsoft-1.1.8 (RubyGem)
13
+ Content-Type:
14
+ - text/xml; charset=utf-8
15
+ Content-Length:
16
+ - '629'
17
+ Connection:
18
+ - keep-alive
19
+ Accept-Encoding:
20
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
21
+ Accept:
22
+ - "*/*"
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Server:
29
+ - Apache-Coyote/1.1
30
+ Pragma:
31
+ - no-cache
32
+ Cache-Control:
33
+ - no-cache, no-store
34
+ Expires:
35
+ - Fri, 10 Apr 2015 20:13:43 GMT
36
+ Content-Type:
37
+ - text/xml;charset=UTF-8
38
+ Content-Length:
39
+ - '131'
40
+ Date:
41
+ - Fri, 10 Apr 2015 08:13:43 GMT
42
+ Set-Cookie:
43
+ - app-lb=2466578442.20480.0000; path=/
44
+ body:
45
+ encoding: UTF-8
46
+ string: <?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><i4>3612</i4></value></param></params></methodResponse>
47
+ http_version:
48
+ recorded_at: Fri, 10 Apr 2015 08:13:43 GMT
49
+ - request:
50
+ method: post
51
+ uri: https://test.infusionsoft.com/api/xmlrpc
52
+ body:
53
+ encoding: UTF-8
54
+ string: |
55
+ <?xml version="1.0" ?><methodCall><methodName>APIEmailService.optIn</methodName><params><param><value><string>not_a_real_key</string></value></param><param><value><string>testing@test.com</string></value></param><param><value><string>requested information</string></value></param></params></methodCall>
56
+ headers:
57
+ User-Agent:
58
+ - Infusionsoft-1.1.8 (RubyGem)
59
+ Content-Type:
60
+ - text/xml; charset=utf-8
61
+ Content-Length:
62
+ - '321'
63
+ Connection:
64
+ - keep-alive
65
+ Accept:
66
+ - "*/*"
67
+ response:
68
+ status:
69
+ code: 200
70
+ message: OK
71
+ headers:
72
+ Server:
73
+ - Apache-Coyote/1.1
74
+ Pragma:
75
+ - no-cache
76
+ Cache-Control:
77
+ - no-cache, no-store
78
+ Expires:
79
+ - Fri, 31 Jul 2015 11:55:20 GMT
80
+ Content-Type:
81
+ - text/xml;charset=UTF-8
82
+ Content-Length:
83
+ - '138'
84
+ Date:
85
+ - Thu, 30 Jul 2015 23:55:20 GMT
86
+ Set-Cookie:
87
+ - app-lb=2466578442.20480.0000; path=/
88
+ body:
89
+ encoding: US-ASCII
90
+ string: <?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><boolean>1</boolean></value></param></params></methodResponse>
91
+ http_version:
92
+ recorded_at: Thu, 30 Jul 2015 23:55:21 GMT
93
+ recorded_with: VCR 2.9.3