Skip to content

Commit c2657ce

Browse files
authored
Merge pull request #4 from jahunt1/graylog
Graylog Provider
2 parents f4eea7f + 255eec7 commit c2657ce

File tree

46 files changed

+1521
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1521
-86
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analyticskit/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion rootProject.ext.minSdkVersion
1010
targetSdkVersion rootProject.ext.targetSdkVersion
11-
versionCode rootProject.ext.versionCode
12-
versionName rootProject.ext.versionName
11+
versionCode = 1
12+
versionName = rootProject.version ? rootProject.version : "unspecified"
1313
}
1414
buildTypes {
1515
release {
@@ -37,7 +37,7 @@ task sourcesJar(type: Jar) {
3737
}
3838

3939
task javadoc(type: Javadoc) {
40-
failOnError false
40+
failOnError false
4141
source = android.sourceSets.main.java.sourceFiles
4242
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
4343
}

analyticskit/src/main/java/com/busybusy/analyticskit_android/AnalyticsEvent.java

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,27 @@
1919
import android.support.annotation.NonNull;
2020
import android.support.annotation.Nullable;
2121

22-
import java.util.HashMap;
22+
import java.io.Serializable;
23+
import java.util.LinkedHashMap;
24+
import java.util.Map;
2325

2426
/**
2527
* Defines information that is needed to distribute the event to the registered analytics providers.
28+
*
2629
* @author John Hunt on 3/5/16.
2730
*/
28-
public class AnalyticsEvent
31+
public class AnalyticsEvent implements Serializable
2932
{
33+
private static final long serialVersionUID = 8237206047809063471L;
34+
3035
final String name;
31-
HashMap<String, Object> attributes;
32-
boolean timed;
36+
Map<String, Object> attributes;
37+
boolean timed;
3338
int priorityLevel = 0;
3439

3540
/**
36-
* Instantiates a new {@code AnalyticsEvent} object
41+
* Instantiates a new {@code AnalyticsEvent} object.
42+
*
3743
* @param name the name of the event
3844
*/
3945
public AnalyticsEvent(@NonNull String name)
@@ -44,7 +50,7 @@ public AnalyticsEvent(@NonNull String name)
4450
}
4551

4652
/**
47-
* Access the event name
53+
* Access the event name.
4854
*
4955
* @return the name of the custom event
5056
*/
@@ -55,7 +61,7 @@ public String name()
5561
}
5662

5763
/**
58-
* Adds an attribute to the event
64+
* Adds an attribute to the event.
5965
*
6066
* @param attributeName the name of the attribute (should be unique)
6167
* @param value the {@link Object} to associate with the name given
@@ -67,7 +73,7 @@ public AnalyticsEvent putAttribute(@NonNull String attributeName, @NonNull Objec
6773
// guard clause - make sure the dictionary is initialized
6874
if (this.attributes == null)
6975
{
70-
this.attributes = new HashMap<>();
76+
this.attributes = new LinkedHashMap<>();
7177
}
7278

7379
this.attributes.put(attributeName, value);
@@ -76,6 +82,7 @@ public AnalyticsEvent putAttribute(@NonNull String attributeName, @NonNull Objec
7682

7783
/**
7884
* Gets the priority of this event.
85+
*
7986
* @return the priority of the event. Returns {@code 0} when {@link #setPriority(int)} has not been called.
8087
*/
8188
public int getPriority()
@@ -87,6 +94,7 @@ public int getPriority()
8794
* Sets the priority of the event. The event defaults to {@code 0} when this method is not called.
8895
* <p/>
8996
* <b>Note:</b> It is up to the developer to define what priority scheme to use (if any).
97+
*
9098
* @param priorityLevel the priority the event should use
9199
* @return the {@link AnalyticsEvent} instance (for builder-style convenience)
92100
*/
@@ -97,19 +105,20 @@ public AnalyticsEvent setPriority(int priorityLevel)
97105
}
98106

