Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intercom Server Side #82

Merged
merged 6 commits into from
Sep 18, 2016
Merged

Add Intercom Server Side #82

merged 6 commits into from
Sep 18, 2016

Conversation

x4d3
Copy link
Contributor

@x4d3 x4d3 commented Sep 15, 2016

  • Separated event logger in 2 listener: Audit Events Listener and Intercom Events Listener

- Separated event logger in 2 listener: Audit Events Listener and Intercom Events Listener
Copy link
Contributor

@ouranos ouranos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @x4d3 for the help on this.

A few required changes, I'll do them before merging.
See my comments and let me know if I'm mistaken.
It'd be great to have the specs before merging.

@hedudelgado FYI

@@ -11,6 +11,8 @@
gem 'shoulda-matchers'
gem 'fakeweb', '~> 1.3'
gem 'timecop'
gem 'timecop'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

}})
rescue Net::ReadTimeout
# Meant to fail
formated_metadata = format_metadata(metadata, object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatted? :)

basic_auth MnoEnterprise.tenant_id, MnoEnterprise.tenant_key
@@listeners = []
@@listeners << AuditEventsListener.new
@@listeners << IntercomEventsListener.new
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ?

@@listeners = [
  AuditEventsListener.new,
  IntercomEventsListener.new
]

@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'coffee-rails', '~> 4.1'
s.add_runtime_dependency 'health_check', '~> 1.5'
s.add_runtime_dependency 'httparty', '~> 0.13.7'

s.add_runtime_dependency 'intercom', '~> 3.5.4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want an optional dependency on it (like sparkpost)


def initialize
if MnoEnterprise.intercom_api_key && MnoEnterprise.intercom_api_secret
self.intercom = ::Intercom::Client.new(app_id: MnoEnterprise.intercom_api_key, api_key: MnoEnterprise.intercom_api_secret)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of mixup between the app id and the api_key (probably because of way the tenant_id work?)

when 'app_add'
event_name = 'added-app-' + object.app.nid
else
event_name = key.gsub!(/_/, '-')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can show off a new trick I learned! I you don't use the regex capture groups in the replacement or if like here you're just doing a string substitution, #tr is order of magnitude faster than #gsub

See this benchmark:

Warming up --------------------------------------
         String#gsub    49.395k i/100ms
           String#tr   134.293k i/100ms
Calculating -------------------------------------
         String#gsub    542.159k (±23.6%) i/s -      2.519M in   5.001670s
           String#tr      2.346M (± 5.8%) i/s -     11.683M in   5.001330s

Comparison:
           String#tr:  2345516.8 i/s
         String#gsub:   542158.9 i/s - 4.33x  slower

def info(key, current_user_id, description, metadata, object)
return unless self.intercom
u = User.find(current_user_id)
begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this begin, the rescue Intercom::IntercomError will apply to the whole method and it's easier to read.

@ouranos
Copy link
Contributor

ouranos commented Sep 16, 2016

@x4d3 see my changes.

I think we still miss the finishedSignUp event and the AddApp event doesn't have the same payload.
See: intercom-svc.js.coffee

read_timeout 0.1
basic_auth MnoEnterprise.tenant_id, MnoEnterprise.tenant_key
@@listeners = [AuditEventsListener.new]
@@listeners << IntercomEventsListener.new if defined?(Intercom)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@x4d3
Copy link
Contributor Author

x4d3 commented Sep 16, 2016

@ouranos I've added specs.
I had to add intercom as a dependency in mno-enterprise/api/mno-enterprise-api.gemspec . Otherwise the require 'intercom' was failing in mno-enterprise/api/lib/mno_enterprise/intercom_events_listener.rb

@ouranos ouranos merged commit a4366b4 into maestrano:master Sep 18, 2016
@x4d3 x4d3 deleted the feature/intercom branch June 19, 2017 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants