A Ruby client for the Livechat REST API
Ruby
Latest commit 167c55e Jan 20, 2017 @nspielman nspielman committed on GitHub Merge pull request #8 from nspielman/use-json-in-requests
Use JSON in requests
Permalink
Failed to load latest commit information.
conf not ready yet. moving machines Aug 18, 2013
lib Fix specs and remove unnecessary white space and variables Jan 20, 2017
spec
.gitignore initial Aug 16, 2013
Gemfile initial Aug 16, 2013
Gemfile.lock
README.md
Rakefile cleanup Aug 19, 2013
livechat_client.gemspec cleanup Aug 19, 2013

README.md

LiveChat API Ruby Client

Install

Via rubygems.org:

$ gem install livechat_client

To build and install the development branch yourself from the latest source:

$ git clone git@github.com:cxz/livechat_client.git
$ cd livechat_client
$ git checkout -b develop
$ rake gem
$ gem install pkg/livechat_client-{version}

Connection

Basic Auth over HTTPS is used to authenticate API requests.

require "livechat"

@livechat = LiveChat::REST::Client.new do |config|
  config[:login] = "joe@example.com"
  config[:api_key] = ""
end

Agents

List all agents

@livechat.agents.list                     # all agents
@livechat.agents.each {|a| ..code.. }     # iterate over requested agents

Get a single agent details

@livechat.agents('john.doe@mycompany.com')

Create a new agent

@livechat.agents.create do |a|
  a[:login] = @alice_id
  a[:name] = 'Alice'
end

Update an agent

@livechat.agents(@jane_id).update do |a|
  a[:job_title] = 'Tester'
  a[:status] = 'not accepting chats'
end

Reset an API key

  @livechat.agents('john.doe@mycompany.com').reset_api_key

Remove an agent

  @livechat.agents('john.doe@mycompany.com').delete

Canned responses

List all canned responses

  @livechat.canned_responses.list

Get a single canned response

  @livechat.canned_responses(3151)

Create a new canned response

  @livechat.canned_responses.create do |r|
    r[:text] = 'Have a great day, goodbye.'
    r[:tags] = ['cu', 'bye']
  end

Update a canned response

  @livechat.canned_responses(3151).update do |r|
    r[:tags] = ['bye']
  end

Remove a canned response

  @livechat.canned_responses(3151).delete

Chats

Get list of chats

  @livechat.chats.list

Get single chat

  @livechat.chats('MH022RD0K5')

Send chat transcript to e-mail

  @livechat.chats('MH022RD0K5').send_transcript(:to => 'john.doe@mycompany.com')

Goals

List all goals

  @livechat.goals.list

Get a single goal details

  @livechat.goals(1181)

Mark goal as successful

  @livechat.goals(1181).mark_as_successful(:visitor_id => 1)

Add a new goal

  @livechat.goals.create do |goal|
    goal[:name] = 'new goal'
    goal[:type] = 'url'
  end

Update a goal

  @livechat.goals(2231).update do |goal|
    goal[:name] = 'updated goal'
  end

Remove a goal

  @livechat.goals(2231).delete

Groups

List all groups

  @livechat.groups.list

Get a single group details

  @livechat.groups(2)

Create a new group

  @livechat.groups.create do |goal|
    group[:name] = 'Human Resources'
    group[:agents] = ['jenny.doe@mycompany.com', 'john.doe@mycompany.com']
  end

Update a group

  @livechat.groups(3).update do |goal|
    group[:name] = 'Quality Assurance'
    group[:agents] = ['jane.doe@mycompany.com']
  end

Remove a group

  @livechat.groups(4).delete

Reports

Get dashboard data

  @livechat.reports.dashboard

Get dashboard data for agent

  @livechat.reports.dashboard(:agent => 'john.doe@mycompany.com')

Get dashboard data for group

  @livechat.reports.dashboard(:group => 1)

Get chats report

  @livechat.reports.chats(:date_from => '2013-01-01')

Get ratings report

  @livechat.reports.ratings(:group => 1)

Get ratings ranking

  @livechat.reports.ratings_ranking(:group => 1)

Get queued visitors report

  @livechat.reports.queued_visitors(:date_from => '2013-01-01')

Get queue waiting times report

  @livechat.reports.queued_visitors_waiting_times(:date_from => '2013-01-01')

Get availability report

  @livechat.reports.availability

Get chatting time report

  @livechat.reports.chatting_time

Get goals report

  @livechat.reports.goals

Status

Get status

  @livechat.status(:group => 0)

Visitors

List all visitors

  @livechat.visitors.list

List only chatting visitors

  @livechat.visitors.chatting

Add custom visitor details

  @livechat.visitors('S1352647457.ac951bfe2e').add_details do |detail|
    detail[:license_id] = '12345'
    detail[:token] = '26132406c42c96ba61ed42689b70f719'
    detail[:id] = 'my-app'
    detail[:fields] = [{:name => 'Age', :value => 36}]
  end

Contributing

Ways you can help:

  • report bugs
  • writing/fixing documentation
  • writing code (refactoring, strengthening areas that are weak, catching typos)

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so we don't break it in a future version unintentionally.
  • Commit
  • Send a pull request. Bonus points for topic branches.

MIT License

Copyright (c) 2013 Alexandre Maia

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.