intercom 3.5.1 → 3.5.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: af771d03313306122d7cd15732e481d1be985ea2
4
- data.tar.gz: 5868caffd6bb8f2f66a674e6610b7e2278a13882
3
+ metadata.gz: d85b66c4f019a0f8c063d8110ac924ac77d1795a
4
+ data.tar.gz: 546be6dc3600a8adae3e671e32fd37f8dd2cf38f
5
5
  SHA512:
6
- metadata.gz: 46b5dec841b7297280ddfddcb79400fc606e73c27324177bbc6f7fee6614851e06e409273b95c271773eec588ddd5b7aca332344ae9f4bd0c793c5f7312a822a
7
- data.tar.gz: c74408ea271f4ab2695d8e9cde03a5e862ad5c59993423f478ca98d05617fea3880daf97dbc583e4ca6cf69936b167085176a9543a151c12b6bd0fb3ebee3e91
6
+ metadata.gz: 672212ab75756e91d0cf82c38b07c3a7eb2acee1e92715d2d0e4181bc527099cce3bf0e0fc828a619124a0db7d309c6e92677f067ca814a35d90b4cf5ea1390e
7
+ data.tar.gz: 7044d4fa88f2ca8ce4fd53230595a473a3770aa480e9952d0a15753a38027edcfe04cb3b0b0513b4affeb212ace7f36b18499bb30d463b3364b56db0077cd890
data/README.md CHANGED
@@ -22,7 +22,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
22
22
 
23
23
  Using bundler:
24
24
 
25
- gem 'intercom', "~> 3.5.0"
25
+ gem 'intercom', "~> 3.5.1"
26
26
 
27
27
  ## Basic Usage
28
28
 
@@ -30,12 +30,17 @@ Using bundler:
30
30
 
31
31
  ```ruby
32
32
  intercom = Intercom::Client.new(app_id: 'my_app_id', api_key: 'my_api_key')
33
+ ```
34
+
35
+ You can get your `app_id` from the URL when you're logged into Intercom (it's the alphanumeric just after `/apps/`) and your API key from the API keys integration settings page (under your app settings - integrations in Intercom).
33
36
 
37
+ ```ruby
34
38
  # With an OAuth token:
35
39
  intercom = Intercom::Client.new(token: 'my_token')
36
40
  ```
37
41
 
