iron_bank 4.2.0 → 4.3.0

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
  SHA256:
3
- metadata.gz: c43b87965a20a054d039009a4da852974532dc4b079b8ceb20d6ec9849a00eb3
4
- data.tar.gz: a23c602da14f5bcfcf1ed9cc9dcece5a21dc083c7d941c63e444870c3384dfb4
3
+ metadata.gz: 00c270266ed85615c32706b617a644cfac0d954a3fc19117733d0a4d1a4a4687
4
+ data.tar.gz: aad4d425eabc0f6ecdcdec124d00913f471edd2ff431b3c18b8fbfce2ff9ee37
5
5
  SHA512:
6
- metadata.gz: e026432778a617ffebe80df42f2fde537a85be17682d34c8f451b8e3548d0d149c74d35c386d7bc038da6bbde18515688e662d582e82ff9a1249853e3a7136d4
7
- data.tar.gz: 8b7ec698f0e0ecf5a19db78d246980ce117abdaae68dbc67bf5572fd98d366fe48160be8ae35ad17e9db609cbe1798f58828104e4dfae4a7fda0e677abd87637
6
+ metadata.gz: 8c74322d9de788d46d9137e8d32435163d1543c5a2d71d7b90ce9b2328df22b4ccd452af557e0692b5af1c15537f00e4045a21b916d0cd76a6dbcf2d98249d8f
7
+ data.tar.gz: 80640919d22b8114f60edff018fb234757ecf4f971166d7beb3a077c1d17a610861994d6b1f4f7abf31ab268e1f4f77be47abf8387420132d5ea4cbae2e75bd0
data/.env.example CHANGED
@@ -4,3 +4,4 @@ ZUORA_AUTH_TYPE=token
4
4
  ZUORA_DOMAIN=rest.apisandbox.zuora.com
5
5
  ZUORA_TENANT_ID=00000
6
6
  ZUORA_EXCLUDED_FIELDS_FILE=excluded_fields.yml
7
+ ZUORA_USERS_FILE=users.csv
data/.gitignore CHANGED
@@ -18,3 +18,6 @@
18
18
 
19
19
  # do not version specific excluded fields
20
20
  excluded_fields.yml
21
+
22
+ # do not version exported users
23
+ users.csv
data/.reek.yml CHANGED
@@ -18,6 +18,7 @@ detectors:
18
18
  - IronBank::Configuration#logger
19
19
  - IronBank::Configuration#middlewares
20
20
  - IronBank::Configuration#schema_directory
21
+ - IronBank::Configuration#users_file
21
22
 
22
23
  BooleanParameter:
23
24
  exclude:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_bank (4.2.0)
4
+ iron_bank (4.3.0)
5
5
  faraday (~> 0)
6
6
  faraday_middleware (~> 0)
7
7
  nokogiri (~> 1)
data/bin/console CHANGED
@@ -12,6 +12,7 @@ IronBank.configure do |config|
12
12
  config.auth_type = ENV.fetch("ZUORA_AUTH_TYPE", "token")
13
13
  config.domain = ENV["ZUORA_DOMAIN"]
14
14
  config.excluded_fields_file = ENV["ZUORA_EXCLUDED_FIELDS_FILE"]
15
+ config.users_file = ENV["ZUORA_USERS_FILE"]
15
16
  end
16
17
 
17
18
  Pry.start
@@ -34,6 +34,9 @@ module IronBank
34
34
  # Directory where the local records are exported.
35
35
  attr_reader :export_directory
36
36
 
37
+ # File path for Zuora users export
38
+ attr_accessor :users_file
39
+
37
40
  def initialize
38
41
  @schema_directory = "./config/schema"
39
42
  @export_directory = "./config/export"
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IronBank
4
+ # A Zuora user, only available if the user data has been exported and provided
5
+ # to IronBank through the `users_file` configuration option.
6
+ #
7
+ # Cf. https://knowledgecenter.zuora.com/CF_Users_and_Administrators/A_Administrator_Settings/Manage_Users#Export_User_Data_to_a_CSV_File
8
+ #
9
+ class User
10
+ extend IronBank::Local
11
+ extend SingleForwardable
12
+
13
+ def_delegators "IronBank.configuration", :users_file
14
+
15
+ class << self
16
+ def store
17
+ return {} unless users_file
18
+
19
+ @store ||= begin
20
+ if File.exist?(users_file)
21
+ load_records
22
+ else
23
+ IronBank.logger.warn "File does not exist: #{users_file}"
24
+ {}
25
+ end
26
+ end
27
+ end
28
+
29
+ def load_records
30
+ CSV.foreach(users_file, headers: true).with_object({}) do |row, store|
31
+ store[row["User ID"]] = new(row.to_h.compact)
32
+ end
33
+ end
34
+
35
+ def all
36
+ store.values
37
+ end
38
+
39
+ def find(user_id)
40
+ store[user_id] || raise(IronBank::NotFoundError, "user id: #{user_id}")
41
+ end
42
+ end
43
+
44
+ US_DATE_FORMAT = "%m/%d/%Y"
45
+
46
+ FIELDS = [
47
+ "User ID",
48
+ "User Name",
49
+ "First Name",
50
+ "Last Name",
51
+ "Status",
52
+ "Work Email",
53
+ "Created On",
54
+ "Zuora Billing Role",
55
+ "Zuora Payment Role",
56
+ "Zuora Commerce Role",
57
+ "Zuora Platform Role",
58
+ "Zuora Finance Role",
59
+ "Zuora Reporting Role",
60
+ "Zuora Insights Role",
61
+ "Last Login"
62
+ ].freeze
63
+
64
+ FIELDS.each do |field|
65
+ method_name = IronBank::Utils.underscore(field.tr(" ", ""))
66
+
67
+ define_method(method_name) do
68
+ attributes[field]
69
+ end
70
+ end
71
+
72
+ attr_reader :attributes
73
+
74
+ alias id user_id
75
+
76
+ def initialize(attributes)
77
+ @attributes = attributes
78
+ end
79
+
80
+ def inspect
81
+ ruby_id = "#{self.class.name}:0x#{(object_id << 1).to_s(16)} id=\"#{id}\""
82
+
83
+ "#<#{ruby_id} user_name=\"#{user_name}\">"
84
+ end
85
+
86
+ def last_login
87
+ @last_login ||= Date.strptime(attributes["Last Login"], US_DATE_FORMAT)
88
+ end
89
+
90
+ def created_on
91
+ @created_on ||= Date.strptime(attributes["Created On"], US_DATE_FORMAT)
92
+ end
93
+ end
94
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IronBank
4
- VERSION = "4.2.0"
4
+ VERSION = "4.3.0"
5
5
  API_VERSION = "v1"
6
6
  end
data/lib/iron_bank.rb CHANGED
@@ -88,6 +88,7 @@ require "iron_bank/object"
88
88
  require "iron_bank/schema"
89
89
  require "iron_bank/query_builder"
90
90
  require "iron_bank/payment_run"
91
+ require "iron_bank/user"
91
92
 
92
93
  # Operations
93
94
  require "iron_bank/operation"
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: 4.2.0
4
+ version: 4.3.0
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: 2019-09-19 00:00:00.000000000 Z
14
+ date: 2019-09-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bump
@@ -330,6 +330,7 @@ files:
330
330
  - lib/iron_bank/resources/taxation_item.rb
331
331
  - lib/iron_bank/resources/usage.rb
332
332
  - lib/iron_bank/schema.rb
333
+ - lib/iron_bank/user.rb
333
334
  - lib/iron_bank/utils.rb
334
335
  - lib/iron_bank/version.rb
335
336
  homepage: https://github.com/zendesk/iron_bank