octocore 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0ea80f8160f1f05b3d5259a207e76f7b2c75410
4
- data.tar.gz: 80624160dd4076191d70c284fcb6c25bce21f660
3
+ metadata.gz: 57da45f6015209dc84edccb5100950f1142874e4
4
+ data.tar.gz: cc6cc5ce82f388aba3d0ecc34a2aa41d6637b25a
5
5
  SHA512:
6
- metadata.gz: efbe9cdda85b673d4adf8e7b4764cfe4eed2aad44e84c35a6f7a70b691ee82461994cb37ddde95fc85f3cd40f643af54d84fde4dab8e02a1232c21a83f0f3c27
7
- data.tar.gz: 8116ecd4d607d55a64823920e48156a2f74dd3388121af4887d91321e82554336fa6b6f50227ef4774ba58c5e774a9fb0f4a840462a004d574e133f80d61162b
6
+ metadata.gz: f11d644298e9cb9cace499cd7d638fb507687b4f7420bbce09955f0b30053f27dd3645065ab14d4542ad6cf615c6a908db25535f48b8840a71227c57dce965df
7
+ data.tar.gz: 715fd3946f9081dabc8ad6713b85189be6e738c6f1d0e45518f1baa36ab3bffab6fa814b6054205c8a2f2841023b4a2a8017f6c4a83987b970ae3f8d6efc55dc
File without changes
data/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ end
10
+
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- octocore (0.0.2)
4
+ octocore (0.0.3)
5
5
  cequel (~> 1.9, >= 1.9.0)
6
6
  descriptive_statistics (~> 2.5.1, >= 2.5.0)
7
7
  elasticsearch (~> 1.0.17, >= 1.0.17)
@@ -82,20 +82,20 @@ GEM
82
82
  redis (~> 3.0)
83
83
  resque (~> 1.25)
84
84
  rufus-scheduler (~> 3.0)
85
- rspec (3.4.0)
86
- rspec-core (~> 3.4.0)
87
- rspec-expectations (~> 3.4.0)
88
- rspec-mocks (~> 3.4.0)
89
- rspec-core (3.4.4)
90
- rspec-support (~> 3.4.0)
91
- rspec-expectations (3.4.0)
85
+ rspec (3.5.0)
86
+ rspec-core (~> 3.5.0)
87
+ rspec-expectations (~> 3.5.0)
88
+ rspec-mocks (~> 3.5.0)
89
+ rspec-core (3.5.2)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-expectations (3.5.0)
92
92
  diff-lcs (>= 1.2.0, < 2.0)
93
- rspec-support (~> 3.4.0)
94
- rspec-mocks (3.4.1)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-mocks (3.5.0)
95
95
  diff-lcs (>= 1.2.0, < 2.0)
96
- rspec-support (~> 3.4.0)
97
- rspec-support (3.4.1)
98
- ruby-kafka (0.3.11)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-support (3.5.0)
98
+ ruby-kafka (0.3.12)
99
99
  rufus-scheduler (3.2.1)
100
100
  sinatra (1.4.7)
101
101
  rack (~> 1.5)
@@ -116,4 +116,8 @@ PLATFORMS
116
116
  DEPENDENCIES
117
117
  octocore!
118
118
  parallel_tests (~> 2.5.0, >= 2.5.0)
