intercom 3.9.5 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +406 -236
  3. data/Rakefile +1 -1
  4. data/changes.txt +32 -0
  5. data/lib/intercom/api_operations/archive.rb +2 -1
  6. data/lib/intercom/api_operations/delete.rb +16 -0
  7. data/lib/intercom/api_operations/find.rb +5 -2
  8. data/lib/intercom/api_operations/find_all.rb +4 -3
  9. data/lib/intercom/api_operations/list.rb +4 -1
  10. data/lib/intercom/api_operations/load.rb +4 -2
  11. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  12. data/lib/intercom/api_operations/save.rb +6 -4
  13. data/lib/intercom/api_operations/scroll.rb +4 -5
  14. data/lib/intercom/api_operations/search.rb +3 -2
  15. data/lib/intercom/article.rb +7 -0
  16. data/lib/intercom/base_collection_proxy.rb +73 -0
  17. data/lib/intercom/client.rb +36 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/collection.rb +7 -0
  20. data/lib/intercom/company.rb +8 -0
  21. data/lib/intercom/contact.rb +22 -3
  22. data/lib/intercom/conversation.rb +5 -0
  23. data/lib/intercom/data_attribute.rb +7 -0
  24. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  25. data/lib/intercom/deprecated_resources.rb +13 -0
  26. data/lib/intercom/errors.rb +3 -0
  27. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  28. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  29. data/lib/intercom/lead.rb +21 -0
  30. data/lib/intercom/lib/dynamic_accessors.rb +9 -10
  31. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  32. data/lib/intercom/note.rb +4 -0
  33. data/lib/intercom/request.rb +37 -33
  34. data/lib/intercom/scroll_collection_proxy.rb +38 -42
  35. data/lib/intercom/search_collection_proxy.rb +30 -65
  36. data/lib/intercom/section.rb +23 -0
  37. data/lib/intercom/segment.rb +4 -0
  38. data/lib/intercom/service/article.rb +20 -0
  39. data/lib/intercom/service/base_service.rb +7 -0
  40. data/lib/intercom/service/collection.rb +24 -0
  41. data/lib/intercom/service/company.rb +2 -12
  42. data/lib/intercom/service/contact.rb +31 -10
  43. data/lib/intercom/service/conversation.rb +12 -3
  44. data/lib/intercom/service/data_attribute.rb +20 -0
  45. data/lib/intercom/service/lead.rb +41 -0
  46. data/lib/intercom/service/note.rb +4 -8
  47. data/lib/intercom/service/section.rb +7 -0
  48. data/lib/intercom/service/subscription.rb +2 -2
  49. data/lib/intercom/service/tag.rb +9 -9
  50. data/lib/intercom/service/visitor.rb +17 -8
  51. data/lib/intercom/tag.rb +4 -0
  52. data/lib/intercom/traits/api_resource.rb +44 -18
  53. data/lib/intercom/traits/dirty_tracking.rb +8 -1
  54. data/lib/intercom/user.rb +12 -3
  55. data/lib/intercom/utils.rb +13 -2
  56. data/lib/intercom/version.rb +1 -1
  57. data/lib/intercom/visitor.rb +0 -2
  58. data/lib/intercom.rb +33 -22
  59. data/spec/spec_helper.rb +843 -520
  60. data/spec/unit/intercom/admin_spec.rb +2 -2
  61. data/spec/unit/intercom/article_spec.rb +40 -0
  62. data/spec/unit/intercom/base_collection_proxy_spec.rb +47 -0
  63. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  64. data/spec/unit/intercom/client_spec.rb +25 -26
  65. data/spec/unit/intercom/collection_spec.rb +32 -0
  66. data/spec/unit/intercom/company_spec.rb +18 -14
  67. data/spec/unit/intercom/contact_spec.rb +385 -33
  68. data/spec/unit/intercom/conversation_spec.rb +55 -7
  69. data/spec/unit/intercom/count_spec.rb +4 -4
  70. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  71. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  72. data/spec/unit/intercom/event_spec.rb +9 -11
  73. data/spec/unit/intercom/job_spec.rb +24 -24
  74. data/spec/unit/intercom/lead_spec.rb +57 -0
  75. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  76. data/spec/unit/intercom/message_spec.rb +1 -1
  77. data/spec/unit/intercom/note_spec.rb +4 -10
  78. data/spec/unit/intercom/request_spec.rb +1 -1
  79. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  80. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  81. data/spec/unit/intercom/section_spec.rb +32 -0
  82. data/spec/unit/intercom/segment_spec.rb +2 -2
  83. data/spec/unit/intercom/subscription_spec.rb +5 -6
  84. data/spec/unit/intercom/tag_spec.rb +22 -14
  85. data/spec/unit/intercom/team_spec.rb +2 -2
  86. data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
  87. data/spec/unit/intercom/user_spec.rb +224 -226
  88. data/spec/unit/intercom/visitor_spec.rb +49 -0
  89. data/spec/unit/intercom_spec.rb +5 -3
  90. metadata +34 -8
  91. data/lib/intercom/customer.rb +0 -10
  92. data/lib/intercom/service/customer.rb +0 -14
  93. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,12 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Intercom::Admin" do
