evva 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,15 @@ describe Evva::AndroidGenerator do
2
2
  let(:generator) { described_class.new("com.hole19golf.hole19.analytics") }
3
3
 
4
4
  describe '#events' do
5
- subject { generator.events(events, "AnalyticsEvent") }
5
+ subject { generator.events(events, "AnalyticsEvent", "AnalyticsEvents", "AnalyticsDestinations") }
6
6
 
7
7
  let(:events) { [
8
- Evva::AnalyticsEvent.new('cp_page_view'),
9
- Evva::AnalyticsEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }),
10
- Evva::AnalyticsEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }),
11
- Evva::AnalyticsEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }),
12
- Evva::AnalyticsEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' })
8
+ Evva::AnalyticsEvent.new('cp_page_view', {}, []),
9
+ Evva::AnalyticsEvent.new('cp_page_view_2', {}, ["firebase"]),
10
+ Evva::AnalyticsEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }, ["firebase", "custom destination"]),
11
+ Evva::AnalyticsEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }, ["firebase"]),
12
+ Evva::AnalyticsEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }, []),
13
+ Evva::AnalyticsEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' }, []),
13
14
  ] }
14
15
 
15
16
  let(:expected) {
@@ -24,9 +25,16 @@ sealed class AnalyticsEvent(event: AnalyticsEvents) {
24
25
  val name = event.key
25
26
 
26
27
  open val properties: Map<String, Any?>? = null
28
+ open val destinations: Array<AnalyticsDestinations> = []
27
29
 
28
30
  object CpPageView : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW)
29
31
 
32
+ data class CpPageView2 : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_2) {
33
+ override val destinations = [
34
+ AnalyticsDestinations.FIREBASE
35
+ ]
36
+ }
37
+
30
38
  data class CpPageViewA(
31
39
  val courseId: Long, val courseName: String
32
40
  ) : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_A) {
@@ -34,6 +42,10 @@ sealed class AnalyticsEvent(event: AnalyticsEvents) {
34
42
  "course_id" to courseId,
35
43
  "course_name" to courseName
36
44
  )
45
+ override val destinations = [
46
+ AnalyticsDestinations.FIREBASE,
47
+ AnalyticsDestinations.CUSTOM_DESTINATION
48
+ ]
37
49
  }
38
50
 
39
51
  data class CpPageViewB(
@@ -44,6 +56,9 @@ sealed class AnalyticsEvent(event: AnalyticsEvents) {
44
56
  "course_name" to courseName,
45
57
  "from_screen" to fromScreen.key
46
58
  )
59
+ override val destinations = [
60
+ AnalyticsDestinations.FIREBASE
61
+ ]
47
62
  }
48
63
 
