embulk-input-stripe 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0aff836b6c0954949a87020f23110c9d3eeceb2f
4
- data.tar.gz: c7526f57d26570220fed99a33e4ab9003600a7af
3
+ metadata.gz: 9dec6b8863fd51c494e86648eee325183181cbfe
4
+ data.tar.gz: 04053c6698600553235ceaed3fba204da86e455d
5
5
  SHA512:
6
- metadata.gz: 1f4333f9ee53eb65c4ef0137711ae4e251da9f1d03846a729dfdd28e2a7a995517da8f5a76fd8dfbf11d830fc8a0708a358d6cd6c912bee0f13669cc82bc5250
7
- data.tar.gz: 1326ef0c452bd0a2df0af8531612a3bb6ce353e412c5f5e5f2cd30573e95e18dcfe6011516aaf3fb97c40e0660a3818cd3026019fd77393be9c9f942a3daaceb
6
+ metadata.gz: c5e78a9a6dacc71c2906dfd75cbc6705637fd357bf8dca8787796959ff04c68fe4209f9bb96e03bf12dad9075884e3a609a69b2425ad6ec37cd9b021fb05bff8
7
+ data.tar.gz: 1a06f0b0ae36bc069cc635924a59f4c45b377487e691d9a7d3e13b2c1ebb189c15551191f0ec843f662fc0497135fb67a92ab6ec3398fb7a69a1cecd5898b669
@@ -4,6 +4,7 @@ require 'stripe'
4
4
  require_relative 'stripe/customers'
5
5
  require_relative 'stripe/invoices'
6
6
  require_relative 'stripe/subscriptions'
7
+ require_relative 'stripe/charges'
7
8
 
8
9
  module Embulk
9
10
  module Input
@@ -22,7 +23,7 @@ module Embulk
22
23
  columns = fields.map.with_index do |field, index|
23
24
  field_name = field['name']
24
25
  field_type = field['type'].to_sym
25
- Column.new(index, field_name.gsub('.', '_'), field_type)
26
+ Column.new(index, field_name.gsub(/[\.\[\]]+/, '_'), field_type)
26
27
  end
27
28
 
28
29
  resume(task, columns, 1, &control)
@@ -47,6 +48,8 @@ module Embulk
47
48
  @invoices = Invoices.new(fields)
48
49
  when 'subscriptions'
49
50
  @subscriptions = Subscriptions.new(fields)
51
+ when 'charges'
52
+ @charges = Charges.new(fields)
50
53
  else
51
54
  raise StandardError, "Resource type #{resource_type} is not supported."
52
55
  end
@@ -60,6 +63,8 @@ module Embulk
60
63
  @invoices
61
64
  when 'subscriptions'
62
65
  @subscriptions
66
+ when 'charges'
67
+ @charges
63
68
  end
64
69
 
65
70
  target_items.get.each do |item|
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stripe'
4
+ require_relative './stripe_items'
5
+
6
+ class Charges < StripeItems
7
+ def items
8
+ Stripe::Charge.list(limit: 100)
9
+ end
10
+ end
@@ -3,6 +3,9 @@
3
3
  require 'embulk/column'
4
4
 
5
5
  class StripeItems
6
+ BEFORE_BRACKET_REGEX = Regexp.compile(/^([^\[]+)/)
7
+ INDEX_REGEX = Regexp.compile(/\[([0-9]+)\]/)
8
+
6
9
  def initialize(fields)
7
10
  @fields = fields
8
11
  end
@@ -27,7 +30,19 @@ class StripeItems
27
30
  # Drill down into sub items (assumes fields are delimited with '.').
28
31
  sub_fields = field['name'].split('.')
29
32
  sub_fields.reduce(sub) do |memo, sub_field|
30
- memo[sub_field]
33
+ name_match = BEFORE_BRACKET_REGEX.match(sub_field)
34
+ before_bracket = name_match[1]
35
+
36
+ child = memo[before_bracket]
37
+
38
+ index_match = INDEX_REGEX.match(sub_field)
39
+
40
+ if index_match
41
+ index = index_match[1]
42
+ child[index.to_i]
43
+ else
44
+ child
45
+ end
31
46
  end
32
47
  end
33
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Shimamoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - lib/embulk/input/stripe.rb
49
+ - lib/embulk/input/stripe/charges.rb
49
50
  - lib/embulk/input/stripe/customers.rb
50
51
  - lib/embulk/input/stripe/invoices.rb
51
52
  - lib/embulk/input/stripe/stripe_items.rb