Skip to content

Commit

Permalink
added goals
Browse files Browse the repository at this point in the history
  • Loading branch information
cxz committed Aug 17, 2013
1 parent ec927aa commit 0ed2b58
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
```


Expand All @@ -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
```


Expand Down
13 changes: 13 additions & 0 deletions lib/livechat/client/goals.rb
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
53 changes: 53 additions & 0 deletions test/livechat/client/goals_test.rb
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

0 comments on commit 0ed2b58

Please sign in to comment.