infusionsoft 1.1.6 → 1.1.7a

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.
@@ -0,0 +1,3 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.homepage = 'https://github.com/nateleavitt/infusionsoft'
13
13
  gem.require_paths = ['lib']
14
14
  gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
15
+ gem.add_development_dependency 'rake'
15
16
 
16
17
  gem.version = Infusionsoft::VERSION.dup
17
18
  end
@@ -1,19 +1,14 @@
1
1
  module Infusionsoft
2
2
  class APILogger
3
3
 
4
- def info; end
5
- def info(msg); $stdout.print msg end
4
+ def info(msg); $stdout.puts msg end
6
5
 
7
- def warn; end
8
- def warn(msg); $stdout.print msg end
6
+ def warn(msg); $stdout.puts msg end
9
7
 
10
- def error; end
11
- def error(msg); $stdout.print msg end
8
+ def error(msg); $stdout.puts msg end
12
9
 
13
- def debug; end
14
- def debug(msg); $stdout.print msg end
10
+ def debug(msg); $stdout.puts msg end
15
11
 
16
- def fatal; end
17
- def fatal(msg); $stdout.print msg end
12
+ def fatal(msg); $stdout.puts msg end
18
13
  end
19
14
  end
@@ -144,7 +144,7 @@ module Infusionsoft
144
144
  # @return [Boolean] returns true/false if teamplate was updated successfully
145
145
  def email_update_template(id, title, category, from, to, cc, bcc, subject,
146
146
  text_body, html_body, content_type, merge_context)
