Breinify 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -9
- data/Breinify-0.1.3.gem +0 -0
- data/{LICENSE.txt → LICENSE} +4 -4
- data/README.md +104 -12
- data/bin/htmldiff +17 -0
- data/bin/ldiff +17 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/brein-api-library-ruby.iml +12 -0
- data/lib/Breinify.rb +246 -157
- data/lib/Breinify/version.rb +1 -1
- data/logo.png +0 -0
- metadata +11 -5
- data/Breinify-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 527fdbae4a1b4eed237e4c56d470592d1bb3e56f
|
4
|
+
data.tar.gz: 7570e979cdab3fe7ed78759ca4dce7e4e36246a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 257effaec403472bdd8501c4b176f219dfe1b40bbf0cccae1479062e136252aba2b1ade9dd11682b3f01dbc4fc99fe0a0147b19040a37fa64e1ec0377cc9fa2c
|
7
|
+
data.tar.gz: c92f4c511a429cda111e3145df5264c28f23b33d985dfdd9b0ac469c9a6fa3a2fdc39811b77d617e0cc876ee2e16a906c29175ea85e244c7874982eeb1ae3465
|
data/.gitignore
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
# Libraries #
|
2
|
+
######################
|
3
|
+
|
4
|
+
|
5
|
+
# Targets #
|
6
|
+
######################
|
7
|
+
|
8
|
+
|
9
|
+
# Configurations #
|
10
|
+
######################
|
11
|
+
|
12
|
+
|
13
|
+
# OS generated files #
|
14
|
+
######################
|
15
|
+
**/.DS_Store
|
16
|
+
**/.DS_Store?
|
data/Breinify-0.1.3.gem
ADDED
Binary file
|
data/{LICENSE.txt → LICENSE}
RENAMED
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
# Breinify
|
2
1
|
|
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/Breinify`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
2
|
|
5
|
-
|
3
|
+
<p align="center">
|
4
|
+
<img src="https://raw.githubusercontent.com/Breinify/brein-api-library-java/master/documentation/img/logo.png" alt="Breinify API Java Library" width="250">
|
5
|
+
</p>
|
6
6
|
|
7
|
-
|
7
|
+
<p align="center">
|
8
|
+
Breinify's DigitalDNA API puts dynamic behavior-based, people-driven data right at your fingertips.
|
9
|
+
</p>
|
10
|
+
|
11
|
+
### Step By Step Introduction
|
12
|
+
|
13
|
+
#### What is Breinify's DigitialDNA
|
14
|
+
|
15
|
+
Breinify's DigitalDNA API puts dynamic behavior-based, people-driven data right at your fingertips. We believe that in many situations, a critical component of a great user experience is personalization. With all the data available on the web it should be easy to provide a unique experience to every visitor, and yet, sometimes you may find yourself wondering why it is so difficult.
|
16
|
+
|
17
|
+
Thanks to **Breinify's DigitalDNA** you are now able to adapt your online presence to your visitors needs and **provide a unique experience**. Let's walk step-by-step through a simple example.
|
18
|
+
|
19
|
+
### Quick start
|
20
|
+
|
21
|
+
#### Step 1: Installation
|
8
22
|
|
9
23
|
Add this line to your application's Gemfile:
|
10
24
|
|
@@ -20,22 +34,100 @@ Or install it yourself as:
|
|
20
34
|
|
21
35
|
$ gem install Breinify
|
22
36
|
|
23
|
-
## Usage
|
24
37
|
|
25
|
-
|
38
|
+
#### Step 2: Configure the library
|
39
|
+
|
40
|
+
In order to use the library you need a valid API-key, which you can get for free at [https://www.breinify.com](https://www.breinify.com). In this example, we assume you have the following api-key:
|
41
|
+
|
42
|
+
**772A-47D7-93A3-4EA9-9D73-85B9-479B-16C6**
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# configure
|
46
|
+
Breinify.setConfig({'apiKey' => '772A-47D7-93A3-4EA9-9D73-85B9-479B-16C6',
|
47
|
+
'activityEndpoint' => '/activity',
|
48
|
+
'lookupEndpoint' => '/lookup',
|
49
|
+
'secret' => 'lmcoj4k2ttzz66qamhg!=',
|
50
|
+
'timeout' => 1000,
|
51
|
+
'category' => 'food'
|
52
|
+
'url' => 'https://api.breinify.com'})
|
53
|
+
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
The Breinify class is now configured with a valid configuration object.
|
58
|
+
|
59
|
+
|
60
|
+
#### Step 3: Start using the library
|
61
|
+
|
62
|
+
##### Placing activity triggers
|
26
63
|
|
27
|
-
|
64
|
+
The engine powering the DigitalDNA API provides two endpoints. The first endpoint is used to inform the engine about the activities performed by visitors of your site. The activities are used to understand the user's current interest and infer the intent. It becomes more and more accurate across different users and verticals as more activities are collected. It should be noted, that any personal information is not stored within the engine, thus each individual's privacy is well protected. The engine understands several different activities performed by a user, e.g., landing, login, search, item selection, or logout.
|
28
65
|
|
29
|
-
|
66
|
+
The engine is informed of an activity by executing *Breinify.activity(...)*.
|
30
67
|
|
31
|
-
|
68
|
+
```Ruby
|
69
|
+
# invoke the activity call
|
70
|
+
Breinify.activity({'user' => {'firstName' => 'Fred',
|
71
|
+
'email' => 'Fred.Firestone@email.com',
|
72
|
+
'lastName' => 'Firestone',
|
73
|
+
'sessionId' => 'r3V2kDAvFFL_-RBhuc_-Dg'},
|
74
|
+
'activity' => {
|
75
|
+
'description' => 'this is the description',
|
76
|
+
'type' => 'checkout',
|
77
|
+
'category' => 'food',
|
78
|
+
'tags' => {'string' => 'string',
|
79
|
+
'int' => 5,
|
80
|
+
'double' => 9.1,
|
81
|
+
'array' => %w(a b c),
|
82
|
+
'null' => nil}
|
83
|
+
}
|
84
|
+
})
|
32
85
|
|
33
|
-
|
86
|
+
```
|
87
|
+
|
88
|
+
That's it! The call will be invoked.
|
89
|
+
|
90
|
+
The following snippets shows a different approach:
|
91
|
+
|
92
|
+
```Ruby
|
93
|
+
|
94
|
+
userData = Hash.new
|
95
|
+
userData['email'] = 'fred.firestone@email.com'
|
96
|
+
userData['lastName'] = 'Fred'
|
97
|
+
userData['firstName'] = 'Firestone'
|
98
|
+
userData['sessionId'] = 'aa8!scdfsf8988'
|
99
|
+
|
100
|
+
additionalData = Hash.new
|
101
|
+
additionalData['referrer'] = 'https://sampleurl.com/track'
|
102
|
+
additionalData['url'] = 'https://sampleurl.com/'
|
103
|
+
|
104
|
+
userData['additional'] = additionalData
|
105
|
+
|
106
|
+
activityData = Hash.new
|
107
|
+
activityData['description'] = 'this is the description'
|
108
|
+
activityData['type'] = 'checkout'
|
34
109
|
|
35
|
-
|
110
|
+
requestData = Hash.new
|
111
|
+
requestData['user'] = userData
|
112
|
+
requestData['activity'] = activityData
|
113
|
+
requestData['ipAddress'] = '10.111.222.333'
|
114
|
+
|
115
|
+
Breinify.activity(requestData)
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
That's it! The call will be invoked.
|
36
120
|
|
37
121
|
|
38
|
-
|
122
|
+
|
123
|
+
### Further information
|
124
|
+
|
125
|
+
|
126
|
+
### License
|
39
127
|
|
40
128
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
129
|
|
130
|
+
### Further links
|
131
|
+
To understand all the capabilities of Breinify's DigitalDNA API, take a look at:
|
132
|
+
|
133
|
+
* [Breinify's Website](https://www.breinify.com).
|
data/bin/htmldiff
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("diff-lcs", "htmldiff")
|
data/bin/ldiff
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'ldiff' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("diff-lcs", "ldiff")
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
7
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
8
|
+
</content>
|
9
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-2.3.1 [rails5.0]" jdkType="RUBY_SDK" />
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
11
|
+
</component>
|
12
|
+
</module>
|
data/lib/Breinify.rb
CHANGED
@@ -3,61 +3,22 @@ require 'json'
|
|
3
3
|
require 'base64'
|
4
4
|
require 'logger'
|
5
5
|
|
6
|
-
require File.join(File.dirname(__FILE__),
|
6
|
+
require File.join(File.dirname(__FILE__), '/Breinify/version.rb')
|
7
7
|
|
8
8
|
module Breinify
|
9
9
|
|
10
|
-
# logger
|
11
|
-
@@logger = Logger.new(STDOUT)
|
12
|
-
@@logger.sev_threshold = Logger::DEBUG
|
13
|
-
# @@logger = Logger.new('breinify.log', 'daily')
|
14
|
-
|
15
|
-
## default values
|
16
|
-
|
17
|
-
##
|
18
|
-
# default endpoint of activity
|
19
|
-
@@defaultActivityEndpoint = '/activity'
|
20
|
-
|
21
|
-
##
|
22
|
-
# default endpoint of lookup
|
23
|
-
@@defaultLookupEndpoint = '/lookup'
|
24
|
-
|
25
|
-
##
|
26
|
-
# default breinify url
|
27
|
-
@@defaultUrl = 'https://api.breinify.com'
|
28
|
-
|
29
|
-
##
|
30
|
-
# default secret value
|
31
|
-
@@defaultSecret = nil
|
32
|
-
|
33
10
|
##
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
##
|
38
|
-
|
39
|
-
##
|
40
|
-
# contains the url
|
41
|
-
@@url
|
42
|
-
|
43
|
-
##
|
44
|
-
# contains the api key
|
45
|
-
@@apiKey
|
46
|
-
|
47
|
-
##
|
48
|
-
# contains the secret
|
49
|
-
@@secret
|
50
|
-
|
51
|
-
##
|
52
|
-
# contains the timeout (in ms)
|
53
|
-
@@timeout
|
11
|
+
# LOGGING
|
12
|
+
# logger
|
13
|
+
$log = Logger.new(STDOUT)
|
14
|
+
## $log = Logger.new('breinify.log', 'daily')
|
15
|
+
$log.sev_threshold = Logger::DEBUG
|
54
16
|
|
55
17
|
##
|
56
18
|
# == Description
|
19
|
+
# Provides the configuration of the library for the properties supplied.
|
57
20
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# - possible parameters are:
|
21
|
+
# Possible parameters are:
|
61
22
|
# apiKey: The API-key to be used (mandatory).
|
62
23
|
# url: The url of the API
|
63
24
|
# activityEndpoint: The end-point of the API to send activities.
|
@@ -67,124 +28,265 @@ module Breinify
|
|
67
28
|
# If the API does not response after this amount of time, the call is cancelled.
|
68
29
|
#
|
69
30
|
# If no parameters are set the default parameters will be used.
|
70
|
-
|
71
|
-
|
31
|
+
class BreinConfig
|
32
|
+
|
33
|
+
##
|
34
|
+
# default endpoint of activity
|
35
|
+
DEF_ACTIVITY_ENDPOINT = '/activity'
|
36
|
+
|
37
|
+
##
|
38
|
+
# default endpoint of lookup
|
39
|
+
DEF_LOOKUP_ENDPOINT = '/lookup'
|
40
|
+
|
41
|
+
##
|
42
|
+
# default breinify url
|
43
|
+
DEF_URL = 'https://api.breinify.com'
|
44
|
+
|
45
|
+
##
|
46
|
+
# default secret value
|
47
|
+
DEF_SECRET = nil
|
48
|
+
|
49
|
+
##
|
50
|
+
# default timeout (open in seconds)
|
51
|
+
DEF_TIMEOUT = 6
|
52
|
+
|
53
|
+
##
|
54
|
+
# default category
|
55
|
+
DEF_CATEGORY = nil
|
56
|
+
|
57
|
+
# instance members
|
58
|
+
attr_accessor :url,
|
59
|
+
:api_key,
|
60
|
+
:secret,
|
61
|
+
:timeout,
|
62
|
+
:activity_endpoint,
|
63
|
+
:lookup_endpoint,
|
64
|
+
:category
|
65
|
+
|
66
|
+
##
|
67
|
+
# === Description
|
68
|
+
#
|
69
|
+
def initialize
|
70
|
+
end
|
71
|
+
|
72
|
+
# create an instance of BreinConfig
|
73
|
+
@@instance = BreinConfig.new
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
# disallow creation
|
76
|
+
#
|
77
|
+
private_class_method :new
|
78
|
+
|
79
|
+
##
|
80
|
+
# === Description
|
81
|
+
# Returns the instance of BreinConfig (Singleton Pattern)
|
82
|
+
#
|
83
|
+
def self.instance
|
84
|
+
return @@instance
|
76
85
|
end
|
77
86
|
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
##
|
88
|
+
# == Description
|
89
|
+
# Sets the configuration for the API
|
90
|
+
#
|
91
|
+
def set_config(options = {})
|
92
|
+
if options == nil
|
93
|
+
$log.debug 'BreinifyConfig: values are nil'
|
94
|
+
return
|
95
|
+
end
|
81
96
|
|
82
|
-
|
83
|
-
|
97
|
+
begin
|
98
|
+
@api_key = options.fetch('apiKey', '')
|
99
|
+
$log.debug ('apiKey: ' + @api_key)
|
84
100
|
|
85
|
-
|
86
|
-
|
101
|
+
@url = options.fetch('url', DEF_URL)
|
102
|
+
$log.debug ('url: ' + @url)
|
87
103
|
|
88
|
-
|
89
|
-
|
104
|
+
@activity_endpoint = options.fetch('activityEndpoint', DEF_ACTIVITY_ENDPOINT)
|
105
|
+
$log.debug ('ActivityEndpoint: ' + @activity_endpoint)
|
90
106
|
|
91
|
-
|
92
|
-
|
107
|
+
@lookup_endpoint = options.fetch('lookupEndpoint', DEF_LOOKUP_ENDPOINT)
|
108
|
+
$log.debug ('LookupEndpoint: ' + @lookup_endpoint)
|
93
109
|
|
94
|
-
|
95
|
-
|
110
|
+
@secret = options.fetch('secret', DEF_SECRET)
|
111
|
+
$log.debug ('Secret: ' + @secret)
|
96
112
|
|
97
|
-
|
98
|
-
|
99
|
-
@@logger.debug ' Backtrace is: ' + e.backtrace.inspect
|
100
|
-
return
|
101
|
-
end
|
113
|
+
@timeout = options.fetch('timeout', DEF_TIMEOUT)
|
114
|
+
$log.debug ('Timeout: ' + @timeout.to_s)
|
102
115
|
|
116
|
+
@category = options.fetch('category', DEF_CATEGORY)
|
117
|
+
$log.debug ('Category: ' + @category)
|
118
|
+
rescue Exception => e
|
119
|
+
$log.debug 'Exception caught: ' + e.message
|
120
|
+
$log.debug ' Backtrace is: ' + e.backtrace.inspect
|
121
|
+
return
|
122
|
+
end
|
123
|
+
end
|
103
124
|
end
|
104
125
|
|
105
126
|
##
|
106
127
|
# == Description
|
128
|
+
# Sends an activity to the engine utilizing the API. The call is done as a POST request.
|
129
|
+
# It is important that a valid API-key is configured prior to using this function.
|
107
130
|
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
if options == nil
|
121
|
-
@@logger.debug 'Breinify activity: values are nil'
|
122
|
-
return
|
131
|
+
class BreinActivity
|
132
|
+
|
133
|
+
attr_accessor :http,
|
134
|
+
:request,
|
135
|
+
:initDone
|
136
|
+
|
137
|
+
##
|
138
|
+
# Create an instance of BreinConfig
|
139
|
+
#
|
140
|
+
def initialize
|
141
|
+
@brein_config = BreinConfig.instance
|
142
|
+
@initDone = false
|
123
143
|
end
|
124
144
|
|
125
|
-
|
145
|
+
##
|
146
|
+
# Initializes the HTTP context
|
147
|
+
def init_rest
|
148
|
+
|
149
|
+
# if the initialization has already been done then go back
|
150
|
+
if @initDone
|
151
|
+
return
|
152
|
+
end
|
126
153
|
|
127
|
-
#
|
128
|
-
|
129
|
-
@@logger.debug 'Unix timestamp is: ' + unixTimestamp.to_s
|
154
|
+
# url to use with activity endpoint
|
155
|
+
full_url = @brein_config.url + @brein_config.activity_endpoint
|
130
156
|
|
131
|
-
|
157
|
+
# retrieve all the options
|
158
|
+
uri = URI(full_url)
|
132
159
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
160
|
+
# Create the HTTP objects
|
161
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
162
|
+
@http.open_timeout = @brein_config.timeout
|
163
|
+
@http.use_ssl = true if uri.scheme == 'https'
|
137
164
|
|
138
|
-
|
139
|
-
|
140
|
-
data['unixTimestamp'] = unixTimestamp
|
165
|
+
# request itself
|
166
|
+
@request = Net::HTTP::Post.new(uri.request_uri, {'accept': 'application/json'})
|
141
167
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
168
|
+
# indicates that the initializing for HTTP instance variables has been done
|
169
|
+
@initDone = true
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Singleton Pattern
|
174
|
+
@@instance = BreinActivity.new
|
175
|
+
|
176
|
+
# disallow creation
|
177
|
+
#
|
178
|
+
private_class_method :new
|
179
|
+
|
180
|
+
##
|
181
|
+
# returns the BreinActivity instance
|
182
|
+
#
|
183
|
+
def self.instance
|
184
|
+
return @@instance
|
185
|
+
end
|
146
186
|
|
147
|
-
|
148
|
-
|
187
|
+
##
|
188
|
+
# Sends an activity to the engine.
|
189
|
+
#
|
190
|
+
def send_activity(options = {})
|
191
|
+
|
192
|
+
if options == nil
|
193
|
+
$log.debug 'Breinify activity: values are nil'
|
194
|
+
return
|
195
|
+
end
|
149
196
|
|
150
|
-
# fetch previous values - if they exists
|
151
197
|
begin
|
152
|
-
|
153
|
-
|
198
|
+
# unix timestamp
|
199
|
+
unix_timestamp = Time.now.getutc.to_i
|
200
|
+
$log.debug 'Unix timestamp is: ' + unix_timestamp.to_s
|
201
|
+
$log.debug 'activity values are: ' + options.to_s
|
202
|
+
|
203
|
+
## the following fields will be added (apiKey, unixTimestamp, secret [if set])
|
204
|
+
data = options
|
205
|
+
data['apiKey'] = @brein_config.api_key
|
206
|
+
data['unixTimestamp'] = unix_timestamp
|
207
|
+
|
208
|
+
# handles the secret / signature
|
209
|
+
signature = handle_signature(options, unix_timestamp)
|
210
|
+
if signature != nil
|
211
|
+
data['signature'] = signature
|
212
|
+
end
|
213
|
+
|
214
|
+
## retrieve the userAgent and set it if available
|
215
|
+
user_agent = get_user_agent
|
216
|
+
|
217
|
+
# fetch previous values - if they exists
|
218
|
+
begin
|
219
|
+
additional_values = options.fetch('user', {}).fetch('additional', {})
|
220
|
+
if additional_values.empty?
|
154
221
|
|
155
|
-
|
156
|
-
|
222
|
+
user_agent_hash = Hash.new
|
223
|
+
user_agent_hash['userAgent'] = user_agent
|
157
224
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
225
|
+
user_data = options.fetch('user', {})
|
226
|
+
user_data['additional'] = user_agent_hash
|
227
|
+
else
|
228
|
+
additional_values['userAgent'] = user_agent
|
229
|
+
end
|
230
|
+
rescue
|
231
|
+
$log.debug 'Could not handle userAgent information'
|
162
232
|
end
|
163
|
-
|
164
|
-
|
233
|
+
|
234
|
+
## check if category has been set, otherwise add default from BreinConfig
|
235
|
+
category_value = options.fetch('activity', {}).fetch('category', {})
|
236
|
+
if category_value.empty?
|
237
|
+
default_category = @brein_config.category
|
238
|
+
category_data = options.fetch('activity', {})
|
239
|
+
category_data['category'] = default_category
|
240
|
+
end
|
241
|
+
|
242
|
+
# prepare the body and send the request
|
243
|
+
init_rest
|
244
|
+
request.body = data.to_json
|
245
|
+
$log.debug 'JSON data request is: ' + data.to_json.to_s
|
246
|
+
|
247
|
+
# Send the request
|
248
|
+
response = http.request(request)
|
249
|
+
$log.debug 'response from call is: ' + response.to_s
|
250
|
+
|
251
|
+
rescue Exception => e
|
252
|
+
$log.debug 'Exception caught: ' + e.message
|
253
|
+
$log.debug ' Backtrace is: ' + e.backtrace.inspect
|
254
|
+
return
|
165
255
|
end
|
166
256
|
|
167
|
-
|
168
|
-
fullUrl = @@url + @@activityEndpoint
|
257
|
+
end
|
169
258
|
|
170
|
-
|
171
|
-
|
259
|
+
##
|
260
|
+
# == Description
|
261
|
+
#
|
262
|
+
# Tries to retrieve the user agent
|
263
|
+
#
|
264
|
+
def get_user_agent
|
265
|
+
begin
|
266
|
+
user_agent = request.user_agent
|
267
|
+
$log.debug 'userAgent is: ' + user_agent
|
268
|
+
rescue
|
269
|
+
$log.debug 'Sorry, no userAgent can be detected'
|
270
|
+
user_agent = nil
|
271
|
+
end
|
272
|
+
user_agent
|
273
|
+
end
|
172
274
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
275
|
+
##
|
276
|
+
# == Description
|
277
|
+
#
|
278
|
+
# This method will crypt the signature.
|
279
|
+
#
|
280
|
+
def handle_signature(options, unix_timestamp)
|
281
|
+
signature = nil
|
282
|
+
if @brein_config.secret != nil
|
283
|
+
activity_data = options.fetch('activity', nil)
|
284
|
+
activity_type = activity_data.fetch('type', nil)
|
285
|
+
message = activity_type + unix_timestamp.to_s + '1'
|
286
|
+
hash = OpenSSL::HMAC.digest('sha256', @brein_config.secret, message)
|
287
|
+
signature = Base64.encode64(hash).strip
|
288
|
+
end
|
289
|
+
signature
|
188
290
|
end
|
189
291
|
|
190
292
|
end
|
@@ -192,37 +294,24 @@ module Breinify
|
|
192
294
|
##
|
193
295
|
# == Description
|
194
296
|
#
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@@logger.debug 'Sorry, no userAgent can be detected'
|
201
|
-
userAgent = nil
|
202
|
-
end
|
203
|
-
userAgent
|
297
|
+
# sets the Breinify Configuration of the library for the properties supplied.
|
298
|
+
#
|
299
|
+
#
|
300
|
+
def self.set_config(options = {})
|
301
|
+
BreinConfig.instance.set_config(options)
|
204
302
|
end
|
205
303
|
|
206
304
|
##
|
207
305
|
# == Description
|
208
306
|
#
|
209
|
-
#
|
307
|
+
# Sends an activity to the engine utilizing the API.
|
308
|
+
# The call is done as a POST request.
|
309
|
+
# It is important that a valid API-key is configured prior
|
310
|
+
# to using this function.
|
210
311
|
#
|
211
|
-
def self.
|
212
|
-
|
213
|
-
if @@secret != nil
|
214
|
-
|
215
|
-
activityData = options.fetch('activity', nil)
|
216
|
-
activityType = activityData.fetch('type', nil)
|
217
|
-
message = activityType + unixTimestamp.to_s + '1'
|
218
|
-
hash = OpenSSL::HMAC.digest('sha256', @@secret, message)
|
219
|
-
signature = Base64.encode64(hash).strip
|
220
|
-
|
221
|
-
@@logger.debug 'Secret value is: ' + signature
|
222
|
-
end
|
223
|
-
signature
|
312
|
+
def self.activity(options = {})
|
313
|
+
BreinActivity.instance.send_activity(options)
|
224
314
|
end
|
225
315
|
|
226
|
-
|
227
316
|
end
|
228
317
|
|
data/lib/Breinify/version.rb
CHANGED
data/logo.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Breinify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,16 +64,22 @@ extensions: []
|
|
64
64
|
extra_rdoc_files: []
|
65
65
|
files:
|
66
66
|
- ".gitignore"
|
67
|
-
- Breinify-0.1.
|
67
|
+
- Breinify-0.1.3.gem
|
68
68
|
- Breinify.gemspec
|
69
69
|
- Gemfile
|
70
|
-
- LICENSE
|
70
|
+
- LICENSE
|
71
71
|
- README.md
|
72
72
|
- Rakefile
|
73
73
|
- bin/console
|
74
|
+
- bin/htmldiff
|
75
|
+
- bin/ldiff
|
76
|
+
- bin/rake
|
77
|
+
- bin/rspec
|
74
78
|
- bin/setup
|
79
|
+
- brein-api-library-ruby.iml
|
75
80
|
- lib/Breinify.rb
|
76
81
|
- lib/Breinify/version.rb
|
82
|
+
- logo.png
|
77
83
|
homepage: http://www.breinfiy.com
|
78
84
|
licenses:
|
79
85
|
- MIT
|
@@ -94,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
100
|
version: '0'
|
95
101
|
requirements: []
|
96
102
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.5.1
|
98
104
|
signing_key:
|
99
105
|
specification_version: 4
|
100
106
|
summary: Breinify´s DigitalDNA API puts dynamic behavior-based, people-driven data
|
data/Breinify-0.1.0.gem
DELETED
Binary file
|