4
- let (:client) { Intercom::Client.new(token: 'token') }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
6
  it "returns a CollectionProxy for all without making any requests" do
7
7
  client.expects(:execute_request).never
8
8
  all = client.admins.all
9
- all.must_be_instance_of(Intercom::ClientCollectionProxy)
9
+ _(all).must_be_instance_of(Intercom::ClientCollectionProxy)
10
10
  end
11
11
 
12
12
  it "gets me (access token method only)" do
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Intercom::Article" do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+
6
+ describe "Getting an Article" do
7
+ it "successfully finds an article" do
8
+ client.expects(:get).with("/articles/1", {}).returns(test_article)
9
+ client.articles.find(id: "1")
10
+ end
11
+ end
12
+
13
+ describe "Creating an Article" do
14
+ it "successfully creates and article with information passed individually" do
15
+ client.expects(:post).with("/articles", {"title" => "new title", "author_id" => 1, "body" => "<p>thingbop</p>", "state" => "draft"}).returns(test_article)
16
+ client.articles.create(:title => "new title", :author_id => 1, :body => "<p>thingbop</p>", :state => "draft")
17
+ end
18
+
19
+ it "successfully creates and article with information in json" do
20
+ client.expects(:post).with("/articles", {"title" => "new title", "author_id" => 1, "body" => "<p>thingbop</p>", "state" => "draft"}).returns(test_article)
21
+ client.articles.create({title: "new title", author_id: 1, body: "<p>thingbop</p>", state: "draft"})
22
+ end
23
+ end
24
+
25
+ describe "Updating an article" do
26
+ it "successfully updates an article" do
27
+ article = Intercom::Article.new(id: 12345)
28
+ client.expects(:put).with('/articles/12345', {})
29
+ client.articles.save(article)
30
+ end
31
+ end
32
+
33
+ describe "Deleting an article" do
34
+ it "successfully deletes an article" do
35
+ article = Intercom::Article.new(id: 12345)
36
+ client.expects(:delete).with('/articles/12345', {})
37
+ client.articles.delete(article)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe Intercom::BaseCollectionProxy do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+
6
+ it "stops iterating if no starting after value" do
7
+ client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
8
+ emails = []
9
+ client.contacts.all.each { |contact| emails << contact.email }
10
+ _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
11
+ end
12
+
13
+ it "keeps iterating if starting after value" do
14
+ client.expects(:get).with("/contacts", {}).returns(page_of_contacts(true))
15
+ client.expects(:get).with('/contacts', { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false))
16
+ emails = []
17
+ client.contacts.all.each { |contact| emails << contact.email }
18
+ _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com test1@example.com test2@example.com test3@example.com]
19
+ end
20
+
21
+ it "supports indexed array access" do
22
+ client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
23
+ _(client.contacts.all[0].email).must_equal "test1@example.com"
24
+ end
25
+
26
+ it "supports map" do
27
+ client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
28
+ emails = client.contacts.all.map { |contact| contact.email }
29
+ _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
30
+ end
31
+
32
+ it "keeps entire collection iterable after first iteration" do
33
+ contacts = client.contacts.all
34
+ emails_iter1 = []
35
+ emails_iter2 = []
36
+ expects_pagination = proc do
37
+ client.expects(:get).with("/contacts", {}).returns(page_of_contacts(true))
38
+ client.expects(:get).with("/contacts", { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false))
39
+ end
40
+
41
+ expects_pagination.call
42
+ contacts.each { |contact| emails_iter1 << contact.email }
43
+ expects_pagination.call
44
+ contacts.each { |contact| emails_iter2 << contact.email }
45
+ _(emails_iter1).must_equal emails_iter2
46
+ end
47
+ end
@@ -1,80 +1,80 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Intercom::ClientCollectionProxy do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
6
  it "stops iterating if no next link" do
