evva 0.12.1 → 0.13.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 +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rubocop_todo.yml +8 -8
- data/Gemfile.lock +2 -2
- data/README.md +9 -5
- data/changelog.md +5 -0
- data/lib/evva/config.rb +4 -2
- data/lib/evva/csv_source.rb +155 -0
- data/lib/evva/google_sheet.rb +3 -141
- data/lib/evva/version.rb +2 -2
- data/lib/evva.rb +3 -3
- data/spec/evva_spec.rb +4 -4
- data/spec/fixtures/test.yml +1 -1
- data/spec/lib/evva/config_spec.rb +7 -2
- data/spec/lib/evva/{google_sheet_spec.rb → csv_source_spec.rb} +65 -3
- data/spec/platform_filter_spec.rb +1 -1
- metadata +5 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11a3e62f36773bd96ad485577a172c40d85649b43d632963de7b187128b8254c
|
|
4
|
+
data.tar.gz: 7e632bd6eb6255aa380e31059c2ae58d5e74a3eeb1a92d86e854fe5d3730855b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc83e148bae17eb161a64eeaba2a3ddad170646b9ea3d1cfeba4a040ad43eec48aae7742f92cc57c988b129076f127901994bc685e538dcb254f1af1f49ac915
|
|
7
|
+
data.tar.gz: d055fb0cfbbd46cebd1ec6db45781a8c5cb2b81bb74d01e677aa9d2155da850d184b25daef2602aa2310326cfcd22e75021d268d6280c1118ca964a279871ac3
|
data/.github/workflows/test.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -43,7 +43,7 @@ Layout/DotPosition:
|
|
|
43
43
|
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
|
|
44
44
|
Layout/ExtraSpacing:
|
|
45
45
|
Exclude:
|
|
46
|
-
- 'spec/lib/evva/
|
|
46
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
47
47
|
|
|
48
48
|
# Offense count: 1
|
|
49
49
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -98,7 +98,7 @@ Layout/SpaceAfterComma:
|
|
|
98
98
|
Exclude:
|
|
99
99
|
- 'lib/evva/kotlin_generator.rb'
|
|
100
100
|
- 'lib/evva/swift_generator.rb'
|
|
101
|
-
- 'spec/lib/evva/
|
|
101
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
102
102
|
|
|
103
103
|
# Offense count: 94
|
|
104
104
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -111,7 +111,7 @@ Layout/SpaceInsideHashLiteralBraces:
|
|
|
111
111
|
- 'lib/evva/logger.rb'
|
|
112
112
|
- 'spec/evva_spec.rb'
|
|
113
113
|
- 'spec/lib/evva/config_spec.rb'
|
|
114
|
-
- 'spec/lib/evva/
|
|
114
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
115
115
|
- 'spec/lib/evva/kotlin_generator_spec.rb'
|
|
116
116
|
- 'spec/lib/evva/object_extension_spec.rb'
|
|
117
117
|
- 'spec/lib/evva/swift_generator_spec.rb'
|
|
@@ -128,7 +128,7 @@ Lint/AmbiguousBlockAssociation:
|
|
|
128
128
|
Lint/AmbiguousRegexpLiteral:
|
|
129
129
|
Exclude:
|
|
130
130
|
- 'spec/lib/evva/config_spec.rb'
|
|
131
|
-
- 'spec/lib/evva/
|
|
131
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
132
132
|
- 'spec/lib/evva/object_extension_spec.rb'
|
|
133
133
|
|
|
134
134
|
# Offense count: 3
|
|
@@ -257,12 +257,12 @@ Style/HashSyntax:
|
|
|
257
257
|
- 'spec/evva_spec.rb'
|
|
258
258
|
- 'spec/platform_filter_spec.rb'
|
|
259
259
|
- 'lib/evva/config.rb'
|
|
260
|
-
- 'lib/evva/
|
|
260
|
+
- 'lib/evva/csv_source.rb'
|
|
261
261
|
- 'lib/evva/kotlin_generator.rb'
|
|
262
262
|
- 'lib/evva/logger.rb'
|
|
263
263
|
- 'lib/evva/swift_generator.rb'
|
|
264
264
|
- 'spec/lib/evva/config_spec.rb'
|
|
265
|
-
- 'spec/lib/evva/
|
|
265
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
266
266
|
- 'spec/lib/evva/kotlin_generator_spec.rb'
|
|
267
267
|
- 'spec/lib/evva/object_extension_spec.rb'
|
|
268
268
|
- 'spec/lib/evva/swift_generator_spec.rb'
|
|
@@ -288,7 +288,7 @@ Style/ModuleFunction:
|
|
|
288
288
|
# SupportedStyles: literals, strict
|
|
289
289
|
Style/MutableConstant:
|
|
290
290
|
Exclude:
|
|
291
|
-
- 'lib/evva/
|
|
291
|
+
- 'lib/evva/csv_source.rb'
|
|
292
292
|
- 'lib/evva/kotlin_generator.rb'
|
|
293
293
|
- 'lib/evva/swift_generator.rb'
|
|
294
294
|
|
|
@@ -363,7 +363,7 @@ Style/SymbolProc:
|
|
|
363
363
|
Style/TrailingCommaInArrayLiteral:
|
|
364
364
|
Exclude:
|
|
365
365
|
- 'spec/evva_spec.rb'
|
|
366
|
-
- 'spec/lib/evva/
|
|
366
|
+
- 'spec/lib/evva/csv_source_spec.rb'
|
|
367
367
|
- 'spec/lib/evva/kotlin_generator_spec.rb'
|
|
368
368
|
- 'spec/lib/evva/swift_generator_spec.rb'
|
|
369
369
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
evva (0.
|
|
4
|
+
evva (0.13.0)
|
|
5
5
|
colorize (~> 1.0)
|
|
6
6
|
csv (~> 3.0)
|
|
7
7
|
safe_yaml (~> 1.0)
|
|
@@ -77,7 +77,7 @@ GEM
|
|
|
77
77
|
simplecov_json_formatter (0.1.4)
|
|
78
78
|
unicode-display_width (3.2.0)
|
|
79
79
|
unicode-emoji (~> 4.1)
|
|
80
|
-
unicode-emoji (4.
|
|
80
|
+
unicode-emoji (4.3.0)
|
|
81
81
|
webmock (3.25.1)
|
|
82
82
|
addressable (>= 2.8.0)
|
|
83
83
|
crack (>= 0.3.2)
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Evva
|
|
|
4
4
|
[](https://travis-ci.org/hole19/evva?branch=master)
|
|
5
5
|
[](http://rubygems.org/gems/evva "View this project in Rubygems")
|
|
6
6
|
|
|
7
|
-
Evva automatically generates code for triggering events based on a Google Sheets
|
|
7
|
+
Evva automatically generates code for triggering events based on a CSV specification, such as a Google Sheets CSV export or an Evva Hub export. It generates code for both Swift (iOS) and Kotlin (Android).
|
|
8
8
|
|
|
9
9
|
# Instalation
|
|
10
10
|
|
|
@@ -23,10 +23,10 @@ Evva automatically generates code for triggering events based on a Google Sheets
|
|
|
23
23
|
type: Android|iOS
|
|
24
24
|
|
|
25
25
|
data_source:
|
|
26
|
-
type:
|
|
27
|
-
events_url: <
|
|
28
|
-
people_properties_url: <
|
|
29
|
-
enum_classes_url: <
|
|
26
|
+
type: csv
|
|
27
|
+
events_url: <EVENTS-CSV-URL>
|
|
28
|
+
people_properties_url: <PEOPLE-PROPERTIES-CSV-URL>
|
|
29
|
+
enum_classes_url: <ENUM-CLASSES-CSV-URL>
|
|
30
30
|
|
|
31
31
|
out_path: /folder/where/analytics/classes/are
|
|
32
32
|
event_file_name: /file/with/tracking/functions
|
|
@@ -40,6 +40,10 @@ Evva automatically generates code for triggering events based on a Google Sheets
|
|
|
40
40
|
- ios
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
`data_source.type: csv` reads each URL as a CSV with a header row. Google Sheets
|
|
44
|
+
(File → Share → Publish to web → CSV) and Evva Hub exports both produce it.
|
|
45
|
+
`google_sheet` is the former name of `csv` and is still accepted.
|
|
46
|
+
|
|
43
47
|
## The events sheet
|
|
44
48
|
|
|
45
49
|
The events sheet is read by column header, so column order does not matter and
|
data/changelog.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.13.0] - 2026-11-19
|
|
6
|
+
|
|
7
|
+
- `data_source.type` is now `csv`, the format both Google Sheets and Evva Hub exports produce. `google_sheet` is still accepted, and `Evva::GoogleSheet` remains as an alias of the renamed `Evva::CsvSource`
|
|
8
|
+
- Tested on Ruby 4.0 in CI. The development lockfile moves `unicode-emoji` to 4.3.0, since 4.1.0 doesn't install on Ruby 4
|
|
9
|
+
|
|
5
10
|
## [0.12.1] - 2026-11-17
|
|
6
11
|
|
|
7
12
|
- Enum `Possible Values` accept the same separators as `Event Properties` (commas and/or one value per line) and trim spaces around each value; an enum with no values stops the run with an error naming it
|
data/lib/evva/config.rb
CHANGED
|
@@ -92,7 +92,7 @@ module Evva
|
|
|
92
92
|
}
|
|
93
93
|
}.freeze
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
CSV_STRUCT = {
|
|
96
96
|
type: Hash,
|
|
97
97
|
elements: {
|
|
98
98
|
type: { type: String },
|
|
@@ -103,7 +103,9 @@ module Evva
|
|
|
103
103
|
}.freeze
|
|
104
104
|
|
|
105
105
|
DICTIONARY_STRUCT = {
|
|
106
|
-
"
|
|
106
|
+
"csv" => CSV_STRUCT,
|
|
107
|
+
# Former name of "csv", still accepted so existing configs keep working.
|
|
108
|
+
"google_sheet" => CSV_STRUCT
|
|
107
109
|
}.freeze
|
|
108
110
|
end
|
|
109
111
|
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
require "net/https"
|
|
2
|
+
require "csv"
|
|
3
|
+
|
|
4
|
+
module Evva
|
|
5
|
+
# Reads the analytics dictionary from CSV files fetched over HTTP. Both the
|
|
6
|
+
# Google Sheets CSV export and the Evva Hub export produce this format.
|
|
7
|
+
class CsvSource
|
|
8
|
+
EVENT_NAME = "Event Name"
|
|
9
|
+
EVENT_PROPERTIES = "Event Properties"
|
|
10
|
+
EVENT_DESTINATION = "Event Destination"
|
|
11
|
+
EVENT_PLATFORM = "Platform"
|
|
12
|
+
|
|
13
|
+
PROPERTY_NAME = "Property Name"
|
|
14
|
+
PROPERTY_TYPE = "Property Type"
|
|
15
|
+
PROPERTY_DESTINATION = "Property Destination"
|
|
16
|
+
|
|
17
|
+
ENUM_NAME = "Enum Name"
|
|
18
|
+
ENUM_VALUES = "Possible Values"
|
|
19
|
+
|
|
20
|
+
def initialize(events_url, people_properties_url, enum_classes_url)
|
|
21
|
+
@events_url = events_url
|
|
22
|
+
@people_properties_url = people_properties_url
|
|
23
|
+
@enum_classes_url = enum_classes_url
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def events
|
|
27
|
+
@events_csv ||= begin
|
|
28
|
+
Logger.info("Downloading events sheet from #{redact(@events_url)}")
|
|
29
|
+
get_csv(@events_url)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
@events ||= begin
|
|
33
|
+
platform_header = header_matching(@events_csv, EVENT_PLATFORM)
|
|
34
|
+
Logger.info("No #{EVENT_PLATFORM} column in the events sheet, every event will be generated for every platform") if platform_header.nil?
|
|
35
|
+
|
|
36
|
+
@events_csv.map do |row|
|
|
37
|
+
event_name = row[EVENT_NAME]
|
|
38
|
+
properties = hash_parser(row[EVENT_PROPERTIES])
|
|
39
|
+
destinations = list_parser(row[EVENT_DESTINATION])
|
|
40
|
+
platforms = platform_parser(platform_header && row[platform_header])
|
|
41
|
+
Evva::AnalyticsEvent.new(event_name, properties, destinations, platforms)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def people_properties
|
|
47
|
+
@people_properties_csv ||= begin
|
|
48
|
+
Logger.info("Downloading people properties sheet from #{redact(@people_properties_url)}")
|
|
49
|
+
get_csv(@people_properties_url)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@people_properties ||= @people_properties_csv.map do |row|
|
|
53
|
+
property_name = row[PROPERTY_NAME]
|
|
54
|
+
property_type = row[PROPERTY_TYPE]
|
|
55
|
+
destinations = list_parser(row[PROPERTY_DESTINATION])
|
|
56
|
+
Evva::AnalyticsProperty.new(property_name, property_type, destinations)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def enum_classes
|
|
61
|
+
@enum_classes_csv ||= begin
|
|
62
|
+
Logger.info("Downloading enums sheet from #{redact(@enum_classes_url)}")
|
|
63
|
+
get_csv(@enum_classes_url)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
@enum_classes ||= @enum_classes_csv.map do |row|
|
|
67
|
+
enum_name = row[ENUM_NAME]
|
|
68
|
+
values = list_parser(row[ENUM_VALUES])
|
|
69
|
+
# An enum with no cases is not valid Swift with a String raw type.
|
|
70
|
+
raise "Enum #{enum_name} has no #{ENUM_VALUES}" if values.empty?
|
|
71
|
+
|
|
72
|
+
Evva::AnalyticsEnum.new(enum_name, values)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def destinations
|
|
77
|
+
@destinations ||= events.map(&:destinations).flatten.uniq
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
# Sheet URLs can carry an auth token in the query string or userinfo, so
|
|
83
|
+
# only scheme, host and path are ever printed.
|
|
84
|
+
def redact(url)
|
|
85
|
+
uri = URI(url.to_s)
|
|
86
|
+
"#{uri.scheme}://#{uri.host}#{uri.path}"
|
|
87
|
+
rescue URI::InvalidURIError
|
|
88
|
+
"<invalid url>"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def get_csv(url)
|
|
92
|
+
data = get(url)
|
|
93
|
+
|
|
94
|
+
begin
|
|
95
|
+
CSV.parse(data, headers: true)
|
|
96
|
+
rescue StandardError => e
|
|
97
|
+
raise "Cannot parse. Expected CSV at #{redact(url)}: #{e}"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def get(url, max_redirects = 1)
|
|
102
|
+
raise "Too may redirects" if max_redirects == -1
|
|
103
|
+
|
|
104
|
+
uri = URI(url)
|
|
105
|
+
|
|
106
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
107
|
+
http.use_ssl = true
|
|
108
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
109
|
+
|
|
110
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
|
111
|
+
response = http.request(request)
|
|
112
|
+
|
|
113
|
+
return get(response["location"], max_redirects - 1) if response.is_a? Net::HTTPRedirection
|
|
114
|
+
|
|
115
|
+
raise "Http Error #{response.body}" if response.code.to_i >= 400
|
|
116
|
+
|
|
117
|
+
response.body
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Matched ignoring case and surrounding whitespace, because a header of
|
|
121
|
+
# "platform" or "Platform " means what it plainly means.
|
|
122
|
+
def header_matching(csv, name)
|
|
123
|
+
csv.headers.compact.find { |header| header.to_s.strip.casecmp?(name) }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# nil (no Platform column or empty cell) means unrestricted (never filtered out).
|
|
127
|
+
# Concrete platform tokens are stored lowercased and deduplicated.
|
|
128
|
+
def platform_parser(platform_list)
|
|
129
|
+
tokens = platform_list.to_s.split(",").map(&:strip).reject(&:empty?)
|
|
130
|
+
return nil if tokens.empty?
|
|
131
|
+
|
|
132
|
+
tokens.map(&:downcase).uniq
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Items may be separated by commas, line breaks, or both, so a long list can
|
|
136
|
+
# be written one item per line in the cell.
|
|
137
|
+
def list_parser(list)
|
|
138
|
+
list.to_s.split(/,|\r\n|\r|\n/).map(&:strip).reject(&:empty?)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def hash_parser(property_array)
|
|
142
|
+
h = {}
|
|
143
|
+
list_parser(property_array).each do |prop|
|
|
144
|
+
split_prop = prop.split(":")
|
|
145
|
+
prop_name = split_prop[0].strip.to_sym
|
|
146
|
+
prop_type = split_prop[1].to_s.strip
|
|
147
|
+
h[prop_name] = prop_type
|
|
148
|
+
end
|
|
149
|
+
h
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Kept so code that referenced the old name still loads.
|
|
154
|
+
GoogleSheet = CsvSource
|
|
155
|
+
end
|
data/lib/evva/google_sheet.rb
CHANGED
|
@@ -1,141 +1,3 @@
|
|
|
1
|
-
require "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module Evva
|
|
5
|
-
class GoogleSheet
|
|
6
|
-
EVENT_NAME = "Event Name"
|
|
7
|
-
EVENT_PROPERTIES = "Event Properties"
|
|
8
|
-
EVENT_DESTINATION = "Event Destination"
|
|
9
|
-
EVENT_PLATFORM = "Platform"
|
|
10
|
-
|
|
11
|
-
PROPERTY_NAME = "Property Name"
|
|
12
|
-
PROPERTY_TYPE = "Property Type"
|
|
13
|
-
PROPERTY_DESTINATION = "Property Destination"
|
|
14
|
-
|
|
15
|
-
ENUM_NAME = "Enum Name"
|
|
16
|
-
ENUM_VALUES = "Possible Values"
|
|
17
|
-
|
|
18
|
-
def initialize(events_url, people_properties_url, enum_classes_url)
|
|
19
|
-
@events_url = events_url
|
|
20
|
-
@people_properties_url = people_properties_url
|
|
21
|
-
@enum_classes_url = enum_classes_url
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def events
|
|
25
|
-
@events_csv ||= begin
|
|
26
|
-
Logger.info("Downloading data from Google Sheet at #{@events_url}")
|
|
27
|
-
get_csv(@events_url)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
@events ||= begin
|
|
31
|
-
platform_header = header_matching(@events_csv, EVENT_PLATFORM)
|
|
32
|
-
Logger.info("No #{EVENT_PLATFORM} column in the events sheet, every event will be generated for every platform") if platform_header.nil?
|
|
33
|
-
|
|
34
|
-
@events_csv.map do |row|
|
|
35
|
-
event_name = row[EVENT_NAME]
|
|
36
|
-
properties = hash_parser(row[EVENT_PROPERTIES])
|
|
37
|
-
destinations = list_parser(row[EVENT_DESTINATION])
|
|
38
|
-
platforms = platform_parser(platform_header && row[platform_header])
|
|
39
|
-
Evva::AnalyticsEvent.new(event_name, properties, destinations, platforms)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def people_properties
|
|
45
|
-
@people_properties_csv ||= begin
|
|
46
|
-
Logger.info("Downloading data from Google Sheet at #{@people_properties_url}")
|
|
47
|
-
get_csv(@people_properties_url)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
@people_properties ||= @people_properties_csv.map do |row|
|
|
51
|
-
property_name = row[PROPERTY_NAME]
|
|
52
|
-
property_type = row[PROPERTY_TYPE]
|
|
53
|
-
destinations = list_parser(row[PROPERTY_DESTINATION])
|
|
54
|
-
Evva::AnalyticsProperty.new(property_name, property_type, destinations)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def enum_classes
|
|
59
|
-
@enum_classes_csv ||= begin
|
|
60
|
-
Logger.info("Downloading data from Google Sheet at #{@enum_classes_url}")
|
|
61
|
-
get_csv(@enum_classes_url)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
@enum_classes ||= @enum_classes_csv.map do |row|
|
|
65
|
-
enum_name = row[ENUM_NAME]
|
|
66
|
-
values = list_parser(row[ENUM_VALUES])
|
|
67
|
-
# An enum with no cases is not valid Swift with a String raw type.
|
|
68
|
-
raise "Enum #{enum_name} has no #{ENUM_VALUES}" if values.empty?
|
|
69
|
-
|
|
70
|
-
Evva::AnalyticsEnum.new(enum_name, values)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def destinations
|
|
75
|
-
@destinations ||= events.map(&:destinations).flatten.uniq
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private
|
|
79
|
-
|
|
80
|
-
def get_csv(url)
|
|
81
|
-
data = get(url)
|
|
82
|
-
|
|
83
|
-
begin
|
|
84
|
-
CSV.parse(data, headers: true)
|
|
85
|
-
rescue StandardError => e
|
|
86
|
-
raise "Cannot parse. Expected CSV at #{url}: #{e}"
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def get(url, max_redirects = 1)
|
|
91
|
-
raise "Too may redirects" if max_redirects == -1
|
|
92
|
-
|
|
93
|
-
uri = URI(url)
|
|
94
|
-
|
|
95
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
96
|
-
http.use_ssl = true
|
|
97
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
98
|
-
|
|
99
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
|
100
|
-
response = http.request(request)
|
|
101
|
-
|
|
102
|
-
return get(response["location"], max_redirects - 1) if response.is_a? Net::HTTPRedirection
|
|
103
|
-
|
|
104
|
-
raise "Http Error #{response.body}" if response.code.to_i >= 400
|
|
105
|
-
|
|
106
|
-
response.body
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Matched ignoring case and surrounding whitespace, because a header of
|
|
110
|
-
# "platform" or "Platform " means what it plainly means.
|
|
111
|
-
def header_matching(csv, name)
|
|
112
|
-
csv.headers.compact.find { |header| header.to_s.strip.casecmp?(name) }
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# nil (no Platform column or empty cell) means unrestricted (never filtered out).
|
|
116
|
-
# Concrete platform tokens are stored lowercased and deduplicated.
|
|
117
|
-
def platform_parser(platform_list)
|
|
118
|
-
tokens = platform_list.to_s.split(",").map(&:strip).reject(&:empty?)
|
|
119
|
-
return nil if tokens.empty?
|
|
120
|
-
|
|
121
|
-
tokens.map(&:downcase).uniq
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Items may be separated by commas, line breaks, or both, so a long list can
|
|
125
|
-
# be written one item per line in the cell.
|
|
126
|
-
def list_parser(list)
|
|
127
|
-
list.to_s.split(/,|\r\n|\r|\n/).map(&:strip).reject(&:empty?)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def hash_parser(property_array)
|
|
131
|
-
h = {}
|
|
132
|
-
list_parser(property_array).each do |prop|
|
|
133
|
-
split_prop = prop.split(":")
|
|
134
|
-
prop_name = split_prop[0].strip.to_sym
|
|
135
|
-
prop_type = split_prop[1].to_s.strip
|
|
136
|
-
h[prop_name] = prop_type
|
|
137
|
-
end
|
|
138
|
-
h
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
1
|
+
# Former location of Evva::CsvSource, kept so `require "evva/google_sheet"`
|
|
2
|
+
# still loads. Evva::GoogleSheet is defined as an alias in csv_source.rb.
|
|
3
|
+
require "evva/csv_source"
|
data/lib/evva/version.rb
CHANGED
data/lib/evva.rb
CHANGED
|
@@ -2,7 +2,7 @@ require "optparse"
|
|
|
2
2
|
require "yaml"
|
|
3
3
|
|
|
4
4
|
require "evva/logger"
|
|
5
|
-
require "evva/
|
|
5
|
+
require "evva/csv_source"
|
|
6
6
|
require "evva/config"
|
|
7
7
|
require "evva/file_reader"
|
|
8
8
|
require "evva/analytics_event"
|
|
@@ -65,8 +65,8 @@ module Evva
|
|
|
65
65
|
def analytics_data(config:)
|
|
66
66
|
source =
|
|
67
67
|
case config[:type]
|
|
68
|
-
when "google_sheet"
|
|
69
|
-
Evva::
|
|
68
|
+
when "csv", "google_sheet"
|
|
69
|
+
Evva::CsvSource.new(config[:events_url], config[:people_properties_url], config[:enum_classes_url])
|
|
70
70
|
end
|
|
71
71
|
events_bundle = {}
|
|
72
72
|
events_bundle[:events] = source.events
|
data/spec/evva_spec.rb
CHANGED
|
@@ -6,10 +6,10 @@ describe Evva do
|
|
|
6
6
|
|
|
7
7
|
before do
|
|
8
8
|
allow_any_instance_of(Evva::FileReader).to receive(:open_file).and_return(file)
|
|
9
|
-
allow_any_instance_of(Evva::
|
|
10
|
-
allow_any_instance_of(Evva::
|
|
11
|
-
allow_any_instance_of(Evva::
|
|
12
|
-
allow_any_instance_of(Evva::
|
|
9
|
+
allow_any_instance_of(Evva::CsvSource).to receive(:events).and_return([])
|
|
10
|
+
allow_any_instance_of(Evva::CsvSource).to receive(:people_properties).and_return([])
|
|
11
|
+
allow_any_instance_of(Evva::CsvSource).to receive(:enum_classes).and_return([])
|
|
12
|
+
allow_any_instance_of(Evva::CsvSource).to receive(:destinations).and_return([])
|
|
13
13
|
allow(Evva).to receive(:write_to_file)
|
|
14
14
|
end
|
|
15
15
|
|
data/spec/fixtures/test.yml
CHANGED
|
@@ -5,7 +5,7 @@ describe Evva::Config do
|
|
|
5
5
|
{
|
|
6
6
|
type: "EvvaOS",
|
|
7
7
|
data_source: {
|
|
8
|
-
type: "
|
|
8
|
+
type: "csv",
|
|
9
9
|
events_url: "https://events.csv",
|
|
10
10
|
people_properties_url: "https://people_properties.csv",
|
|
11
11
|
enum_classes_url: "https://enum_classes.csv",
|
|
@@ -39,7 +39,12 @@ describe Evva::Config do
|
|
|
39
39
|
describe "#data_source" do
|
|
40
40
|
subject(:data_source) { config.data_source }
|
|
41
41
|
|
|
42
|
-
it { should eq(type: "
|
|
42
|
+
it { should eq(type: "csv", events_url: "https://events.csv", people_properties_url: "https://people_properties.csv", enum_classes_url: "https://enum_classes.csv") }
|
|
43
|
+
|
|
44
|
+
context "when given the legacy google_sheet type" do
|
|
45
|
+
before { hash[:data_source][:type] = "google_sheet" }
|
|
46
|
+
it { should include(type: "google_sheet", events_url: "https://events.csv") }
|
|
47
|
+
end
|
|
43
48
|
|
|
44
49
|
context "when given an unknown type data source" do
|
|
45
50
|
before { hash[:data_source] = { type: "i_dunno" } }
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require "open3"
|
|
2
|
+
|
|
3
|
+
describe Evva::CsvSource do
|
|
4
|
+
let(:sheet) { Evva::CsvSource.new(events_sheet, people_sheet, enum_sheet) }
|
|
3
5
|
|
|
4
6
|
let(:events_sheet) { "https://wtvr1" }
|
|
5
7
|
let(:people_sheet) { "https://wtvr2" }
|
|
@@ -14,6 +16,37 @@ describe Evva::GoogleSheet do
|
|
|
14
16
|
stub_request(:get, enum_sheet).to_return(status: 200, body: enum_file, headers: {})
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
describe "auth token in sheet URLs" do
|
|
20
|
+
let(:events_sheet) { "https://example.com/export/events.csv?token=evv_secret" }
|
|
21
|
+
let(:people_sheet) { "https://example.com/export/people.csv?token=evv_secret" }
|
|
22
|
+
let(:enum_sheet) { "https://example.com/export/enums.csv?token=evv_secret" }
|
|
23
|
+
let(:logged) { [] }
|
|
24
|
+
|
|
25
|
+
before do
|
|
26
|
+
allow(Evva::Logger).to receive(:info) { |msg| logged << msg }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "does not log the token or credentials when downloading" do
|
|
30
|
+
sheet.events
|
|
31
|
+
sheet.people_properties
|
|
32
|
+
sheet.enum_classes
|
|
33
|
+
|
|
34
|
+
expect(logged).to include("Downloading events sheet from https://example.com/export/events.csv")
|
|
35
|
+
expect(logged.join("\n")).not_to match(/evv_secret|token=/)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when the response is not valid CSV" do
|
|
39
|
+
let(:events_file) { "\"unterminated" }
|
|
40
|
+
|
|
41
|
+
it "does not include the token in the error" do
|
|
42
|
+
expect { sheet.events }.to raise_error(RuntimeError) { |e|
|
|
43
|
+
expect(e.message).to include("https://example.com/export/events.csv")
|
|
44
|
+
expect(e.message).not_to match(/evv_secret|token=/)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
17
50
|
describe "#events" do
|
|
18
51
|
subject(:events) { sheet.events }
|
|
19
52
|
|
|
@@ -35,7 +68,7 @@ describe Evva::GoogleSheet do
|
|
|
35
68
|
let(:events_file) { File.read("spec/fixtures/sample_public_events_multiline.csv") }
|
|
36
69
|
|
|
37
70
|
it "reads each multi-line cell as one field and parses it like the comma separated sheet" do
|
|
38
|
-
comma_separated = Evva::
|
|
71
|
+
comma_separated = Evva::CsvSource.new(events_sheet, people_sheet, enum_sheet)
|
|
39
72
|
stub_request(:get, events_sheet).to_return(status: 200, body: File.read("spec/fixtures/sample_public_events.csv"))
|
|
40
73
|
expected = comma_separated.events
|
|
41
74
|
|
|
@@ -323,3 +356,32 @@ describe Evva::GoogleSheet do
|
|
|
323
356
|
end
|
|
324
357
|
end
|
|
325
358
|
end
|
|
359
|
+
|
|
360
|
+
describe "CSV data source compatibility" do
|
|
361
|
+
let(:urls) { { events_url: "https://wtvr1", people_properties_url: "https://wtvr2", enum_classes_url: "https://wtvr3" } }
|
|
362
|
+
|
|
363
|
+
before do
|
|
364
|
+
stub_request(:get, urls[:events_url]).to_return(status: 200, body: File.read("spec/fixtures/sample_public_events.csv"))
|
|
365
|
+
stub_request(:get, urls[:people_properties_url]).to_return(status: 200, body: File.read("spec/fixtures/sample_public_people_properties.csv"))
|
|
366
|
+
stub_request(:get, urls[:enum_classes_url]).to_return(status: 200, body: File.read("spec/fixtures/sample_public_enums.csv"))
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
it "keeps Evva::GoogleSheet as an alias of Evva::CsvSource" do
|
|
370
|
+
expect(Evva::GoogleSheet).to equal(Evva::CsvSource)
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# Run in a fresh process so nothing the suite already loaded can hide a
|
|
374
|
+
# missing file.
|
|
375
|
+
it "still loads through the former require path" do
|
|
376
|
+
script = 'require "evva/google_sheet"; exit(Evva::GoogleSheet.equal?(Evva::CsvSource) ? 0 : 1)'
|
|
377
|
+
output, status = Open3.capture2e(RbConfig.ruby, "-Ilib", "-e", script)
|
|
378
|
+
expect(status).to be_success, output
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
it "reads the same data for the legacy 'google_sheet' type as for 'csv'" do
|
|
382
|
+
csv = Evva.analytics_data(config: urls.merge(type: "csv"))
|
|
383
|
+
legacy = Evva.analytics_data(config: urls.merge(type: "google_sheet"))
|
|
384
|
+
expect(legacy[:events]).to eq(csv[:events])
|
|
385
|
+
expect(csv[:events]).not_to be_empty
|
|
386
|
+
end
|
|
387
|
+
end
|
metadata
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: evva
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- André Andrade
|
|
8
8
|
- João Costa
|
|
9
9
|
- Ricardo Trindade
|
|
10
|
-
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date: 2026-11-
|
|
12
|
+
date: 2026-11-19 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
15
|
name: colorize
|
|
@@ -78,6 +77,7 @@ files:
|
|
|
78
77
|
- lib/evva/analytics_event.rb
|
|
79
78
|
- lib/evva/analytics_property.rb
|
|
80
79
|
- lib/evva/config.rb
|
|
80
|
+
- lib/evva/csv_source.rb
|
|
81
81
|
- lib/evva/file_reader.rb
|
|
82
82
|
- lib/evva/google_sheet.rb
|
|
83
83
|
- lib/evva/kotlin_generator.rb
|
|
@@ -108,7 +108,7 @@ files:
|
|
|
108
108
|
- spec/fixtures/sample_public_people_properties_spaced.csv
|
|
109
109
|
- spec/fixtures/test.yml
|
|
110
110
|
- spec/lib/evva/config_spec.rb
|
|
111
|
-
- spec/lib/evva/
|
|
111
|
+
- spec/lib/evva/csv_source_spec.rb
|
|
112
112
|
- spec/lib/evva/kotlin_generator_spec.rb
|
|
113
113
|
- spec/lib/evva/logger_spec.rb
|
|
114
114
|
- spec/lib/evva/object_extension_spec.rb
|
|
@@ -119,7 +119,6 @@ homepage: https://github.com/hole19/
|
|
|
119
119
|
licenses:
|
|
120
120
|
- MIT
|
|
121
121
|
metadata: {}
|
|
122
|
-
post_install_message:
|
|
123
122
|
rdoc_options: []
|
|
124
123
|
require_paths:
|
|
125
124
|
- lib
|
|
@@ -134,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
134
133
|
- !ruby/object:Gem::Version
|
|
135
134
|
version: '0'
|
|
136
135
|
requirements: []
|
|
137
|
-
rubygems_version:
|
|
138
|
-
signing_key:
|
|
136
|
+
rubygems_version: 4.0.10
|
|
139
137
|
specification_version: 4
|
|
140
138
|
summary: An event generating service
|
|
141
139
|
test_files: []
|