livechat_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +39 -0
- data/README.md +327 -0
- data/Rakefile +13 -0
- data/conf/cacert.pem +3376 -0
- data/lib/livechat.rb +23 -0
- data/lib/livechat/rest/agents.rb +19 -0
- data/lib/livechat/rest/canned_responses.rb +9 -0
- data/lib/livechat/rest/chats.rb +18 -0
- data/lib/livechat/rest/client.rb +142 -0
- data/lib/livechat/rest/errors.rb +14 -0
- data/lib/livechat/rest/goals.rb +14 -0
- data/lib/livechat/rest/groups.rb +9 -0
- data/lib/livechat/rest/instance_resource.rb +115 -0
- data/lib/livechat/rest/list_resource.rb +115 -0
- data/lib/livechat/rest/reports.rb +116 -0
- data/lib/livechat/rest/status.rb +13 -0
- data/lib/livechat/rest/utils.rb +25 -0
- data/lib/livechat/rest/visitors.rb +17 -0
- data/lib/livechat/util.rb +7 -0
- data/lib/livechat/version.rb +3 -0
- data/livechat_client.gemspec +33 -0
- data/spec/fixtures/agent.json +30 -0
- data/spec/fixtures/agents.json +16 -0
- data/spec/fixtures/canned_response.json +12 -0
- data/spec/fixtures/canned_responses.json +37 -0
- data/spec/fixtures/chat.json +129 -0
- data/spec/fixtures/chats.json +135 -0
- data/spec/fixtures/goal.json +8 -0
- data/spec/fixtures/goals.json +12 -0
- data/spec/fixtures/group.json +10 -0
- data/spec/fixtures/groups.json +32 -0
- data/spec/fixtures/visitors.json +91 -0
- data/spec/livechat/rest/agents_spec.rb +56 -0
- data/spec/livechat/rest/canned_responses_spec.rb +43 -0
- data/spec/livechat/rest/chats_spec.rb +37 -0
- data/spec/livechat/rest/goals_spec.rb +50 -0
- data/spec/livechat/rest/groups_spec.rb +45 -0
- data/spec/livechat/rest/reports_spec.rb +67 -0
- data/spec/livechat/rest/status_spec.rb +22 -0
- data/spec/livechat/rest/visitors_spec.rb +44 -0
- data/spec/spec_helper.rb +38 -0
- metadata +185 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
|
6
|
+
describe LiveChat::REST::Groups do
|
7
|
+
before do
|
8
|
+
@livechat = create_client
|
9
|
+
|
10
|
+
stub_rest 'groups'
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
WebMock.reset!
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
it "lists all groups" do
|
19
|
+
@livechat.groups
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets a single group details" do
|
23
|
+
@livechat.groups(2)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates a new group" do
|
27
|
+
@livechat.groups.create do |group|
|
28
|
+
group[:name] = 'Human Resources'
|
29
|
+
group[:agents] = ['jenny.doe@mycompany.com', 'john.doe@mycompany.com']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "updates a group" do
|
34
|
+
@livechat.groups(3).update do |group|
|
35
|
+
group[:name] = 'Quality Assurance'
|
36
|
+
group[:agents] = ['jane.doe@mycompany.com']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "removes a group" do
|
41
|
+
@livechat.groups(4).delete
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
|
6
|
+
describe LiveChat::REST::Reports do
|
7
|
+
before do
|
8
|
+
@livechat = create_client
|
9
|
+
@reports_base = "#{ENDPOINT}/reports"
|
10
|
+
stub_request(:get, /#{@reports_base}/).to_return(:body => {})
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
WebMock.reset!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gets dashboard data" do
|
18
|
+
@livechat.reports.dashboard
|
19
|
+
expect(@livechat.last_request.path).to eq '/reports/dashboard'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets dashboard data for agent" do
|
23
|
+
@livechat.reports.dashboard(:agent => 'john.doe@mycompany.com')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "gets dashboard data for group" do
|
27
|
+
@livechat.reports.dashboard(:group => 1)
|
28
|
+
expect(@livechat.last_request.path).to eq '/reports/dashboard/group/1'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "gets chats report" do
|
32
|
+
@livechat.reports.chats(:date_from => '2013-01-01')
|
33
|
+
expect(@livechat.last_request.path).to eq '/reports/chats?date_from=2013-01-01'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "gets ratings report" do
|
37
|
+
@livechat.reports.ratings(:group => 1)
|
38
|
+
expect(@livechat.last_request.path).to eq '/reports/ratings?group=1'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "gets ratings ranking" do
|
42
|
+
@livechat.reports.ratings_ranking(:group => 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "gets queued visitors report" do
|
46
|
+
@livechat.reports.queued_visitors(:date_from => '2013-01-01')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "gets queue waiting times report" do
|
50
|
+
@livechat.reports.queued_visitors_waiting_times(:date_from => '2013-01-01')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "gets availability report" do
|
54
|
+
@livechat.reports.availability
|
55
|
+
end
|
56
|
+
|
57
|
+
it "gets chatting time report" do
|
58
|
+
@livechat.reports.chatting_time
|
59
|
+
end
|
60
|
+
|
61
|
+
it "gets goals report" do
|
62
|
+
@livechat.reports.goals
|
63
|
+
expect(@livechat.last_request.path).to eq '/reports/goals'
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
|
6
|
+
describe LiveChat::REST::Status do
|
7
|
+
before do
|
8
|
+
@livechat = create_client
|
9
|
+
|
10
|
+
stub_request(:any, /.*status/)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
WebMock.reset!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gets status" do
|
18
|
+
@livechat.status(:group => 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
|
6
|
+
describe LiveChat::REST::Visitors do
|
7
|
+
before do
|
8
|
+
@livechat = create_client
|
9
|
+
|
10
|
+
base = "#{ENDPOINT}/visitors"
|
11
|
+
stub_request(:post, /#{base}/)
|
12
|
+
stub_request(:get, "#{base}").to_return(:body => fixture('visitors.json'))
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
WebMock.reset!
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
it "lists all visitors" do
|
22
|
+
visitors = @livechat.visitors
|
23
|
+
expect(visitors.list.length).to be(2)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "lists only chatting visitors" do
|
28
|
+
@livechat.visitors.chatting
|
29
|
+
end
|
30
|
+
|
31
|
+
it "adds custom visitor details" do
|
32
|
+
@livechat.visitors('S1352647457.ac951bfe2e').add_details do |detail|
|
33
|
+
detail[:license_id] = '12345'
|
34
|
+
detail[:token] = '26132406c42c96ba61ed42689b70f719'
|
35
|
+
detail[:id] = 'my-app'
|
36
|
+
#todo: need to test array encoding for the fields parameter. example:
|
37
|
+
#curl -H X-API-Version:2 https://api.livechatinc.com/visitors/S1352647457.ac951bfe2e/details -X POST
|
38
|
+
#-d "license_id=12345&token=26132406c42c96ba61ed42689b70f719&id=my-app&fields[0][name]=Age&fields[0][value]=36"
|
39
|
+
detail[:fields] = [{:name => 'Age', :value => 36}]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'livechat'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
def fixture_path
|
8
|
+
File.expand_path("../fixtures", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture(file)
|
12
|
+
File.new(fixture_path + "/" + file).read.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def stub_rest(resource_name)
|
16
|
+
base = "#{ENDPOINT}/#{resource_name}"
|
17
|
+
singular = resource_name.chop #todo inflect
|
18
|
+
stub_request(:delete, /#{base}/)
|
19
|
+
stub_request(:any, /#{base}/).to_return(:body => fixture("#{singular}.json"))
|
20
|
+
stub_request(:get, "#{base}").to_return(:body => fixture("#{resource_name}.json"))
|
21
|
+
end
|
22
|
+
|
23
|
+
if ENV["LIVE"]
|
24
|
+
LOGIN = ENV["LIVECHAT_LOGIN"]
|
25
|
+
API_KEY = ENV["LIVECHAT_API_KEY"]
|
26
|
+
else
|
27
|
+
LOGIN, API_KEY = "ignored_login", "ignored_api_key"
|
28
|
+
ENDPOINT = "https://#{LOGIN}:#{API_KEY}@ignored:443"
|
29
|
+
end
|
30
|
+
|
31
|
+
LiveChat::REST::Client::DEFAULTS[:host] = 'ignored'
|
32
|
+
|
33
|
+
def create_client
|
34
|
+
LiveChat::REST::Client.new do |config|
|
35
|
+
config[:login] = LOGIN
|
36
|
+
config[:api_key] = API_KEY
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: livechat_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexandre Maia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.9.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.9.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hashie
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.2'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: multi_json
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Ruby wrapper for the REST API at http://developers.livechatinc.com/rest-api/
|
95
|
+
email:
|
96
|
+
- alexandre.maia@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- conf/cacert.pem
|
107
|
+
- lib/livechat.rb
|
108
|
+
- lib/livechat/rest/agents.rb
|
109
|
+
- lib/livechat/rest/canned_responses.rb
|
110
|
+
- lib/livechat/rest/chats.rb
|
111
|
+
- lib/livechat/rest/client.rb
|
112
|
+
- lib/livechat/rest/errors.rb
|
113
|
+
- lib/livechat/rest/goals.rb
|
114
|
+
- lib/livechat/rest/groups.rb
|
115
|
+
- lib/livechat/rest/instance_resource.rb
|
116
|
+
- lib/livechat/rest/list_resource.rb
|
117
|
+
- lib/livechat/rest/reports.rb
|
118
|
+
- lib/livechat/rest/status.rb
|
119
|
+
- lib/livechat/rest/utils.rb
|
120
|
+
- lib/livechat/rest/visitors.rb
|
121
|
+
- lib/livechat/util.rb
|
122
|
+
- lib/livechat/version.rb
|
123
|
+
- livechat_client.gemspec
|
124
|
+
- spec/fixtures/agent.json
|
125
|
+
- spec/fixtures/agents.json
|
126
|
+
- spec/fixtures/canned_response.json
|
127
|
+
- spec/fixtures/canned_responses.json
|
128
|
+
- spec/fixtures/chat.json
|
129
|
+
- spec/fixtures/chats.json
|
130
|
+
- spec/fixtures/goal.json
|
131
|
+
- spec/fixtures/goals.json
|
132
|
+
- spec/fixtures/group.json
|
133
|
+
- spec/fixtures/groups.json
|
134
|
+
- spec/fixtures/visitors.json
|
135
|
+
- spec/livechat/rest/agents_spec.rb
|
136
|
+
- spec/livechat/rest/canned_responses_spec.rb
|
137
|
+
- spec/livechat/rest/chats_spec.rb
|
138
|
+
- spec/livechat/rest/goals_spec.rb
|
139
|
+
- spec/livechat/rest/groups_spec.rb
|
140
|
+
- spec/livechat/rest/reports_spec.rb
|
141
|
+
- spec/livechat/rest/status_spec.rb
|
142
|
+
- spec/livechat/rest/visitors_spec.rb
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
homepage: https://github.com/cxz/livechat_client
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options:
|
149
|
+
- --line-numbers
|
150
|
+
- --inline-source
|
151
|
+
- --title
|
152
|
+
- livechat
|
153
|
+
- --main
|
154
|
+
- README.md
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 1.8.7
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.3.6
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.24
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: LiveChat REST API Client
|
175
|
+
test_files:
|
176
|
+
- spec/livechat/rest/agents_spec.rb
|
177
|
+
- spec/livechat/rest/groups_spec.rb
|
178
|
+
- spec/livechat/rest/status_spec.rb
|
179
|
+
- spec/livechat/rest/chats_spec.rb
|
180
|
+
- spec/livechat/rest/canned_responses_spec.rb
|
181
|
+
- spec/livechat/rest/goals_spec.rb
|
182
|
+
- spec/livechat/rest/visitors_spec.rb
|
183
|
+
- spec/livechat/rest/reports_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
has_rdoc:
|