exact_target_sdk 0.0.1 → 0.0.2

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,15 @@
1
1
  = ExactTarget SDK
2
2
 
3
+ == Version 0.0.2
4
+ * Adding thorough unit tests throughout
5
+ * Using ActiveModel::Callbacks instead of home-baked before_validation
6
+ * Adding UnknownError class to handle all unexpected exceptions
7
+ * Fixing bug where properties that were simple strings or numbers were not rendered properly
8
+
9
+ == Version 0.0.1
10
+ * Fixing improperly tested bugs limiting basic functionality
11
+ * Adding to README
12
+
3
13
  == Version 0.0.0
4
14
  * Initial release
5
15
  * Supports Create method
@@ -9,6 +9,7 @@ module ExactTargetSDK
9
9
  class APIObject
10
10
 
11
11
  include ::ActiveModel::Validations
12
+ include ::ActiveModel::Validations::Callbacks
12
13
 
13
14
  class << self
14
15
 
@@ -63,22 +64,11 @@ class APIObject
63
64
  validates name.to_sym, :numericality => { :allow_nil => true, :only_integer => true }
64
65
  end
65
66
 
66
- # Takes one or more method names as symbols, and executes them in order
67
- # before validation occurs on this object.
68
- def before_validation(*args)
69
- before_validation_methods.concat(args)
70
- end
71
-
72
67
  # Returns an array of all registered properties.
73
68
  def properties
74
69
  @properties || []
75
70
  end
76
71
 
77
- # Returns the method names declared using #before_validation.
78
- def before_validation_methods
79
- @before_validation_methods ||= []
80
- end
81
-
82
72
  private
83
73
 
84
74
  # Stores the given property name to be used at render time.
@@ -108,11 +98,10 @@ class APIObject
108
98
 
109
99
  # By default, runs validation and executes #render_properties!.
110
100
  #
111
- # If overridden, the child class should execute the before_validation
112
- # methods, check wehter or not the object is valid, and then render
113
- # the object.
101
+ # If overridden, the child class should check wehter or not the
102
+ # object is valid, and then render the object. In general,
103
+ # the render_properties! method should be overridden instead.
114
104
  def render!(xml)
115
- self.class.before_validation_methods.each { |method| self.send(method) }
116
105
  raise(InvalidAPIObject, self) if invalid?
117
106
  render_properties!(xml)
118
107
  end
@@ -124,22 +113,22 @@ class APIObject
124
113
  def render_properties!(xml)
125
114
  self.class.properties.each do |property|
126
115
  next unless instance_variable_get("@_set_#{property}")
127
-
128
116
  property_value = self.send(property)
117
+ render_property!(property, property_value, xml)
118
+ end
119
+ end
129
120
 
130
- if property_value.is_a?(APIObject)
131
- xml.__send__(property) do
132
- property_value.render!(xml)
133
- end
134
- elsif property_value.is_a?(Array)
135
- property_value.each do |current|
136
- xml.__send__(property) do
137
- current.render!(xml)
138
- end
139
- end
140
- else
141
- xml.__send__(property, property_value)
121
+ def render_property!(property_name, property_value, xml)
122
+ if property_value.is_a?(APIObject)
123
+ xml.__send__(property_name) do
124
+ property_value.render!(xml)
125
+ end
126
+ elsif property_value.is_a?(Array)
127
+ property_value.each do |current|
128
+ render_property!(property_name, current, xml)
142
129
  end
130
+ else
131
+ xml.__send__(property_name, property_value.to_s)
143
132
  end
144
133
  end
145
134
 
@@ -64,6 +64,10 @@ class Client
64
64
  CreateResponse.new(response)
65
65
  end
66
66
 
67
+ def logger
68
+ config[:logger]
69
+ end
70
+
67
71
  private
68
72
 
69
73
  attr_accessor :config, :client
@@ -129,9 +133,11 @@ class Client
129
133
 
130
134
  response
131
135
  rescue ::Timeout::Error => e
132
- timeout = ::ExactTargetSDK::Timeout.new("#{e.message}; open_timeout: #{config[:open_timeout]}; read_timeout: #{config[:read_timeout]}")
136
+ timeout = ::ExactTargetSDK::TimeoutError.new("#{e.message}; open_timeout: #{config[:open_timeout]}; read_timeout: #{config[:read_timeout]}")
133
137
  timeout.set_backtrace(e.backtrace)
134
138
  raise timeout
139
+ rescue Exception => e
140
+ raise ::ExactTargetSDK::UnknownError, e
135
141
  end
136
142
  end
137
143
 
@@ -8,6 +8,7 @@ class CreateResponse
8
8
  @OverallStatus = response[:overall_status]
9
9
  @RequestID = response[:request_id]
10
10
  @Results = []
11
+
11
12
  results = if response[:results].is_a? Array
12
13
  response[:results]
13
14
  elsif response[:results].is_a? Hash
@@ -13,7 +13,16 @@ class SOAPFault < Error
13
13
  end
14
14
 
15
15
  # Indicates the open or read timeouts were reached
16
- class Timeout < Error
16
+ class TimeoutError < Error
17
+ end
18
+
19
+ # Indicates any type of unexpected error
20
+ class UnknownError < Error
21
+ attr_reader :wrapped_exception
22
+
23
+ def initialize(e)
24
+ @wrapped_exception = e
25
+ end
17
26
  end
18
27
 
19
28
  # Indicates validation failed on an APIObject, which is referenced
@@ -1,3 +1,3 @@
1
1
  module ExactTargetSDK
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exact_target_sdk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Dawson