bg-common 0.1.2 → 0.1.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: e883f346c3f8661fc5f2c269ef693266c40eb99d
4
- data.tar.gz: 5558811d182ab1b697a35d6a6f3d0766e5b9d5ee
3
+ metadata.gz: 32c5b7cf0dbee6773715a5d12a06bbc031e13e39
4
+ data.tar.gz: 53bac4ac88f1d5af07b4e9da2a1507cad219a1e1
5
5
  SHA512:
6
- metadata.gz: cc0876b3c344f6d8381b2e9d501b41cb5d725a63dffe1d1c7b5b394139bcffea4141bce1804fbafa4bf4df63ddec3876cb8c03ddb5d713a32be5e569f4fe95ec
7
- data.tar.gz: 01203b4d6242e815e52c02229e114ddefa7a62c6e791061cb4f713e7f604faa3600be1514eaa5c3723d80154aa66bb2cb866ba9abc5a0a78e8841e1c4836ec9f
6
+ metadata.gz: d3706f3cafd53430cea56bcfe15e40438a98b18bb571651198bf35f3f687a0e8b0434d70b9c43d2de639cf6d801bb40fcd5feaf42478eae75ab97f3e3d5ca472
7
+ data.tar.gz: ee7ee55d4b56925f1cfe7ffd0e5b9ec04298279b319bbad69df6f8b859a4816594057ea6063672a9afdcc02a0bb05700e784dcef82d82352016c7fd0f7a9195b
data/README.md CHANGED
@@ -270,5 +270,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
270
270
 
271
271
  ## Contributing
272
272
 
273
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bg-common. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
273
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bearandgiraffe/bg-common. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
274
274
 
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -5,7 +7,7 @@ module BG
5
7
  queue_as :analytics
6
8
 
7
9
  def perform data
8
- GA::Client.new.call data
10
+ BG::Common::Analytics::GA::Client.call data
9
11
  end
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -5,7 +7,7 @@ module BG
5
7
  queue_as :analytics
6
8
 
7
9
  def perform data
8
- Intercom::Client.new.make_intercom_call do |client|
10
+ BG::Common::Analytics::Intercom::Client.new.make_intercom_call do |client|
9
11
  client.users.create data
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -5,7 +7,7 @@ module BG
5
7
  queue_as :analytics
6
8
 
7
9
  def perform data
8
- Intercom::Client.new.call data
10
+ BG::Common::Analytics::Intercom::Client.call data
9
11
  end
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -5,7 +7,7 @@ module BG
5
7
  queue_as :analytics
6
8
 
7
9
  def perform data
8
- Intercom::Client.new.make_intercom_call do |client|
10
+ BG::Common::Analytics::Intercom::Client.new.make_intercom_call do |client|
9
11
  client.users.submit_bulk_job(create_items: data)
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -8,7 +10,7 @@ module BG
8
10
  users = User.all
9
11
 
10
12
  users.each do |user|
11
- Analytics::Intercom.update_user user
13
+ BG::Common::Analytics::Intercom.update_user user
12
14
  end unless users.blank?
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ require 'bg/common/analytics'
2
+
1
3
  module BG
2
4
  module Common
3
5
  module Analytics
@@ -5,7 +7,7 @@ module BG
5
7
  queue_as :analytics
6
8
 
7
9
  def perform event, data
8
- Keen::Client.new.call event, data
10
+ BG::Common::Analytics::Keen::Client.call event, data
9
11
  end
10
12
  end
11
13
  end
data/lib/bg/common.rb CHANGED
@@ -13,17 +13,26 @@ module BG
13
13
 
14
14
  def logger
15
15
  # TODO: Make this configurable
16
- @logger ||= Logging.logger['bg_common']
17
- @logger.level = :debug
16
+ if defined?(::Logging)
17
+ @logger ||= ::Logging.logger['bg_common']
18
+ @logger.level = :debug
19
+
20
+ @logger.add_appenders \
21
+ ::Logging.appenders.stdout,
22
+ ::Logging.appenders.file('log/bg_common.log')
23
+ else
24
+ require 'logger'
25
+
26
+ @logger ||= ::Logger.new(STDOUT)
27
+ @logger.level = ::Logger::DEBUG
28
+ end
18
29
 
19
- @logger.add_appenders \
20
- Logging.appenders.stdout,
21
- Logging.appenders.file('log/bg_common.log')
30
+ return @logger
22
31
  end
23
32
 
24
33
  # Paths
25
34
  def gem_path
26
- @gem_path ||= File.expand_path '../..', File.dirname(__FILE__)
35
+ @gem_path ||= ::File.expand_path '../..', ::File.dirname(__FILE__)
27
36
  end
28
37
 
29
38
  def active_job?
@@ -11,15 +11,36 @@ module BG
11
11
  end
12
12
 
13
13
  def ga?
14
- defined?(::Gabba) && ENV['GA_TRACKER_CODE'] && ENV['GA_DOMAIN']
14
+ begin
15
+ require 'gabba'
16
+ defined?(::Gabba) && ENV['GA_TRACKER_CODE'] && ENV['GA_DOMAIN']
17
+ rescue LoadError
18
+ BG::Common.logger.info 'GA is not loaded'
19
+
20
+ return false
21
+ end
15
22
  end
16
23
 
17
24
  def intercom?
18
- defined?(::Intercom) && ENV['INTERCOM_ACCESS_TOKEN']
25
+ begin
26
+ require 'intercom'
27
+ defined?(::Intercom) && ENV['INTERCOM_ACCESS_TOKEN']
28
+ rescue LoadError
29
+ BG::Common.logger.info 'Intercom is not loaded'
30
+
31
+ return false
32
+ end
19
33
  end
20
34
 
21
35
  def keen?
22
- defined?(::Keen) && ENV['KEEN_PROJECT_ID']
36
+ begin
37
+ require 'keen'
38
+ defined?(::Keen) && ENV['KEEN_PROJECT_ID']
39
+ rescue LoadError
40
+ BG::Common.logger.info 'Keen is not loaded'
41
+
42
+ return false
43
+ end
23
44
  end
24
45
 
25
46
  private
@@ -11,6 +11,10 @@ module BG
11
11
  @ga ||= ::Gabba::Gabba.new(ENV['GA_TRACKER_CODE'], ENV['GA_DOMAIN'])
12
12
  end
13
13
 
14
+ def self.call data
15
+ self.new.call data
16
+ end
17
+
14
18
  def call data
15
19
  ga.event(
16
20
  data[:category],
@@ -29,7 +29,7 @@ module BG
29
29
  if BG::Common.active_job?
30
30
  GAEventJob.perform_later data
31
31
  else
32
- Client.new.call data
32
+ BG::Common::Analytics::GA::Client.new.call data
33
33
  end
34
34
  end
35
35
  end
@@ -11,6 +11,10 @@ module BG
11
11
  @intercom ||= ::Intercom::Client.new token: ENV['INTERCOM_ACCESS_TOKEN']
12
12
  end
13
13
 
14
+ def self.call data
15
+ self.new.call data
16
+ end
17
+
14
18
  def call data
15
19
  make_intercom_call do |client|
16
20
  client.events.create data
@@ -26,7 +26,7 @@ module BG
26
26
  if BG::Common.active_job?
27
27
  IntercomEventJob.perform_later data
28
28
  else
29
- Client.new.call data
29
+ BG::Common::Analytics::Intercom::Client.new.call data
30
30
  end
31
31
  end
32
32
  end
@@ -6,6 +6,10 @@ module BG
6
6
  def initialize
7
7
  end
8
8
 
9
+ def self.call event, data = {}
10
+ self.new.call event, data
11
+ end
12
+
9
13
  def call event, data = {}
10
14
  ::Keen.publish event.to_sym, data
11
15
  end
@@ -19,9 +19,9 @@ module BG
19
19
  #
20
20
  def create_event event, data
21
21
  if BG::Common.active_job?
22
- KeenEventJob.perform_later event, data
22
+ BG::Common::Analytics::KeenEventJob.perform_later event, data
23
23
  else
24
- Client.new.call event, data
24
+ BG::Common::Analytics::Keen::Client.call event, data
25
25
  end
26
26
  end
27
27
  end
@@ -5,17 +5,21 @@ module BG
5
5
  def initialize
6
6
  end
7
7
 
8
+ def self.call data
9
+ self.new.call data
10
+ end
11
+
8
12
  def call data
9
- if Analytics.ga? and data[:ga]
10
- GA.create_event data[:ga]
13
+ if BG::Common::Analytics.ga? and data[:ga]
14
+ BG::Common::Analytics::GA.create_event data[:ga]
11
15
  end
12
16
 
13
- if Analytics.intercom? and data[:intercom]
14
- Intercom.create_event data[:intercom]
17
+ if BG::Common::Analytics.intercom? and data[:intercom]
18
+ BG::Common::Analytics::Intercom.create_event data[:intercom]
15
19
  end
16
20
 
17
- if Analytics.keen? and data[:keen]
18
- Keen.create_event data[:keen][:event], data[:keen][:data]
21
+ if BG::Common::Analytics.keen? and data[:keen]
22
+ BG::Common::Analytics::Keen.create_event data[:keen][:event], data[:keen][:data]
19
23
  end
20
24
  end
21
25
  end
@@ -1,5 +1,5 @@
1
1
  module BG
2
2
  module Common
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bg-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Youssef Chaker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler