gotransverse-tract-api 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1c38c026591c1c63f33dd05330b3fcf5da1140e
4
- data.tar.gz: 5617de649a6f0afe16e934cd55908f5a0c959d3f
3
+ metadata.gz: fce9f9f3e3f911147aaf81a575781c67600ddd97
4
+ data.tar.gz: f776201ed0e6a007baff0db725c7c752ea84a1ed
5
5
  SHA512:
6
- metadata.gz: 8d81eec88b40f116b0e1b9dc98f901272d95ad96a6790284edf3f47db65a1ae1282a85891db133421b78ea267016fd0df5eacb5733b512651bd514f43c2c9b3c
7
- data.tar.gz: 4fcf5c8bc8e5965fa622aa4af21cb097e1bd78b265bb485b45eceb973c5897eb56f7b16902ce15335c1dc56f1c30b4e2712b9e5aaed3cff223001229a2d59e01
6
+ metadata.gz: 570bb59248b7a871f612ad16db32846c5461e6f6d9268ff46551663901f509bfb8b1571091bd0e6e82f7116c0cd6dfbbd2d0bdd819eba2a08288aef4dee40be3
7
+ data.tar.gz: 68f1dbab0601e8e1b09b7f1315f7b4917f89c4b3c66a33256d69a0286154208e3ae32939da19c3ee4298a1182c4cff0b0382d8ccc2c0549205a6cdfefbacc0fa
@@ -212,7 +212,7 @@ module GoTransverseTractApi
212
212
  startDate: billing_account[:start_date],
213
213
  taxExempt: billing_account[:tax_exempt],
214
214
  eid: billing_account[:eid]
215
- }.delete_if{|k,v| v.nil?},
215
+ },
216
216
  dailyBillCycle: {
217
217
  name: billing_account[:daily_bill_cycle][:name],
218
218
  startDate: billing_account[:daily_bill_cycle][:start_date],
@@ -222,7 +222,7 @@ module GoTransverseTractApi
222
222
  usePaymentTerm: billing_account[:daily_bill_cycle][:use_payment_term],
223
223
  status: billing_account[:daily_bill_cycle][:status],
224
224
  eid: billing_account[:daily_bill_cycle][:eid]
225
- }.delete_if{|k,v| v.nil?},
225
+ },
226
226
  person: {
227
227
  attributes: {
228
228
  firstName: billing_account[:person][:first_name],
@@ -230,22 +230,22 @@ module GoTransverseTractApi
230
230
  eid: billing_account[:person][:eid]
231
231
  },
232
232
  addresses: get_addresses(billing_account[:person])
233
- }.delete_if{|k,v| v.nil?},
233
+ },
234
234
  billingAccountCategory: {
235
235
  type: billing_account[:billing_account_category][:type],
236
236
  description: billing_account[:billing_account_category][:description],
237
237
  status: billing_account[:billing_account_category][:status],
238
238
  eid: billing_account[:billing_account_category][:eid]
239
- }.delete_if{|k,v| v.nil?},
239
+ },
240
240
  paymentTerm: {
241
241
  name: billing_account[:payment_term][:name],
242
242
  termDays: billing_account[:payment_term][:term_days],
243
243
  graceDays: billing_account[:payment_term][:grace_days],
244
244
  eid: billing_account[:payment_term][:eid]
245
- }.delete_if{|k,v| v.nil?}
245
+ }
246
246
  }
247
247
 
248
- ba_details.delete_if{|k,v| v.nil?}
248
+ compact ba_details
249
249
  end
250
250
 
251
251
  def get_query_params(params, options={})
@@ -262,53 +262,92 @@ module GoTransverseTractApi
262
262
  }
263
263
 
264
264
  if entity[:addresses].has_key?(:email_address)
265
- email_address = {
266
- emailAddress: {
267
- purpose: entity[:addresses][:email_address][:purpose],
268
- email: entity[:addresses][:email_address][:email],
269
- }.delete_if{|k,v| v.nil?}
270
- }.delete_if{|k,v| v.nil?}
271
-
265
+ email_address = get_email_address(entity[:addresses][:email_address])
272
266
  addresses.merge! email_address if email_address.present?
