iron_bank 2.0.0 → 2.0.1

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
- SHA1:
3
- metadata.gz: 7b44c23ef147468febcaa424fc386905e956383b
4
- data.tar.gz: c75b2d1b28b9b46ade61e3b3a2500c9908fefab3
2
+ SHA256:
3
+ metadata.gz: 8234b3d722f4748c284fd3d3e0a1e813e9f41835156937971cb8777e6fb3df94
4
+ data.tar.gz: 3009116645a7c107b0d046993d4b75df937f04c0ef68e6547fb5aebcff3ce873
5
5
  SHA512:
6
- metadata.gz: a79828f6152c630e86f4e56b25d95cb533d4e66ce348ac623c486c962944165b8d0b0d388beea9a116b04997a02d0b4692c7ce7ac7c9c36b5be82abcb3eaab41
7
- data.tar.gz: d323fbda75c7d13afe62b8a2f02ef363bd7268cea1427b5016442fb077e08de23feb27366d6dab0b11a7f4a12f7039b2333e8958d7823dd250b868319ba6033b
6
+ metadata.gz: e327dc8139567cec93b02a5dce35bce8f83031f6481b78d6f021a4556415b3a1e2a04aeb789e49eca4e32c70efabb0759396ec276b5bba5337d99115b8c78adc
7
+ data.tar.gz: caaf42d97da52409e99c1f777a1b2b2f200a49728ad9aa3a4b0bf892ca6f1fac17ce67dbf29f109d4fb129161d1c116b36fb5d30a2a8bc09161f184e30e5c733
data/.reek.yml CHANGED
@@ -60,6 +60,7 @@ detectors:
60
60
  - IronBank::Schema#self.import
61
61
  - IronBank::Local#where
62
62
  - IronBank::Local#load_records
63
+ - IronBank::LocalRecords#export
63
64
  - IronBank::Resources::ProductRatePlanChargeTier#self.load_records
64
65
 
65
66
  NilCheck:
@@ -43,18 +43,25 @@ module IronBank
43
43
  # this line, delete the other one, since `Hash#compact` is available in
44
44
  # 2.4.x and we can remove two smells from `.reek` while we are at it
45
45
  #
46
- # store[row['Id']] = new(row.to_h.compact)
47
- store[row['Id']] = new(row.to_h.reject { |_, value| value.nil? })
46
+ # store[row[:id]] = new(row.to_h.compact)
47
+ store[row[:id]] = new(row.to_h.reject { |_, value| value.nil? })
48
48
  end
49
49
  end
50
50
 
51
51
  def csv_options
52
52
  {
53
- headers: true,
54
- converters: csv_converters
53
+ headers: true,
54
+ header_converters: header_converters,
55
+ converters: csv_converters
55
56
  }
56
57
  end
57
58
 
59
+ def header_converters
60
+ %i[
61
+ symbol
62
+ ]
63
+ end
64
+
58
65
  def csv_converters
