Skip to content
This repository

Adding support to tag and untag groups of users #21

Closed
wants to merge 2 commits into from

2 participants

Jeff Gardner Ben McRedmond
Jeff Gardner
Owner

No description provided.

Ben McRedmond
Owner

I don't love this.

It feels totally weird to be handling tagging operations on a class which is typically used to represent a single user.

Maybe we could have a Tag class instead? A tag would have a users attribute which you could use to tag people. e.g.

  t = Intercom::Tag.new(:name => "my tag")
  t.users << "ben@intercom.io"
  t.save

Thoughts?

Ben McRedmond
Owner

eek didn't mean to close

Ben McRedmond benmcredmond commented on the diff
lib/intercom/user.rb
((10 lines not shown))
  89 + # Intercom::User.tag(:user_ids => ["joe@example.com", "bob@example.com"], :tag => "Test Tag")
  90 + #
  91 + # returns a hash of the tag name and the users tagged.
  92 + #
  93 + # @return [Hash]
  94 + def self.tag(params)
  95 + Intercom.post("/v1/users/tag", params)
  96 + end
  97 +
  98 + # Untags a group of users with a tag on your application.
  99 + #
  100 + # Calls POST https://api.intercom.io/v1/users/untag
  101 + #
  102 + # Examples:
  103 + # Intercom::User.untag(:user_ids => ["abc123", "def456"], :tag => "Test Tag")
  104 + # Intercom::User.untag(:user_ids => ["joe@example.com", "bob@example.com"], :tag => "Test Tag")
1
Ben McRedmond Owner

The actual API seems to reference user_emails for emails (which I also think we should change because we don't call it that anywhere else, should be emails)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5 changes.txt
... ... @@ -1,5 +1,8 @@
  1 +0.1.6
  2 + - add support for tagging and untagging of users
  3 +
1 4 0.1.5
2   - - Always convert times to unix timestamps for the wire (thanks @jgwhite)
  5 + - always convert times to unix timestamps for the wire (thanks @jgwhite)
3 6
4 7 0.1.4
5 8 - Intercom::User.all now includes Enumerable
30 lib/intercom/user.rb
@@ -80,6 +80,36 @@ def self.all
80 80 UserCollectionProxy.new
81 81 end
82 82
  83 + # Tags a group of users with a tag on your application.
  84 + #
  85 + # Calls POST https://api.intercom.io/v1/users/tag
  86 + #
  87 + # Examples:
  88 + # Intercom::User.tag(:user_ids => ["abc123", "def456"], :tag => "Test Tag")
  89 + # Intercom::User.tag(:user_ids => ["joe@example.com", "bob@example.com"], :tag => "Test Tag")
  90 + #
  91 + # returns a hash of the tag name and the users tagged.
  92 + #
  93 + # @return [Hash]
  94 + def self.tag(params)
  95 + Intercom.post("/v1/users/tag", params)
  96 + end
  97 +
  98 + # Untags a group of users with a tag on your application.
  99 + #
  100 + # Calls POST https://api.intercom.io/v1/users/untag
  101 + #
  102 + # Examples:
  103 + # Intercom::User.untag(:user_ids => ["abc123", "def456"], :tag => "Test Tag")
  104 + # Intercom::User.untag(:user_ids => ["joe@example.com", "bob@example.com"], :tag => "Test Tag")
  105 + #
  106 + # returns a hash of the tag name and the users untagged.
  107 + #
  108 + # @return [Hash]
  109 + def self.untag(params)
  110 + Intercom.post("/v1/users/untag", params)
  111 + end
  112 +
83 113 # Fetches a count of all Users tracked on Intercom.
84 114 # Example:
85 115 # Intercom::User.all.count
2  lib/intercom/version.rb
... ... @@ -1,3 +1,3 @@
1 1 module Intercom #:nodoc:
2   - VERSION = "0.1.5"
  2 + VERSION = "0.1.6"
3 3 end
22 spec/spec_helper.rb
... ... @@ -1,6 +1,6 @@
1 1 require 'intercom'
2 2 require 'minitest/autorun'
3   -require 'mocha/setup'
  3 +require 'mocha'
4 4
5 5 def test_user(email="bob@example.com")
6 6 {
@@ -87,6 +87,26 @@ def page_of_users(page=1, per_page=10)
87 87 }
88 88 end
89 89
  90 +def tagging_response
  91 + {
  92 + :tag => "Test Tag",
  93 + :users => [
  94 + "abc123",
  95 + "def456"
  96 + ]
  97 + }.to_json
  98 +end
  99 +
  100 +def untagging_response
  101 + {
  102 + :untag => "Test Tag",
  103 + :users => [
  104 + "abc123",
  105 + "def456"
  106 + ]
  107 + }.to_json
  108 +end
  109 +
90 110 def error_on_modify_frozen
91 111 RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
92 112 end
12 spec/unit/intercom/user_spec.rb
@@ -184,6 +184,18 @@
184 184 all.must_be_instance_of(Intercom::UserCollectionProxy)
185 185 end
186 186
  187 + describe "tagging and untagging" do
  188 + it "tags a group of users" do
  189 + Intercom.expects(:post).with("/v1/users/tag", {:user_ids => ["abc123", "def456"], :tag => "Test Tag"}).returns(tagging_response)
  190 + Intercom::User.tag(:user_ids => ["abc123", "def456"], :tag => "Test Tag")
  191 + end
  192 +
  193 + it "untags a group of users" do
  194 + Intercom.expects(:post).with("/v1/users/untag", {:user_ids => ["abc123", "def456"], :tag => "Test Tag"}).returns(untagging_response)
  195 + Intercom::User.untag(:user_ids => ["abc123", "def456"], :tag => "Test Tag")
  196 + end
  197 + end
  198 +
187 199 it "returns the total number of users" do
188 200 Intercom.expects(:get).with("/v1/users", {:per_page => 1}).returns(page_of_users)
189 201 Intercom::User.count.must_be_kind_of(Integer)

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.