273
267
  end
274
-
275
- if entity[:addresses].has_key?(:postal_address)
276
- postal_address = {
277
- postalAddress: {
278
- purpose: entity[:addresses][:postal_address][:purpose],
279
- country: entity[:addresses][:postal_address][:country],
280
- city: entity[:addresses][:postal_address][:city],
281
- regionOrState: entity[:addresses][:postal_address][:region_or_state],
282
- attention: entity[:addresses][:postal_address][:attention],
283
- postalCode: entity[:addresses][:postal_address][:postal_code],
284
- line1: entity[:addresses][:postal_address][:line1],
285
- }.delete_if{|k,v| v.nil?}
286
- }.delete_if{|k,v| v.nil?}
287
268
 
269
+ if entity[:addresses].has_key?(:postal_address)
270
+ postal_address = get_postal_address(entity[:addresses][:postal_address])
288
271
  addresses.merge! postal_address if postal_address.present?
289
272
  end
290
273
 
291
274
  if entity[:addresses].has_key?(:telecom_address)
292
- tele_address = {
293
- telecomAddress: {
294
- dialingPrefix: entity[:addresses].try(:[],:telecom_address).try(:[],:dialing_prefix),
295
- countryCode: entity[:addresses].try(:[],:telecom_address).try(:[],:country_code),
296
- areaCode: entity[:addresses].try(:[],:telecom_address).try(:[],:area_code),
297
- number: entity[:addresses].try(:[],:telecom_address).try(:[],:number),
298
- extension: entity[:addresses].try(:[],:telecom_address).try(:[],:extension),
299
- purpose: entity[:addresses].try(:[],:telecom_address).try(:[],:purpose),
300
- eid: entity[:addresses].try(:[],:telecom_address).try(:[],:eid)
301
- }.delete_if{|k,v| v.nil?}
302
- }.delete_if{|k,v| v.nil?}
303
-
275
+ tele_address = get_telecom_address(entity[:addresses][:telecom_address])
304
276
  addresses.merge! tele_address if tele_address.present?
305
277
  end
306
278
 
307
- addresses
279
+ compact addresses
308
280
 
309
281
  rescue
310
282
  {}
311
283
  end
312
284
 
285
+ # Returns {Hash} Postal Address
286
+ def get_postal_address(entity)
287
+ postal_address = {
288
+ postalAddress: {
289
+ purpose: entity[:purpose],
290
+ country: entity[:country],
291
+ city: entity[:city],
292
+ regionOrState: entity[:region_or_state],
293
+ attention: entity[:attention],
294
+ postalCode: entity[:postal_code],
295
+ line1: entity[:line1]
296
+ }
297
+ }
298
+
299
+ compact postal_address
300
+ end
301
+
302
+ # Returns {Hash} Email Address
303
+ def get_email_address(entity)
304
+ email_address = {
305
+ emailAddress: {
306
+ purpose: entity[:purpose],
307
+ email: entity[:email]
308
+ }
309
+ }
310
+
311
+ compact email_address
312
+ end
313
+
314
+ # Returns {Hash} Telecom Address
315
+ def get_telecom_address(entity)
316
+ tele_address = {
317
+ telecomAddress: {
318
+ dialingPrefix: entity.try(:[],:dialing_prefix),
319
+ countryCode: entity.try(:[],:country_code),
320
+ areaCode: entity.try(:[],:area_code),
321
+ number: entity.try(:[],:number),
322
+ extension: entity.try(:[],:extension),
323
+ purpose: entity.try(:[],:purpose),
324
+ eid: entity.try(:[],:eid)
325
+ }
326
+ }
327
+
328
+ compact tele_address
329
+ end
330
+
331
+ # Remove all nil elements from hash
332
+ def compact(h={})
333
+ h.each do|k,v|
334
+ if v.nil?
335
+ h.delete(k)
336
+ elsif (v.is_a?(Hash) && v.empty?)
337
+ next
338
+ end
339
+
340
+ compact v if v.is_a?Hash
341
+ end
342
+
343
+ # Remove all empty hashes except first key if it is empty
344
+ # since that is required for XML root element attributes
345
+ h.delete_if do|k,v|
346
+ v.is_a?(Hash) && v.empty? && k != h.keys[0]
347
+ end
348
+
349
+ h
350
+ end
351
+
313
352
  end