59
66
  %i[
60
67
  decimal_integer
@@ -24,7 +24,8 @@ module IronBank
24
24
 
25
25
  def export
26
26
  CSV.open(file_path, 'w') do |csv|
27
- csv << klass.fields # headers
27
+ # first row = CSV headers
28
+ csv << klass.fields.map { |field| IronBank::Utils.underscore(field) }
28
29
  write_records(csv)
29
30
  end
30
31
  end
@@ -28,8 +28,8 @@ module IronBank
28
28
 
29
29
  def with_schema
30
30
  fields.each do |field|
31
- method_name = IronBank::Utils.underscore(field)
32
- define_method(:"#{method_name}") { remote[field] }
31
+ field_name = IronBank::Utils.underscore(field).to_sym
32
+ define_method(:"#{field_name}") { remote[field_name] }
33
33
  end
34
34
  end
35
35
  end
@@ -8,9 +8,11 @@ module IronBank
8
8
  def find(id)
9
9
  raise IronBank::NotFound unless id
10
10
 
11
- new(
12
- IronBank.client.connection.get("v1/object/#{object_name}/#{id}").body
11
+ response = IronBank.client.connection.get(
12
+ "v1/object/#{object_name}/#{id}"
13
13
  )
14
+
15
+ new(IronBank::Object.new(response.body).deep_underscore)
14
16
  end
15
17
 
16
18
  # This methods leverages the fact that Zuora only returns 2,000 records at a
@@ -23,10 +25,10 @@ module IronBank
23
25
  query_result = client.query(query_string) # up to 2k records from Zuora
24
26
 
25
27
  loop do
26
- query_result['records'].each { |data| yield new(data) }
27
- break if query_result['done']
28
+ query_result[:records].each { |data| yield new(data) }
29
+ break if query_result[:done]
28
30
 
29
- query_result = client.query_more(query_result['queryLocator'])
31
+ query_result = client.query_more(query_result[:queryLocator])
30
32
  end
31
33
  end
32
34
 
@@ -44,7 +46,7 @@ module IronBank
44
46
  # FIXME: need to use logger instance instead
45
47
  # puts "query: #{query_string}"
46
48
 
47
- records = IronBank::Query.call(query_string)['records']
49
+ records = IronBank::Query.call(query_string)[:records]
48
50
  return [] unless records
49
51
 
50
52
  records.each.with_object([]) do |data, result|
@@ -31,7 +31,7 @@ module IronBank
31
31
  # Every Zuora object has an ID, so we can safely declare it for each
32
32
  # resource
33
33
  def id
34
- remote['Id']
34
+ remote[:id]
35
35
  end
36
36
 
37
37
  def inspect
@@ -56,7 +56,7 @@ module IronBank
56
56
 
57
57
  def to_csv_row
58
58
  self.class.fields.each.with_object([]) do |field, row|
59
- row << remote[field]
59
+ row << remote[IronBank::Utils.underscore(field).to_sym]
60
60
  end
61
61
  end
62
62
 
@@ -30,7 +30,7 @@ module IronBank
30
30
  # We can only retrieve one invoice body at a time, hence Body is excluded
31
31
  # from the query fields, but is populated using the `find` class method
32
32
  def body
33
- remote['Body'] || reload['Body']
33
+ remote[:body] || reload[:body]
34
34
  end
35
35
  end
36
36
  end
@@ -36,7 +36,7 @@ module IronBank
36
36
  # discount-fixed amount and regular pricing).
37
37
  def to_csv_row
38
38
  ProductRatePlanChargeTier.fields.each.with_object([]) do |field, row|
39
- row << remote[field]
39
+ row << remote[IronBank::Utils.underscore(field).to_sym]
40
40
  end
41
41
  end
42
42
 
@@ -44,15 +44,15 @@ module IronBank
44
44
  CSV.foreach(file_path, csv_options).with_object({}) do |row, store|
45
45
  remote = row.to_h.reject { |_, value| value.nil? }
46
46
 
47
- record = if remote['DiscountAmount']
47
+ record = if remote[:discount_amount]
48
48
  CatalogTiers::DiscountAmount.new(remote)
49
- elsif remote['DiscountPercentage']
49
+ elsif remote[:discount_percentage]
50
50
  CatalogTiers::DiscountPercentage.new(remote)
51
51
  else
52
52
  CatalogTiers::Price.new(remote)
53
53
  end
54
54
 
55
- store[row['Id']] = record
55
+ store[row[:id]] = record
56
56
  end
57
57
  end
58
58
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IronBank
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  API_VERSION = 'v1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Pham
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2018-12-08 00:00:00.000000000 Z
14
+ date: 2018-12-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bump
@@ -380,7 +380,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
380
  version: '0'
381
381
  requirements: []
382
382
  rubyforge_project:
383
- rubygems_version: 2.5.2.3
383
+ rubygems_version: 2.7.8
384
384
  signing_key:
385
385
  specification_version: 4
386
386
  summary: An opinionated Ruby interface to the Zuora API.