119
- rspec (~> 3.4.0, >= 3.4.0)
119
+ rake
120
+ rspec
121
+
122
+ BUNDLED WITH
123
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
File without changes
data/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Octo.ai, (C) 2015,2016 Aurora Borealis Technologies Pvt. Ltd.
2
+
3
+ This product includes software developed at Aurora Borealis Technologies Pvt. Ltd (https://octo.ai/).
4
+
5
+ The Octoai project contains unmodified/modified subcomponents too with
6
+ separate copyright notices and license terms. Your use of the source
7
+ code for these subcomponents is subject to the terms and conditions
8
+ of the following licenses.
data/README.md CHANGED
@@ -2,29 +2,44 @@
2
2
 
3
3
  This is the Octomatic Enterprise Core gem. It provides most of the ORM stuff. Class and modules for different tables.
4
4
 
5
+ ## Installting
5
6
 
6
- **Rake Tasks**
7
+ - `gem install octocore`
8
+
9
+
10
+
11
+ ## DB Migrations
12
+
13
+ ### OctoAdmin CLI
14
+
15
+ This gem comes with a handy utility called `octocore-admin`. You can use this utility for db migrations, reset and init.
7
16
 
8
17
  ```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
18
+ $ octocore-admin action path/to/config/dir
15
19
  ```
16
20
 
17
- # Building
21
+ Where
22
+
23
+ - `action`: The action to be performed. One of `init`, `migrate` or `reset`
24
+ - `/path/to/config/dir`: The path where your config dir is placed
25
+
26
+
27
+ # Development
28
+
29
+ ## Clone the repo
30
+
31
+ `$ git clone git@github.com:octoai/gem-octocore.git`
32
+
33
+ ## Building
18
34
 
19
35
  ```bash
20
- ./bin/clean_setup.sh
36
+ $ ./bin/clean_setup.sh
21
37
  ```
22
38
 
23
- # Specs
39
+ ## Specs
24
40
 
25
- ```
26
- lang=bash
27
- rake spec
41
+ ```bash
42
+ $ rake spec
28
43
  ```
29
44
 
30
45
  # Verifying connectivity
@@ -32,9 +47,9 @@ rake spec
32
47
  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
48
 
34
49
  ```ruby
35
- %w(octocore).each { |x| require x }
36
- config_file = 'lib/octocore/config/config.yml'
37
- Octo.connect_with_config_file(config_file)
50
+ require 'octocore'
51
+ config_dir = '/path/to/config/dir'
52
+ Octo.connect_with_config_file config_dir
38
53
  ```
39
54
 
40
55
  # Creating fake stream
@@ -42,11 +57,5 @@ Octo.connect_with_config_file(config_file)
42
57
  It ships with a utility called `fakestream`. It will automatically stream random data. To use just open your console and type
43
58
 
44
59
  ```
45
- fakestream
46
- ```
47
-
48
- Optionally provide a config file for octo to connect as
49
-
50
- ```
51
- fakestream /path/to/octo_config.yml
60
+ $ fakestream /path/to/config/dir
52
61
  ```
data/Rakefile CHANGED
@@ -9,13 +9,13 @@ require 'octocore/config'
9
9
  RSpec::Core::RakeTask.new('spec')
10
10
 
11
11
  task :environment do
12
- config_dir = 'lib/octocore/config'
12
+ config_dir = ENV['CONFIG_DIR'] || 'lib/octocore/config/'
13
13
  config = {}
14
- Dir['**{,/*/**}/*.yml'].each do |file|
14
+ Dir[config_dir + '**{,/*/**}/*.yml'].each do |file|
15
15
  _config = YAML.load_file(file)
16
16
  if _config
17
17
  puts "loading from file: #{ file }"
18
- config.merge!(_config.deep_symbolize_keys)
18
+ config = config.merge(_config.deep_symbolize_keys)
19
19
  end
20
20
  end
21
21
  Octo.load_config config
@@ -36,7 +36,7 @@ end
36
36
  namespace :octo do
37
37
 
38
38
  desc 'Create keyspace and tables for all defined models'
39
- task :init => %w(cequel:keyspace:create octo:migrate)
39
+ task :init => %w(environment cequel:keyspace:create octo:migrate)
40
40
 
41
41
  desc 'Drop keyspace if exists, then create and migrate'
42
42
  task :reset => :environment do
@@ -136,3 +136,4 @@ def migrate
136
136
  end
137
137
  end
138
138
  end
139
+
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A simple utility to provide easy migrations, reset
4
+ # and all the rake tasks that you may need to do
5
+
6
+ # ./octocore-admin --tasks
7
+
8
+ require 'open3'
9
+
10
+ module Octo
11
+ module CliAdmin
12
+
13
+ VALID_ACTIONS = %w(init migrate reset)
14
+
15
+ module ClassMethods
16
+ def perform(action, config_dir)
17
+ if VALID_ACTIONS.include?(action)
18
+ cmd = ['rake', '-f', spec.gem_dir + '/Rakefile',
19
+ '--verbose', "octo:#{ action }",
20
+ "CONFIG_DIR=#{ config_dir }"]
21
+ #STDOUT.puts "** Executing: #{ cmd }"
22
+ Open3.popen3(*cmd) do |stdout, stderr, status, thread|
23
+ stderr.sync = true
24
+ while line=stderr.gets do
25
+ puts(line)
26
+ end
27
+ end
28
+ else
29
+ STDOUT.puts "Invalid action: #{ action }"
30
+ end
31
+ end
32
+
33
+ def spec
34
+ @spec ||= Gem::Specification.find_by_name 'octocore'
35
+ end
36
+ end
37
+
38
+ class Cli
39
+ extend ClassMethods
40
+ end
41
+
42
+ def self.main
43
+ STDOUT.sync = true
44
+ action = ARGV[0]
45
+ config_dir = ARGV[1]
46
+ Octo::CliAdmin::Cli.perform(action, config_dir)
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+
53
+ Octo::CliAdmin.main
54
+
@@ -4,6 +4,8 @@ require 'logger'
4
4
 
5
5
  require 'octocore/version'
6
6
  require 'octocore/config'
7
+ require 'octocore/featureflag'
8
+
7
9
  require 'octocore/models'
8
10
  require 'octocore/counter'
9
11
  require 'octocore/email'
@@ -19,6 +21,8 @@ require 'octocore/segment'
19
21
  require 'octocore/mailer'
20
22
  require 'octocore/scheduler'
21
23
 
24
+ require 'octocore/message_parser'
25
+
22
26
  require 'octocore/schedeuleable'
23
27
  require 'octocore/helpers'
24
28
  require 'octocore/kafka_bridge'
@@ -143,4 +147,4 @@ module Octo
143
147
  @logger
144
148
  end
145
149
 
146
- end
150
+ end
@@ -70,10 +70,12 @@ module Octo
70
70
  # product_page_view to redis.
71
71
  # It self expires in n seconds from last hit
72
72
  def add_session(opts)
73
- if opts.has_key?(:type)
74
- createRedisShadowKey(opts[:enterprise].id.to_s + '_' + opts[:user].id.to_s,
75
- opts[:type].to_s,
76
- Octo.get_config(:session_length))
73
+ if Octo.is_not_flagged?(Octo::Funnel)
74
+ if opts.has_key?(:type)
75
+ createRedisShadowKey(opts[:enterprise].id.to_s + '_' + opts[:user].id.to_s,
76
+ opts[:type].to_s,
77
+ Octo.get_config(:session_length))
78
+ end
77
79
  end
78
80
  end
79
81
 
@@ -102,4 +104,4 @@ module Octo
102
104
  include Hooks
103
105
  include Octo::OctoHooks
104
106
  end
105
- end
107
+ end
@@ -3,7 +3,7 @@ require 'resque'
3
3
  require 'resque-scheduler'
4
4
 
5
5
  module Octo
6
-
6
+
7
7
  # Octo Email Sender
8
8
  module Email
9
9
 
@@ -16,7 +16,7 @@ module Octo
16
16
  raise ArgumentError, 'Email Address or Subject is missing'
17
17
  else
18
18
  message = {
19
- from_name: Octo.get_config(:email_sender).fetch(:name),
19
+ from_name: Octo.get_config(:email_sender).fetch(:name),
20
20
  from_email: Octo.get_config(:email_sender).fetch(:email),
21
21
 
22
22
  subject: subject,
@@ -30,7 +30,8 @@ module Octo
30
30
  }]
31
31
  }
32
32
  # Pass the message to resque only when mandrill key is present
33
- if Octo.get_config(:mandrill_api_key) != ''
33
+ _mandrill_config = ENV['MANDRILL_API_KEY'] || Octo.get_config(:mandrill_api_key)
34
+ if _mandrill_config and !_mandrill_config.empty?
34
35
  enqueue_msg(message)
35
36
  end
36
37
  end
@@ -46,16 +47,17 @@ module Octo
46
47
 
47
48
  # Class to perform Resque operations for sending email
48
49
  class EmailSender
49
-
50
+
50
51
  @queue = :email_sender
51
-
52
+
52
53
  # Resque Perform method
53
54
  # @param [Hash] message The details of email
54
55
  def self.perform(message)
55
- m = Mandrill::API.new Octo.get_config(:mandrill_api_key)
56
+ _mandrill_config = ENV['MANDRILL_API_KEY'] || Octo.get_config(:mandrill_api_key)
57
+ m = Mandrill::API.new _mandrill_config
56
58
  m.messages.send message
57
59
  end
58
60
 
59
61
  end
62
+ end
60
63
 
61
- end
@@ -0,0 +1,77 @@
1
+ require 'set'
2
+
3
+ module Octo
4
+
5
+ # The FeatureFlag Module
6
+ #
7
+ # This module flags some functionalities as OFF or DISABLED state.
8
+ module FeatureFlag
9
+
10
+ def self.included(base)
11
+ base.extend ClassMethods
12
+ end
13
+
14
+ module ClassMethods
15
+
16
+ # Set the featureflag for a module or class to the state. If the
17
+ # featureflag is set to true, it means that the feature is disabled. If
18
+ # the featureflag is set to false, it means that the feature is enabled.
19
+ #
20
+ # It also defined a `is_flagged?` method on the module which returns
21
+ # the state of featureflag
22
+ #
23
+ # @param [Module] klass The class or module to be feature flagged
24
+ # @param [Boolean] state The boolean state to set for the class
25
+ #
26
+ def featureflag(klass, state)
27
+ if state
28
+ unless flags.include?klass
29
+ flags << klass
30
+ klass.instance_eval do
31
+ def is_flagged?
32
+ true
33
+ end
34
+ end
35
+ end
36
+ else
37
+ if flags.include?klass
38
+ flags.delete(klass)
39
+ klass.instance_eval do
40
+ def is_flagged?
41
+ false
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # Get the list of all flags
49
+ # @return [Set] A set of all flags
50
+ #
51
+ def flags
52
+ @flags ||= Set.new([])
53
+ end
54
+
55
+ # Helper method to find if a module is feature flagged or not
56
+ # @param [Module] feature The module to be tested
57
+ # @return [Boolean] Boolean value specifying if the feature is flagged
58
+ # or not
59
+ #
60
+ def is_flagged?(feature)
61
+ flags.include?feature
62
+ end
63
+
64
+ # Returns if the flag is not set
65
+ # @param [Module] feature The module to be tested
66
+ # @return [Boolean] Boolean value specifying the status
67
+ #
68
+ def is_not_flagged?(feature)
69
+ !is_flagged?feature
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ include FeatureFlag
76
+ end
77
+
@@ -4,8 +4,10 @@ require 'set'
4
4
  module Octo
5
5
  module Helpers
6
6
 
7
+ # Helper Module for Octo Consumer
7
8
  module ApiConsumerHelper
8
9
  extend Cequel::Metal
10
+
9
11
  # Get all the valid events
10
12
  # @return [Set<Symbol>] Valid events globally
11
13
  def valid_events
@@ -20,95 +22,103 @@ module Octo
20
22
  Set.new(%w(app.init app.login app.logout page.view productpage.view update.profile))
21
23
  end
22
24
 
25
+ # Handles Kafka messages and perform required operations
26
+ # @param [Hash] msg Hash Message
23
27
  def handle(msg)
24
- msg_dump = msg
25
- msg = parse(msg)
26
- eventName = msg.delete(:event_name)
27
- if (valid_events.include?eventName)
28
- enterprise = checkEnterprise(msg)
29
- unless enterprise
30
- Octo.logger.info 'Unable to find enterprise. Something\'s wrong'
31
- end
32
- user = checkUser(enterprise, msg)
33
-
34
- hook_opts = {
35
- enterprise: enterprise,
36
- user: user
37
- }
38
-
39
- if api_events.include?eventName
40
- hook_opts[:event] = register_api_event(enterprise, eventName)
41
- Octo::ApiTrack.new(customid: msg[:id],
42
- created_at: Time.now,
43
- json_dump: msg_dump,
44
- type: eventName).save!
45
- end
28
+ msg_obj = Octo::Message::Message.new(msg)
29
+ msg = msg_obj.to_h
30
+ eventName = msg.delete(:event_name)
31
+ if (valid_events.include?eventName)
32
+ enterprise = checkEnterprise(msg)
33
+ unless enterprise
34
+ Octo.logger.info 'Unable to find enterprise. Something\'s wrong'
35
+ end
36
+ user = checkUser(enterprise, msg)
37
+
38
+ hook_opts = {
39
+ enterprise: enterprise,
40
+ user: user
41
+ }
42
+
43
+ if api_events.include?eventName
44
+ hook_opts[:event] = register_api_event(enterprise, eventName)
45
+ Octo::ApiTrack.new(customid: msg[:id],
46
+ created_at: Time.now,
47
+ json_dump: msg_obj.message,
48
+ type: eventName).save!
49
+ end
46
50
 
47
- case eventName
48
- when 'app.init'
49
- Octo::AppInit.new(enterprise: enterprise,
50
- created_at: Time.now,
51
- userid: user.id).save!
52
- updateUserDeviceDetails(user, msg)
53
- hook_opts.merge!({type: 'init'})
54
- call_hooks(eventName, hook_opts)
55
- when 'app.login'
56
- Octo::AppLogin.new(enterprise: enterprise,
57
- created_at: Time.now,
58
- userid: user.id).save!
59
- updateUserDeviceDetails(user, msg)
60
- call_hooks(eventName, hook_opts)
61
- when 'app.logout'
62
- event = Octo::AppLogout.new(enterprise: enterprise,
63
- created_at: Time.now,
64
- userid: user.id).save!
65
- updateUserDeviceDetails(user, msg)
66
- call_hooks(eventName, hook_opts)
67
- when 'page.view'
68
- page, categories, tags = checkPage(enterprise, msg)
69
- Octo::PageView.new(enterprise: enterprise,
70
- created_at: Time.now,
71
- userid: user.id,
72
- routeurl: page.routeurl
73
- ).save!
74
- hook_opts.merge!({type: page.routeurl})
75
- updateUserDeviceDetails(user, msg)
76
- call_hooks(eventName, hook_opts)
77
- when 'productpage.view'
78
- product, categories, tags = checkProduct(enterprise, msg)
79
- Octo::ProductPageView.new(
80
- enterprise: enterprise,
81
- created_at: Time.now,
82
- userid: user.id,
83
- product_id: product.id
84
- ).save!
85
- updateUserDeviceDetails(user, msg)
86
- hook_opts.merge!({ product: product,
87
- categories: categories,
88
- tags: tags,
89
- type: product.routeurl
90
- })
91
- call_hooks(eventName, hook_opts)
92
- when 'update.profile'
93
- checkUserProfileDetails(enterprise, user, msg)
94
- updateUserDeviceDetails(user, msg)
95
- call_hooks(eventName, hook_opts)
96
- when 'update.push_token'
97
- checkPushToken(enterprise, user, msg)
98
- checkPushKey(enterprise, msg)
99
- when 'funnel_update'
100
- checkRedisSession(enterprise,msg)
101
- end
51
+ case eventName
52
+ when 'app.init'
53
+ Octo::AppInit.new(enterprise: enterprise,
54
+ created_at: Time.now,
55
+ userid: user.id).save!
56
+ updateUserDeviceDetails(user, msg)
57
+ hook_opts.merge!({type: 'init'})
58
+ call_hooks(eventName, hook_opts)
59
+ when 'app.login'
60
+ Octo::AppLogin.new(enterprise: enterprise,
61
+ created_at: Time.now,
62
+ userid: user.id).save!
63
+ updateUserDeviceDetails(user, msg)
64
+ call_hooks(eventName, hook_opts)
65
+ when 'app.logout'
66
+ event = Octo::AppLogout.new(enterprise: enterprise,
67
+ created_at: Time.now,
68
+ userid: user.id).save!
69
+ updateUserDeviceDetails(user, msg)
70
+ call_hooks(eventName, hook_opts)
71
+ when 'page.view'
72
+ page, categories, tags = checkPage(enterprise, msg)
73
+ Octo::PageView.new(enterprise: enterprise,
74
+ created_at: Time.now,
75
+ userid: user.id,
76
+ routeurl: page.routeurl
77
+ ).save!
78
+ hook_opts.merge!({type: page.routeurl})
79
+ updateUserDeviceDetails(user, msg)
80
+ call_hooks(eventName, hook_opts)
81
+ when 'productpage.view'
82
+ product, categories, tags = checkProduct(enterprise, msg)
83
+ Octo::ProductPageView.new(
84
+ enterprise: enterprise,
85
+ created_at: Time.now,
86
+ userid: user.id,
87
+ product_id: product.id
88
+ ).save!
89
+ updateUserDeviceDetails(user, msg)
90
+ hook_opts.merge!({ product: product,
91
+ categories: categories,
92
+ tags: tags,
93
+ type: product.routeurl
94
+ })
95
+ call_hooks(eventName, hook_opts)
96
+ when 'update.profile'
97
+ checkUserProfileDetails(enterprise, user, msg)
98
+ updateUserDeviceDetails(user, msg)
99
+ call_hooks(eventName, hook_opts)
100
+ when 'update.push_token'
101
+ checkPushToken(enterprise, user, msg)
102
+ checkPushKey(enterprise, msg)
103
+ when 'funnel_update'
104
+ checkRedisSession(enterprise,msg)
102
105
  end
106
+ end
103
107
  end
104
108
 
105
109
  private
106
110
 
111
+ # Make an entry of Event type
112
+ # @param [Octo::Enterprise] enterprise
113
+ # @param [String] event_name Name of Event
107
114
  def register_api_event(enterprise, event_name)
108
115
  Octo::ApiEvent.findOrCreate({ enterprise_id: enterprise.id,
109
116
  eventname: event_name})
110
117
  end
111
118
 
119
+ # Set Octo callbacks
120
+ # @param [String] event Event name
121
+ # @param [Hash] *args Points to the messsage hash
112
122
  def call_hooks(event, *args)
113
123
  hook = [:after, event.gsub('.', '_')].join('_').to_sym
114
124
  Octo::Callbacks.run_hook(hook, *args)
@@ -158,6 +168,11 @@ module Octo
158
168
  Octo::FunnelTracker.findOrCreateOrAdjust(args_from,counters)
159
169
  end
160
170
 
171
+ # Creeate or Update Profile details of a user
172
+ # @param [Octo::Enterprise] enterprise Object of enterprise model
173
+ # @param [Octo::User] user Object of user model
174
+ # @param [Hash] msg Hash of message
175
+ # @return [Octo::UserProfileDetails] User Profile
161
176
  def checkUserProfileDetails(enterprise, user, msg)
162
177
  args = {
163
178
  user_id: user.id,
@@ -357,70 +372,6 @@ module Octo
357
372
  end
358
373
  end
359
374
 
360
- def parse(msg)
361
- msg2 = JSON.parse(msg)
362
- msg = msg2
363
- m = { event_name: msg['event_name'] }
364
- case msg['event_name']
365
- when 'funnel_update'
366
- m.merge!({
367
- rediskey: msg['rediskey']
368
- })
369
- # return m
370
- when 'update.profile'
371
- m.merge!({
372
- profileDetails: msg['profileDetails']
373
- })
374
- when 'page.view'
375
- m.merge!({
376
- routeUrl: msg['routeUrl'],
377
- categories: msg.fetch('categories', []),
378
- tags: msg.fetch('tags', [])
379
- })
380
- when 'productpage.view'
381
- m.merge!({
382
- routeUrl: msg['routeUrl'],
383
- categories: msg.fetch('categories', []),
384
- tags: msg.fetch('tags', []),
385
- productId: msg['productId'],
386
- productName: msg['productName'],
387
- price: msg['price']
388
- })
389
- when 'update.push_token'
390
- m.merge!({
391
- pushType: msg['notificationType'],
392
- pushKey: msg['pushKey'],
393
- pushToken: msg['pushToken']
394
- })
395
- end
396
- enterprise = msg['enterprise']
397
- raise StandardError, 'Parse Error' if enterprise.nil?
398
-
399
- eid = if enterprise.has_key?'custom_id'
400
- enterprise['custom_id']
401
- elsif enterprise.has_key?'customId'
402
- enterprise['customId']
403
- end
404
-
405
- ename = if enterprise.has_key?'user_name'
406
- enterprise['user_name']
407
- elsif enterprise.has_key?'userName'
408
- enterprise['userName']
409
- else
410
- nil
411
- end
412
- m.merge!({
413
- id: msg.fetch('uuid', nil),
414
- enterpriseId: eid,
415
- enterpriseName: ename,
416
- phone: msg.fetch('phoneDetails', nil),
417
- browser: msg.fetch('browserDetails', nil),
418
- userId: msg.fetch('userId', -1),
419
- created_at: Time.now
420
- })
421
-
422
- m
423
- end
424
375
  end
425
376
  end
426
377
  end
@@ -0,0 +1,99 @@
1
+ require 'json'
2
+ require 'set'
3
+
4
+ module Octo
5
+ # Message abstraction module
6
+ module Message
7
+
8
+ # Parsing kafka messages for octo consumer
9
+ module MessageParser
10
+
11
+ # Parsing Message hash in Octo compatible form
12
+ # @param [Hash] Message Hash
13
+ # @return [Hash] Hash in Octo form
14
+ def parse(msg)
15
+ msg = JSON.parse(msg)
16
+ m = { event_name: msg['event_name'] }
17
+ case msg['event_name']
18
+ when 'funnel_update'
19
+ m.merge!({
20
+ rediskey: msg['rediskey']
21
+ })
22
+ when 'update.profile'
23
+ m.merge!({
24
+ profileDetails: msg['profileDetails']
25
+ })
26
+ when 'page.view'
27
+ m.merge!({
28
+ routeUrl: msg['routeUrl'],
29
+ categories: msg.fetch('categories', []),
30
+ tags: msg.fetch('tags', [])
31
+ })
32
+ when 'productpage.view'
33
+ m.merge!({
34
+ routeUrl: msg['routeUrl'],
35
+ categories: msg.fetch('categories', []),
36
+ tags: msg.fetch('tags', []),
37
+ productId: msg['productId'],
38
+ productName: msg['productName'],
39
+ price: msg['price']
40
+ })
41
+ when 'update.push_token'
42
+ m.merge!({
43
+ pushType: msg['notificationType'],
44
+ pushKey: msg['pushKey'],
45
+ pushToken: msg['pushToken']
46
+ })
47
+ end
48
+ enterprise = msg['enterprise']
49
+ raise StandardError, 'Parse Error' if enterprise.nil?
50
+
51
+ eid = if enterprise.has_key?'custom_id'
52
+ enterprise['custom_id']
53
+ elsif enterprise.has_key?'customId'
54
+ enterprise['customId']
55
+ end
56
+
57
+ ename = if enterprise.has_key?'user_name'
58
+ enterprise['user_name']
59
+ elsif enterprise.has_key?'userName'
60
+ enterprise['userName']
61
+ else
62
+ nil
63
+ end
64
+ m.merge!({
65
+ id: msg.fetch('uuid', nil),
66
+ enterpriseId: eid,
67
+ enterpriseName: ename,
68
+ phone: msg.fetch('phoneDetails', nil),
69
+ browser: msg.fetch('browserDetails', nil),
70
+ userId: msg.fetch('userId', -1),
71
+ created_at: Time.now
72
+ })
73
+
74
+ m
75
+ end
76
+
77
+ end
78
+
79
+ # To handle message abstraction
80
+ class Message
81
+ include MessageParser
82
+
83
+ attr_reader :message
84
+
85
+ # Converting Message hash in Octo compatible form
86
+ # @param [Hash] Message Hash
87
+ def initialize(msg)
88
+ @message = msg
89
+ end
90
+
91
+ # To get hash message
92
+ # @return [Hash] Message Hash
93
+ def to_h
94
+ parse(@message)
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -6,6 +6,9 @@ module Octo
6
6
 
7
7
  # Stores the funnel for the enterprise
8
8
  class Funnel
9
+
10
+ Octo.featureflag self, true
11
+
9
12
  include Cequel::Record
10
13
  include Octo::Record
11
14
 
@@ -7,6 +7,8 @@ module Octo
7
7
  # The Segmentation module
8
8
  module Segmentation
9
9
 
10
+ Octo.featureflag self, true
11
+
10
12
  extend ActiveSupport::Concern
11
13
 
12
14
  module Helpers
@@ -0,0 +1,4 @@
1
+ task :environment do
2
+ end
3
+
4
+
@@ -1,4 +1,4 @@
1
1
  module Octo
2
2
  # The current version of the library
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octocore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pranav Prakash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cequel
@@ -336,16 +336,22 @@ description: |
336
336
  email: pp@octo.ai
337
337
  executables:
338
338
  - fakestream
339
+ - octocore-admin
339
340
  extensions: []
340
341
  extra_rdoc_files:
341
342
  - README.md
342
343
  files:
343
344
  - CHANGES.md
345
+ - CONTRIBUTING
344
346
  - Gemfile
345
347
  - Gemfile.lock
348
+ - LICENSE
349
+ - MAINTAINERS
350
+ - NOTICE
346
351
  - README.md
347
352
  - Rakefile
348
353
  - bin/fakestream
354
+ - bin/octocore-admin
349
355
  - lib/octocore.rb
350
356
  - lib/octocore/baseline.rb
351
357
  - lib/octocore/callbacks.rb
@@ -355,6 +361,7 @@ files:
355
361
  - lib/octocore/counter.rb
356
362
  - lib/octocore/counter/helpers.rb
357
363
  - lib/octocore/email.rb
364
+ - lib/octocore/featureflag.rb
358
365
  - lib/octocore/helpers.rb
359
366
  - lib/octocore/helpers/api_consumer_helper.rb
360
367
  - lib/octocore/helpers/api_helper.rb
@@ -366,6 +373,7 @@ files:
366
373
  - lib/octocore/kldivergence.rb
367
374
  - lib/octocore/mailer.rb
368
375
  - lib/octocore/mailer/subscriber_mailer.rb
376
+ - lib/octocore/message_parser.rb
369
377
  - lib/octocore/models.rb
370
378
  - lib/octocore/models/contactus.rb
371
379
  - lib/octocore/models/enterprise.rb
@@ -427,6 +435,7 @@ files:
427
435
  - lib/octocore/search/setup.rb
428
436
  - lib/octocore/segment.rb
429
437
  - lib/octocore/stats.rb
438
+ - lib/octocore/tasks.rb
430
439
  - lib/octocore/trendable.rb
431
440
  - lib/octocore/trends.rb
432
441
  - lib/octocore/utils.rb