314
353
  end
@@ -61,25 +61,18 @@ module GoTransverseTractApi
61
61
  end
62
62
 
63
63
  if (address.has_key?(:postal_address))
64
- postal_address = {
65
- postalAddress: {
66
- purpose: address[:postal_address][:purpose],
67
- country: address[:postal_address][:country],
68
- city: address[:postal_address][:city],
69
- regionOrState: address[:postal_address][:region_or_state],
70
- attention: address[:postal_address][:attention],
71
- postalCode: address[:postal_address][:postal_code],
72
- line1: address[:postal_address][:line1],
73
- }.delete_if{|k,v| v.nil?}
74
- }.delete_if{|k,v| v.nil?}
75
-
76
- data.merge!({ postalAddress: postal_address[:postalAddress] })
64
+ postal_address = GoTransverseTractApi::ApiData.new.get_postal_address(address[:postal_address])
65
+ data.merge!(postal_address)
77
66
  end
67
+
78
68
  if (address.has_key?(:email_address))
79
- data.merge!({ emailAddress: address[:email_address] })
69
+ email_address = GoTransverseTractApi::ApiData.new.get_email_address(address[:email_address])
70
+ data.merge!(email_address)
80
71
  end
72
+
81
73
  if (address.has_key?(:telecom_address))
82
- data.merge!({ telecomAddress: address[:telecom_address] })
74
+ telecom_address = GoTransverseTractApi::ApiData.new.get_telecom_address(address[:telecom_address])
75
+ data.merge!(telecom_address)
83
76
  end
84
77
 
85
78
  xml_data = GoTransverseTractApi.generateXML(data, 'addAddressToParty')
@@ -73,28 +73,6 @@ module GoTransverseTractApi
73
73
  GoTransverseTractApi.put_request_for(self, {eid: eid}, xml_data)
74
74
  end
75
75
 
76
- #
77
- # @param {Long} eid
78
- # @param {Hash} address
79
- #
80
- def self.add_address eid, address
81
- data = {
82
- addAddressToParty: {},
83
- person: {eid: eid},
84
- postalAddress: {
85
- purpose: address[:purpose],
86
- country: address[:country],
87
- city: address[:city],
88
- regionOrState: address[:region_or_state],
89
- postalCode: address[:postal_code],
90
- line1: address[:line1]
91
- }
92
- }
93
-
94
- xml_data = GoTransverseTractApi.generateXML(data, 'addAddressToParty')
95
- GoTransverseTractApi.post_request_for(self, {eid: eid}, xml_data, "addAddress")
96
- end
97
-
98
76
  end
99
77
 
100
78
  end
@@ -6,6 +6,14 @@ module GoTransverseTractApi
6
6
 
7
7
  class << self
8
8
 
9
+ #
10
+ # @param {Hash} options
11
+ #
12
+ def find_all options={}
13
+ params ||= GoTransverseTractApi::ApiData.new.get_query_params({}, options)
14
+ GoTransverseTractApi.get_response_for(self, params)
15
+ end
16
+
9
17
  #
10
18
  # @param {Long} eid
11
19
  # @param {Hash} options
@@ -1,6 +1,6 @@
1
1
  module GoTransverseTractApi
2
2
 
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  TARGET_API_VERSION = "1.29"
5
5
 
