eco-helpers 0.6.13 → 0.6.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/eco-helpers.gemspec +1 -1
  3. data/lib/eco/api.rb +1 -2
  4. data/lib/eco/api/common/people/person_entry.rb +1 -1
  5. data/lib/eco/api/common/people/person_factory.rb +3 -3
  6. data/lib/eco/api/common/session/base_session.rb +14 -2
  7. data/lib/eco/api/common/session/environment.rb +9 -7
  8. data/lib/eco/api/common/version_patches/external_person.rb +16 -2
  9. data/lib/eco/api/common/version_patches/internal_person.rb +17 -0
  10. data/lib/eco/api/session.rb +13 -19
  11. data/lib/eco/api/session/batch.rb +4 -17
  12. data/lib/eco/api/session/batch_job.rb +4 -13
  13. data/lib/eco/api/session/{job_group.rb → batch_jobs.rb} +6 -8
  14. data/lib/eco/api/session/batch_status.rb +3 -7
  15. data/lib/eco/api/session/config.rb +186 -0
  16. data/lib/eco/api/session/config/api.rb +49 -0
  17. data/lib/eco/api/session/config/apis.rb +91 -0
  18. data/lib/eco/api/session/config/files.rb +32 -0
  19. data/lib/eco/api/session/config/logger.rb +56 -0
  20. data/lib/eco/api/session/config/mailer.rb +67 -0
  21. data/lib/eco/api/session/config/people.rb +95 -0
  22. data/lib/eco/api/session/config/s3_storage.rb +64 -0
  23. data/lib/eco/api/session/config/use_cases.rb +33 -0
  24. data/lib/eco/api/session/job_groups.rb +4 -6
  25. data/lib/eco/api/session/task.rb +2 -13
  26. data/lib/eco/version.rb +1 -1
  27. metadata +18 -11
  28. data/lib/eco/api/session_config.rb +0 -187
  29. data/lib/eco/api/session_config/api.rb +0 -47
  30. data/lib/eco/api/session_config/apis.rb +0 -89
  31. data/lib/eco/api/session_config/files.rb +0 -30
  32. data/lib/eco/api/session_config/logger.rb +0 -54
  33. data/lib/eco/api/session_config/mailer.rb +0 -65
  34. data/lib/eco/api/session_config/people.rb +0 -93
  35. data/lib/eco/api/session_config/s3_storage.rb +0 -62
  36. data/lib/eco/api/session_config/use_cases.rb +0 -31
