dopaminekit 0.1.0 → 0.2.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/README.md +1 -1
- data/Rakefile +2 -0
- data/dopaminekit.gemspec +2 -2
- data/lib/dopaminekit.rb +94 -35
- data/lib/dopaminekit/version.rb +2 -2
- data/tasks/rspec.rake +3 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e964622f0840d37642bde997f71d22196cf86be6
|
4
|
+
data.tar.gz: 974a1e996f8e9894bff8a3fecef2b742bcb5c1d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb3d13fabcdae3553833533ae8776845142d2b715f6cf7ce2a9790bad466751d49ca05c1ee4c67e58920892336e5b9d29e913f120d1e42d39a766c2fe9b3c2e
|
7
|
+
data.tar.gz: b6e70384f77a0b4de032549709bcb114240745e9108f6a4c9cddc0de0a0ab70a6c9635ae0996cabc8357e44b81c33a0a279aa3d625ab509908c447fdc62f4b68
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# DopamineKit
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dopaminekit`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
data/Rakefile
CHANGED
data/dopaminekit.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["kash650@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{"A class to use DopamineLabs machine learning API"}
|
13
|
-
spec.description = %q{This gem provides a class for interacting with the DopamineAPI from ruby. After you have received your API key and configured the actions and reinforcements relevant to your app on the Dopamine Developer Dashboard, you may use this gem to place 'tracking', and 'reinforcement' calls from inside your app that will communicate directly with the DopamineAPI.}
|
13
|
+
spec.description = %q{This gem provides a class for interacting with the DopamineAPI from ruby. After you have received your API key and configured the actions and reinforcements relevant to your app on the [Dopamine Developer Dashboard](dashboard.usedopamine.com), you may use this gem to place 'tracking', and 'reinforcement' calls from inside your app that will communicate directly with the DopamineAPI.}
|
14
14
|
spec.homepage = "https://github.com/DopamineLabs/DopamineKit-Ruby"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "minitest", "~> 5.0"
|
33
33
|
|
34
34
|
spec.add_development_dependency "rspec", "~> 3.4.0"
|
35
|
-
spec.add_dependency "json", "~> 1.
|
35
|
+
spec.add_dependency "json", "~> 1.8.2"
|
36
36
|
end
|
data/lib/dopaminekit.rb
CHANGED
@@ -2,8 +2,15 @@ require 'dopaminekit/version'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
# The main driver for the DopamineAPI
|
5
6
|
class DopamineKit
|
7
|
+
|
8
|
+
##
|
9
|
+
# Get your credentials from dashboard.usedopamine.com and enter them during initilization
|
10
|
+
#
|
6
11
|
def initialize(appID, productionSecret, developmentSecret, inProduction, versionID)
|
12
|
+
@clientSDKVersion = '3.0.0'
|
13
|
+
@persistentMetaData = Hash.new
|
7
14
|
@debugMode = true
|
8
15
|
|
9
16
|
@credentials = {
|
@@ -11,39 +18,18 @@ class DopamineKit
|
|
11
18
|
:secret => inProduction ? productionSecret : developmentSecret,
|
12
19
|
:versionID => versionID
|
13
20
|
}
|
14
|
-
|
15
|
-
@persistentMetadata = Hash.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def addPersistentMetadata(key, value)
|
19
|
-
@persistentMetadata[key.to_sym] = value
|
20
|
-
end
|
21
|
-
|
22
|
-
def setPersistentMetadata(hash)
|
23
|
-
if hash.is_a? Hash
|
24
|
-
@persistentMetadata = hash.clone
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def clearPersistentMetadata()
|
29
|
-
@persistentMetadata.clear
|
30
|
-
end
|
31
|
-
|
32
|
-
def getPersistentMetadata()
|
33
|
-
return @persistentMetadata.clone
|
34
|
-
end
|
35
|
-
|
36
|
-
def getBasePostData()
|
37
|
-
postData = {
|
38
|
-
:clientOS => "Ruby",
|
39
|
-
:clientOSVersion => "#{RUBY_VERSION}",
|
40
|
-
:clientSDKVersion => "2.9.9",
|
41
|
-
:UTC => Time.now.utc.to_i,
|
42
|
-
:localTime => Time.now.utc.to_i,
|
43
|
-
}
|
44
|
-
return postData.merge(@credentials)
|
45
21
|
end
|
46
22
|
|
23
|
+
##
|
24
|
+
# Used to send tracking calls to the DopamineAPI.
|
25
|
+
# actionID - a descriptive name for an action or behavior to be tracked
|
26
|
+
# identity - a string used an identifier for anonymized experiments
|
27
|
+
# metaData - a hash of metadata to get better experiment results.
|
28
|
+
# Can be set to 'nil'
|
29
|
+
#
|
30
|
+
# Returns a JSON object containing a key 'status', and
|
31
|
+
# if 'status' != 200 the object contains another key 'errors'
|
32
|
+
#
|
47
33
|
def track(actionID, identity, metaData)
|
48
34
|
if !actionID.is_a? String
|
49
35
|
puts "[DopamineKit] - Invalid actionID #{actionID}"
|
@@ -57,8 +43,10 @@ class DopamineKit
|
|
57
43
|
postData = getBasePostData()
|
58
44
|
postData[:actionID] = actionID
|
59
45
|
postData[:primaryIdentity] = identity
|
60
|
-
if(metaData != nil)
|
61
|
-
postData[:metaData] = metaData.merge(@
|
46
|
+
if(metaData.is_a? Hash and metaData != nil)
|
47
|
+
postData[:metaData] = metaData.merge(@persistentMetaData){|key, meta, persistentmeta| meta}
|
48
|
+
else
|
49
|
+
postData[:metaData] = @persistentMetaData
|
62
50
|
end
|
63
51
|
|
64
52
|
response = JSON.parse( send(:tracking, postData) )
|
@@ -66,6 +54,16 @@ class DopamineKit
|
|
66
54
|
return response
|
67
55
|
end
|
68
56
|
|
57
|
+
##
|
58
|
+
# Used to send reinforcement calls to the DopamineAPI.
|
59
|
+
# actionID - registered string from the Dopamine Developer Dashboard
|
60
|
+
# identity - a string used an identifier for anonymized experiments
|
61
|
+
# metaData - a hash of metadata to get better experiment results.
|
62
|
+
# Can be set to 'nil'
|
63
|
+
#
|
64
|
+
# Returns a string that is the reinforcement decision,
|
65
|
+
# picked from a set declared on the Dopamine Developer Dashboard
|
66
|
+
#
|
69
67
|
def reinforce(actionID, identity, metaData)
|
70
68
|
if !actionID.is_a? String
|
71
69
|
puts "[DopamineKit] - Invalid actionID #{actionID}"
|
@@ -80,8 +78,10 @@ class DopamineKit
|
|
80
78
|
postData = getBasePostData()
|
81
79
|
postData[:actionID] = actionID
|
82
80
|
postData[:primaryIdentity] = identity
|
83
|
-
if(metaData != nil)
|
84
|
-
postData[:metaData] = metaData.merge(@
|
81
|
+
if(metaData.is_a? Hash and metaData != nil)
|
82
|
+
postData[:metaData] = metaData.merge(@persistentMetaData){|key, meta, persistentmeta| meta}
|
83
|
+
else
|
84
|
+
postData[:metaData] = @persistentMetaData
|
85
85
|
end
|
86
86
|
|
87
87
|
response = JSON.parse( send(:reinforcement, postData) )
|
@@ -93,6 +93,65 @@ class DopamineKit
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
|
97
|
+
##
|
98
|
+
# Add some metaData that you want to include multiple reinforce/tracking calls.
|
99
|
+
# Use setPersistentMetaData() to replace the entire persistentMetaData hashtable,
|
100
|
+
# and use clearPersistentMetaData() to clear it.
|
101
|
+
#
|
102
|
+
def addPersistentMetaData(key, value)
|
103
|
+
@persistentMetaData[key.to_sym] = value
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Replace all contents within the persistentMetaData hash,
|
108
|
+
# and replace them with the hash passed in
|
109
|
+
#
|
110
|
+
def setPersistentMetaData(hash)
|
111
|
+
if hash.is_a? Hash
|
112
|
+
@persistentMetaData = hash.clone
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Clear all entries into the persistentMetaData hash.
|
118
|
+
#
|
119
|
+
def clearPersistentMetaData()
|
120
|
+
@persistentMetaData.clear
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Retreive a copy of the persistentMetaData hash.
|
125
|
+
#
|
126
|
+
def getPersistentMetaData()
|
127
|
+
return @persistentMetaData.clone
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
############################################
|
132
|
+
##
|
133
|
+
## Internal functions
|
134
|
+
##
|
135
|
+
############################################
|
136
|
+
|
137
|
+
|
138
|
+
##
|
139
|
+
# Privately used function to get POST data with basic information and time
|
140
|
+
#
|
141
|
+
def getBasePostData()
|
142
|
+
postData = {
|
143
|
+
:clientOS => "Ruby",
|
144
|
+
:clientOSVersion => "#{RUBY_VERSION}",
|
145
|
+
:clientSDKVersion => @clientSDKVersion,
|
146
|
+
:UTC => Time.now.utc.to_i,
|
147
|
+
:localTime => Time.now.utc.to_i,
|
148
|
+
}
|
149
|
+
return postData.merge(@credentials)
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# Privately used function to send an HTTP POST
|
154
|
+
#
|
96
155
|
def send(type, data)
|
97
156
|
url = "https://api.usedopamine.com/v3/app/"
|
98
157
|
case type
|
data/lib/dopaminekit/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class Dopaminekit
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
data/tasks/rspec.rake
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dopaminekit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akash Desai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,19 +72,19 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
75
|
+
version: 1.8.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.8.2
|
83
83
|
description: This gem provides a class for interacting with the DopamineAPI from ruby.
|
84
84
|
After you have received your API key and configured the actions and reinforcements
|
85
|
-
relevant to your app on the Dopamine Developer Dashboard,
|
86
|
-
place 'tracking', and 'reinforcement' calls from inside
|
87
|
-
directly with the DopamineAPI.
|
85
|
+
relevant to your app on the [Dopamine Developer Dashboard](dashboard.usedopamine.com),
|
86
|
+
you may use this gem to place 'tracking', and 'reinforcement' calls from inside
|
87
|
+
your app that will communicate directly with the DopamineAPI.
|
88
88
|
email:
|
89
89
|
- kash650@gmail.com
|
90
90
|
executables: []
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- dopaminekit.gemspec
|
104
104
|
- lib/dopaminekit.rb
|
105
105
|
- lib/dopaminekit/version.rb
|
106
|
+
- tasks/rspec.rake
|
106
107
|
homepage: https://github.com/DopamineLabs/DopamineKit-Ruby
|
107
108
|
licenses:
|
108
109
|
- MIT
|