intercom-app 0.2.1 → 0.2.2

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: 3b0feb331e88775fbb025a0935d5c6467714a300
4
- data.tar.gz: 40506ec35b6b610b04438595eb8ee8e69b97ae8a
3
+ metadata.gz: b7f46437a2cf130cdd55c76cc0cd98308793834b
4
+ data.tar.gz: b3de97e1517c26d4e3b3283e3efce18d4ad56386
5
5
  SHA512:
6
- metadata.gz: d914328e498bd9ed91be8d906e8217f43066b4f9fd3f75929427f63e4474e50cf478ca90318f0702698acdde2c206056ad34828ceea1baf2bfd274f4aa9272cc
7
- data.tar.gz: 2de850e9d4740f6bb1159ba3aeb59c128414317e923d81601338ecf4938b5921ecad53f803ed1ef8dba0e54cbc18870e27f0200c0e026920da8f1843ce5f4694
6
+ metadata.gz: 4a49259db239d5a5c087a11c2f6144436deef5b9a61c117531c4fef9f7c416f2f6a3d3c847319e5de1f618cde01b0552116292ccad193464a9df1fcce5d384ad
7
+ data.tar.gz: a099e74a36e04a9eb83dc6860b11f187608b13169e5b6b47c6a46356cdb5f9313082e38c8389fe9271edca7938d5a2a06e0f4b38cf2b64e9a651be4f567a9a38
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  test/intercom_ruby_app_example/log
3
3
  test/generators/tmp
4
4
  test/tmp
5
+ todolist.md
@@ -23,3 +23,10 @@ Features:
23
23
  ## 0.2.1 (2016-08-17)
24
24
 
25
25
  * Fix webhook subscription fail (@Skaelv)
26
+
27
+ ## 0.2.2 (2016-10-11)
28
+
29
+ * Add callback_hash Proc for custom storage
30
+ * Add session_storage_on_login Proc for custom storage
31
+ * Rename token to intercom_token
32
+ * Allow custom storage to intercom App model (@Skaelv)
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
- Intercom App
1
+ Intercom Integration
2
2
  ===========
3
3
 
4
4
  Intercom Application Rails engine and generator
5
5
 
6
- *Note this SDK is in beta version and still needs a lot of improvements. We advise you to use it only if you feel you can help contributing and fix issues when you find them*
7
-
8
6
  Description
9
7
  -----------
