Breinify 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 834380f85b20847ad9a4a84b990c53cd07c000a1
4
+ data.tar.gz: 963f53dde61eb7b60c1adb2b50b529b956c198b4
5
+ SHA512:
6
+ metadata.gz: 902830b56e1ed24c50ee283af0e17e70571e5edd6d197229d593d008c1f074b403560f05d1582f03c26dcbdf7ffdf045a975ac0b0e95c0151c817ebc71f54cc7
7
+ data.tar.gz: 3a8c276d5c353ddda12939c6f843a05d09c22a34383bf848cc8ffcbcec745331c0f3afce00207b726797593a7fb1ca60529089523859b15894e6baf95a364f63
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Breinify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Breinify"
8
+ spec.version = Breinify::VERSION
9
+ spec.authors = ["Marco"]
10
+ spec.email = ["marco.recchioni@breinify.com"]
11
+
12
+ spec.summary = %q{Breinify´s DigitalDNA API puts dynamic behavior-based, people-driven data right at your fingertips.}
13
+ spec.description = %q{Breinifys 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..}
14
+ spec.homepage = 'http://www.breinfiy.com'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.1.0"
36
+
37
+ end
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Breinify.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Breinify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Breinify
2
+
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
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'Breinify'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install Breinify
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Breinify.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Breinify"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,197 @@
1
+ # require "Breinify/version"
2
+
3
+ #require 'rubygems'
4
+ #require 'uri'
5
+ #require 'net/http'
6
+
7
+ require 'net/https'
8
+ require 'json'
9
+ require 'base64'
10
+ require 'logger'
11
+
12
+ require File.join(File.dirname(__FILE__), "/Breinify/version.rb")
13
+
14
+ module Breinify
15
+
16
+ # logger
17
+ @@logger = Logger.new(STDOUT)
18
+ @@logger.sev_threshold = Logger::DEBUG
19
+ # @@logger = Logger.new('breinify.log', 'daily')
20
+
21
+
22
+ ## question should I have a class ???
23
+ class BreinConfig
24
+ end
25
+
26
+ ## default values
27
+
28
+ ##
29
+ # default endpoint of activity
30
+ @@defaultActivityEndpoint = '/activity'
31
+
32
+ ##
33
+ # default endpoint of lookup
34
+ @@defaultLookupEndpoint = '/lookup'
35
+
36
+ ##
37
+ # default breinify url
38
+ @@defaultUrl = 'https://api.breinify.com'
39
+
40
+ ##
41
+ # default secret value
42
+ @@defaultSecret = nil
43
+
44
+ ##
45
+ # default timeout
46
+ @@defaultTimeout = 6000
47
+
48
+ ## module values
49
+
50
+ ##
51
+ # url
52
+ @@url
53
+
54
+ ##
55
+ # api key
56
+ @@apiKey
57
+
58
+ ##
59
+ # secret
60
+ @@secret
61
+
62
+ ##
63
+ # timeout (in ms)
64
+ @@timeout
65
+
66
+ ##
67
+ # == Description
68
+ #
69
+ # sets the Breinify Configuration of the library for the properties supplied.
70
+ #
71
+ # - possible parameters are:
72
+ # apiKey: The API-key to be used (mandatory).
73
+ # url: The url of the API
74
+ # activityEndpoint: The end-point of the API to send activities.
75
+ # lookupEndpoint: The end-point of the API to retrieve lookup results.
76
+ # secret: The secret attached to the API-key
77
+ # timeout: The maximum amount of time in milliseconds an API-call should take.
78
+ # If the API does not response after this amount of time, the call is cancelled.
79
+ #
80
+ # If no parameters are set the default parameters will be used.
81
+ #
82
+ def self.setConfig(options = {})
83
+
84
+ if options == nil
85
+ @@logger.debug 'BreinifyConfig: values are nil'
86
+ return
87
+ end
88
+
89
+ begin
90
+ @@apiKey = options.fetch(:apiKey, '')
91
+ @@logger.debug ('apiKey: ' + @@apiKey)
92
+
93
+ @@url = options.fetch(:url, @@defaultUrl)
94
+ @@logger.debug ('url: ' + @@url)
95
+
96
+ @@activityEndpoint = options.fetch(:activityEndpoint, @@defaultActivityEndpoint)
97
+ @@logger.debug ('ActivityEndpoint: ' + @@activityEndpoint)
98
+
99
+ @@lookupEndpoint = options.fetch(:lookupEndpoint, @@defaultLookupEndpoint)
100
+ @@logger.debug ('LookupEndpoint: ' + @@lookupEndpoint)
101
+
102
+ @@secret = options.fetch(:secret, @@defaultSecret)
103
+ @@logger.debug ('Secret: ' + @@secret)
104
+
105
+ @@timeout = options.fetch(:timeout, @@defaultTimeout)
106
+ @@logger.debug ('Timeout: ' + @@timeout.to_s)
107
+
108
+ rescue Exception => e
109
+ @@logger.debug 'Exception caught: ' + e.message
110
+ @@logger.debug ' Backtrace is: ' + e.backtrace.inspect
111
+ return
112
+ end
113
+
114
+ end
115
+
116
+ ##
117
+ # == Description
118
+ #
119
+ # Sends an activity to the engine utilizing the API.
120
+ # The call is done asynchronously as a POST request.
121
+ # It is important that a valid API-key is configured prior
122
+ # to using this function.
123
+ #
124
+ # Possible parameters are:
125
+ #
126
+ # Example:
127
+ #
128
+ #
129
+ def self.activity(options = {})
130
+
131
+ if options == nil
132
+ @@logger.debug 'Breinify activity: values are nil'
133
+ return
134
+ end
135
+
136
+ begin
137
+
138
+ # url to use with actvitiy endpoint
139
+ fullUrl = @@url + @@activityEndpoint
140
+
141
+ # retrieve all the options
142
+ uri = URI(fullUrl)
143
+ header = {'accept': 'application/json'}
144
+
145
+ # unix timestamp
146
+ unixTimestamp = Time.now.getutc.to_i
147
+ @@logger.debug 'Unix timestamp is: ' + unixTimestamp.to_s
148
+
149
+ signature = nil
150
+ if @@secret != nil
151
+
152
+ activityData = options.fetch('activity', nil)
153
+ activityType = activityData.fetch('type', nil)
154
+ message = activityType + unixTimestamp.to_s + '1'
155
+ hash = OpenSSL::HMAC.digest('sha256', @@secret, message)
156
+ signature = Base64.encode64(hash).strip
157
+
158
+ @@logger.debug 'Secret value is: ' + signature
159
+ end
160
+
161
+ @@logger.debug 'activity values are: ' + options.to_s
162
+
163
+
164
+ ## the following fields have to be added
165
+ # apiKey
166
+ # unixTimestamp
167
+ # secret (if set)
168
+
169
+ data = options
170
+ data['apiKey'] = @@apiKey
171
+ data['unixTimestamp'] = unixTimestamp
172
+
173
+ if signature != nil
174
+ data['signature'] = signature
175
+ end
176
+
177
+ # Create the HTTP objects
178
+ http = Net::HTTP.new(uri.host, uri.port)
179
+ http.use_ssl = true if uri.scheme == 'https'
180
+ request = Net::HTTP::Post.new(uri.request_uri, header)
181
+ request.body = data.to_json
182
+ @@logger.debug 'JSON data is: ' + data.to_json.to_s
183
+
184
+ # Send the request
185
+ response = http.request(request)
186
+ @@logger.debug 'response from call is: ' + response
187
+
188
+ rescue Exception => e
189
+ @@logger.debug 'Exception caught: ' + e.message
190
+ @@logger.debug ' Backtrace is: ' + e.backtrace.inspect
191
+ return
192
+ end
193
+
194
+ end
195
+
196
+ end
197
+
@@ -0,0 +1,3 @@
1
+ module Breinify
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Breinify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description: Breinifys DigitalDNA API puts dynamic behavior-based, people-driven data
56
+ right at your fingertips. We believe that in many situations, a critical component
57
+ of a great user experience is personalization. With all the data available on the
58
+ web it should be easy to provide a unique experience to every visitor, and yet,
59
+ sometimes you may find yourself wondering why it is so difficult..
60
+ email:
61
+ - marco.recchioni@breinify.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - Breinify.gemspec
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/Breinify.rb
75
+ - lib/Breinify/version.rb
76
+ - rspec.rake
77
+ homepage: http://www.breinfiy.com
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Breinify´s DigitalDNA API puts dynamic behavior-based, people-driven data
102
+ right at your fingertips.
103
+ test_files: []