99107
/**
100-
* Access the attributes of this event
108+
* Access the attributes of this event.
101109
*
102110
* @return A non-empty map of attributes set on this event.
103111
* Returns {@code null} if no attributes have been added to the event.
104112
*/
105113
@Nullable
106-
public HashMap<String, Object> getAttributes()
114+
public Map<String, Object> getAttributes()
107115
{
108116
return this.attributes;
109117
}
110118

111119
/**
112-
* Access a single attribute of this event
120+
* Access a single attribute of this event.
121+
*
113122
* @param name the name the of the attribute to retrieve
114123
* @return the value associated with the given attribute name.
115124
* Returns {@code null} if the attribute has not been set.
@@ -121,7 +130,8 @@ public Object getAttribute(@NonNull String name)
121130
}
122131

123132
/**
124-
* Indicates if this event is a timed event
133+
* Indicates if this event is a timed event.
134+
*
125135
* @return {@code true} if the event has been set to be a timed event. Returns {@code false} otherwise.
126136
*/
127137
public boolean isTimed()
@@ -130,7 +140,8 @@ public boolean isTimed()
130140
}
131141

132142
/**
133-
* Sets whether this event should capture timing
143+
* Sets whether this event should capture timing.
144+
*
134145
* @param timed {@code true} to set the event to track the time
135146
* @return the {@link AnalyticsEvent} instance
136147
*/
@@ -157,4 +168,54 @@ public AnalyticsEvent send()
157168
return this;
158169
}
159170

171+
@Override
172+
public boolean equals(Object other)
173+
{
174+
if (this == other)
175+
{
176+
return true;
177+
}
178+
if (other == null || getClass() != other.getClass())
179+
{
180+
return false;
181+
}
182+
183+
AnalyticsEvent that = (AnalyticsEvent) other;
184+
185+
if (timed != that.timed)
186+
{
187+
return false;
188+
}
189+
if (priorityLevel != that.priorityLevel)
190+
{
191+
return false;
192+
}
193+
if (name != null ? !name.equals(that.name) : that.name != null)
194+
{
195+
return false;
196+
}
197+
return attributes != null ? attributes.equals(that.attributes) : that.attributes == null;
198+
199+
}
200+
201+
@Override
202+
public int hashCode()
203+
{
204+
int result = name != null ? name.hashCode() : 0;
205+
result = 31 * result + (attributes != null ? attributes.hashCode() : 0);
206+
result = 31 * result + (timed ? 1 : 0);
207+
result = 31 * result + priorityLevel;
208+
return result;
209+
}
210+
211+
@Override
212+
public String toString()
213+
{
214+
return "AnalyticsEvent{" +
215+
"name='" + name + '\'' +
216+
", attributes=" + attributes +
217+
", timed=" + timed +
218+
", priorityLevel=" + priorityLevel +
219+
'}';
220+
}
160221
}

analyticskit/src/main/java/com/busybusy/analyticskit_android/AnalyticsKit.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class AnalyticsKit
3030
{
3131
private static AnalyticsKit singletonInstance = null;
32-
HashSet<AnalyticsKitProvider> providers;
32+
HashSet<AnalyticsKitProvider> providers;
3333
HashMap<String, AnalyticsEvent> timedEvents;
3434

3535
private AnalyticsKit()
@@ -38,7 +38,8 @@ private AnalyticsKit()
3838
}
3939

4040
/**
41-
* Returns the AnalyticsKit singleton
41+
* Returns the AnalyticsKit singleton.
42+
*
4243
* @return the singleton instance
4344
*/
4445
public static AnalyticsKit getInstance()
@@ -60,7 +61,8 @@ public static AnalyticsKit getInstance()
6061
}
6162