147
- response = get('APIEmailService.updateEmailTemplate', title, category, from,
147
+ response = get('APIEmailService.updateEmailTemplate', id, title, category, from,
148
148
  to, cc, bcc, subject, text_body, html_body, content_type, merge_context)
149
149
  end
150
150
  end
@@ -1,4 +1,5 @@
1
1
  require "xmlrpc/client"
2
+ require 'infusionsoft/exception_handler'
2
3
 
3
4
  module Infusionsoft
4
5
  module Connection
@@ -18,10 +19,10 @@ module Infusionsoft
18
19
  rescue Timeout::Error => timeout
19
20
  # Retry up to 5 times on a Timeout before raising it
20
21
  ok_to_retry(timeout) ? retry : raise
21
- rescue => e
22
- # Wrap the underlying error in an InfusionAPIError
23
- raise InfusionAPIError.new(e.to_s, e)
24
- end
22
+ rescue XMLRPC::FaultException => xmlrpc_error
23
+ # Catch all XMLRPC exceptions and rethrow specific exceptions for each type of xmlrpc fault code
24
+ Infusionsoft::ExceptionHandler.new(xmlrpc_error)
25
+ end # Purposefully not catching other exceptions so that they can be handled up the stack
25
26
 
26
27
  api_logger.info "RESULT:#{result.inspect}"
27
28
  return result
@@ -39,14 +40,3 @@ module Infusionsoft
39
40
 
40
41
  end
41
42
  end
42
-
43
- # Extend StandardError to keep track of Error being wrapped
44
- # Pattern from Exceptional Ruby by Avdi Grimm (http://avdi.org/talks/exceptional-ruby-2011-02-04/)
45
- class InfusionAPIError < StandardError
46
- attr_reader :original
47
- def initialize(msg, original=nil);
48
- api_logger.error "ERROR: #{msg}"
49
- super(msg);
50
- @original = original;
51
- end
52
- end
@@ -0,0 +1,32 @@
1
+ require 'infusionsoft/exceptions'
2
+
3
+ class Infusionsoft::ExceptionHandler
4
+
5
+ ERRORS = {
6
+ 1 => Infusionsoft::InvalidConfigError,
7
+ 2 => Infusionsoft::InvalidKeyError,
8
+ 3 => Infusionsoft::UnexpectedError,
9
+ 4 => Infusionsoft::DatabaseError,
10
+ 5 => Infusionsoft::RecordNotFoundError,
11
+ 6 => Infusionsoft::LoadingError,
12
+ 7 => Infusionsoft::NoTableAccessError,
13
+ 8 => Infusionsoft::NoFieldAccessError,
14
+ 9 => Infusionsoft::NoTableFoundError,
15
+ 10 => Infusionsoft::NoFieldFoundError,
16
+ 11 => Infusionsoft::NoFieldsError,
17
+ 12 => Infusionsoft::InvalidParameterError,
18
+ 13 => Infusionsoft::FailedLoginAttemptError,
19
+ 14 => Infusionsoft::NoAccessError,
20
+ 15 => Infusionsoft::FailedLoginAttemptPasswordExpiredError,
21
+ }
22
+
23
+ def initialize(xmlrpc_exception)
24
+ error_class = ERRORS[xmlrpc_exception.faultCode]
25
+ if error_class
26
+ raise error_class, xmlrpc_exception.faultString
27
+ else
28
+ raise InfusionAPIError, xmlrpc_exception.faultString
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,58 @@
1
+ # Extend StandardError to keep track of Error being wrapped
2
+ # Pattern from Exceptional Ruby by Avdi Grimm (http://avdi.org/talks/exceptional-ruby-2011-02-04/)
3
+ class InfusionAPIError < StandardError
4
+ attr_reader :original
5
+ def initialize(msg, original=nil);
6
+ Infusionsoft.api_logger.error "ERROR: #{msg}"
7
+ super(msg);
8
+ @original = original;
9
+ end
10
+ end
11
+
12
+ module Infusionsoft
13
+ # For now I'm inheriting from InfusionAPIError so that the code will remain backwards compatible...may be deprecated in the future
14
+ class InvalidConfigError < InfusionAPIError
15
+ end
16
+
17
+ class InvalidKeyError < InfusionAPIError
18
+ end
19
+
20
+ class UnexpectedError < InfusionAPIError
21
+ end
22
+
23
+ class DatabaseError < InfusionAPIError
24
+ end
25
+
26
+ class RecordNotFoundError < InfusionAPIError
27
+ end
28
+
29
+ class LoadingError < InfusionAPIError
30
+ end
31
+
32
+ class NoTableAccessError < InfusionAPIError
33
+ end
34
+
35
+ class NoFieldAccessError < InfusionAPIError
36
+ end
37
+
38
+ class NoTableFoundError < InfusionAPIError
39
+ end
40
+
41
+ class NoFieldFoundError < InfusionAPIError
42
+ end
43
+
44
+ class NoFieldsError < InfusionAPIError
45
+ end
46
+
47
+ class InvalidParameterError < InfusionAPIError
48
+ end
49
+
50
+ class FailedLoginAttemptError < InfusionAPIError
51
+ end
52
+
53
+ class NoAccessError < InfusionAPIError
54
+ end
55
+
56
+ class FailedLoginAttemptPasswordExpiredError < InfusionAPIError
57
+ end
58
+ end
@@ -1,4 +1,4 @@
1
1
  module Infusionsoft
2
2
  # The version of the gem
3
- VERSION = '1.1.6'.freeze unless defined?(::Infusionsoft::VERSION)
3
+ VERSION = '1.1.7a'.freeze unless defined?(::Infusionsoft::VERSION)
4
4
  end
@@ -0,0 +1,113 @@
1
+ require 'test/unit'
2
+ require 'infusionsoft'
3
+
4
+
5
+ # override XMLRPC call method
6
+ class XMLRPC::Client
7
+
8
+ def call(method, *args)
9
+ raise XMLRPC::FaultException.new(@@code, @@message)
10
+ end
11
+
12
+ def self.set_fault_response(code, message)
13
+ @@code = code
14
+ @@message = message
15
+ end
16
+ end
17
+
18
+ class TestLogger
19
+ def info(msg); end
20
+ def warn(msg); end
21
+ def error(msg); end
22
+ def debug(msg); end
23
+ def fatal(msg); end
24
+ end
25
+
26
+
27
+ class TestExceptions < Test::Unit::TestCase
28
+
29
+ def setup
30
+ Infusionsoft.configure do |c|
31
+ c.api_logger = TestLogger.new()
32
+ end
33
+ end
34
+
35
+ def test_should_raise_invalid_config
36
+ exception_test(Infusionsoft::InvalidConfigError, 1, 'The configuration for the application is invalid. Usually this is because there has not been a passphrase entered to generate an encrypted key.')
37
+ end
38
+
39
+ def test_should_raise_invalid_key
40
+ exception_test(Infusionsoft::InvalidKeyError, 2, "The key passed up for authentication was not valid. It was either empty or didn't match.")
41
+ end
42
+
43
+ def test_should_raise_unexpected_error
44
+ exception_test(Infusionsoft::UnexpectedError, 3, "An unexpected error has occurred. There was either an error in the data you passed up or there was an unknown error on")
45
+ end
46
+
47
+ def test_should_raise_database_error
48
+ exception_test(Infusionsoft::DatabaseError, 4, "There was an error in the database access")
49
+ end
50
+
51
+ def test_should_raise_record_not_found
52
+ exception_test(Infusionsoft::RecordNotFoundError, 5, "A requested record was not found in the database.")
53
+ end
54
+
55
+ def test_should_raise_loading_error
56
+ exception_test(Infusionsoft::LoadingError, 6, "There was a problem loading a record from the database.")
57
+ end
58
+
59
+ def test_should_raise_no_table_access
60
+ exception_test(Infusionsoft::NoTableAccessError, 7, "A table was accessed without the proper permission")
61
+ end
62
+
63
+ def test_should_raise_no_field_access
64
+ exception_test(Infusionsoft::NoFieldAccessError, 8, "A field was accessed without the proper permission.")
65
+ end
66
+
67
+ def test_should_raise_no_table_found
68
+ exception_test(Infusionsoft::NoTableFoundError, 9, "A table was accessed that doesn't exist in the Data Spec.")
69
+ end
70
+
71
+ def test_should_raise_no_field_found
72
+ exception_test(Infusionsoft::NoFieldFoundError, 10, "A field was accessed that doesn't exist in the Data Spec.")
73
+ end
74
+
75
+ def test_should_raise_no_fields_error
76
+ exception_test(Infusionsoft::NoFieldsError, 11, "An update or add operation was attempted with no valid fields to update or add.")
77
+ end
78
+
79
+ def test_should_raise_invalid_parameter_error
80
+ exception_test(Infusionsoft::InvalidParameterError, 12, "Data sent into the call was invalid.")
81
+ end
82
+
83
+ def test_should_raise_failed_login_attempt
84
+ exception_test(Infusionsoft::FailedLoginAttemptError, 13, "Someone attempted to authenticate a user and failed.")
85
+ end
86
+
87
+ def test_should_raise_no_access_error
88
+ exception_test(Infusionsoft::NoAccessError, 14, "Someone attempted to access a plugin they are not paying for.")
89
+ end
90
+
91
+ def test_should_raise_failed_login_attempt_password_expired
92
+ exception_test(Infusionsoft::FailedLoginAttemptPasswordExpiredError, 15, "Someone attempted to authenticate a user and the password is expired.")
93
+ end
94
+
95
+ def test_should_raise_infusionapierror_when_fault_code_unknown
96
+ exception_test(InfusionAPIError, 42, "Some random error occurred")
97
+ end
98
+
99
+
100
+ private
101
+ def exception_test(exception, code, message)
102
+ XMLRPC::Client.set_fault_response(code, message)
103
+ caught = false
104
+ begin
105
+ Infusionsoft.data_query(:Contact, 1, 0, {}, [:BlahdyDah])
106
+ rescue exception => e
107
+ caught = true
108
+ assert_equal message, e.message
109
+ end
110
+ assert_equal true, caught
111
+ end
112
+
113
+ end
metadata CHANGED
@@ -1,16 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infusionsoft
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
5
- prerelease:
4
+ version: 1.1.7a
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan Leavitt
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-21 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
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'
14
30
  description: A Ruby wrapper written for the Infusionsoft API
15
31
  email:
16
32
  - nate@infusedsystems.com
@@ -21,6 +37,7 @@ files:
21
37
  - .gitignore
22
38
  - LICENSE.md
23
39
  - README.md
40
+ - Rakefile
24
41
  - infusionsoft.gemspec
25
42
  - lib/infusionsoft.rb
26
43
  - lib/infusionsoft/api.rb
@@ -38,9 +55,12 @@ files:
38
55
  - lib/infusionsoft/client/version.rb
39
56
  - lib/infusionsoft/configuration.rb
40
57
  - lib/infusionsoft/connection.rb
58
+ - lib/infusionsoft/exception_handler.rb
59
+ - lib/infusionsoft/exceptions.rb
41
60
  - lib/infusionsoft/request.rb
42
61
  - lib/infusionsoft/version.rb
43
62
  - test/api_infusion_test.rb
63
+ - test/test_exceptions.rb
44
64
  homepage: https://github.com/nateleavitt/infusionsoft
45
65
  licenses: []
46
66
  post_install_message:
@@ -56,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
76
  required_rubygems_version: !ruby/object:Gem::Requirement
57
77
  none: false
58
78
  requirements:
59
- - - ! '>='
79
+ - - ! '>'
60
80
  - !ruby/object:Gem::Version
61
- version: 1.3.6
81
+ version: 1.3.1
62
82
  requirements: []
63
83
  rubyforge_project:
64
84
  rubygems_version: 1.8.24