Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from intercom/Skaelv/visitors_endpoint
visitor endpoint
- Loading branch information
Showing
6 changed files
with
133 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'intercom/service/base_service' | ||
require 'intercom/api_operations/load' | ||
require 'intercom/api_operations/list' | ||
require 'intercom/api_operations/find' | ||
require 'intercom/api_operations/find_all' | ||
require 'intercom/api_operations/save' | ||
require 'intercom/api_operations/convert' | ||
require 'intercom/api_operations/delete' | ||
|
||
module Intercom | ||
module Service | ||
class Visitor < BaseService | ||
include ApiOperations::Load | ||
include ApiOperations::List | ||
include ApiOperations::Find | ||
include ApiOperations::FindAll | ||
include ApiOperations::Save | ||
include ApiOperations::Convert | ||
include ApiOperations::Delete | ||
|
||
def collection_class | ||
Intercom::Visitor | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'intercom/traits/incrementable_attributes' | ||
require 'intercom/traits/api_resource' | ||
|
||
module Intercom | ||
class Visitor | ||
include Traits::IncrementableAttributes | ||
include Traits::ApiResource | ||
|
||
def identity_vars ; [:id, :email, :user_id] ; end | ||
def flat_store_attributes ; [:custom_attributes] ; end | ||
def update_verb ; 'put' ; end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "spec_helper" | ||
|
||
describe "Intercom::Visitors" do | ||
let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') } | ||
|
||
it 'should be listable' do | ||
proxy = client.visitors.all | ||
proxy.resource_name.must_equal 'visitors' | ||
proxy.finder_url.must_equal '/visitors' | ||
proxy.resource_class.must_equal Intercom::Visitor | ||
end | ||
|
||
it 'can update a visitor with an id' do | ||
visitor = Intercom::Visitor.new(:id => "de45ae78gae1289cb") | ||
client.expects(:put).with("/visitors/de45ae78gae1289cb", {'custom_attributes' => {}}) | ||
client.visitors.save(visitor) | ||
end | ||
|
||
describe 'converting' do | ||
let(:visitor) { Intercom::Visitor.from_api(user_id: 'visitor_id') } | ||
let(:user) { Intercom::User.from_api(id: 'user_id') } | ||
|
||
it 'visitor to user' do | ||
client.expects(:post).with( | ||
"/visitors/convert", | ||
{ | ||
visitor: { user_id: visitor.user_id }, | ||
user: { 'id' => user.id }, | ||
type:'user' | ||
} | ||
).returns(test_user) | ||
|
||
client.visitors.convert(visitor, user) | ||
end | ||
|
||
it 'visitor to lead' do | ||
client.expects(:post).with( | ||
"/visitors/convert", | ||
{ | ||
visitor: { user_id: visitor.user_id }, | ||
type:'lead' | ||
} | ||
).returns(test_user) | ||
|
||
client.visitors.convert(visitor) | ||
end | ||
end | ||
|
||
it "returns a ClientCollectionProxy for all without making any requests" do | ||
client.expects(:execute_request).never | ||
all = client.visitors.all | ||
all.must_be_instance_of(Intercom::ClientCollectionProxy) | ||
end | ||
|
||
it "deletes a visitor" do | ||
visitor = Intercom::Visitor.new("id" => "1") | ||
client.expects(:delete).with("/visitors/1", {}).returns(visitor) | ||
client.visitors.delete(visitor) | ||
end | ||
|
||
end |