49
64
  data class CpPageViewC(
@@ -75,7 +90,7 @@ Kotlin
75
90
  subject { generator.special_property_enums(enums) }
76
91
  let(:enums) { [
77
92
  Evva::AnalyticsEnum.new('CourseProfileSource', ['course_discovery', 'synced_courses']),
78
- Evva::AnalyticsEnum.new('PremiumFrom', ['Course Profile', 'Round Setup'])
93
+ Evva::AnalyticsEnum.new('PremiumFrom', ['Course Profile', 'Round Setup']),
79
94
  ] }
80
95
  let(:expected) {
81
96
  <<-Kotlin
@@ -102,8 +117,8 @@ Kotlin
102
117
  describe '#event_enum' do
103
118
  subject { generator.event_enum(event_bundle, 'AnalyticsEvents') }
104
119
  let(:event_bundle) { [
105
- Evva::AnalyticsEvent.new('nav_feed_tap', {}),
106
- Evva::AnalyticsEvent.new('nav_performance_tap', {})
120
+ Evva::AnalyticsEvent.new('nav_feed_tap', {}, []),
121
+ Evva::AnalyticsEvent.new('nav_performance_tap', {}, []),
107
122
  ] }
108
123
  let(:expected) {
109
124
  <<-Kotlin
@@ -123,8 +138,53 @@ Kotlin
123
138
  end
124
139
 
125
140
  describe '#people_properties' do
126
- subject { generator.people_properties(people_bundle, 'AnalyticsProperties') }
127
- let(:people_bundle) { ['rounds_with_wear', 'friends_from_facebook'] }
141
+ subject { generator.people_properties(people_bundle, 'AnalyticsProperty', 'AnalyticsProperties', 'AnalyticsDestinations') }
142
+ let(:people_bundle) { [
143
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', []),
144
+ Evva::AnalyticsProperty.new('wear_platform', 'WearableAppPlatform', ["firebase", "custom destination"]),
145
+ ] }
146
+ let(:expected) {
147
+ <<-Kotlin
148
+ package com.hole19golf.hole19.analytics
149
+
150
+ /**
151
+ * This file was automatically generated by evva: https://github.com/hole19/evva
152
+ */
153
+
154
+ sealed class AnalyticsProperty(property: AnalyticsProperties) {
155
+ val name = property.key
156
+
157
+ open val value: Any = ""
158
+ open val destinations: Array<AnalyticsDestinations> = []
159
+
160
+ data class RoundsWithWear(
161
+ val value: String
162
+ ) : AnalyticsProperty(AnalyticsProperties.ROUNDS_WITH_WEAR) {
163
+ override val value = value
164
+ }
165
+
166
+ data class WearPlatform(
167
+ val value: WearableAppPlatform
168
+ ) : AnalyticsProperty(AnalyticsProperties.WEAR_PLATFORM) {
169
+ override val value = value.key
170
+ override val destinations = [
171
+ AnalyticsDestinations.FIREBASE,
172
+ AnalyticsDestinations.CUSTOM_DESTINATION
173
+ ]
174
+ }
175
+ }
176
+ Kotlin
177
+ }
178
+
179
+ it { should eq expected }
180
+ end
181
+
182
+ describe '#people_properties_enum' do
183
+ subject { generator.people_properties_enum(people_bundle, 'AnalyticsProperties') }
184
+ let(:people_bundle) { [
185
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', ["firebase"]),
186
+ Evva::AnalyticsProperty.new('wear_platform', 'WearableAppPlatform', ["firebase", "custom destination"]),
187
+ ] }
128
188
  let(:expected) {
129
189
  <<-Kotlin
130
190
  package com.hole19golf.hole19.analytics
@@ -135,7 +195,30 @@ package com.hole19golf.hole19.analytics
135
195
 
136
196
  enum class AnalyticsProperties(val key: String) {
137
197
  ROUNDS_WITH_WEAR("rounds_with_wear"),
138
- FRIENDS_FROM_FACEBOOK("friends_from_facebook");
198
+ WEAR_PLATFORM("wear_platform");
199
+ }
200
+ Kotlin
201
+ }
202
+ it { should eq expected }
203
+ end
204
+
205
+ describe '#destinations' do
206
+ subject { generator.destinations(destinations_bundle, 'AnalyticsDestinations') }
207
+ let(:destinations_bundle) { [
208
+ 'firebase',
209
+ 'whatever you want really'
210
+ ] }
211
+ let(:expected) {
212
+ <<-Kotlin
213
+ package com.hole19golf.hole19.analytics
214
+
215
+ /**
216
+ * This file was automatically generated by evva: https://github.com/hole19/evva
217
+ */
218
+
219
+ enum class AnalyticsDestinations {
220
+ FIREBASE,
221
+ WHATEVER_YOU_WANT_REALLY;
139
222
  }
140
223
  Kotlin
141
224
  }
@@ -12,9 +12,11 @@ describe Evva::Config do
12
12
  },
13
13
  out_path: 'clear/path/to/event',
14
14
  event_file_name: 'event/file/name',
15
- people_file_name: 'people/file/name',
16
15
  event_enum_file_name: 'event/enum/file',
17
- package_name: 'com.package.name.analytics'
16
+ people_file_name: 'people/file/name',
17
+ people_enum_file_name: 'people/enum/file/name',
18
+ destinations_file_name: 'destinations/file/name',
19
+ package_name: 'com.package.name.analytics',
18
20
  }
19
21
  end
20
22
 
@@ -27,8 +29,10 @@ describe Evva::Config do
27
29
  its(:type) { should eq('EvvaOS') }
28
30
  its(:out_path) { should eq('clear/path/to/event') }
29
31
  its(:event_file_name) { should eq('event/file/name') }
30
- its(:people_file_name) { should eq('people/file/name') }
31
32
  its(:event_enum_file_name) { should eq 'event/enum/file' }
33
+ its(:people_file_name) { should eq('people/file/name') }
34
+ its(:people_enum_file_name) { should eq('people/enum/file/name') }
35
+ its(:destinations_file_name) { should eq 'destinations/file/name' }
32
36
  its(:package_name) { should eq 'com.package.name.analytics' }
33
37
 
34
38
  describe '#data_source' do
@@ -22,9 +22,11 @@ describe Evva::GoogleSheet do
22
22
  end
23
23
 
24
24
  it 'returns an array with the corresponding events' do
25
- expected = [Evva::AnalyticsEvent.new('cp_page_view', { course_id: 'Long', course_name: 'String' }),
26
- Evva::AnalyticsEvent.new('nav_feed_tap', {}),
27
- Evva::AnalyticsEvent.new('cp_view_scorecard', { course_id: 'Long', course_name: 'String' })]
25
+ expected = [
26
+ Evva::AnalyticsEvent.new('cp_page_view', { course_id: 'Long', course_name: 'String' }, ['firebase', 'custom destination']),
27
+ Evva::AnalyticsEvent.new('nav_feed_tap', {}, []),
28
+ Evva::AnalyticsEvent.new('cp_view_scorecard', { course_id: 'Long', course_name: 'String' }, ['custom destination']),
29
+ ]
28
30
  expect(events).to eq(expected)
29
31
  end
30
32
 
@@ -54,8 +56,9 @@ describe Evva::GoogleSheet do
54
56
 
55
57
  it 'returns an array with the corresponding events' do
56
58
  expect(people_properties).to eq [
57
- 'rounds_with_wear',
58
- 'total_friends'
59
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', ['firebase', 'custom destination']),
60
+ Evva::AnalyticsProperty.new('total_friends', 'Int', []),
61
+ Evva::AnalyticsProperty.new('wearable_platform', 'WearableAppPlatform', ['firebase']),
59
62
  ]
60
63
  end
61
64
  end
@@ -74,4 +77,19 @@ describe Evva::GoogleSheet do
74
77
  ]