7
- client.expects(:get).with("/users", {}).returns(page_of_users(false))
8
- emails = []
9
- client.users.all.each { |user| emails << user.email }
10
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
7
+ client.expects(:get).with("/companies", {}).returns(page_of_companies(false))
8
+ names = []
9
+ client.companies.all.each { |company| names << company.name }
10
+ _(names).must_equal %W(company1 company2 company3)
11
11
  end
12
12
 
13
13
  it "keeps iterating if next link" do
14
- client.expects(:get).with("/users", {}).returns(page_of_users(true))
15
- client.expects(:get).with('https://api.intercom.io/users?per_page=50&page=2', {}).returns(page_of_users(false))
16
- emails = []
17
- client.users.all.each { |user| emails << user.email }
14
+ client.expects(:get).with("/companies", {}).returns(page_of_companies(true))
15
+ client.expects(:get).with('https://api.intercom.io/companies?per_page=50&page=2', {}).returns(page_of_companies(false))
16
+ names = []
17
+ client.companies.all.each { |company| names << company.name }
18
18
  end
19
19
 
20
20
  it "supports indexed array access" do
21
- client.expects(:get).with("/users", {}).returns(page_of_users(false))
22
- client.users.all[0].email.must_equal 'user1@example.com'
21
+ client.expects(:get).with("/companies", {}).returns(page_of_companies(false))
22
+ _(client.companies.all[0].name).must_equal 'company1'
23
23
  end
24
24
 
25
25
  it "supports map" do
26
- client.expects(:get).with("/users", {}).returns(page_of_users(false))
27
- emails = client.users.all.map { |user| user.email }
28
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
26
+ client.expects(:get).with("/companies", {}).returns(page_of_companies(false))
27
+ names = client.companies.all.map { |company| company.name }
28
+ _(names).must_equal %W(company1 company2 company3)
29
29
  end
30
30
 
31
31
  it "supports querying" do
32
- client.expects(:get).with("/users", {:tag_name => 'Taggart J'}).returns(page_of_users(false))
33
- client.users.find_all(:tag_name => 'Taggart J').map(&:email).must_equal %W(user1@example.com user2@example.com user3@example.com)
32
+ client.expects(:get).with("/companies", {:tag_name => 'Taggart J'}).returns(page_of_companies(false))
33
+ _(client.companies.find_all(:tag_name => 'Taggart J').map(&:name)).must_equal %W(company1 company2 company3)
34
34
  end
35
35
 
36
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(include_next_link: 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)
37
+ companies = [test_company("company1"), test_company("company2"), test_company("company3"),
38
+ test_company("company4"), test_company("company5"), test_company("company6"),
39
+ test_company("company7"), test_company("company8"), test_company("company9"),
40
+ test_company("company10")]
41
+ client.expects(:get).with("/companies", {:type=>'companies', :per_page => 10, :page => 1}).returns(companies_pagination(include_next_link: false, per_page: 10, page: 1, total_pages: 1, total_count: 10, company_list: companies))
42
+ result = client.companies.find_all(:type=>'companies', :per_page => 10, :page => 1).map {|company| company.name }
43
+ _(result).must_equal %W(company1 company2 company3 company4 company5 company6 company7 company8 company9 company10)
44
44
  end
45
45
 