10
- This gem includes a Rails Engine and generators for writing Rails applications using the Intercom API. The Engine provides a SessionsController and all the required code for authenticating with an app via Oauth.
8
+ This gem includes a Rails Engine and generators for writing Rails applications using the Intercom API. The Engine provides a SessionsController and all the required code for authenticating with an app via OAuth.
9
+
10
+ [Getting started with Intercom Integrations](https://developers.intercom.io/docs/integration-setup-guide)
11
11
 
12
12
  Apply to become an Intercom Developer
13
13
  --------------------------------
14
- To create an Intercom application and get your `app_key` and `app_secret` you will need to create an [Intercom application](https://app.intercom.io) first.
15
- Once your application is created you can apply for an oauth application in the "App Settings >> Oauth" section.
16
-
14
+ To create an Intercom application and get your `client_id` and `client_secret` you will need to create an [Intercom account](https://app.intercom.io) first.
15
+ Once your application is created you can apply for an OAuth application in the "App Settings >> OAuth" section.
16
+ Make sure you request read admin permission to use [omniauth-intercom](http://github.com/intercom/omniauth-intercom).
17
17
  Installation
18
18
  ------------
19
19
  To get started create a new rails app :
@@ -24,7 +24,7 @@ $ rails new my_intercom_app
24
24
  $ cd my_intercom_app
25
25
  ```
26
26
  Then add `intercom-app` to your Gemfile and bundle install :
27
- `gem 'intercom-app'`
27
+ `gem 'intercom-app', '>= 0.2.1'`
28
28
  and run :
29
29
  ``` sh
30
30
  $ bundle install
@@ -41,7 +41,7 @@ Generators
41
41
  The default generator will run the `install`, `app_model`, and `home_controller` generators. This is the recommended way to start your app.
42
42
 
43
43
  ```sh
44
- $ rails generate intercom_app --app_key <your_app_key> --app_secret <your_app_secret> --oauth_modal true
44
+ $ rails generate intercom_app --app_key <intercom_client_id> --app_secret <intercom_client_secret> --oauth_modal true
45
45
  ```
46
46
  **oauth_modal**:
47
47
  - If true you can authenticate with Intercom using a modal
@@ -50,6 +50,12 @@ $ rails generate intercom_app --app_key <your_app_key> --app_secret <your_app_se
50
50
 
51
51
  *Note that you will need to run rake db:migrate after this generator*
52
52
 
53
+ At this point you've finished the setup. You can run `rails s` and complete Intercom Authentication to generate a new intercom_token.
54
+ You can make calls to Intercom APIs using `@intercom_client` in all controllers that inherits from `IntercomApp::AuthenticatedController`. This `@intercom_client` variable is instantiated with the token associated to the current session.
55
+
56
+ ### Adding your own Intercom app to your Integration
57
+
58
+ If you want to add Intercom's widget for your integration (which you definitely should!), we recommend that you configure [intercom-rails]("https://github.com/intercom/intercom-rails") independently.
53
59
  ### Install Generator
54
60
 
55
61
  ```sh
@@ -57,15 +63,15 @@ $ rails generate intercom_app:install
57
63
 
58
64
  # or optionally with arguments:
59
65
 
60
- $ rails generate intercom_app:install --app_key <your_app_key> --secret <your_app_secret> --oauth_modal true
66
+ $ rails generate intercom_app:install --app_key <intercom_client_id> --app_secret <intercom_client_secret> --oauth_modal true
61
67
  ```
62
68
 
69
+ *Note that you will need to run rake db:migrate after this generator*
70
+
63
71
  You can update any of these settings later on easily, the arguments are simply for convenience.
64
72
 
65
73
  The generator adds IntercomApp and the required initializers to the host Rails application.
66
74
 
67
- After running the `install` generator, you can start your app with `bundle exec rails server` and install your app by visiting localhost.
68
-
69
75
 
70
76
  ### App Model Generator
71
77
 
@@ -73,9 +79,9 @@ After running the `install` generator, you can start your app with `bundle exec
73
79
  $ rails generate intercom_app:app_model
74
80
  ```
75
81
 
76
- The install generator doesn't create any database models for you and if you are starting a new app its quite likely that you will want one (most of our internally developed apps do!). This generator creates a simple app model and a migration. It also creates a model called `SessionStorage` which interacts with `IntercomApp::SessionRepository`. Check out the later section to learn more about `IntercomApp::SessionRepository`
82
+ The install generator doesn't create any database models for you and if you are starting a new app its quite likely that you will want one (most of our internally developed apps do!). This generator creates a simple `App` model and a migration. It also creates a model called `SessionStorage` which interacts with `IntercomApp::SessionRepository`. Check out the later section to learn more about `IntercomApp::SessionRepository`
83
+
77
84
 
78
- *Note that you will need to run rake db:migrate after this generator*
79
85
 
80
86
 
81
87
  ### Home Controller Generator
@@ -101,10 +107,51 @@ The `install` generator places your App credentials directly into the intercom_a
101
107
  IntercomApp.configure do |config|
102
108
  config.api_key = ENV['INTERCOM_CLIENT_APP_KEY']
103
109
  config.app_secret = ENV['INTERCOM_CLIENT_APP_SECRET']
110
+ config.hub_secret = ENV['INTERCOM_WEBHOOK_HUB_SECRET']
104
111
  config.oauth_modal = false
105
112
  end
106
113
  ```
107
114
 
115
+ Session storage
116
+ ----------------------
117
+
118
+ Configure the `store_in_session_before_login` Proc to store parameters in session before OAuth.
119
+ ```ruby
120
+ IntercomApp.configure do |config|
121
+ # storing data in the session before the authentication helps you access them on the callback
122
+ # params contains omniauth hash (https://github.com/intercom/omniauth-intercom)
123
+ config.store_in_session_before_login = Proc.new do |session, params|
124
+ session[:name] = params[:name]
125
+ session[:third_party_admin_id] = params[:third_party_admin_id]
126
+ end
127
+ }
128
+ end
129
+ ```
130
+
131
+
132
+ Callback Storage
133
+ ----------------------
134
+
135
+ When customers authenticate your app against Intercom, the OAuth `token` and the `intercom_app_id` are stored in the `App` model.
136
+ To store custom data you simply need to add new attributes to `App` model by running a migration and configure the `callback_hash` Proc to return this custom data :
137
+
138
+ ```shell
139
+ rails generate migration addNameAndThirdPartyAdminIdToApp
140
+ ```
141
+
142
+ ```ruby
143
+ IntercomApp.configure do |config|
144
+ # retrieve previously stored in session params
145
+ # response contains omniauth hash (https://github.com/intercom/omniauth-intercom)
146
+ config.callback_hash = Proc.new { |session, response|
147
+ {
148
+ name: response[:name],
149
+ third_party_admin_id: session[:admin_id]
150
+ }
151
+ }
152
+ end
153
+ ```
154
+
108
155
  Webhooks Subscriptions
109
156
  ----------------------
110
157
 
@@ -123,9 +170,31 @@ end
123
170
  **Important** You will need to request the `manage_webhooks` permissions from Intercom to receive webhooks from Intercom.
124
171
 
125
172
 
173
+ Intercom-Wix
174
+ ----------------------
175
+
176
+ The [intercom-wix](https://github.com/Skaelv/intercom-wix) app is an example of an integration generated with the `intercom-ruby-app`.
177
+
126
178
  Connect to the Intercom API
127
179
  ----------------------
128
180
  This gem includes the following libraries :
129
181
 
130
182
  http://github.com/intercom/omniauth-intercom <= Simple rake middleware to authenticate your customers with Intercom
131
183
  http://github.com/intercom/intercom-ruby <= Intercom Ruby API wrapper
184
+
185
+
186
+ ## Pull Requests
187
+
188
+ - **Add tests!** Your patch won't be accepted if it doesn't have tests.
189
+
190
+ - **Document any change in behaviour**. Make sure the README and any other
191
+ relevant documentation are kept up-to-date.
192
+
193
+ - **Create topic branches**. Don't ask us to pull from your master branch.
194
+
195
+ - **One pull request per feature**. If you want to do more than one thing, send
196
+ multiple pull requests.
197
+
198
+ - **Send coherent history**. Make sure each individual commit in your pull
199
+ request is meaningful. If you had to make multiple intermediate commits while
200
+ developing, please squash them before sending them to us.
data/RELEASING CHANGED
@@ -3,9 +3,9 @@ To release a new version of the intercom-ruby-app gem :
3
3
  2. Add a CHANGELOG entry
4
4
  3. Commit to master with an explicit message : "Bump to vX.Y.Z"
5
5
  4. Tag the new release :
6
- $ git tag VX.Y.Z
6
+ $ git tag -a vx.y.z -m 'Tag message'
7
7
  5. Push the new release :
8
- $ git push
8
+ $ git push origin master
9
9
  6. Push the new tag :
10
10
  $ git push --tags
11
11
  7. Build the new gem :
@@ -19,5 +19,7 @@
19
19
  });
20
20
  </script>
21
21
  <% else %>
22
- <a href="/auth/intercom">Login</a>
22
+ <a href="/auth/intercom">
23
+ <img src="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png" srcset="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png 1x, https://static.intercomassets.com/assets/oauth/primary@2x-0d69ca2141dfdfa0535634610be80994.png 2x, https://static.intercomassets.com/assets/oauth/primary@3x-788ed3c44d63a6aec3927285e920f542.png 3x"/>
24
+ </a>
23
25
  <% end %>
@@ -1,6 +1,8 @@
1
1
  class HomeController < IntercomApp::AuthenticatedController
2
2
 
3
3
  def index
4
- @users_names = @intercom_client.users.find_all(:type=>'users', :per_page => 10, :page => 1, :order => "desc", :sort => "created_at").map(&:name)
4
+ # Example of an API request using intercom-ruby gem
5
+ # Request 'read users' permission for the following request
6
+ # @users_names = @intercom_client.users.find_all(:type=>'users', :per_page => 10, :page => 1, :order => "desc", :sort => "created_at").map(&:name)
5
7
  end
6
8
  end
@@ -1,8 +1,10 @@
1
- <a href="/login">Login</a>
1
+ <a href="/auth/intercom">
2
+ <img src="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png" srcset="https://static.intercomassets.com/assets/oauth/primary-7edb2ebce84c088063f4b86049747c3a.png 1x, https://static.intercomassets.com/assets/oauth/primary@2x-0d69ca2141dfdfa0535634610be80994.png 2x, https://static.intercomassets.com/assets/oauth/primary@3x-788ed3c44d63a6aec3927285e920f542.png 3x"/>
3
+ </a>
2
4
  <h1>Intercom application</h1>
3
- <h2>Users list:</h2>
5
+ <!-- <h2>Users list:</h2>
4
6
  <ul>
5
7
  <% @users_names.each do | name | %>
6
8
  <li> <%= name %></li>
7
- <% end %>
9
+ <% end %> -->
8
10
  </ul>
@@ -6,6 +6,8 @@ module IntercomApp
6
6
  attr_accessor :oauth_modal
7
7
  attr_accessor :webhooks
8
8
  attr_accessor :hub_secret
9
+ attr_accessor :callback_hash
10
+ attr_accessor :store_in_session_before_login
9
11
 
10
12
  def initialize
11
13
  end
@@ -9,7 +9,7 @@ module IntercomApp
9
9
  def intercom_session
10
10
  if app_session
11
11
  begin
12
- @intercom_client = Intercom::Client.new(token: app_session[:token])
12
+ @intercom_client = Intercom::Client.new(token: app_session[:intercom_token])
13
13
  yield
14
14
  end
15
15
  else
@@ -5,7 +5,7 @@ module IntercomApp
5
5
  class_methods do
6
6
  def store(sess)
7
7
  app = self.find_or_initialize_by(intercom_app_id: sess[:intercom_app_id])
8
- app.intercom_token = sess[:token]
8
+ sess.each {|k,v| app[k] = v}
9
9
  app.save!
10
10
  app.id
11
11
  end
@@ -13,11 +13,9 @@ module IntercomApp
13
13
  def retrieve(id)
14
14
  return unless id
15
15
  if app = self.find_by(id: id)
16
- session = {
17
- id: app.id,
18
- intercom_app_id: app.intercom_app_id,
19
- token: app.intercom_token
20
- }
16
+ session = {}
17
+ app.instance_variables{|k| session[k] = app[k]}
18
+ session
21
19
  end
22
20
  end
23
21
  end
@@ -6,15 +6,22 @@ module IntercomApp
6
6
  include IntercomApp::LoginProtection
7
7
  end
8
8
 
9
+ def login
10
+ store_in_session_before_login.call(session, params) if store_in_session_before_login
11
+ end
12
+
9
13
  def callback
10
14
  if response = request.env['omniauth.auth']
11
15
  app = {
12
- token: response['credentials']['token'],
13
- intercom_app_id: response['extra']['raw_info']['app']['id_code']
16
+ intercom_token: response['credentials']['token'],
17
+ intercom_app_id: response['extra']['raw_info']['app']['id_code'],
18
+ name: response['extra']['raw_info']['name'],
19
+ email: response['extra']['raw_info']['email']
14
20
  }
21
+ app = app.merge(callback_hash.call(session, response)) if callback_hash
15
22
  session[:intercom] = IntercomApp::SessionRepository.store(app)
16
23
  session[:intercom_app_id] = app[:intercom_app_id]
17
- IntercomApp::WebhooksManager.new(intercom_token: app[:token]).create_webhooks_subscriptions if IntercomApp.configuration.webhooks.present?
24
+ IntercomApp::WebhooksManager.new(intercom_token: app[:intercom_token]).create_webhooks_subscriptions if IntercomApp.configuration.webhooks.present?
18
25
  redirect_to return_address unless IntercomApp.configuration.oauth_modal
19
26
  else
20
27
  redirect_to login_url
@@ -24,6 +31,7 @@ module IntercomApp
24
31
  def destroy
25
32
  session[:intercom] = nil
26
33
  session[:intercom_app_id] = nil
34
+ session[:intercom_token] = nil
27
35
  redirect_to login_url
28
36
  end
29
37
 
@@ -32,5 +40,12 @@ module IntercomApp
32
40
  session.delete(:return_to) || '/'
33
41
  end
34
42
 
43
+ def callback_hash
44
+ IntercomApp.configuration.callback_hash
45
+ end
46
+
47
+ def store_in_session_before_login
48
+ IntercomApp.configuration.store_in_session_before_login
49
+ end
35
50
  end
36
51
  end
@@ -1,3 +1,3 @@
1
1
  module IntercomApp
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Antoine
@@ -195,8 +195,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  requirements: []
197
197
  rubyforge_project:
198
- rubygems_version: 2.5.1
198
+ rubygems_version: 2.6.1
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: Intercom.io ruby application boilerplate
202
202
  test_files: []
203
+ has_rdoc: