From 0ed2b58bf4a50ef97ffee985bbe6b955629dd5fa Mon Sep 17 00:00:00 2001 From: amaia Date: Sat, 17 Aug 2013 01:57:28 -0300 Subject: [PATCH] added goals --- README.md | 14 ++++++++ lib/livechat/client/goals.rb | 13 ++++++++ test/livechat/client/goals_test.rb | 53 ++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 test/livechat/client/goals_test.rb diff --git a/README.md b/README.md index 34fcc99..e19d0fa 100644 --- a/README.md +++ b/README.md @@ -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 => 'john.doe@mycompany.com') ``` @@ -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 ``` diff --git a/lib/livechat/client/goals.rb b/lib/livechat/client/goals.rb index 10d5a9d..fdbbfe4 100644 --- a/lib/livechat/client/goals.rb +++ b/lib/livechat/client/goals.rb @@ -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 diff --git a/test/livechat/client/goals_test.rb b/test/livechat/client/goals_test.rb new file mode 100644 index 0000000..6a5b557 --- /dev/null +++ b/test/livechat/client/goals_test.rb @@ -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 +