46
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(include_next_link: 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)
47
+ companies = [test_company("company3"), test_company("company4")]
48
+ client.expects(:get).with("/companies", {:type=>'companies', :per_page => 2, :page => 3}).returns(companies_pagination(include_next_link: true, per_page: 2, page: 3, total_pages: 5, total_count: 10, company_list: companies))
49
+ result = client.companies.find_all(:type=>'companies', :per_page => 2, :page => 3).map {|company| company.name }
50
+ _(result).must_equal %W(company3 company4)
51
51
  end
52
52
 
53
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(include_next_link: 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()
54
+ companies = []
55
+ client.expects(:get).with("/companies", {:type=>'companies', :per_page => 2, :page => 30}).returns(companies_pagination(include_next_link: true, per_page: 2, page: 30, total_pages: 2, total_count: 3, company_list: companies))
56
+ result = client.companies.find_all(:type=>'companies', :per_page => 2, :page => 30).map {|company| company.name }
57
+ _(result).must_equal %W()
58
58
  end
59
59
 
60
60
  it "works with asc order" do
61
61
  test_date=1457337600
62
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(include_next_link: 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)
63
+ companies = [test_company_dates(name="company1", created_at=test_date), test_company_dates(name="company2", created_at=test_date-time_increment),
64
+ test_company_dates(name="company3", created_at=test_date-2*time_increment), test_company_dates(name="company4", created_at=test_date-3*time_increment)]
65
+ client.expects(:get).with("/companies", {:type=>'companies', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at"}).returns(companies_pagination(include_next_link: true, per_page: 4, page: 5, total_pages: 6, total_count: 30, company_list: companies))
66
+ result = client.companies.find_all(:type=>'companies', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at").map(&:name)
67
+ _(result).must_equal %W(company1 company2 company3 company4)
68
68
  end
69
69
 
70
70
  it "works with desc order" do
71
71
  test_date=1457337600
72
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(include_next_link: 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)
73
+ companies = [test_company_dates(name="company4", created_at=3*test_date), test_company_dates(name="company3", created_at=test_date-2*time_increment),
74
+ test_company_dates(name="company2", created_at=test_date-time_increment), test_company_dates(name="company1", created_at=test_date)]
75
+ client.expects(:get).with("/companies", {:type=>'companies', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at"}).returns(companies_pagination(include_next_link: true, per_page: 4, page: 5, total_pages: 6, total_count: 30, company_list: companies))
76
+ result = client.companies.find_all(:type=>'companies', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at").map {|company| company.name }
77
+ _(result).must_equal %W(company4 company3 company2 company1)
78
78
  end
79
79
 
80
80
  end
@@ -1,19 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Intercom
4
6
  describe Client do
5
- let(:app_id) { 'myappid' }
6
- let(:api_key) { 'myapikey' }
7
+ let(:token) { 'my_access_token' }
7
8
  let(:client) do
8
9
  Client.new(
9
- app_id: app_id,
10
- api_key: api_key,
10
+ token: token,
11
11
  handle_rate_limit: true
12
12
  )
13
13
  end
14
14
 
15
15
  it 'should set the base url' do
16
- client.base_url.must_equal('https://api.intercom.io')
16
+ _(client.base_url).must_equal('https://api.intercom.io')
17
17
  end
18
18
 
19
19
  it 'should have handle_rate_limit set' do
@@ -22,34 +22,34 @@ module Intercom
22
22
 
23
23
  it 'should be able to change the base url' do
24
24
  prev = client.options(Intercom::Client.set_base_url('https://mymockintercom.io'))
25
- client.base_url.must_equal('https://mymockintercom.io')
25
+ _(client.base_url).must_equal('https://mymockintercom.io')
26
26
  client.options(prev)
27
- client.base_url.must_equal('https://api.intercom.io')
27
+ _(client.base_url).must_equal('https://api.intercom.io')
28
28
  end
29
29
 
30
30
  it 'should be able to change the timeouts' do
31
31
  prev = client.options(Intercom::Client.set_timeouts(open_timeout: 10, read_timeout: 15))
32
- client.timeouts.must_equal(open_timeout: 10, read_timeout: 15)
32
+ _(client.timeouts).must_equal(open_timeout: 10, read_timeout: 15)
33
33
  client.options(prev)
34
- client.timeouts.must_equal(open_timeout: 30, read_timeout: 90)
34
+ _(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
35
35
  end
36
36
 
37
37
  it 'should be able to change the open timeout individually' do
38
38
  prev = client.options(Intercom::Client.set_timeouts(open_timeout: 50))
39
- client.timeouts.must_equal(open_timeout: 50, read_timeout: 90)
39
+ _(client.timeouts).must_equal(open_timeout: 50, read_timeout: 90)
40
40
  client.options(prev)
41
- client.timeouts.must_equal(open_timeout: 30, read_timeout: 90)
41
+ _(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
42
42
  end
43
43
 
44
44
  it 'should be able to change the read timeout individually' do
45
45
  prev = client.options(Intercom::Client.set_timeouts(read_timeout: 50))
46
- client.timeouts.must_equal(open_timeout: 30, read_timeout: 50)
46
+ _(client.timeouts).must_equal(open_timeout: 30, read_timeout: 50)
47
47
  client.options(prev)
48
- client.timeouts.must_equal(open_timeout: 30, read_timeout: 90)
48
+ _(client.timeouts).must_equal(open_timeout: 30, read_timeout: 90)
49
49
  end
50
50
 
51
51
  it 'should raise on nil credentials' do
52
- proc { Client.new(app_id: nil, api_key: nil) }.must_raise MisconfiguredClientError
52
+ _(proc { Client.new(token: nil) }).must_raise MisconfiguredClientError
53
53
  end
54
54
 
55
55
  describe 'API version' do
@@ -58,42 +58,41 @@ module Intercom
58
58
  end
59
59
 
60
60
  it 'allows api version to be provided' do
61
- Client.new(app_id: app_id, api_key: api_key, api_version: '1.0').api_version.must_equal('1.0')
61
+ _(Client.new(token: token, api_version: '2.0').api_version).must_equal('2.0')
62
62
  end
63
63
 
64
64
  it 'allows api version to be nil' do
65
65
  # matches default behavior, and will honor version set in the Developer Hub
66
- assert_nil(Client.new(app_id: app_id, api_key: api_key, api_version: nil).api_version)
66
+ assert_nil(Client.new(token: token, api_version: nil).api_version)
67
67
  end
68
68
 
69
69
  it 'allows api version to be Unstable' do
70
- Client.new(app_id: app_id, api_key: api_key, api_version: 'Unstable').api_version.must_equal('Unstable')
70
+ _(Client.new(token: token, api_version: 'Unstable').api_version).must_equal('Unstable')
71
71
  end
72
72
 
73
73
  it 'raises on invalid api version' do
74
- proc { Client.new(app_id: app_id, api_key: api_key, api_version: '0.2') }.must_raise MisconfiguredClientError
74
+ _(proc { Client.new(token: token, api_version: '0.2') }).must_raise MisconfiguredClientError
75
75
  end
76
76
 
77
77
  it 'raises on empty api version' do
78
- proc { Client.new(app_id: app_id, api_key: api_key, api_version: '') }.must_raise MisconfiguredClientError
78
+ _(proc { Client.new(token: token, api_version: '') }).must_raise MisconfiguredClientError
79
79
  end
80
80
 
81
- it "assigns works" do
82
- stub_request(:any, "https://api.intercom.io/users?id=123").to_return(
83
- status: [200, "OK"],
81
+ it 'assigns works' do
82
+ stub_request(:any, 'https://api.intercom.io/contacts?id=123').to_return(
83
+ status: [200, 'OK'],
84
84
  headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 },
85
- body: { "test": "testing" }.to_json
85
+ body: { "test": 'testing' }.to_json
86
86
  )
87
87
 
88
- client.get("/users", { id: "123" })
88
+ client.get('/contacts', id: '123')
89
89
  end
90
90
  end
91
91
 
92
92
  describe 'OAuth clients' do
93
93
  it 'supports "token"' do
94
94
  client = Client.new(token: 'foo')
95
- client.username_part.must_equal('foo')
96
- client.password_part.must_equal('')
95
+ _(client.token).must_equal('foo')
97
96
  end
98
97
  end
99
98
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intercom::Collection do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+
6
+ it 'creates a collection' do
7
+ client.expects(:post).with('/help_center/collections', { 'name' => 'Collection 1', 'description' => 'Collection desc' }).returns(test_collection)
8
+ client.collections.create(:name => 'Collection 1', :description => 'Collection desc')
9
+ end
10
+
11
+ it 'lists collections' do
12
+ client.expects(:get).with('/help_center/collections', {}).returns(test_collection_list)
13
+ client.collections.all.each { |t| }
14
+ end
15
+
16
+ it 'finds a collection' do
17
+ client.expects(:get).with('/help_center/collections/1', {}).returns(test_collection)
18
+ client.collections.find(id: '1')
19
+ end
20
+
21
+ it 'updates a collection' do
22
+ collection = Intercom::Collection.new(id: '12345')
23
+ client.expects(:put).with('/help_center/collections/12345', {})
24
+ client.collections.save(collection)
25
+ end
26
+
27
+ it 'deletes a collection' do
28
+ collection = Intercom::Collection.new(id: '12345')
29
+ client.expects(:delete).with('/help_center/collections/12345', {})
30
+ client.collections.delete(collection)
31
+ end
32
+ end
@@ -1,40 +1,44 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Intercom::Company do
4
- let (:client) { Intercom::Client.new(app_id: "app_id", api_key: "api_key") }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
6
  describe "when no response raises error" do
7
7
  it "on find" do
8
8
  client.expects(:get).with("/companies", {:company_id => "4"}).returns(nil)
9
- proc {client.companies.find(:company_id => "4")}.must_raise Intercom::HttpError
9
+ _(proc { client.companies.find(:company_id => "4")}).must_raise Intercom::HttpError
10
10
  end
11
11
 
12
12
  it "on find_all" do
13
13
  client.expects(:get).with("/companies", {}).returns(nil)
14
- proc {client.companies.all.each {|company| }}.must_raise Intercom::HttpError
14
+ _(proc { client.companies.all.each {|company| }}).must_raise Intercom::HttpError
15
15
  end
16
16
 
17
17
  it "on load" do
18
18
  client.expects(:get).with("/companies", {:company_id => "4"}).returns({"type" =>"user", "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa", "company_id" => "4", "name" => "MyCo"})
19
19
  company = client.companies.find(:company_id => "4")
20
20
  client.expects(:get).with("/companies/aaaaaaaaaaaaaaaaaaaaaaaa", {}).returns(nil)
21
- proc {client.companies.load(company)}.must_raise Intercom::HttpError
21
+ _(proc { client.companies.load(company)}).must_raise Intercom::HttpError
22
22
  end
23
23
  end
24
24
 
25
- it "gets users in a company by intercom ID" do
26
- client.expects(:get).with("/companies/abc123/users", {}).returns(page_of_users(false))
27
- client.companies.users_by_intercom_company_id("abc123").each { |u| }
25
+ it "finds a company" do
26
+ client.expects(:get).with("/companies/531ee472cce572a6ec000006", {}).returns(test_company)
27
+ company = client.companies.find(id: "531ee472cce572a6ec000006")
28
+ _(company.name).must_equal("Blue Sun")
28
29
  end
29
30
 
30
- it "gets users in a company by external company ID" do
31
- client.expects(:get).with("/companies", { company_id: "abc123", type: "user" }).returns(page_of_users(false))
32
- client.companies.users_by_company_id("abc123").each { |u| }
31
+ it "returns a collection proxy for listing contacts" do
32
+ company = Intercom::Company.new("id" => "1")
33
+ proxy = company.contacts
34
+ _(proxy.resource_name).must_equal 'contacts'
35
+ _(proxy.url).must_equal '/companies/1/contacts'
36
+ _(proxy.resource_class).must_equal Intercom::Contact
33
37
  end
34
38
 
35
- it "finds a company" do
36
- client.expects(:get).with("/companies/531ee472cce572a6ec000006", {}).returns(test_company)
37
- company = client.companies.find(id: "531ee472cce572a6ec000006")
38
- company.name.must_equal("Blue Sun")
39
+ it "deletes a company" do
40
+ company = Intercom::Company.new("id" => "1")
41
+ client.expects(:delete).with("/companies/1", {})
42
+ client.companies.delete(company)
39
43
  end
40
44
  end