intercom 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/changes.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.4
2
+ - Intercom::User.all now includes Enumerable
3
+
1
4
  0.0.12
2
5
  - add support for multiple endpoints, with failover on service unavailable / socket connect timeout. (only relevant to customers who must use static ip addresses to access our API)
3
6
 
data/lib/intercom/user.rb CHANGED
@@ -8,13 +8,13 @@ module Intercom
8
8
  #
9
9
  # == Example usage
10
10
  # * Fetching a user
11
- # Intercom::User.find_by_email("bob@example.")
11
+ # Intercom::User.find_by_email("bob@example.com")
12
12
  #
13
13
  # * Getting the count of all users
14
14
  # Intercom::User.all.count
15
15
  #
16
16
  # * Fetching all users
17
- # Intercom::User.all.each {|user| puts user.email }
17
+ # Intercom::User.all.each { |user| puts user.email }
18
18
  #
19
19
  # * Updating custom data on a user
20
20
  # user = Intercom::User.find_by_email("bob@example.com")
@@ -68,13 +68,11 @@ module Intercom
68
68
 
69
69
  # Retrieve all the users
70
70
  # Examples:
71
- # Intercom::User.all.count
72
- # > 5346
73
- # Intercom::User.each do |user|
71
+ # Intercom::User.all.each do |user|
74
72
  # puts user.inspect
75
73
  # end
76
74
  # > ["user1@example.com" ,"user2@example.com" ,....]
77
- # Intercom::User.map(&:email)
75
+ # Intercom::User.all.map(&:email)
78
76
  # > ["user1@example.com" ,"user2@example.com" ,....]
79
77
  #
80
78
  # @return [UserCollectionProxy]
@@ -82,6 +80,17 @@ module Intercom
82
80
  UserCollectionProxy.new
83
81
  end
84
82
 
83
+ # Fetches a count of all Users tracked on Intercom.
84
+ # Example:
85
+ # Intercom::User.all.count
86
+ # > 5346
87
+ #
88
+ # @return [Integer]
89
+ def self.count
90
+ response = Intercom.get("/v1/users", {:per_page => 1})
91
+ response["total_count"]
92
+ end
93
+
85
94
  # Deletes a user record on your application.
86
95
  #
87
96
  # Calls DELETE https://api.intercom.io/v1/users
@@ -8,21 +8,12 @@ module Intercom
8
8
  #
9
9
  # == Examples:
10
10
  #
11
- # Fetching a count of all Users tracked on Intercom
12
- # Intercom::User.all.count
13
- #
14
11
  # Iterating over each user
15
- # Intercom::User.each do |user|
12
+ # Intercom::User.all.each do |user|
16
13
  # puts user.inspect
17
14
  # end
18
15
  #
19
16
  class UserCollectionProxy
20
- # @return [Integer] number of users tracked on Intercom for this application
21
- def count
22
- response = Intercom.get("/v1/users", {:per_page => 1})
23
- response["total_count"]
24
- end
25
-
26
17
  # yields each {User} to the block provided
27
18
  # @return [void]
28
19
  def each(&block)
@@ -38,14 +29,15 @@ module Intercom
38
29
  end
39
30
  end
40
31
 
41
- # yields each {User} to the block provided and collects the output in the same way as Enumerable#map
42
- # @return [Array<Object>]
43
- def map
44
- out = []
45
- each { |e| out << yield(e) }
46
- out
47
- end
32
+ include Enumerable
33
+
34
+ # This method exists as an optimisation of Enumerable#count,
35
+ # which would potentially fetch multiple pages of users.
36
+ def count(item=nil) #:nodoc:
37
+ return super unless item.nil?
38
+ return super if block_given?
48
39
 
49
- alias :collect :map
40
+ Intercom::User.count
41
+ end
50
42
  end
51
43
  end
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -18,15 +18,15 @@ describe Intercom::UserCollectionProxy do
18
18
  Intercom::User.all.collect { |user| user.email }.must_equal %W(user1@example.com user2@example.com user3@example.com)
19
19
  end
20
20
 
21
- it "yields each user to the block" do
22
- Intercom.expects(:get).with("/v1/users", {:per_page => 1}).returns(page_of_users(1,1))
23
- Intercom::User.all.count.must_equal 3
24
- end
25
-
26
21
  it "loads multiple pages" do
27
22
  Intercom.expects(:get).with("/v1/users", {:page => 1}).returns(page_of_users(1, 1))
28
23
  Intercom.expects(:get).with("/v1/users", {:page => 2}).returns(page_of_users(2, 1))
29
24
  Intercom.expects(:get).with("/v1/users", {:page => 3}).returns(page_of_users(3, 1))
30
25
  Intercom::User.all.map { |user| user.email }.must_equal %W(user1@example.com user2@example.com user3@example.com)
31
26
  end
27
+
28
+ it "only loads the first page when counting" do
29
+ Intercom.expects(:get).with("/v1/users", {:per_page => 1}).returns(page_of_users(1, 1))
30
+ Intercom::User.all.count.must_equal(3)
31
+ end
32
32
  end
@@ -74,7 +74,6 @@ describe "Intercom::User" do
74
74
  end
75
75
 
76
76
  it "allows easy setting of company data" do
77
- now = Time.now
78
77
  user = Intercom::User.new()
79
78
  user.company["name"] = "Intercom"
80
79
  user.company["id"] = 6
@@ -185,6 +184,11 @@ describe "Intercom::User" do
185
184
  all.must_be_instance_of(Intercom::UserCollectionProxy)
186
185
  end
187
186
 
187
+ it "returns the total number of users" do
188
+ Intercom.expects(:get).with("/v1/users", {:per_page => 1}).returns(page_of_users)
189
+ Intercom::User.count.must_be_kind_of(Integer)
190
+ end
191
+
188
192
  it "can find_by_email" do
189
193
  Intercom::User.expects(:find).with(:email => "bob@example.com")
190
194
  Intercom::User.find_by_email("bob@example.com")
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: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-02-28 00:00:00.000000000 Z
16
+ date: 2013-03-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: minitest