forked from cxz/livechat_client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,14 +98,17 @@ end | |
|
||
**Get list of chats** | ||
```ruby | ||
@livechat.chats.fetch | ||
``` | ||
|
||
**Get single chat** | ||
```ruby | ||
@livechat.chats('MH022RD0K5').fetch | ||
``` | ||
|
||
**Send chat transcript to e-mail** | ||
```ruby | ||
@livechat.chats('MH022RD0K5').send_transcript(:to => '[email protected]') | ||
``` | ||
|
||
|
||
|
@@ -115,26 +118,37 @@ end | |
|
||
**List all goals** | ||
```ruby | ||
@livechat.goals.fetch | ||
``` | ||
|
||
**Get a single goal details** | ||
```ruby | ||
@livechat.goals(1181).fetch | ||
``` | ||
|
||
**Mark goal as successful** | ||
```ruby | ||
@livechat.goals(1181).mark_as_successful(:visitor_id => 1) | ||
``` | ||
|
||
**Add a new goal** | ||
```ruby | ||
@livechat.goals.create do |goal| | ||
goal[:name] = 'new goal' | ||
goal[:type] = 'url' | ||
end | ||
``` | ||
|
||
**Update a goal** | ||
```ruby | ||
@livechat.goals(2231).update do |goal| | ||
goal[:name] = 'updated goal' | ||
end | ||
``` | ||
|
||
**Remove a goal** | ||
```ruby | ||
@livechat.goals(2231).delete | ||
``` | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,6 +1,19 @@ | ||
module LiveChat | ||
class Client | ||
module Goals | ||
def goals(*args) | ||
GoalsCollection.new(self, *args) | ||
end | ||
end | ||
|
||
class GoalsCollection < Collection | ||
def initialize(client, *args) | ||
super(client, :goal, *args) | ||
end | ||
|
||
def mark_as_successful(*args) | ||
post("#{@query[:path]}/mark_as_successful", Hash[*args]) | ||
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,53 @@ | ||
require "test_helper" | ||
|
||
include WebMock::API | ||
|
||
|
||
describe LiveChat::Client::Chats do | ||
before do | ||
@livechat = LiveChat::Client.new do |config| | ||
config.login = LOGIN | ||
config.api_key = API_KEY | ||
config.debug = true | ||
end | ||
|
||
request_path = "https://#{LOGIN}:#{API_KEY}@#{ENDPOINT}/goals" | ||
stub_request(:any, /#{request_path}.*/) | ||
end | ||
|
||
after do | ||
WebMock.reset! | ||
end | ||
|
||
|
||
it "lists all goals" do | ||
@livechat.goals.fetch | ||
end | ||
|
||
it "gets a single goal details" do | ||
@livechat.goals(1181).fetch | ||
end | ||
|
||
it "marks goal as successful" do | ||
@livechat.goals(1181).mark_as_successful(:visitor_id => 1) | ||
end | ||
|
||
it "adds a new goal" do | ||
@livechat.goals.create do |goal| | ||
goal[:name] = 'new goal' | ||
goal[:type] = 'url' | ||
end | ||
end | ||
|
||
it "updates a goal" do | ||
@livechat.goals(2231).update do |goal| | ||
goal[:name] = 'updated goal' | ||
end | ||
end | ||
|
||
it "removes a goal" do | ||
@livechat.goals(2231).delete | ||
end | ||
|
||
end | ||
|