Sha256: dca306cef08bca816fa3e267d75b7c9324a0e707e72ec56d6b38c9c4892819db

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'intercom/requires_parameters'
require 'intercom/hashable_object'

module Intercom

  ##
  # Represents a tag
  #
  # A tag consists of a name, and (optionally) a color and users that you would like to tag. Returns details about the tag and a count of the number of users currently tagged.
  #
  # == Examples
  #
  #  tag = Intercom::Tag.create(:name => "Super Tag", :color => "red", :user_ids => ['abc123', 'def456'])
  #  tag = Intercom::Tag.create(:name => "Super Tag", :color => "red", :emails => ['bob@example.com', 'joe@example.com'])
  #
  #  You can also create a tag and save it like this:
  #  tag = Intercom::Tag.new
  #  tag.name = "Super Tag"
  #  tag.color = "red"
  #  tag.user_ids = ['abc123', 'def456']
  #  tag.tag_or_untag = "tag"
  #  tag.save
  #
  #  Or update a tag and save it like this:
  #  tag = Intercom::Tag.find_by_name "Super Tag"
  #  tag.color = "green"
  #  tag.user_ids << 'abc123'
  #  tag.tag_or_untag = "untag"
  #  tag.save

  class Tag
    extend RequiresParameters
    include HashableObject

    attr_accessor :name, :color, :user_ids, :emails, :tag_or_untag, :segment, :tagged_user_count, :id

    def initialize(attributes={})
      from_hash(attributes)
    end

    ##
    # Finds a Tag using params
    def self.find(params)
      response = Intercom.get("/v1/tags", params)
      from_api(response)
    end

    def self.from_api(api_response)
      tag = Tag.new
      tag.from_hash(api_response)
      tag
    end

    ##
    # Finds a Tag using a name
    def self.find_by_name(name)
      find({:name => name})
    end

    ##
    # Creates a new Tag using params and saves it
    # @see #save
    def self.create(params)
      requires_parameters(params, %W(name))
      Tag.new(params).save
    end

    ##
    # Saves a Tag on your application
    def save
      response = Intercom.post("/v1/tags", to_hash)
      self.from_hash(response)
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
intercom-0.1.8 lib/intercom/tag.rb