38
- You can get your `app_id` from the URL when you're logged into Intercom (it's the alphanumeric just after `/apps/`) and your API key from the API keys integration settings page (under your app settings - integrations in Intercom).
42
+ If you are building a third party application you can get your access_tokens by [setting-up-oauth](https://developers.intercom.io/page/setting-up-oauth) for Intercom.
43
+ You can also use the [omniauth-intercom lib](https://github.com/intercom/omniauth-intercom) which is a middleware helping you to handle the authentication process with Intercom.
39
44
 
40
45
  ### Resources
41
46
 
@@ -439,10 +444,9 @@ intercom.jobs.errors(id: 'job_abcd1234')
439
444
 
440
445
  There are different styles for error handling - some people prefer exceptions; some prefer nil and check; some prefer error objects/codes. Balancing these preferences alongside our wish to provide an idiomatic gem has brought us to use the current mechanism of throwing specific exceptions. Our approach in the client is to propagate errors and signal our failure loudly so that erroneous data does not get propagated through our customers' systems - in other words, if you see a `Intercom::ServiceUnavailableError` you know where the problem is.
441
446
 
442
- You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of `Intercom::Error` will be raised. If desired, you can get at the http_code of an `Intercom::Error` via its `http_code` method.
447
+ You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of `Intercom::IntercomError` will be raised. If desired, you can get at the http_code of an `Intercom::IntercomError` via its `http_code` method.
443
448
 
444
- The list of different error subclasses are listed below. As they all inherit off Intercom::IntercomError you can choose to rescue Intercom::IntercomError or
445
- else rescue the more specific error subclass.
449
+ The list of different error subclasses are listed below. As they all inherit off Intercom::IntercomError you can choose to rescue Intercom::IntercomError or else rescue the more specific error subclass.
446
450
 
447
451
  ```ruby
448
452
  Intercom::AuthenticationError
data/changes.txt CHANGED
@@ -1,3 +1,10 @@
1
+ 3.5.2
2
+ - Add Support for pagination
3
+
4
+ 3.5.1
5
+ - Support for 'visitors'
6
+ - Fix utf8 body parsing
7
+
1
8
  3.4.0
2
9
  - Add a "token" keyword for OAuth clients
3
10
 
@@ -5,7 +5,8 @@ module Intercom
5
5
  raise BadRequestError, "#{self}#find takes a hash as its parameter but you supplied #{params.inspect}" unless params.is_a? Hash
6
6
  collection_name = Utils.resource_class_to_collection_name(collection_class)
7
7
  if params[:id]
8
- response = @client.get("/#{collection_name}/#{params[:id]}", {})
8
+ id = params.delete(:id)
9
+ response = @client.get("/#{collection_name}/#{id}", params)
9
10
  else
10
11
  response = @client.get("/#{collection_name}", params)
11
12
  end
@@ -16,6 +16,7 @@ module Intercom
16
16
 
17
17
  def each(&block)
18
18
  next_page = nil
19
+ current_page = nil
19
20
  loop do
20
21
  if next_page
21
22
  response_hash = @client.get(next_page, {})
@@ -23,9 +24,10 @@ module Intercom
23
24
  response_hash = @client.get(@finder_url, @finder_params)
24
25
  end
25
26
  raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
27
+ current_page = extract_current_page(response_hash)
26
28
  deserialize_response_hash(response_hash, block)
27
29
  next_page = extract_next_link(response_hash)
28
- break if next_page.nil?
30
+ break if next_page.nil? or (@finder_params[:page] and (current_page >= @finder_params[:page]))
29
31
  end
30
32
  self
31
33
  end
@@ -62,5 +64,10 @@ module Intercom
62
64
  paging_info = response_hash.delete('pages')
63
65
  paging_info["next"]
64
66
  end
67
+
68
+ def extract_current_page(response_hash)
69
+ return nil unless paging_info_present?(response_hash)
70
+ response_hash['pages']['page']
71
+ end
65
72
  end
66
73
  end
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.5.1"
2
+ VERSION = "3.5.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -57,6 +57,61 @@ def test_user(email="bob@example.com")
57
57
  }
58
58
  end
59
59
 
60
+ def test_user_dates(email="bob@example.com", created_at=1401970114, last_request_at=1401970113)
61
+ {
62
+ "type" =>"user",
63
+ "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa",
64
+ "user_id" => 'id-from-customers-app',
65
+ "email" => email,
66
+ "name" => "Joe Schmoe",
67
+ "avatar" => {"type"=>"avatar", "image_url"=>"https://graph.facebook.com/1/picture?width=24&height=24"},
68
+ "app_id" => "the-app-id",
69
+ "custom_attributes" => {"a" => "b", "b" => 2},
70
+ "companies" =>
71
+ {"type"=>"company.list",
72
+ "companies"=>
73
+ [{"type"=>"company",
74
+ "company_id"=>"123",
75
+ "id"=>"bbbbbbbbbbbbbbbbbbbbbbbb",
76
+ "app_id"=>"the-app-id",
77
+ "name"=>"Company 1",
78
+ "remote_created_at"=>1390936440,
79
+ "created_at"=>1401970114,
80
+ "updated_at"=>1401970114,
81
+ "last_request_at"=>1401970113,
82
+ "monthly_spend"=>0,
83
+ "session_count"=>0,
84
+ "user_count"=>1,
85
+ "tag_ids"=>[],
86
+ "custom_attributes"=>{"category"=>"Tech"}}]},
87
+ "session_count" => 123,
88
+ "unsubscribed_from_emails" => true,
89
+ "last_request_at" =>last_request_at,
90
+ "created_at" =>created_at,
91
+ "remote_created_at" =>1393613864,
92
+ "updated_at" =>1401970114,
93
+ "user_agent_data" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
94
+ "social_profiles" =>{"type"=>"social_profile.list",
95
+ "social_profiles" => [
96
+ {"type" => "social_profile", "name" => "twitter", "url" => "http://twitter.com/abc", "username" => "abc", "id" => nil},
97
+ {"type" => "social_profile", "name" => "twitter", "username" => "abc2", "url" => "http://twitter.com/abc2", "id" => nil},
98
+ {"type" => "social_profile", "name" => "facebook", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"},
99
+ {"type" => "social_profile", "name" => "quora", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"}
100
+ ]},
101
+ "location_data"=>
102
+ {"type"=>"location_data",
103
+ "city_name"=> 'Dublin',
104
+ "continent_code"=> 'EU',
105
+ "country_name"=> 'Ireland',
106
+ "latitude"=> '90',
107
+ "longitude"=> '10',
108
+ "postal_code"=> 'IE',
109
+ "region_name"=> 'Europe',
110
+ "timezone"=> '+1000',
111
+ "country_code" => "IRL"}
112
+ }
113
+ end
114
+
60
115
  def test_admin_list
61
116
  {
62
117
  "type" => "admin.list",
@@ -161,6 +216,23 @@ def page_of_users(include_next_link= false)
161
216
  }
162
217
  end
163
218
 
219
+ def users_pagination(include_next_link=false, per_page=0, page=0, total_pages=0, total_count=0, user_list=[])
220
+ {
221
+ "type"=>"user.list",
222
+ "pages"=>
223
+ {
224
+ "type"=>"pages",
225
+ "next"=> (include_next_link ? "https://api.intercom.io/users?per_page=" \
226
+ + per_page.to_s + "&page=" + (page+1).to_s : nil),
227
+ "page"=>page,
228
+ "per_page"=>per_page,
229
+ "total_pages"=>total_pages
230
+ },
231
+ "users"=> user_list,
232
+ "total_count"=>total_count
233
+ }
234
+ end
235
+
164
236
  def test_conversation
165
237
  {
166
238
  "type" => "conversation",
@@ -32,4 +32,49 @@ describe Intercom::ClientCollectionProxy do
32
32
  client.expects(:get).with("/users", {:tag_name => 'Taggart J'}).returns(page_of_users(false))
33
33
  client.users.find_all(:tag_name => 'Taggart J').map(&:email).must_equal %W(user1@example.com user2@example.com user3@example.com)
34
34
  end
35
+
36
+ it "supports single page pagination" do
37
+ users = [test_user("user1@example.com"), test_user("user2@example.com"), test_user("user3@example.com"),
38
+ test_user("user4@example.com"), test_user("user5@example.com"), test_user("user6@example.com"),
39
+ test_user("user7@example.com"), test_user("user8@example.com"), test_user("user9@example.com"),
40
+ test_user("user10@example.com")]
41
+ client.expects(:get).with("/users", {:type=>'users', :per_page => 10, :page => 1}).returns(users_pagination(false, per_page=10, page=1, total_pages=1, total_count=10, user_list=users))
42
+ result = client.users.find_all(:type=>'users', :per_page => 10, :page => 1).map {|user| user.email }
43
+ result.must_equal %W(user1@example.com user2@example.com user3@example.com user4@example.com user5@example.com user6@example.com user7@example.com user8@example.com user9@example.com user10@example.com)
44
+ end
45
+
46
+ it "supports multi page pagination" do
47
+ users = [test_user("user3@example.com"), test_user("user4@example.com")]
48
+ client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 3}).returns(users_pagination(true, per_page=2, page=3, total_pages=5, total_count=10, user_list=users))
49
+ result = client.users.find_all(:type=>'users', :per_page => 2, :page => 3).map {|user| user.email }
50
+ result.must_equal %W(user3@example.com user4@example.com)
51
+ end
52
+
53
+ it "works with page out of range request" do
54
+ users = []
55
+ client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 30}).returns(users_pagination(true, per_page=2, page=30, total_pages=2, total_count=3, user_list=users))
56
+ result = client.users.find_all(:type=>'users', :per_page => 2, :page => 30).map {|user| user.email }
57
+ result.must_equal %W()
58
+ end
59
+
60
+ it "works with asc order" do
61
+ test_date=1457337600
62
+ time_increment=1000
63
+ users = [test_user_dates(email="user1@example.com", created_at=test_date), test_user_dates(email="user2@example.com", created_at=test_date-time_increment),
64
+ test_user_dates(email="user3@example.com", created_at=test_date-2*time_increment), test_user_dates(email="user4@example.com", created_at=test_date-3*time_increment)]
65
+ client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at"}).returns(users_pagination(true, per_page=4, page=5, total_pages=6, total_count=30, user_list=users))
66
+ result = client.users.find_all(:type=>'users', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at").map(&:email)
67
+ result.must_equal %W(user1@example.com user2@example.com user3@example.com user4@example.com)
68
+ end
69
+
70
+ it "works with desc order" do
71
+ test_date=1457337600
72
+ time_increment=1000
73
+ users = [test_user_dates(email="user4@example.com", created_at=3*test_date), test_user_dates(email="user3@example.com", created_at=test_date-2*time_increment),
74
+ test_user_dates(email="user2@example.com", created_at=test_date-time_increment), test_user_dates(email="user1@example.com", created_at=test_date)]
75
+ client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at"}).returns(users_pagination(true, per_page=4, page=5, total_pages=6, total_count=30, user_list=users))
76
+ result = client.users.find_all(:type=>'users', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at").map {|user| user.email }
77
+ result.must_equal %W(user4@example.com user3@example.com user2@example.com user1@example.com)
78
+ end
79
+
35
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2016-05-24 00:00:00.000000000 Z
18
+ date: 2016-07-08 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  version: '0'
226
226
  requirements: []
227
227
  rubyforge_project: intercom
228
- rubygems_version: 2.4.8
228
+ rubygems_version: 2.5.1
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: Ruby bindings for the Intercom API
@@ -251,4 +251,3 @@ test_files:
251
251
  - spec/unit/intercom/user_spec.rb
252
252
  - spec/unit/intercom/visitors_spec.rb
253
253
  - spec/unit/intercom_spec.rb
254
- has_rdoc: