eco-helpers 1.5.1 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api.rb +2 -0
- data/lib/eco/api/common.rb +4 -0
- data/lib/eco/api/common/base_loader.rb +54 -0
- data/lib/eco/api/common/class_auto_loader.rb +109 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/class_hierarchy.rb +1 -1
- data/lib/eco/api/common/class_meta_basics.rb +16 -0
- data/lib/eco/api/common/loaders.rb +13 -0
- data/lib/eco/api/common/loaders/error_handler.rb +41 -0
- data/lib/eco/api/common/loaders/parser.rb +127 -0
- data/lib/eco/api/common/loaders/policy.rb +25 -0
- data/lib/eco/api/common/loaders/use_case.rb +40 -0
- data/lib/eco/api/common/people/default_parsers.rb +3 -12
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +15 -25
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +24 -35
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +10 -8
- data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
- data/lib/eco/api/common/people/person_entry.rb +308 -216
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +3 -2
- data/lib/eco/api/common/people/person_parser.rb +51 -18
- data/lib/eco/api/common/session/logger.rb +4 -0
- data/lib/eco/api/common/version_patches.rb +1 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +1 -1
- data/lib/eco/api/common/version_patches/exception.rb +22 -0
- data/lib/eco/api/common/version_patches/object.rb +10 -0
- data/lib/eco/api/custom.rb +13 -0
- data/lib/eco/api/custom/error_handler.rb +20 -0
- data/lib/eco/api/custom/namespace.rb +7 -0
- data/lib/eco/api/custom/parser.rb +50 -0
- data/lib/eco/api/custom/policy.rb +28 -0
- data/lib/eco/api/custom/use_case.rb +16 -0
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/error/handlers.rb +10 -3
- data/lib/eco/api/microcases.rb +17 -13
- data/lib/eco/api/microcases/account_excluded.rb +24 -0
- data/lib/eco/api/microcases/append_usergroups.rb +19 -0
- data/lib/eco/api/microcases/core_excluded.rb +4 -4
- data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
- data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
- data/lib/eco/api/microcases/people_cache.rb +17 -0
- data/lib/eco/api/microcases/people_load.rb +59 -0
- data/lib/eco/api/microcases/people_refresh.rb +31 -0
- data/lib/eco/api/microcases/people_search.rb +65 -0
- data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
- data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
- data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
- data/lib/eco/api/microcases/set_account.rb +7 -19
- data/lib/eco/api/microcases/set_core.rb +5 -5
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +17 -13
- data/lib/eco/api/microcases/strict_search.rb +12 -7
- data/lib/eco/api/microcases/with_each.rb +27 -0
- data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
- data/lib/eco/api/microcases/with_each_present.rb +30 -0
- data/lib/eco/api/microcases/with_each_starter.rb +30 -0
- data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
- data/lib/eco/api/microcases/with_supervisor.rb +36 -0
- data/lib/eco/api/organization/people.rb +72 -35
- data/lib/eco/api/organization/presets_factory.rb +13 -4
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +54 -24
- data/lib/eco/api/session/batch.rb +1 -1
- data/lib/eco/api/session/batch/base_policy.rb +7 -6
- data/lib/eco/api/session/batch/errors.rb +28 -4
- data/lib/eco/api/session/batch/feedback.rb +7 -1
- data/lib/eco/api/session/batch/job.rb +40 -23
- data/lib/eco/api/session/batch/jobs.rb +9 -4
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
- data/lib/eco/api/session/batch/request_stats.rb +95 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +104 -42
- data/lib/eco/api/session/config/api.rb +17 -6
- data/lib/eco/api/session/config/logger.rb +2 -2
- data/lib/eco/api/session/config/post_launch.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +8 -7
- data/lib/eco/api/usecases.rb +47 -33
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
- data/lib/eco/api/usecases/backup/create_case.rb +104 -0
- data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
- data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
- data/lib/eco/api/usecases/backup/update_case.rb +112 -0
- data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
- data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
- data/lib/eco/api/usecases/base_case.rb +2 -0
- data/lib/eco/api/usecases/base_io.rb +3 -3
- data/lib/eco/api/usecases/default_cases.rb +23 -53
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
- data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
- data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +101 -0
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +104 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
- data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
- data/lib/eco/api/usecases/use_case.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +9 -10
- data/lib/eco/cli/config.rb +10 -2
- data/lib/eco/cli/config/default.rb +2 -1
- data/lib/eco/cli/config/default/input_filters.rb +58 -0
- data/lib/eco/cli/config/default/options.rb +60 -25
- data/lib/eco/cli/config/default/people.rb +4 -4
- data/lib/eco/cli/config/default/people_filters.rb +108 -0
- data/lib/eco/cli/config/default/usecases.rb +89 -31
- data/lib/eco/cli/config/default/workflow.rb +37 -27
- data/lib/eco/cli/config/filters.rb +50 -0
- data/lib/eco/cli/config/filters/input_filters.rb +29 -0
- data/lib/eco/cli/config/filters/people_filters.rb +29 -0
- data/lib/eco/cli/config/help.rb +49 -0
- data/lib/eco/cli/config/options_set.rb +17 -1
- data/lib/eco/cli/config/use_cases.rb +79 -53
- data/lib/eco/cli/scripting.rb +10 -2
- data/lib/eco/cli/scripting/args_helpers.rb +25 -15
- data/lib/eco/cli/scripting/argument.rb +1 -0
- data/lib/eco/cli/scripting/arguments.rb +1 -1
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/language/match.rb +19 -9
- data/lib/eco/language/match_modifier.rb +13 -5
- data/lib/eco/language/models/collection.rb +77 -56
- data/lib/eco/language/models/parser_serializer.rb +39 -15
- data/lib/eco/version.rb +1 -1
- metadata +64 -18
- data/lib/eco/api/microcases/set_default_tag.rb +0 -23
- data/lib/eco/api/session/task.rb +0 -175
- data/lib/eco/api/usecases/default_case.rb +0 -19
- data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -99
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
- data/lib/eco/api/usecases/microed_cases/hris_case.rb +0 -53
- data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
- data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
- data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -0,0 +1,41 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Loaders
|
5
|
+
class ErrorHandler < Eco::API::Common::BaseLoader
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :error
|
9
|
+
|
10
|
+
# @return [Eco::API::Error] the error class, child of `Eco::API::Error`.
|
11
|
+
def error(value = nil)
|
12
|
+
unless value
|
13
|
+
return @error || raise("You should specify an error type for #{self.class}")
|
14
|
+
end
|
15
|
+
@error = value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(handlers)
|
20
|
+
raise "Expected Eco::API::Policies. Given #{handlers.class}" unless handlers.is_a?(Eco::API::Error::Handlers)
|
21
|
+
handlers.on(self.error, &self.method(:main))
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param people [Eco::API::Organization::People] the people in the queue of the current `job`
|
25
|
+
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
26
|
+
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
27
|
+
# @param handler [Eco::API::Error::Hanlder] the `error handler` instance object.
|
28
|
+
# @param job [Eco::API::Session::Batch::Job] the `Batch::Job` made on purpose for this handler.
|
29
|
+
def main(people, session, options, handler, job)
|
30
|
+
raise "You should implement this method"
|
31
|
+
end
|
32
|
+
|
33
|
+
def error
|
34
|
+
self.class.error
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Loaders
|
5
|
+
class Parser < Eco::API::Common::BaseLoader
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_reader :active_when
|
9
|
+
|
10
|
+
# @param value [String, Symbol] the attribute or type to be parsed/serialized
|
11
|
+
# 1. when `String`: the internal name of the field/attribute this parser/serializer manages for.
|
12
|
+
# 2. when `Symbol`: the type of data this parser converts between `String` and the specific type.
|
13
|
+
# @return [String] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
|
14
|
+
def attribute(value = nil)
|
15
|
+
unless value
|
16
|
+
return @attribute || raise("You should specify the 'attribute' this parser/serializer, #{self.class}, is linked to")
|
17
|
+
end
|
18
|
+
name value
|
19
|
+
@attribute = value
|
20
|
+
end
|
21
|
+
|
22
|
+
# Some parsers require dependencies to do their job.
|
23
|
+
def dependencies(value = nil)
|
24
|
+
@dependencies ||= {}
|
25
|
+
return @dependencies unless value
|
26
|
+
@dependencies = value
|
27
|
+
end
|
28
|
+
|
29
|
+
# Define or get the `phase` that the `parser` kicks in.
|
30
|
+
# @param phase [Symbol] the phase when this parser should be active.
|
31
|
+
# Must be one of [`:internal`, `:final`]
|
32
|
+
def parsing_phase(phase = nil)
|
33
|
+
@parsing_phase ||= :internal
|
34
|
+
return @parsing_phase unless phase
|
35
|
+
@parsing_phase = phase
|
36
|
+
end
|
37
|
+
|
38
|
+
# Define or get the `phase` that the `serializer` kicks in.
|
39
|
+
# @param phase [Symbol] the phase when this serializer should be active.
|
40
|
+
# Must be one of [`:person,` `:final`, `:internal`]
|
41
|
+
def serializing_phase(phase = nil)
|
42
|
+
@serializing_phase ||= :person
|
43
|
+
return @serializing_phase unless phase
|
44
|
+
@serializing_phase = phase
|
45
|
+
end
|
46
|
+
|
47
|
+
# Helper to build the `active_when` condition.
|
48
|
+
def active_when_any(*attrs)
|
49
|
+
@active_when = Proc.new do |source_data|
|
50
|
+
keys = data_keys(source_data)
|
51
|
+
attrs.any? {|key| keys.include?(key)}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Helper to build the `active_when` condition.
|
56
|
+
def active_when_all(*attrs)
|
57
|
+
@active_when = Proc.new do |source_data|
|
58
|
+
keys = data_keys(source_data)
|
59
|
+
attrs.all? {|key| keys.include?(key)}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Helper to obtain the current internal named attributes of the data
|
64
|
+
# @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
|
65
|
+
# @return [Array<String>] `keys` of `source_data`
|
66
|
+
def data_keys(source_data)
|
67
|
+
case source_data
|
68
|
+
when Array
|
69
|
+
keys = source_data
|
70
|
+
when Hash
|
71
|
+
keys = source_data.keys
|
72
|
+
else
|
73
|
+
keys = []
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize(person_parser)
|
80
|
+
raise "Expected Eco::API::Common::People::PersonParser. Given #{policies.class}" unless person_parser.is_a?(Eco::API::Common::People::PersonParser)
|
81
|
+
person_parser.define_attribute(self.attribute, dependencies: self.class.dependencies) do |attr_parser|
|
82
|
+
_define_parser(attr_parser)
|
83
|
+
_define_serializer(attr_parser)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @param data [Hash] all the person data at the specified `parsing_phase`:
|
88
|
+
# - when `:internal`: the parser will receive external types (i.e. String with '|' delimiters instead of an Array).
|
89
|
+
# - when `:final`: the parser will receive the typed values (i.e. Array instread of String with '|' delimiters).
|
90
|
+
# @param deps [Hash] the merged dependencies (default to the class object and when calling the parser).
|
91
|
+
def parser(data, deps)
|
92
|
+
raise "You should implement this method"
|
93
|
+
end
|
94
|
+
|
95
|
+
# @param data [Hash, Ecoportal::API::V1::Person] all the person data at the specified `serializing_phase`:
|
96
|
+
# - when `:internal`: it will receive a `Hash` with the **internal values** but the types already serialized to `String`.
|
97
|
+
# - when `:final`: it will receive a `Hash` with the **internal values** and **types**.
|
98
|
+
# - when `:person`: it will receive the `person` object.
|
99
|
+
# @param deps [Hash] the merged dependencies (default to the class object and when calling the parser).
|
100
|
+
def seralizer(data, deps)
|
101
|
+
raise "You should implement this method"
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [String, Symbol] the field/attribute or type this parser is linked to.
|
105
|
+
def attribute
|
106
|
+
self.class.attribute
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def _define_parser(attr_parser)
|
112
|
+
if active_when = self.class.active_when
|
113
|
+
attr_parser.def_parser(self.class.parsing_phase, active_when: active_when, &self.method(:parser))
|
114
|
+
else
|
115
|
+
attr_parser.def_parser(self.class.parsing_phase, &self.method(:parser))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def _define_serializer(attr_parser)
|
120
|
+
attr_parser.def_serializer(self.class.serializing_phase, &self.method(:serializer))
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Loaders
|
5
|
+
class Policy < Eco::API::Common::BaseLoader
|
6
|
+
|
7
|
+
def initialize(policies)
|
8
|
+
raise "Expected Eco::API::Policies. Given #{policies.class}" unless policies.is_a?(Eco::API::Policies)
|
9
|
+
policies.define(self.name, &self.method(:main))
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param people [Eco::API::Organization::People] the people in the queue of the current `job`
|
13
|
+
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
14
|
+
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
15
|
+
# @param policy [Eco::API::Policies::Policy] the `policy` instance object.
|
16
|
+
# @param job [Eco::API::Session::Batch::Job] the `Batch::Job` that these `people` belong to the queue thereof.
|
17
|
+
def main(people, session, options, policy, job)
|
18
|
+
raise "You should implement this method"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Loaders
|
5
|
+
class UseCase < Eco::API::Common::BaseLoader
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# @return [Symbol] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
|
9
|
+
def type(value = nil)
|
10
|
+
unless value
|
11
|
+
return @type || raise("You should specify a type of case [:sync, :transform, :import, :other] for #{self.class}")
|
12
|
+
end
|
13
|
+
@type = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(usecases)
|
18
|
+
raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases)
|
19
|
+
usecases.define(self.name, type: self.type, &self.method(:main))
|
20
|
+
end
|
21
|
+
|
22
|
+
# The parameters of this method will depend on the `type` of usecase.
|
23
|
+
# @param entries [Eco::API::Common::People::Entries] the input entries with the data.
|
24
|
+
# @param people [Eco::API::Organization::People] the people in the queue of the current `job`
|
25
|
+
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
26
|
+
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
27
|
+
# @param usecase [Eco::API::Policies::Policy] the `usecase` instance object.
|
28
|
+
def main(entries, people, session, options, usecase)
|
29
|
+
raise "You should implement this method"
|
30
|
+
end
|
31
|
+
|
32
|
+
def type
|
33
|
+
self.class.type
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -5,6 +5,8 @@ module Eco
|
|
5
5
|
|
6
6
|
# Class to define a set of default attribute parsers
|
7
7
|
class DefaultParsers < PersonParser
|
8
|
+
autoloads_children_of "Eco::API::Common::Loaders::Parser"
|
9
|
+
autoload_namespace "Eco::API::Common::People::DefaultParsers"
|
8
10
|
|
9
11
|
def initialize(*args)
|
10
12
|
super(*args)
|
@@ -24,18 +26,6 @@ module Eco
|
|
24
26
|
end.compact.to_h
|
25
27
|
|
26
28
|
SelectParser.new(self, select_hashes: select_hashes).process
|
27
|
-
BooleanParser.new(self).process
|
28
|
-
NumericParser.new(self).process
|
29
|
-
DateParser.new(self).process
|
30
|
-
MultiParser.new(self).process
|
31
|
-
|
32
|
-
# ALWAYS PRESENT FIELDS
|
33
|
-
SendInvitesParser.new(self).process
|
34
|
-
FreemiumParser.new(self).process
|
35
|
-
PolicyGroupsParser.new(self).process
|
36
|
-
|
37
|
-
# FORMAT PARSER
|
38
|
-
CSVParser.new(self).process
|
39
29
|
end
|
40
30
|
|
41
31
|
end
|
@@ -52,4 +42,5 @@ require_relative 'default_parsers/multi_parser'
|
|
52
42
|
require_relative 'default_parsers/send_invites_parser'
|
53
43
|
require_relative 'default_parsers/freemium_parser'
|
54
44
|
require_relative 'default_parsers/policy_groups_parser'
|
45
|
+
require_relative 'default_parsers/login_providers_parser'
|
55
46
|
require_relative 'default_parsers/csv_parser'
|
@@ -1,28 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Common
|
4
|
-
module People
|
5
|
-
class DefaultParsers
|
6
|
-
class BooleanParser < People::BaseParser
|
1
|
+
class Eco::API::Common::People::DefaultParsers::BooleanParser < Eco::API::Common::Loaders::Parser
|
2
|
+
attribute :boolean
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
4
|
+
def parser(value, deps)
|
5
|
+
value.is_a?(Array) ? value.map { |v| truthy(v) } : truthy(value)
|
6
|
+
end
|
7
|
+
|
8
|
+
def serializer(value, deps)
|
9
|
+
value.to_s
|
10
|
+
end
|
17
11
|
|
18
|
-
|
12
|
+
private
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
14
|
+
def truthy (value)
|
15
|
+
%w[true y yes x].include?(value.to_s.strip.downcase)
|
27
16
|
end
|
17
|
+
|
28
18
|
end
|
@@ -1,41 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Common
|
4
|
-
module People
|
5
|
-
class DefaultParsers
|
6
|
-
class CSVParser < People::BaseParser
|
1
|
+
class Eco::API::Common::People::DefaultParsers::CSVParser < Eco::API::Common::Loaders::Parser
|
2
|
+
attribute :csv
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
hash[attr] = value.to_s.empty?? nil : value
|
19
|
-
end
|
20
|
-
arr_hash.push(row_hash)
|
21
|
-
end
|
22
|
-
arr_hash
|
23
|
-
end.def_serializer do |array_hash, deps|
|
24
|
-
arr_rows = []
|
25
|
-
unless array_hash.empty?
|
26
|
-
header = array_hash.first.keys
|
27
|
-
arr_rows = array_hash.map do |csv_row|
|
28
|
-
CSV::Row.new(header, csv_row.values_at(*header))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
CSV::Table.new(arr_rows).to_csv
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
4
|
+
def parser(data, deps)
|
5
|
+
Eco::CSV.parse(data, headers: true, skip_blanks: true).each_with_object([]) do |row, arr_hash|
|
6
|
+
row_hash = row.headers.uniq.each_with_object({}) do |attr, hash|
|
7
|
+
next if attr.to_s.strip.empty?
|
8
|
+
value = row[attr]
|
9
|
+
hash[attr.strip] = value.to_s.empty?? nil : value
|
10
|
+
end
|
11
|
+
arr_hash.push(row_hash)
|
12
|
+
end
|
13
|
+
end
|
35
14
|
|
36
|
-
|
37
|
-
|
15
|
+
def serializer(array_hash, deps)
|
16
|
+
arr_rows = []
|
17
|
+
unless array_hash.empty?
|
18
|
+
header = array_hash.first.keys
|
19
|
+
arr_rows = array_hash.map do |csv_row|
|
20
|
+
CSV::Row.new(header, csv_row.values_at(*header))
|
38
21
|
end
|
39
22
|
end
|
23
|
+
CSV::Table.new(arr_rows).to_csv
|
40
24
|
end
|
25
|
+
|
41
26
|
end
|
@@ -1,33 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Common
|
4
|
-
module People
|
5
|
-
class DefaultParsers
|
6
|
-
class DateParser < People::BaseParser
|
1
|
+
class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::Loaders::Parser
|
2
|
+
attribute :date
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
|
12
|
-
end.def_serializer do |value|
|
13
|
-
value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
4
|
+
def parser(value, deps)
|
5
|
+
value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
|
6
|
+
end
|
17
7
|
|
18
|
-
|
8
|
+
def serializer(value, deps)
|
9
|
+
value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
|
10
|
+
end
|
19
11
|
|
20
|
-
|
21
|
-
begin
|
22
|
-
(value.to_s.empty?) ? nil : Date.parse(value)
|
23
|
-
rescue
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
12
|
+
private
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
14
|
+
def parse_date(value)
|
15
|
+
begin
|
16
|
+
(value.to_s.empty?) ? nil : Date.parse(value)
|
17
|
+
rescue
|
18
|
+
nil
|
31
19
|
end
|
32
20
|
end
|
21
|
+
|
33
22
|
end
|
@@ -1,30 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Common
|
4
|
-
module People
|
5
|
-
class DefaultParsers
|
6
|
-
class FreemiumParser < People::BaseParser
|
1
|
+
class Eco::API::Common::People::DefaultParsers::FreemiumParser < Eco::API::Common::Loaders::Parser
|
2
|
+
attribute "freemium"
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
4
|
+
def parser(hash, deps)
|
5
|
+
value = hash["freemium"]
|
6
|
+
value = value.first if value.is_a?(Array)
|
7
|
+
truthy(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def serializer(person, deps)
|
11
|
+
person.freemium&.to_s
|
12
|
+
end
|
19
13
|
|
20
|
-
|
14
|
+
private
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
16
|
+
def truthy (value)
|
17
|
+
%w[true y yes x].include?(value.to_s&.downcase)
|
29
18
|
end
|
19
|
+
|
30
20
|
end
|