fuelsdk 0.1.2 → 0.1.3

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.md CHANGED
@@ -1,9 +1,16 @@
1
1
  FuelSDK-Ruby
2
2
  ============
3
3
 
4
+ 2013-09-18: Version 0.1.3
5
+ ```
6
+ augment soap_cud to handle dataextensions better
7
+
8
+ array.wrap so we can be less terse
9
+ ```
10
+
4
11
  2013-09-18: Version 0.1.2
5
12
  ```
6
- get properties for dataextension for retrieve and edit calls
13
+ get dataextension properties sugar method
7
14
 
8
15
  clear soap client on refresh so the client gets re-established with header with new token
9
16
 
data/lib/fuelsdk.rb CHANGED
@@ -5,6 +5,18 @@ require 'date'
5
5
  require 'jwt'
6
6
  require 'active_support/inflector'
7
7
 
8
+ class Array
9
+ class << self
10
+ def wrap subject
11
+ if subject.kind_of? Array
12
+ subject
13
+ else
14
+ [subject]
15
+ end
16
+ end
17
+ end
18
+ end
19
+
8
20
  module FuelSDK
9
21
  require 'fuelsdk/utils'
10
22
  autoload :HTTPRequest, 'fuelsdk/http_request'
data/lib/fuelsdk/soap.rb CHANGED
@@ -47,7 +47,7 @@ module FuelSDK
47
47
  def unpack_rslts raw
48
48
  @more = (raw.body[raw.body.keys.first][:overall_status] == 'MoreDataAvailable')
49
49
  rslts = raw.body[raw.body.keys.first][:results] || []
50
- rslts = [rslts] unless rslts.kind_of? Array
50
+ rslts = Array.wrap(rslts)
51
51
  rslts
52
52
  rescue
53
53
  []
@@ -71,7 +71,7 @@ module FuelSDK
71
71
  # ugly, but a necessary evil
72
72
  _exts = definition[:extended_properties].nil? ? {} : definition[:extended_properties] # if they have no extended properties nil is returned
73
73
  _exts = _exts[:extended_property] || [] # if no properties nil and we need an array to iterate
74
- _exts = [_exts] unless _exts.kind_of? Array # if they have only one extended property we need to wrap it in array to iterate
74
+ _exts = Array.wrap(_exts) # if they have only one extended property we need to wrap it in array to iterate
75
75
  _exts.each do |p|
76
76
  @viewable << p[:name] if p[:is_viewable]
77
77
  @editable << p[:name] if p[:is_editable]
@@ -121,16 +121,41 @@ module FuelSDK
121
121
  )
122
122
  end
123
123
 
124
- def soap_describe object_type
125
- message = {
124
+ def describe_object_type_message object_type
125
+ {
126
126
  'DescribeRequests' => {
127
127
  'ObjectDefinitionRequest' => {
128
128
  'ObjectType' => object_type
129
129
  }
130
130
  }
131
131
  }
132
+ end
132
133
 
133
- soap_request :describe, message
134
+ def describe_dataextension_message dataextension
135
+ {
136
+ 'Property' => "DataExtension.CustomerKey",
137
+ 'SimpleOperator' => 'equals',
138
+ 'Value' => dataextension
139
+ }
140
+ end
141
+
142
+ def describe_data_extension dataextension
143
+ soap_get('DataExtensionField',
144
+ 'Name',
145
+ describe_dataextension_message(dataextension)
146
+ )
147
+ end
148
+
149
+ def soap_describe object_type
150
+ soap_request :describe, describe_object_type_message(object_type)
151
+ end
152
+
153
+ def describe object_type
154
+ rsp = soap_describe(object_type)
155
+ unless rsp.success?
156
+ rsp = describe_data_extension object_type
157
+ end
158
+ rsp
134
159
  end
135
160
 
136
161
  def get_all_object_properties object_type
@@ -140,12 +165,8 @@ module FuelSDK
140
165
  end
141
166
 
142
167
  def get_dataextension_properties dataextension
143
- soap_get('DataExtensionField',
144
- 'Name',
145
- 'Property' => "DataExtension.CustomerKey",
146
- 'SimpleOperator' => 'equals',
147
- 'Value' => dataextension
148
- ).results.collect{|f| f[:name]}
168
+ describe_dataextension(dataextension)
169
+ .results.collect{|f| f[:name]}
149
170
  end
150
171
 
151
172
  def cache_properties action, object_type, properties
@@ -168,6 +189,8 @@ module FuelSDK
168
189
  def get_retrievable_properties object_type
169
190
  if props=retrievable_properties_cached?(object_type)
170
191
  props
192
+ elsif is_a_dataextension? object_type
193
+ []
171
194
  else
172
195
  cache_retrievable object_type, get_all_object_properties(object_type).retrievable
173
196
  end
@@ -184,6 +207,8 @@ module FuelSDK
184
207
  def get_editable_properties object_type
185
208
  if props=editable_properties_cached?(object_type)
186
209
  props
210
+ elsif is_a_dataextension? object_type
211
+ []
187
212
  else
188
213
  cache_editable object_type, get_all_object_properties(object_type).editable
189
214
  end
@@ -263,7 +288,7 @@ module FuelSDK
263
288
  end
264
289
 
265
290
  def create_action_message message_type, object_type, properties, action
266
- properties = [properties] unless properties.kind_of? Array
291
+ properties = Array.wrap(properties)
267
292
  {
268
293
  'Action' => action,
269
294
  message_type => {
@@ -295,14 +320,29 @@ module FuelSDK
295
320
  }
296
321
  end
297
322
 
298
- def normalize_properties_for_cud object_type, properties
299
- properties = [properties] unless properties.kind_of? Array
300
- raise 'Object properties must be a Hash' unless properties.first.kind_of? Hash
323
+ def format_dataextension_cud_properties properties
324
+ Array.wrap(properties).each do |p|
325
+ formated_attrs = []
326
+ p.each do |k, v|
327
+ unless k == 'CustomerKey'
328
+ p.delete k
329
+ attrs = FuelSDK.format_name_value_pairs k => v
330
+ formated_attrs.concat attrs
331
+ end
332
+ end
333
+ unless formated_attrs.blank?
334
+ p['Properties'] ||= {}
335
+ (p['Properties']['Property'] ||= []).concat formated_attrs
336
+ end
337
+ end
338
+ end
301
339
 
302
- # get a list of attributes so we can seperate
303
- # them from standard object properties
304
- type_attrs = get_editable_properties object_type
340
+ def is_a_dataextension? object_type
341
+ object_type == 'DataExtensionObject'
342
+ end
305
343
 
344
+ def format_object_cud_properties object_type, properties
345
+ type_attrs = get_editable_properties object_type
306
346
  properties.each do |p|
307
347
  formated_attrs = []
308
348
  p.each do |k, v|
@@ -316,6 +356,18 @@ module FuelSDK
316
356
  end
317
357
  end
318
358
 
359
+ def normalize_properties_for_cud object_type, properties
360
+ properties = Array.wrap(properties)
361
+ raise 'Object properties must be a Hash' unless properties.first.kind_of? Hash
362
+
363
+ if is_a_dataextension? object_type
364
+ format_dataextension_cud_properties properties
365
+ else
366
+ format_object_cud_properties object_type, properties
367
+ end
368
+
369
+ end
370
+
319
371
  private
320
372
 
321
373
  def soap_cud action, object_type, properties
@@ -1,3 +1,3 @@
1
1
  module FuelSDK
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+
5
+ it '#self.wrap returns subject wrapped in an array' do
6
+ expect(Array.wrap(1)).to eq([1])
7
+ end
8
+
9
+ it '#self.wrap returns subject as is when already wrapped' do
10
+ expect(Array.wrap([1])).to eq([1])
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe FuelSDK::Soap do
4
+
5
+ let(:client) { FuelSDK::Client.new }
6
+
7
+ subject { client }
8
+
9
+ describe '#format_cud_properties_for_dataextension' do
10
+ let(:de_properties) {
11
+ [{'CustomerKey' => 'Orders', 'total' => 1}]
12
+ }
13
+ it 'leaves CustomerKey alone an puts other attributes in name value pairs under Properies' do
14
+ expect(client.format_dataextension_cud_properties de_properties).to eq([{
15
+ 'CustomerKey' => 'Orders',
16
+ 'Properties' => {'Property' => [{'Name' => 'total', 'Value' => 1}]}
17
+ }])
18
+ end
19
+ end
20
+
21
+ end
22
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuelsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -196,6 +196,7 @@ files:
196
196
  - samples/sample-triggeredsend.rb
197
197
  - samples/sample-unsubevent.rb
198
198
  - samples/sample_helper.rb
199
+ - spec/array_spec.rb
199
200
  - spec/client_spec.rb
200
201
  - spec/fuelsdk_response_spec.rb
201
202
  - spec/helper_funcs_spec.rb
@@ -204,6 +205,7 @@ files:
204
205
  - spec/rest_spec.rb
205
206
  - spec/soap/configure_spec.rb
206
207
  - spec/soap/cud_spec.rb
208
+ - spec/soap/dataextension_spec.rb
207
209
  - spec/soap/describe_error_spec.rb
208
210
  - spec/soap/get_spec.rb
209
211
  - spec/soap/perform_spec.rb
@@ -254,6 +256,7 @@ test_files:
254
256
  - samples/sample-triggeredsend.rb
255
257
  - samples/sample-unsubevent.rb
256
258
  - samples/sample_helper.rb
259
+ - spec/array_spec.rb
257
260
  - spec/client_spec.rb
258
261
  - spec/fuelsdk_response_spec.rb
259
262
  - spec/helper_funcs_spec.rb
@@ -262,6 +265,7 @@ test_files:
262
265
  - spec/rest_spec.rb
263
266
  - spec/soap/configure_spec.rb
264
267
  - spec/soap/cud_spec.rb
268
+ - spec/soap/dataextension_spec.rb
265
269
  - spec/soap/describe_error_spec.rb
266
270
  - spec/soap/get_spec.rb
267
271
  - spec/soap/perform_spec.rb