6263
/**
63-
* Registers an {@code AnalyticsKitProvider} instance to receive future events
64+
* Registers an {@code AnalyticsKitProvider} instance to receive future events.
65+
*
6466
* @param provider the {@code AnalyticsKitProvider} to notify on future calls to {@link AnalyticsKit#logEvent(AnalyticsEvent)}.
6567
* @return the {@code AnalyticsKit} instance so multiple calls to {@code registerProvider(AnalyticsKitProvider)} can be chained.
6668
*/
@@ -72,6 +74,7 @@ public AnalyticsKit registerProvider(@NonNull AnalyticsKitProvider provider)
7274

7375
/**
7476
* Sends the given event to all registered analytics providers (OR just to select providers if the event has been set to restrict the providers).
77+
*
7578
* @param event the event to capture with analytics tools
7679
*/
7780
public void logEvent(AnalyticsEvent event) throws IllegalStateException
@@ -108,7 +111,8 @@ public void logEvent(AnalyticsEvent event) throws IllegalStateException
108111
}
109112

110113
/**
111-
* Marks the end of a timed event
114+
* Marks the end of a timed event.
115+
*
112116
* @param eventName the unique name of the event that has finished
113117
*/
114118
public void endTimedEvent(@NonNull String eventName) throws IllegalStateException
@@ -150,7 +154,8 @@ public void endTimedEvent(@NonNull String eventName) throws IllegalStateExceptio
150154
}
151155

152156
/**
153-
* Marks the end of a timed event
157+
* Marks the end of a timed event.
158+
*
154159
* @param event the event that has finished
155160
*/
156161
public void endTimedEvent(@NonNull AnalyticsEvent event)

analyticskit/src/main/java/com/busybusy/analyticskit_android/AnalyticsKitProvider.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/**
2222
* Defines the interface for provider plugins to be used with AnalyticsKit-Android.
23-
*
23+
* <p>
2424
* Note: in your provider implementation, make sure the underlying provider SDK calls are
2525
* executed asynchronously. Otherwise, you will have network operations running on the main thread.
2626
*
@@ -29,20 +29,23 @@
2929
public interface AnalyticsKitProvider
3030
{
3131
/**
32-
* Returns the filter used to restrict events by priority
32+
* Returns the filter used to restrict events by priority.
33+
*
3334
* @return the {@link PriorityFilter} instance the provider is using to determine if an event of a given priority should be logged
3435
*/
3536
@NonNull
3637
PriorityFilter getPriorityFilter();
3738

3839
/**
39-
* Sends the event using provider-specific code
40+
* Sends the event using provider-specific code.
41+
*
4042
* @param event an instantiated event
4143
*/
4244
void sendEvent(@NonNull AnalyticsEvent event);
4345

4446
/**
45-
* End the timed event
47+
* End the timed event.
48+
*
4649
* @param timedEvent the event which has finished
4750
*/
4851
void endTimedEvent(@NonNull AnalyticsEvent timedEvent);
@@ -55,8 +58,9 @@ interface PriorityFilter
5558
{
5659
/**
5760
* Determines if a provider should log an event with a given priority
61+
*
5862
* @param priorityLevel the priority value from an {@link AnalyticsEvent} object
59-
* (Generally {@link AnalyticsEvent#getPriority()})
63+
* (Generally {@link AnalyticsEvent#getPriority()})
6064
* @return {@code true} if the event should be logged by the provider.
6165
* Returns {@code false} otherwise.
6266
*/

analyticskit/src/main/java/com/busybusy/analyticskit_android/ContentViewEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
/**
2222
* Defines information that is needed to distribute a "Content View" event to the registered analytics providers.
23+
*
2324
* @author John Hunt on 3/16/16.
2425
*/
2526
public class ContentViewEvent extends AnalyticsEvent
2627
{
27-
public final static String CONTENT_NAME = "contentName";
28+
public static final String CONTENT_NAME = "contentName";
2829

2930
/**
3031
* Instantiates a new {@code ContentViewEvent} object.
32+
*
3133
* @param contentName The name/title of the content that is viewed
3234
*/
3335
public ContentViewEvent(@NonNull String contentName)

0 commit comments

Comments
 (0)