@@ -0,0 +1,49 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class Api < Hash
6
+
7
+ def initialize(key:, host:, version:, mode: :local, root:)
8
+ super(nil)
9
+ @root = root
10
+ self["key"] = key
11
+ self["host"] = host
12
+ self["version"] = version
13
+ self["mode"] = mode
14
+ end
15
+
16
+ def key
17
+ self["key"]
18
+ end
19
+
20
+ def host
21
+ self["host"]
22
+ end
23
+
24
+ def mode=(mode)
25
+ self["mode"] = (mode == :remote)? :remote : :local
26
+ end
27
+
28
+ def mode
29
+ self["mode"]
30
+ end
31
+
32
+ def local?
33
+ mode == :local
34
+ end
35
+
36
+ def remote?
37
+ !local?
38
+ end
39
+
40
+ def version
41
+ self["version"]
42
+ end
43
+
44
+
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,91 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class Apis < Hash
6
+
7
+ def initialize(root:)
8
+ super(nil)
9
+ @root = root
10
+ end
11
+
12
+ def apis
13
+ self["apis"] ||= {}
14
+ end
15
+
16
+ def apis?
17
+ apis.keys.length > 0
18
+ end
19
+
20
+ def defined?(name)
21
+ apis.key?(name)
22
+ end
23
+
24
+ def any_defined?(*names)
25
+ [names].flatten.any? do |name|
26
+ self.defined?(name)
27
+ end
28
+ end
29
+
30
+ def add(name, key:, host:, version: :internal, mode: :local)
31
+ apis[name] = Session::Config::Api.new(
32
+ key: key,
33
+ host: host,
34
+ version: version,
35
+ mode: mode,
36
+ root: self
37
+ )
38
+ self
39
+ end
40
+
41
+ def active_name=(name)
42
+ raise "'#{name}' Api environment not defined" if !apis[name]
43
+ self["active-name"] = name
44
+ self["active-api"] = apis[name]
45
+ self
46
+ end
47
+
48
+ def active_name
49
+ self["active-name"]
50
+ end
51
+
52
+ # you can create multiple apis under same root_name (same org)
53
+ def active_root_name
54
+ active_name.split("-").first
55
+ end
56
+
57
+ def active_api
58
+ self["active-api"]
59
+ end
60
+
61
+ def service_up?
62
+ api_klass = (active_api.version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
63
+ @api_test ||= api_klass.new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL))
64
+ status = @api_test.client.get("/policy_groups").status
65
+ # 401 Unauthorized "Permission denied. API key may be invalid."
66
+ status == 401
67
+ end
68
+
69
+ def api(logger = ::Logger.new(IO::NULL), force_new: false)
70
+ key = active_api.key
71
+ host = active_api.host
72
+ mode = active_api.mode
73
+ version = active_api.version
74
+ return @api if (!force_new) && @api && key == @key && host == @host && @mode == mode && version == @version
75
+
76
+ api_klass = (version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
77
+
78
+ @api = api_klass.new(key, host: host, logger: logger)
79
+ @key = key; @host = host; @mode = mode; @version = version
80
+ @api
81
+ end
82
+
83
+ def new_api(logger = ::Logger.new(IO::NULL))
84
+ api(logger, force_new: true)
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,32 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class Files < Hash
6
+
7
+ def initialize(root:)
8
+ super(nil)
9
+ @root = root
10
+ end
11
+
12
+ def working_directory=(path)
13
+ self["dir"] = path
14
+ end
15
+
16
+ def working_directory
17
+ self["dir"]
18
+ end
19
+
20
+ def timestamp_pattern=(pattern)
21
+ self["timestamp_pattern"] = pattern
22
+ end
23
+
24
+ def timestamp_pattern
25
+ self["timestamp_pattern"]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class Logger < Hash
6
+
7
+ def initialize(root:)
8
+ super(nil)
9
+ @root = root
10
+ end
11
+
12
+ def console_level=(value)
13
+ self["console_level"] = value
14
+ end
15
+
16
+ def console_level
17
+ self["console_level"]
18
+ end
19
+
20
+ def file_level=(value)
21
+ self["file_level"] = value
22
+ end
23
+
24
+ def file_level
25
+ self["file_level"]
26
+ end
27
+
28
+ def file=(file)
29
+ self["file"] = file
30
+ end
31
+
32
+ def file
33
+ self["file"]
34
+ end
35
+
36
+ def timestamp_console=(value)
37
+ self["timestamp_console"] = value
38
+ end
39
+
40
+ def timestamp_console
41
+ self["timestamp_console"]
42
+ end
43
+
44
+ def log_connection=(value)
45
+ self["log_connection"] = value
46
+ end
47
+
48
+ def log_connection?
49
+ !!self["log_connection"]
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,67 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class Mailer < Hash
6
+
7
+ def initialize(root:)
8
+ super(nil)
9
+ @root = root
10
+ end
11
+
12
+ def from=(value)
13
+ self["from"] = value
14
+ end
15
+
16
+ def from
17
+ self["from"]
18
+ end
19
+
20
+ def access_key_id=(key)
21
+ self["access_key_id"] = key
22
+ end
23
+
24
+ def access_key_id
25
+ self["access_key_id"]
26
+ end
27
+
28
+ def secret_access_key=(key)
29
+ self["secret_access_key"] = key
30
+ end
31
+
32
+ def secret_access_key
33
+ self["secret_access_key"]
34
+ end
35
+
36
+ # AWS::SES::Client
37
+ def region=(region)
38
+ self["region"] = region
39
+ end
40
+
41
+ def region
42
+ self["region"]
43
+ end
44
+
45
+ # AWS::SES::Base
46
+ def server=(domain)
47
+ self["server"] = domain
48
+ end
49
+
50
+ def server
51
+ self["server"]
52
+ end
53
+
54
+ # AWS::SES::Base
55
+ def message_id_domain=(domain)
56
+ self["message_id_domain"] = domain
57
+ end
58
+
59
+ def message_id_domain
60
+ self["message_id_domain"]
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,95 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class People < Hash
6
+ attr_reader :config
7
+
8
+ def initialize(root:)
9
+ super(nil)
10
+ @root = root
11
+ @config = @root
12
+ end
13
+
14
+ def cache=(file)
15
+ self["cache"] = file
16
+ end
17
+
18
+ def cache
19
+ self["cache"]
20
+ end
21
+
22
+ # api queried logs
23
+ def requests_folder=(folder)
24
+ self["requests_folder"] = folder
25
+ end
26
+
27
+ def requests_folder
28
+ self["requests_folder"]
29
+ end
30
+
31
+ # people to exclude from update feeds
32
+ def discarded_file=(file)
33
+ self["discarded_file"] = file
34
+ end
35
+
36
+ def discarded_file
37
+ self["discarded_file"]
38
+ end
39
+
40
+ # internal-external fields map
41
+ def fields_mapper=(file)
42
+ self["fields_mapper"] = file
43
+ end
44
+
45
+ def fields_mapper
46
+ self["fields_mapper"]
47
+ end
48
+
49
+ # person model
50
+ def default_schema=(name)
51
+ self["default_schema"] = name
52
+ end
53
+
54
+ def default_schema
55
+ self["default_schema"]
56
+ end
57
+
58
+ def presets_custom=(file)
59
+ self["presets_custom"] = file
60
+ end
61
+
62
+ def presets_custom
63
+ self["presets_custom"]
64
+ end
65
+
66
+ def presets_map=(file)
67
+ self["presets_map"] = file
68
+ end
69
+
70
+ def presets_map
71
+ self["presets_map"]
72
+ end
73
+
74
+ # CUSTOM PERSON PARSERS
75
+ def add_parser(format: :csv)
76
+ new_parsers = Eco::API::Common::People::PersonParser.new
77
+ yield(new_parsers, config)
78
+
79
+ parsers[format] ||= Eco::API::Common::People::PersonParser.new
80
+ parsers[format] = parsers[format] ? parsers[format].merge(new_parsers) : new_parsers
81
+ end
82
+
83
+ def parsers
84
+ self["parsers"] ||= {}
85
+ end
86
+
87
+ def parser(format: :csv)
88
+ parsers[format]
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,64 @@
1
+ module Eco
2
+ module API
3
+ class Session
4
+ class Config
5
+ class S3Storage < Hash
6
+
7
+ def initialize(root:)
8
+ super(nil)
9
+ @root = root
10
+ end
11
+
12
+ def bucket_name=(value)
13
+ self["bucket_name"] = value
14
+ end
15
+
16
+ def bucket_name
17
+ self["bucket_name"]
18
+ end
19
+
20
+ def prefix=(value)
21
+ self["prefix"] = value
22
+ end
23
+
24
+ def prefix
25
+ self["prefix"]
26
+ end
27
+
28
+ def access_key_id=(key)
29
+ self["access_key_id"] = key
30
+ end
31
+
32
+ def access_key_id
33
+ self["access_key_id"]
34
+ end
35
+
36
+ def secret_access_key=(key)
37
+ self["secret_access_key"] = key
38
+ end
39
+
40
+ def secret_access_key
41
+ self["secret_access_key"]
42
+ end
43
+
44
+ def region=(region)
45
+ self["region"] = region
46
+ end
47
+
48
+ def region
49
+ self["region"]
50
+ end
51
+
52
+ def target_directories=(value)
53
+ self["target_directories"] = [value].flatten
54
+ end
55
+
56
+ def target_directories
57
+ self["target_directories"]
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end