octocore 0.0.2
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 +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +117 -0
- data/README.md +50 -0
- data/Rakefile +138 -0
- data/bin/fakestream +258 -0
- data/lib/octocore.rb +141 -0
- data/lib/octocore/baseline.rb +131 -0
- data/lib/octocore/callbacks.rb +78 -0
- data/lib/octocore/config.rb +37 -0
- data/lib/octocore/config/config.yml +1 -0
- data/lib/octocore/config/search/index/user.yml +42 -0
- data/lib/octocore/counter.rb +265 -0
- data/lib/octocore/counter/helpers.rb +168 -0
- data/lib/octocore/helpers.rb +6 -0
- data/lib/octocore/helpers/api_consumer_helper.rb +371 -0
- data/lib/octocore/helpers/api_helper.rb +53 -0
- data/lib/octocore/helpers/api_logger.rb +14 -0
- data/lib/octocore/helpers/client_helper.rb +104 -0
- data/lib/octocore/helpers/kong_helper.rb +156 -0
- data/lib/octocore/helpers/sinatra_helper.rb +22 -0
- data/lib/octocore/kafka_bridge.rb +60 -0
- data/lib/octocore/kldivergence.rb +14 -0
- data/lib/octocore/models.rb +260 -0
- data/lib/octocore/models/contactus.rb +17 -0
- data/lib/octocore/models/enterprise.rb +76 -0
- data/lib/octocore/models/enterprise/api_event.rb +14 -0
- data/lib/octocore/models/enterprise/api_hit.rb +20 -0
- data/lib/octocore/models/enterprise/api_track.rb +13 -0
- data/lib/octocore/models/enterprise/app_init.rb +13 -0
- data/lib/octocore/models/enterprise/app_login.rb +12 -0
- data/lib/octocore/models/enterprise/app_logout.rb +12 -0
- data/lib/octocore/models/enterprise/authorization.rb +61 -0
- data/lib/octocore/models/enterprise/category.rb +14 -0
- data/lib/octocore/models/enterprise/category_baseline.rb +19 -0
- data/lib/octocore/models/enterprise/category_hit.rb +26 -0
- data/lib/octocore/models/enterprise/category_trend.rb +19 -0
- data/lib/octocore/models/enterprise/conversions.rb +69 -0
- data/lib/octocore/models/enterprise/ctr.rb +54 -0
- data/lib/octocore/models/enterprise/dimension_choice.rb +21 -0
- data/lib/octocore/models/enterprise/engagement_time.rb +43 -0
- data/lib/octocore/models/enterprise/funnel_data.rb +20 -0
- data/lib/octocore/models/enterprise/funnels.rb +126 -0
- data/lib/octocore/models/enterprise/gcm.rb +21 -0
- data/lib/octocore/models/enterprise/newsfeed_hit.rb +52 -0
- data/lib/octocore/models/enterprise/notification_hit.rb +42 -0
- data/lib/octocore/models/enterprise/page.rb +15 -0
- data/lib/octocore/models/enterprise/page_view.rb +14 -0
- data/lib/octocore/models/enterprise/pageload_time.rb +43 -0
- data/lib/octocore/models/enterprise/product.rb +22 -0
- data/lib/octocore/models/enterprise/product_baseline.rb +20 -0
- data/lib/octocore/models/enterprise/product_hit.rb +26 -0
- data/lib/octocore/models/enterprise/product_page_view.rb +13 -0
- data/lib/octocore/models/enterprise/product_trend.rb +18 -0
- data/lib/octocore/models/enterprise/push_key.rb +15 -0
- data/lib/octocore/models/enterprise/rules.rb +45 -0
- data/lib/octocore/models/enterprise/segment.rb +65 -0
- data/lib/octocore/models/enterprise/segment_data.rb +22 -0
- data/lib/octocore/models/enterprise/tag.rb +14 -0
- data/lib/octocore/models/enterprise/tag_baseline.rb +19 -0
- data/lib/octocore/models/enterprise/tag_hit.rb +26 -0
- data/lib/octocore/models/enterprise/tag_trend.rb +19 -0
- data/lib/octocore/models/enterprise/template.rb +18 -0
- data/lib/octocore/models/plans.rb +17 -0
- data/lib/octocore/models/subscribe.rb +12 -0
- data/lib/octocore/models/user.rb +22 -0
- data/lib/octocore/models/user/push_token.rb +15 -0
- data/lib/octocore/models/user/user_browser_details.rb +16 -0
- data/lib/octocore/models/user/user_location_history.rb +15 -0
- data/lib/octocore/models/user/user_persona.rb +101 -0
- data/lib/octocore/models/user/user_phone_details.rb +17 -0
- data/lib/octocore/models/user/user_profile.rb +20 -0
- data/lib/octocore/models/user/user_timeline.rb +111 -0
- data/lib/octocore/record.rb +20 -0
- data/lib/octocore/schedeuleable.rb +20 -0
- data/lib/octocore/scheduler.rb +59 -0
- data/lib/octocore/search.rb +5 -0
- data/lib/octocore/search/client.rb +33 -0
- data/lib/octocore/search/indexer.rb +0 -0
- data/lib/octocore/search/searchable.rb +18 -0
- data/lib/octocore/search/setup.rb +71 -0
- data/lib/octocore/segment.rb +285 -0
- data/lib/octocore/stats.rb +33 -0
- data/lib/octocore/trendable.rb +88 -0
- data/lib/octocore/trends.rb +158 -0
- data/lib/octocore/utils.rb +90 -0
- data/lib/octocore/version.rb +4 -0
- data/spec/lib/stats_spec.rb +20 -0
- data/spec/spec_helper.rb +103 -0
- metadata +436 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bcac24a9385b4c0d121884a5adeb0e82d00b1631
|
|
4
|
+
data.tar.gz: bcc0bcf99db9de3cf2b5072bc2d4df75caf09311
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a0070adb0ba6bac071e6416f6588b4749bf445dba882a2a2a90ec1c3730c7adb2638dc561f4e7224b19bd2a2e3ef9c0c81407be98fd4423e39cba738a6a59d24
|
|
7
|
+
data.tar.gz: 8eb6efe92b8d54bc435d967268e608a4735e3d12fd2d6c20cb9262ed2f659d41993c09796f51fd8cdb8bcdd6b3cc7a5529c2da7082c87653bbb7ea0fedf35f34
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
octocore (0.0.1)
|
|
5
|
+
cequel (~> 1.9, >= 1.9.0)
|
|
6
|
+
descriptive_statistics (~> 2.5.1, >= 2.5.0)
|
|
7
|
+
elasticsearch (~> 1.0.17, >= 1.0.17)
|
|
8
|
+
faraday (~> 0.9.2, >= 0.9.2)
|
|
9
|
+
hiredis (~> 0.6.1, >= 0.6.0)
|
|
10
|
+
hooks (~> 0.4.1, >= 0.4.1)
|
|
11
|
+
json (~> 1.8.1, >= 1.8.1)
|
|
12
|
+
rake (~> 11.1.0, >= 11.1.0)
|
|
13
|
+
redis (~> 3.2.2, >= 3.2.0)
|
|
14
|
+
resque (~> 1.26.0, >= 1.26.0)
|
|
15
|
+
resque-scheduler (~> 4.1.0, >= 4.1.0)
|
|
16
|
+
ruby-kafka (~> 0.3.2, >= 0.3.2)
|
|
17
|
+
statsd-ruby (~> 1.3.0, >= 1.3.0)
|
|
18
|
+
|
|
19
|
+
GEM
|
|
20
|
+
remote: https://rubygems.org/
|
|
21
|
+
specs:
|
|
22
|
+
activemodel (4.2.7)
|
|
23
|
+
activesupport (= 4.2.7)
|
|
24
|
+
builder (~> 3.1)
|
|
25
|
+
activesupport (4.2.7)
|
|
26
|
+
i18n (~> 0.7)
|
|
27
|
+
json (~> 1.7, >= 1.7.7)
|
|
28
|
+
minitest (~> 5.1)
|
|
29
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
30
|
+
tzinfo (~> 1.1)
|
|
31
|
+
builder (3.2.2)
|
|
32
|
+
cassandra-driver (2.1.6)
|
|
33
|
+
ione (~> 1.2)
|
|
34
|
+
cequel (1.10.0)
|
|
35
|
+
activemodel (~> 4.0)
|
|
36
|
+
cassandra-driver (~> 2.0)
|
|
37
|
+
descriptive_statistics (2.5.1)
|
|
38
|
+
diff-lcs (1.2.5)
|
|
39
|
+
elasticsearch (1.0.18)
|
|
40
|
+
elasticsearch-api (= 1.0.18)
|
|
41
|
+
elasticsearch-transport (= 1.0.18)
|
|
42
|
+
elasticsearch-api (1.0.18)
|
|
43
|
+
multi_json
|
|
44
|
+
elasticsearch-transport (1.0.18)
|
|
45
|
+
faraday
|
|
46
|
+
multi_json
|
|
47
|
+
faraday (0.9.2)
|
|
48
|
+
multipart-post (>= 1.2, < 3)
|
|
49
|
+
hiredis (0.6.1)
|
|
50
|
+
hooks (0.4.1)
|
|
51
|
+
uber (~> 0.0.14)
|
|
52
|
+
i18n (0.7.0)
|
|
53
|
+
ione (1.2.3)
|
|
54
|
+
json (1.8.3)
|
|
55
|
+
minitest (5.9.0)
|
|
56
|
+
mono_logger (1.1.0)
|
|
57
|
+
multi_json (1.12.1)
|
|
58
|
+
multipart-post (2.0.0)
|
|
59
|
+
parallel (1.9.0)
|
|
60
|
+
parallel_tests (2.5.0)
|
|
61
|
+
parallel
|
|
62
|
+
rack (1.6.4)
|
|
63
|
+
rack-protection (1.5.3)
|
|
64
|
+
rack
|
|
65
|
+
rake (11.1.2)
|
|
66
|
+
redis (3.2.2)
|
|
67
|
+
redis-namespace (1.5.2)
|
|
68
|
+
redis (~> 3.0, >= 3.0.4)
|
|
69
|
+
resque (1.26.0)
|
|
70
|
+
mono_logger (~> 1.0)
|
|
71
|
+
multi_json (~> 1.0)
|
|
72
|
+
redis-namespace (~> 1.3)
|
|
73
|
+
sinatra (>= 0.9.2)
|
|
74
|
+
vegas (~> 0.1.2)
|
|
75
|
+
resque-scheduler (4.1.0)
|
|
76
|
+
mono_logger (~> 1.0)
|
|
77
|
+
redis (~> 3.0)
|
|
78
|
+
resque (~> 1.25)
|
|
79
|
+
rufus-scheduler (~> 3.0)
|
|
80
|
+
rspec (3.4.0)
|
|
81
|
+
rspec-core (~> 3.4.0)
|
|
82
|
+
rspec-expectations (~> 3.4.0)
|
|
83
|
+
rspec-mocks (~> 3.4.0)
|
|
84
|
+
rspec-core (3.4.4)
|
|
85
|
+
rspec-support (~> 3.4.0)
|
|
86
|
+
rspec-expectations (3.4.0)
|
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
88
|
+
rspec-support (~> 3.4.0)
|
|
89
|
+
rspec-mocks (3.4.1)
|
|
90
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
91
|
+
rspec-support (~> 3.4.0)
|
|
92
|
+
rspec-support (3.4.1)
|
|
93
|
+
ruby-kafka (0.3.10)
|
|
94
|
+
rufus-scheduler (3.2.1)
|
|
95
|
+
sinatra (1.4.7)
|
|
96
|
+
rack (~> 1.5)
|
|
97
|
+
rack-protection (~> 1.4)
|
|
98
|
+
tilt (>= 1.3, < 3)
|
|
99
|
+
statsd-ruby (1.3.0)
|
|
100
|
+
thread_safe (0.3.5)
|
|
101
|
+
tilt (2.0.5)
|
|
102
|
+
tzinfo (1.2.2)
|
|
103
|
+
thread_safe (~> 0.1)
|
|
104
|
+
uber (0.0.15)
|
|
105
|
+
vegas (0.1.11)
|
|
106
|
+
rack (>= 1.0.0)
|
|
107
|
+
|
|
108
|
+
PLATFORMS
|
|
109
|
+
ruby
|
|
110
|
+
|
|
111
|
+
DEPENDENCIES
|
|
112
|
+
octocore!
|
|
113
|
+
parallel_tests (~> 2.5.0, >= 2.5.0)
|
|
114
|
+
rspec (~> 3.4.0, >= 3.4.0)
|
|
115
|
+
|
|
116
|
+
BUNDLED WITH
|
|
117
|
+
1.11.2
|
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# octo-core
|
|
2
|
+
|
|
3
|
+
This is the Octomatic Enterprise Core gem. It provides most of the ORM stuff. Class and modules for different tables.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
**Rake Tasks**
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
rake cequel:keyspace:create # Initialize Cassandra keyspace
|
|
10
|
+
rake cequel:keyspace:drop # Drop Cassandra keyspace
|
|
11
|
+
rake octo:init # Create keyspace and tables for all defined models
|
|
12
|
+
rake octo:migrate # Synchronize all models defined in `lib/octocore/models' with Cassandra database schema
|
|
13
|
+
rake octo:reset # Drop keyspace if exists, then create and migrate
|
|
14
|
+
rake spec # Run RSpec code examples
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
# Building
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
./bin/clean_setup.sh
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
# Specs
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
lang=bash
|
|
27
|
+
rake spec
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Verifying connectivity
|
|
31
|
+
|
|
32
|
+
You can use the following set of commands in `irb` to verify all things working with this gem. Execute it from irb in PROJ_DIR.
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
require 'octocore';config_dir = 'lib/octocore/config/';Octo.connect_with(config_dir);nil
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Creating fake stream
|
|
39
|
+
|
|
40
|
+
It ships with a utility called `fakestream`. It will automatically stream random data. To use just open your console and type
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
fakestream
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Optionally provide a config file for octo to connect as
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
fakestream /path/to/octo_config.yml
|
|
50
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
require 'cequel'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require 'redis'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
|
|
6
|
+
require 'octocore/helpers/kong_helper'
|
|
7
|
+
require 'octocore/config'
|
|
8
|
+
|
|
9
|
+
RSpec::Core::RakeTask.new('spec')
|
|
10
|
+
|
|
11
|
+
task :environment do
|
|
12
|
+
config_dir = 'lib/octocore/config/'
|
|
13
|
+
config = {}
|
|
14
|
+
Dir[config_dir + '**{,/*/**}/*.yml'].each do |file|
|
|
15
|
+
_config = YAML.load_file(file)
|
|
16
|
+
if _config
|
|
17
|
+
puts "loading from file: #{ file }"
|
|
18
|
+
config = config.merge(_config.deep_symbolize_keys)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
Octo.load_config config
|
|
22
|
+
connection = Cequel.connect(Octo.get_config(:cassandra))
|
|
23
|
+
Cequel::Record.connection = connection
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Load default tasks from Cequel
|
|
27
|
+
spec = Gem::Specification.find_by_name 'cequel'
|
|
28
|
+
load "#{spec.gem_dir}/lib/cequel/record/tasks.rb"
|
|
29
|
+
|
|
30
|
+
# Remove those tasks from cequel which we shall override
|
|
31
|
+
%w(cequel:init cequel:migrate cequel:reset).each do |t|
|
|
32
|
+
Rake.application.instance_variable_get('@tasks').delete(t)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Overriding rake actions
|
|
36
|
+
namespace :octo do
|
|
37
|
+
|
|
38
|
+
desc 'Create keyspace and tables for all defined models'
|
|
39
|
+
task :init => %w(cequel:keyspace:create octo:migrate)
|
|
40
|
+
|
|
41
|
+
desc 'Drop keyspace if exists, then create and migrate'
|
|
42
|
+
task :reset => :environment do
|
|
43
|
+
kong_delete
|
|
44
|
+
clear_cache
|
|
45
|
+
if Cequel::Record.connection.schema.exists?
|
|
46
|
+
task('cequel:keyspace:drop').invoke
|
|
47
|
+
end
|
|
48
|
+
task('cequel:keyspace:create').invoke
|
|
49
|
+
migrate
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
desc "Synchronize all models defined in `lib/octocore/models' with Cassandra " \
|
|
53
|
+
"database schema"
|
|
54
|
+
task :migrate => :environment do
|
|
55
|
+
migrate
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Delete Kong Consumers and Apis
|
|
60
|
+
def kong_delete
|
|
61
|
+
Octo::Helpers::KongBridge.delete_all
|
|
62
|
+
puts 'Kong Cleaned'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Clear Cache
|
|
66
|
+
def clear_cache
|
|
67
|
+
default_cache = {
|
|
68
|
+
host: '127.0.0.1', port: 6379
|
|
69
|
+
}
|
|
70
|
+
redis = Redis.new(default_cache.merge(driver: :hiredis))
|
|
71
|
+
redis.flushall
|
|
72
|
+
puts 'Cache Cleaned'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def migrate
|
|
76
|
+
watch_stack = ActiveSupport::Dependencies::WatchStack.new
|
|
77
|
+
|
|
78
|
+
migration_table_names = Set[]
|
|
79
|
+
|
|
80
|
+
classes = Set[]
|
|
81
|
+
|
|
82
|
+
project_root = Dir.pwd
|
|
83
|
+
models_dir_path = "#{File.expand_path('lib/octocore/models', project_root)}/"
|
|
84
|
+
model_files = Dir.glob(File.join(models_dir_path, '**', '*.rb'))
|
|
85
|
+
|
|
86
|
+
model_files.sort.each do |file|
|
|
87
|
+
watch_namespaces = ["Object"]
|
|
88
|
+
model_file_name = file.sub(/^#{Regexp.escape(models_dir_path)}/, "")
|
|
89
|
+
dirname = File.dirname(model_file_name)
|
|
90
|
+
watch_namespaces << dirname.classify unless dirname == "."
|
|
91
|
+
watch_stack.watch_namespaces(watch_namespaces)
|
|
92
|
+
|
|
93
|
+
require_dependency(file)
|
|
94
|
+
|
|
95
|
+
new_constants = watch_stack.new_constants
|
|
96
|
+
if new_constants.empty?
|
|
97
|
+
_new = model_file_name.sub(/\.rb$/, "")
|
|
98
|
+
if Octo.constants.include?_new.classify.to_sym
|
|
99
|
+
new_constants << "Octo"
|
|
100
|
+
else
|
|
101
|
+
new_constants << "Octo"
|
|
102
|
+
#new_constants << _new.classify
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
new_constants.each do |class_name|
|
|
107
|
+
begin
|
|
108
|
+
clazz = class_name.constantize
|
|
109
|
+
rescue LoadError, RuntimeError, NameError => e
|
|
110
|
+
puts e
|
|
111
|
+
else
|
|
112
|
+
if clazz.is_a?(Class)
|
|
113
|
+
if clazz.ancestors.include?(Cequel::Record) &&
|
|
114
|
+
!migration_table_names.include?(clazz.table_name.to_sym)
|
|
115
|
+
clazz.synchronize_schema
|
|
116
|
+
migration_table_names << clazz.table_name.to_sym
|
|
117
|
+
puts "** Synchronized schema for #{class_name}"
|
|
118
|
+
end
|
|
119
|
+
elsif clazz.is_a?(Module)
|
|
120
|
+
method_name = :constants
|
|
121
|
+
clazzes = clazz.public_send(method_name) if clazz.respond_to? method_name
|
|
122
|
+
clazzes.each do |_clazz|
|
|
123
|
+
_cls = clazz.const_get(_clazz)
|
|
124
|
+
if _cls.is_a?(Class) and !classes.include?_cls
|
|
125
|
+
if _cls.ancestors.include?(Cequel::Record) &&
|
|
126
|
+
!migration_table_names.include?(_cls.table_name.to_sym)
|
|
127
|
+
_cls.synchronize_schema
|
|
128
|
+
migration_table_names << _cls.table_name.to_sym
|
|
129
|
+
puts "Synchronized schema for #{_cls}"
|
|
130
|
+
classes << _cls
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
data/bin/fakestream
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# A simple utility to generate fake stream of data
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# ./fakestream
|
|
7
|
+
|
|
8
|
+
require 'net/http'
|
|
9
|
+
require 'json'
|
|
10
|
+
|
|
11
|
+
require 'octocore'
|
|
12
|
+
|
|
13
|
+
module Octo
|
|
14
|
+
class FakeStream
|
|
15
|
+
|
|
16
|
+
BASE_URL = 'http://127.0.0.1:8000'
|
|
17
|
+
|
|
18
|
+
MAX_USERS = 100
|
|
19
|
+
|
|
20
|
+
MAX_PAGES = 30
|
|
21
|
+
MAX_PRODUCTS = 200
|
|
22
|
+
|
|
23
|
+
MAX_CATEGORIES = 10
|
|
24
|
+
|
|
25
|
+
MAX_TAGS = 15
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
#How many no. of pages to view before going to product page
|
|
31
|
+
MAX_PAGES_TO_VISIT = 3
|
|
32
|
+
|
|
33
|
+
# Initialize with the URL
|
|
34
|
+
def initialize
|
|
35
|
+
@_apikeys = {}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def stream
|
|
39
|
+
user = fakeuser
|
|
40
|
+
|
|
41
|
+
# simulate an app login
|
|
42
|
+
app_init user
|
|
43
|
+
|
|
44
|
+
# simulate a random number of page views before going to product
|
|
45
|
+
for i in 1..(1+rand(MAX_PAGES_TO_VISIT))
|
|
46
|
+
pv user, fakepage(user.enterprise)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# simulate a product page view
|
|
50
|
+
ppv user, fakeproduct(user.enterprise)
|
|
51
|
+
|
|
52
|
+
#visit a page or not after going to the product page
|
|
53
|
+
for i in 0..rand(2)
|
|
54
|
+
pv user, fakepage(user.enterprise)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def stream_forever
|
|
60
|
+
while 1
|
|
61
|
+
stream
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
# Create an APP INIT request
|
|
68
|
+
def app_init(user)
|
|
69
|
+
payload = {
|
|
70
|
+
userId: user.id,
|
|
71
|
+
phoneDetails: phonedetails
|
|
72
|
+
}
|
|
73
|
+
key = apikey(user.enterprise)
|
|
74
|
+
url = '/events/app.init/'
|
|
75
|
+
post(url, key, payload)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Create a page view request
|
|
79
|
+
def pv(user, page)
|
|
80
|
+
payload = {
|
|
81
|
+
userId: user.id,
|
|
82
|
+
phoneDetails: phonedetails,
|
|
83
|
+
routeUrl: page.routeurl,
|
|
84
|
+
categories: fakecategories,
|
|
85
|
+
tags: faketags,
|
|
86
|
+
}
|
|
87
|
+
key = apikey user.enterprise
|
|
88
|
+
url = '/events/page.view/'
|
|
89
|
+
post(url, key, payload)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Create a product page view request
|
|
94
|
+
def ppv(user, product)
|
|
95
|
+
payload = {
|
|
96
|
+
userId: user.id,
|
|
97
|
+
phoneDetails: phonedetails,
|
|
98
|
+
routeUrl: product.routeurl,
|
|
99
|
+
categories: fakecategories,
|
|
100
|
+
tags: faketags,
|
|
101
|
+
productId: product.id,
|
|
102
|
+
productName: product.name,
|
|
103
|
+
price: product.price
|
|
104
|
+
}
|
|
105
|
+
key = apikey user.enterprise
|
|
106
|
+
url = '/events/productpage.view/'
|
|
107
|
+
post(url, key, payload)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Hash containing phone details
|
|
111
|
+
# @return [Hash]
|
|
112
|
+
def phonedetails
|
|
113
|
+
{
|
|
114
|
+
deviceId: 'FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9',
|
|
115
|
+
manufacturer: 'Apple',
|
|
116
|
+
model: 'iPhone 6',
|
|
117
|
+
latitude: 28.6139,
|
|
118
|
+
longitude: 77.209
|
|
119
|
+
}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Creates a fake user for the enterprise on the fly
|
|
123
|
+
# @param [Octo::Enterprise] enterprise
|
|
124
|
+
# @return [Octo::User]
|
|
125
|
+
def fakeuser(enterprise = enterprises.to_a.sample)
|
|
126
|
+
Octo::User.new(enterprise_id: enterprise.id,
|
|
127
|
+
id: rand(MAX_USERS))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Generates a fake page for the enterprise
|
|
131
|
+
# @param [Octo::Enterprise] enterprise
|
|
132
|
+
# @return [Octo::Product]
|
|
133
|
+
def fakepage(enterprise)
|
|
134
|
+
id = rand(MAX_PAGES)
|
|
135
|
+
Octo::Page.new(
|
|
136
|
+
enterprise_id: enterprise.id,
|
|
137
|
+
routeurl: "/PageUrl/#{ id }",
|
|
138
|
+
categories: fakecategories,
|
|
139
|
+
tags: faketags
|
|
140
|
+
)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# Generates a fake product for the enterprise
|
|
145
|
+
# @param [Octo::Enterprise] enterprise
|
|
146
|
+
# @return [Octo::Product]
|
|
147
|
+
def fakeproduct(enterprise)
|
|
148
|
+
id = rand(MAX_PRODUCTS)
|
|
149
|
+
Octo::Product.new(
|
|
150
|
+
enterprise_id: enterprise.id,
|
|
151
|
+
id: id,
|
|
152
|
+
price: rand(10000).to_f,
|
|
153
|
+
name: "Fake Product #{ id }",
|
|
154
|
+
routeurl: "/Some/Url/#{ id }",
|
|
155
|
+
categories: fakecategories,
|
|
156
|
+
tags: faketags
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Generates fake categories
|
|
161
|
+
# @return [Array<String>] Array of fake categories
|
|
162
|
+
def fakecategories(count = 2)
|
|
163
|
+
(0..MAX_CATEGORIES).to_a.sample(count).collect { |x| "Fake Category #{ x }"}
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Generates fake tags
|
|
167
|
+
# @return [Array<String>] Array of fake tags
|
|
168
|
+
def faketags(count = 2)
|
|
169
|
+
(0..MAX_TAGS).to_a.sample(count).collect { |x| "Fake Tag #{ x }"}
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Fetches the APIKey for the enterprise
|
|
173
|
+
def apikey(enterprise)
|
|
174
|
+
unless @_apikeys.has_key?(enterprise.id)
|
|
175
|
+
@_apikeys[enterprise.id] = Octo::Authorization.find_by_username(enterprise.name).apikey
|
|
176
|
+
end
|
|
177
|
+
@_apikeys[enterprise.id]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Creates the URI
|
|
181
|
+
def uri(url = BASE_URL)
|
|
182
|
+
URI(url)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Find all enterprises
|
|
186
|
+
# @return [Cequel::RecordSet]
|
|
187
|
+
def enterprises
|
|
188
|
+
Octo::Enterprise.all.select { |x| !x.name.nil? and x.fakedata? }
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Make the POST call
|
|
192
|
+
# @param [String] url The endpoint url
|
|
193
|
+
# @param [String] apikey The API Key
|
|
194
|
+
# @param [Hash] payload The payload
|
|
195
|
+
def post(url, apikey, payload)
|
|
196
|
+
headers = {
|
|
197
|
+
'Content-Type' => 'application/json',
|
|
198
|
+
'Accept' => 'application/json',
|
|
199
|
+
'apikey' => apikey
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
_uri = uri(BASE_URL + url)
|
|
203
|
+
req = Net::HTTP::Post.new(_uri, headers)
|
|
204
|
+
req.content_type = 'application/json'
|
|
205
|
+
req.body = payload.to_json
|
|
206
|
+
|
|
207
|
+
res = Net::HTTP.start(_uri.hostname, _uri.port) do |http|
|
|
208
|
+
http.request(req)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
case res
|
|
212
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
213
|
+
puts res.body
|
|
214
|
+
else
|
|
215
|
+
puts res.value
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# All the main Job
|
|
224
|
+
def _main(config_file)
|
|
225
|
+
|
|
226
|
+
# setup signal trap
|
|
227
|
+
Signal.trap('INT') {
|
|
228
|
+
puts 'Halting on user request'
|
|
229
|
+
exit
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
# connect Octo and start the show
|
|
233
|
+
Octo.connect_with config_file
|
|
234
|
+
streamer = Octo::FakeStream.new
|
|
235
|
+
streamer.stream_forever
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def main
|
|
239
|
+
config_file = if ARGV[0]
|
|
240
|
+
ARGV[0]
|
|
241
|
+
else
|
|
242
|
+
spec = Gem::Specification.find_by_name('octocore')
|
|
243
|
+
gem_root = spec.gem_dir
|
|
244
|
+
File.join(gem_root, 'lib', 'octocore' ,'config')
|
|
245
|
+
end
|
|
246
|
+
puts config_file
|
|
247
|
+
if File.exist?config_file
|
|
248
|
+
_main(config_file)
|
|
249
|
+
else
|
|
250
|
+
puts "Config file '#{ config_file }' does not exist. Exiting..."
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
main
|
|
255
|
+
|
|
256
|
+
if __FILE__ == $0
|
|
257
|
+
main
|
|
258
|
+
end
|