6
6
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module GoTransverseTractApi
4
+
5
+ RSpec.describe ApiData do
6
+ before(:each) { http_auth }
7
+
8
+ describe ".compact" do
9
+ it "returns a hash by eliminating all nil" do
10
+ given_hash = {a: {}, c: 'p', s: nil, d: {e: nil, m: nil}, f: {g: {}, x: {n: 'h', i: nil, j: 'l'}}}
11
+ expected_hash = {:a=>{}, :c=>"p", :f=>{:g=>{}, :x=>{:n=>"h", :j=>"l"}}}
12
+
13
+ expect(described_class.new.compact(given_hash)).to eq(expected_hash)
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -8,24 +8,6 @@ module GoTransverseTractApi
8
8
  let(:eid) { '4096' }
9
9
  let(:response) { {a: 'b', c: 'd'} }
10
10
 
11
- context ".add_address" do
12
- it "adds address for the customer" do
13
- eid = '48406'
14
-
15
- data = {
16
- city: 'fsfsfs',
17
- country: 'USA',
18
- line1: 'wefsvgg ggdgdgd',
19
- postal_code: '232433',
20
- purpose: 'Billing',
21
- region_or_state: 'CA'
22
- }
23
-
24
- allow(subject).to receive(:add_address).with(eid, data).and_return(response)
25
- expect(subject.add_address(eid, data)).to eq(response)
26
- end
27
- end
28
-
29
11
  context ".update" do
30
12
  it "updates a person details" do
31
13
  data = { eid: eid, name: 'John Smith', tax_id_number: '124224242' }
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module GoTransverseTractApi
4
+
5
+ RSpec.describe Usage::RateTable do
6
+ before(:each) { http_auth }
7
+
8
+ let(:response) { {a: 'b', c: 'd'} }
9
+
10
+ describe ".find_all" do
11
+ it "returns all rate table entries" do
12
+ data = described_class.find_all
13
+ expect(data).to_not be_nil
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotransverse-tract-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien DeFrance
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-12 00:00:00.000000000 Z
12
+ date: 2016-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -207,6 +207,7 @@ files:
207
207
  - lib/gotransverse-tract-api/usage/usage_some.rb
208
208
  - lib/gotransverse-tract-api/version.rb
209
209
  - spec/auth_helper.rb
210
+ - spec/gotransverse-tract-api/api_data_spec.rb
210
211
  - spec/gotransverse-tract-api/billing_account/adjustment_spec.rb
211
212
  - spec/gotransverse-tract-api/billing_account/billing_account_spec.rb
212
213
  - spec/gotransverse-tract-api/billing_account/counter_spec.rb
@@ -232,6 +233,7 @@ files:
232
233
  - spec/gotransverse-tract-api/service/service_spec.rb
233
234
  - spec/gotransverse-tract-api/usage/order_item_usage_rule_spec.rb
234
235
  - spec/gotransverse-tract-api/usage/product_usage_rule_spec.rb
236
+ - spec/gotransverse-tract-api/usage/rate_table_spec.rb
235
237
  - spec/gotransverse-tract-api/usage/usage_event_spec.rb
236
238
  - spec/gotransverse-tract-api_spec.rb
237
239
  - spec/spec_helper.rb
@@ -262,6 +264,7 @@ summary: A ruby gem allowing developers to conveniently integrate with GoTransve
262
264
  TRACT API.
263
265
  test_files:
264
266
  - spec/auth_helper.rb
267
+ - spec/gotransverse-tract-api/api_data_spec.rb
265
268
  - spec/gotransverse-tract-api/billing_account/adjustment_spec.rb
266
269
  - spec/gotransverse-tract-api/billing_account/billing_account_spec.rb
267
270
  - spec/gotransverse-tract-api/billing_account/counter_spec.rb
@@ -287,6 +290,7 @@ test_files:
287
290
  - spec/gotransverse-tract-api/service/service_spec.rb
288
291
  - spec/gotransverse-tract-api/usage/order_item_usage_rule_spec.rb
289
292
  - spec/gotransverse-tract-api/usage/product_usage_rule_spec.rb
293
+ - spec/gotransverse-tract-api/usage/rate_table_spec.rb
290
294
  - spec/gotransverse-tract-api/usage/usage_event_spec.rb
291
295
  - spec/gotransverse-tract-api_spec.rb
292
296
  - spec/spec_helper.rb