75
78
  end
76
79
  end
80
+
81
+ describe '#destinations' do
82
+ subject(:destinations) { sheet.destinations }
83
+
84
+ it do
85
+ expect { destinations }.not_to raise_error
86
+ end
87
+
88
+ it 'returns an array with the corresponding events' do
89
+ expect(destinations).to eq [
90
+ 'firebase',
91
+ 'custom destination',
92
+ ]
93
+ end
94
+ end
77
95
  end
@@ -2,14 +2,14 @@ describe Evva::SwiftGenerator do
2
2
  let(:generator) { described_class.new }
3
3
 
4
4
  describe '#events' do
5
- subject { generator.events(event_bundle, "") }
5
+ subject { generator.events(event_bundle, nil, nil, nil) }
6
6
 
7
7
  let(:event_bundle) { [
8
- Evva::AnalyticsEvent.new('cp_page_view'),
9
- Evva::AnalyticsEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }),
10
- Evva::AnalyticsEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }),
11
- Evva::AnalyticsEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }),
12
- Evva::AnalyticsEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' })
8
+ Evva::AnalyticsEvent.new('cp_page_view', {}, ['firebase']),
9
+ Evva::AnalyticsEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }, ['firebase', 'Custom Destination']),
10
+ Evva::AnalyticsEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }, []),
11
+ Evva::AnalyticsEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }, []),
12
+ Evva::AnalyticsEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' }, []),
13
13
  ] }
14
14
 
15
15
  let(:expected) {
@@ -19,6 +19,29 @@ describe Evva::SwiftGenerator do
19
19
  import Foundation
20
20
 
21
21
  extension Analytics {
22
+ struct EventData {
23
+ let name: String
24
+ var properties: [String: Any]?
25
+ let destinations: [Destination]
26
+
27
+ init(name: String, properties: [String: Any]?, destinations: [Destination]) {
28
+ self.name = name
29
+ self.properties = properties
30
+ self.destinations = destinations
31
+ }
32
+
33
+ init(name: EventName, properties: [String: Any]?, destinations: [Destination]) {
34
+ self.init(name: name.rawValue, properties: properties, destinations: destinations)
35
+ }
36
+ }
37
+
38
+ enum EventName: String {
39
+ case cpPageView = "cp_page_view"
40
+ case cpPageViewA = "cp_page_view_a"
41
+ case cpPageViewB = "cp_page_view_b"
42
+ case cpPageViewC = "cp_page_view_c"
43
+ case cpPageViewD = "cp_page_view_d"
44
+ }
22
45
 
23
46
  enum Event {
24
47
  case cpPageView
@@ -30,33 +53,48 @@ extension Analytics {
30
53
  var data: EventData {
31
54
  switch self {
32
55
  case .cpPageView:
33
- return EventData(name: "cp_page_view")
34
-
35
- case .cpPageViewA(let course_id, let course_name):
36
- return EventData(name: "cp_page_view_a", properties: [
37
- "course_id": course_id as Any,
38
- "course_name": course_name as Any ]
39
- )
40
-
41
- case .cpPageViewB(let course_id, let course_name, let from_screen):
42
- return EventData(name: "cp_page_view_b", properties: [
43
- "course_id": course_id as Any,
44
- "course_name": course_name as Any,
45
- "from_screen": from_screen.rawValue as Any ]
46
- )
47
-
48
- case .cpPageViewC(let course_id, let course_name, let from_screen):
49
- return EventData(name: "cp_page_view_c", properties: [
50
- "course_id": course_id as Any,
51
- "course_name": course_name as Any,
52
- "from_screen": from_screen?.rawValue as Any ]
53
- )
54
-
55
- case .cpPageViewD(let course_id, let course_name):
56
- return EventData(name: "cp_page_view_d", properties: [
57
- "course_id": course_id as Any,
58
- "course_name": course_name as Any ]
59
- )
56
+ return EventData(name: .cpPageView,
57
+ properties: nil,
58
+ destinations: [
59
+ .firebase,
60
+ ])
61
+
62
+ case let .cpPageViewA(course_id, course_name):
63
+ return EventData(name: .cpPageViewA,
64
+ properties: [
65
+ "course_id": course_id as Any,
66
+ "course_name": course_name as Any,
67
+ ],
68
+ destinations: [
69
+ .firebase,
70
+ .customDestination,
71
+ ])
72
+
73
+ case let .cpPageViewB(course_id, course_name, from_screen):
74
+ return EventData(name: .cpPageViewB,
75
+ properties: [
76
+ "course_id": course_id as Any,
77
+ "course_name": course_name as Any,
78
+ "from_screen": from_screen.rawValue as Any,
79
+ ],
80
+ destinations: [])
81
+
82
+ case let .cpPageViewC(course_id, course_name, from_screen):
83
+ return EventData(name: .cpPageViewC,
84
+ properties: [
85
+ "course_id": course_id as Any,
86
+ "course_name": course_name as Any,
87
+ "from_screen": from_screen?.rawValue as Any,
88
+ ],
89
+ destinations: [])
90
+
91
+ case let .cpPageViewD(course_id, course_name):
92
+ return EventData(name: .cpPageViewD,
93
+ properties: [
94
+ "course_id": course_id as Any,
95
+ "course_name": course_name as Any,
96
+ ],
97
+ destinations: [])
60
98
  }
61
99
  }
62
100
  }
@@ -72,7 +110,7 @@ Swift
72
110
 
73
111
  let(:enums) { [
74
112
  Evva::AnalyticsEnum.new('CourseProfileSource', ['course_discovery', 'synced_courses']),
75
- Evva::AnalyticsEnum.new('PremiumFrom', ['Course Profile', 'Round Setup'])
113
+ Evva::AnalyticsEnum.new('PremiumFrom', ['Course Profile', 'Round Setup']),
76
114
  ] }
77
115
 
78
116
  let(:expected) {
@@ -82,7 +120,6 @@ Swift
82
120
  import Foundation
83
121
 
84
122
  extension Analytics {
85
-
86
123
  enum CourseProfileSource: String {
87
124
  case courseDiscovery = "course_discovery"
88
125
  case syncedCourses = "synced_courses"
@@ -100,9 +137,13 @@ Swift
100
137
  end
101
138
 
102
139
  describe "#people_properties" do
103
- subject { generator.people_properties(people_bundle, "") }
140
+ subject { generator.people_properties(people_bundle, "", "", "") }
104
141
 
105
- let(:people_bundle) { ['rounds_with_wear', 'friends_from_facebook'] }
142
+ let(:people_bundle) { [
143
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', ["firebase"]),
144
+ Evva::AnalyticsProperty.new('wear_platform', 'WearableAppPlatform', ["firebase", "custom destination"]),
145
+ Evva::AnalyticsProperty.new('number_of_times_it_happened', 'Long', []),
146
+ ] }
106
147
 
107
148
  let(:expected) {
108
149
  <<-Swift
@@ -111,10 +152,82 @@ Swift
111
152
  import Foundation
112
153
 
113
154
  extension Analytics {
155
+ struct PropertyData {
156
+ let name: String
157
+ let value: Any
158
+ let destinations: [Destination]
159
+
160
+ init(name: String, value: Any, destinations: [Destination]) {
161
+ self.name = name
162
+ self.value = value
163
+ self.destinations = destinations
164
+ }
114
165
 
115
- enum Property: String {
166
+ init(name: PropertyName, value: Any, destinations: [Destination]) {
167
+ self.init(name: name.rawValue, value: value, destinations: destinations)
168
+ }
169
+ }
170
+
171
+ enum PropertyName: String {
116
172
  case roundsWithWear = "rounds_with_wear"
117
- case friendsFromFacebook = "friends_from_facebook"
173
+ case wearPlatform = "wear_platform"
174
+ case numberOfTimesItHappened = "number_of_times_it_happened"
175
+ }
176
+
177
+ enum Property {
178
+ case roundsWithWear(String)
179
+ case wearPlatform(WearableAppPlatform)
180
+ case numberOfTimesItHappened(Int)
181
+
182
+ var data: PropertyData {
183
+ switch self {
184
+ case let .roundsWithWear(value):
185
+ return PropertyData(name: .roundsWithWear,
186
+ value: value,
187
+ destinations: [
188
+ .firebase,
189
+ ])
190
+
191
+ case let .wearPlatform(value):
192
+ return PropertyData(name: .wearPlatform,
193
+ value: value.rawValue,
194
+ destinations: [
195
+ .firebase,
196
+ .customDestination,
197
+ ])
198
+
199
+ case let .numberOfTimesItHappened(value):
200
+ return PropertyData(name: .numberOfTimesItHappened,
201
+ value: value,
202
+ destinations: [])
203
+ }
204
+ }
205
+ }
206
+ }
207
+ Swift
208
+ }
209
+
210
+ it { should eq expected }
211
+ end
212
+
213
+ describe "#destinations" do
214
+ subject { generator.destinations(destinations, "") }
215
+
216
+ let(:destinations) { [
217
+ 'firebase',
218
+ 'whatever you want really'
219
+ ] }
220
+
221
+ let(:expected) {
222
+ <<-Swift
223
+ // This file was automatically generated by evva: https://github.com/hole19/evva
224
+
225
+ import Foundation
226
+
227
+ extension Analytics {
228
+ enum Destination {
229
+ case firebase
230
+ case whateverYouWantReally
118
231
  }
119
232
  }
120
233
  Swift
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evva
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RicardoTrindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-16 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -56,10 +56,10 @@ files:
56
56
  - bin/evva
57
57
  - changelog.md
58
58
  - evva.gemspec
59
- - evva_config.yml
60
59
  - lib/evva.rb
61
60
  - lib/evva/analytics_enum.rb
62
61
  - lib/evva/analytics_event.rb
62
+ - lib/evva/analytics_property.rb
63
63
  - lib/evva/android_generator.rb
64
64
  - lib/evva/config.rb
65
65
  - lib/evva/file_reader.rb
@@ -67,6 +67,18 @@ files:
67
67
  - lib/evva/logger.rb
68
68
  - lib/evva/object_extension.rb
69
69
  - lib/evva/swift_generator.rb
70
+ - lib/evva/templates/kotlin/base.kt
71
+ - lib/evva/templates/kotlin/destinations.kt
72
+ - lib/evva/templates/kotlin/event_enum.kt
73
+ - lib/evva/templates/kotlin/events.kt
74
+ - lib/evva/templates/kotlin/people_properties.kt
75
+ - lib/evva/templates/kotlin/people_properties_enum.kt
76
+ - lib/evva/templates/kotlin/special_property_enums.kt
77
+ - lib/evva/templates/swift/base.swift
78
+ - lib/evva/templates/swift/destinations.swift
79
+ - lib/evva/templates/swift/events.swift
80
+ - lib/evva/templates/swift/people_properties.swift
81
+ - lib/evva/templates/swift/special_property_enums.swift
70
82
  - lib/evva/version.rb
71
83
  - rubocop.yml
72
84
  - spec/evva_spec.rb
data/evva_config.yml DELETED
@@ -1,14 +0,0 @@
1
- type: iOS
2
-
3
- data_source:
4
- type: google_sheet
5
- sheet_id: 1LaJd68os3g_GFlerogC64grNIlXb2iukMznOvdml7A4
6
- events_url: https://path-to-csv
7
- people_properties_url: https://path-to-csv
8
- enum_classes_url: https://path-to-csv
9
-
10
- out_path: analytics
11
- event_file_name: AnalyticsEvent
12
- event_enum_file_name: AnalyticsEvents
13
- people_file_name: AnalyticsProperties
14
- package_name: com.hole19golf.hole19.analytics