livechat_client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +39 -0
  4. data/README.md +327 -0
  5. data/Rakefile +13 -0
  6. data/conf/cacert.pem +3376 -0
  7. data/lib/livechat.rb +23 -0
  8. data/lib/livechat/rest/agents.rb +19 -0
  9. data/lib/livechat/rest/canned_responses.rb +9 -0
  10. data/lib/livechat/rest/chats.rb +18 -0
  11. data/lib/livechat/rest/client.rb +142 -0
  12. data/lib/livechat/rest/errors.rb +14 -0
  13. data/lib/livechat/rest/goals.rb +14 -0
  14. data/lib/livechat/rest/groups.rb +9 -0
  15. data/lib/livechat/rest/instance_resource.rb +115 -0
  16. data/lib/livechat/rest/list_resource.rb +115 -0
  17. data/lib/livechat/rest/reports.rb +116 -0
  18. data/lib/livechat/rest/status.rb +13 -0
  19. data/lib/livechat/rest/utils.rb +25 -0
  20. data/lib/livechat/rest/visitors.rb +17 -0
  21. data/lib/livechat/util.rb +7 -0
  22. data/lib/livechat/version.rb +3 -0
  23. data/livechat_client.gemspec +33 -0
  24. data/spec/fixtures/agent.json +30 -0
  25. data/spec/fixtures/agents.json +16 -0
  26. data/spec/fixtures/canned_response.json +12 -0
  27. data/spec/fixtures/canned_responses.json +37 -0
  28. data/spec/fixtures/chat.json +129 -0
  29. data/spec/fixtures/chats.json +135 -0
  30. data/spec/fixtures/goal.json +8 -0
  31. data/spec/fixtures/goals.json +12 -0
  32. data/spec/fixtures/group.json +10 -0
  33. data/spec/fixtures/groups.json +32 -0
  34. data/spec/fixtures/visitors.json +91 -0
  35. data/spec/livechat/rest/agents_spec.rb +56 -0
  36. data/spec/livechat/rest/canned_responses_spec.rb +43 -0
  37. data/spec/livechat/rest/chats_spec.rb +37 -0
  38. data/spec/livechat/rest/goals_spec.rb +50 -0
  39. data/spec/livechat/rest/groups_spec.rb +45 -0
  40. data/spec/livechat/rest/reports_spec.rb +67 -0
  41. data/spec/livechat/rest/status_spec.rb +22 -0
  42. data/spec/livechat/rest/visitors_spec.rb +44 -0
  43. data/spec/spec_helper.rb +38 -0
  44. metadata +185 -0
@@ -0,0 +1,135 @@
1
+ {
2
+ "chats": [
3
+ {
4
+ "type": "chat",
5
+ "id": "MH022RD0K5",
6
+ "visitor_name": "Mary Brown",
7
+ "visitor_id": "S1355415390.49b8940793",
8
+ "agents": [
9
+ {
10
+ "display_name": "John Doe",
11
+ "email": "john.doe@mycompany.com"
12
+ }
13
+ ],
14
+ "supervisors": [
15
+ {
16
+ "display_name": "Jane Doe",
17
+ "email": "jane.doe@mycompany.com"
18
+ }
19
+ ],
20
+ "rate": "not_rated",
21
+ "duration": 1456, // in seconds
22
+ "group": [
23
+ 0
24
+ ],
25
+ "started": "Wed, 01/23/13 11:40:53 am",
26
+ "prechat_survey": [
27
+ {
28
+ "key": "Name:",
29
+ "value": "",
30
+ "id": "13589376348060238"
31
+ },
32
+ {
33
+ "key": "E-mail:",
34
+ "value": "",
35
+ "id": "135893763480606511"
36
+ }
37
+ ],
38
+ "postchat_survey": [
39
+ {
40
+ "key": "How would you rate the quality of support?",
41
+ "value": "Good",
42
+ "id": "137164167769201638"
43
+ }
44
+ ],
45
+ "custom_variables": [
46
+ {
47
+ "key": "customer_login",
48
+ "value": "mary_brown"
49
+ }
50
+ ],
51
+ "integration_variables": [
52
+ {
53
+ "key": "facebook.id",
54
+ "value": "123456789"
55
+ },
56
+ {
57
+ "key": "facebook.name",
58
+ "value": "Mary Brown"
59
+ },
60
+ {
61
+ "key": "facebook.first_name",
62
+ "value": "Mary"
63
+ },
64
+ {
65
+ "key": "facebook.last_name",
66
+ "value": "Brown"
67
+ },
68
+ {
69
+ "key": "facebook.gender",
70
+ "value": "female"
71
+ },
72
+ {
73
+ "key": "facebook.locale",
74
+ "value": "en_US"
75
+ },
76
+ {
77
+ "key": "facebook.link",
78
+ "value": "http://www.facebook.com/mary.brown"
79
+ },
80
+ {
81
+ "key": "facebook.username",
82
+ "value": "mary.brown"
83
+ },
84
+ {
85
+ "key": "facebook.email",
86
+ "value": "mary.brown@email.com"
87
+ }
88
+ ],
89
+ "goals": [
90
+ {
91
+ "id": 71,
92
+ "name": "goal_name"
93
+ }
94
+ ],
95
+ "messages": [
96
+ {
97
+ "author_name": "John Doe",
98
+ "text": "Hello",
99
+ "date": "Wed, 01/23/13 11:40:53 am",
100
+ "timestamp": 1358937653,
101
+ "user_type": "agent",
102
+ "agent_id": "john.doe@mycompany.com"
103
+ },
104
+ {
105
+ "author_name": "Mary Brown",
106
+ "text": "How are you?",
107
+ "date": "Wed, 01/23/13 11:41:01 am",
108
+ "timestamp": 1358937661,
109
+ "user_type": "visitor"
110
+ },
111
+ {
112
+ "author_name": "John Doe",
113
+ "text": "Thanks, fine :)",
114
+ "date": "Wed, 01/23/13 11:41:05 am",
115
+ "timestamp": 1358937665,
116
+ "user_type": "agent",
117
+ "agent_id": "john.doe@mycompany.com"
118
+ },
119
+ {
120
+ "author_name": "Jane Doe",
121
+ "text": "Message from supervisor.",
122
+ "date": "Wed, 01/23/13 11:57:13 am",
123
+ "timestamp": 1358938633,
124
+ "user_type": "supervisor",
125
+ "agent_id": "jane.doe@mycompany.com"
126
+ }
127
+ ],
128
+ "started_timestamp": 1358937653,
129
+ "ended_timestamp": 1358939109,
130
+ "ended": "Wed, 01/23/13 12:05:09 pm"
131
+ }
132
+ ],
133
+ "total": 1,
134
+ "pages": 1
135
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": 1181,
3
+ "name": "nike shoes variable",
4
+ "active": 1,
5
+ "type": "custom_variable",
6
+ "custom_variable_name": "nike_shoes",
7
+ "custom_variable_value": "true"
8
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "id": 1041,
4
+ "name": "purchase",
5
+ "active": 1
6
+ },
7
+ {
8
+ "id": 1181,
9
+ "name": "nike shoes variable",
10
+ "active": 1
11
+ }
12
+ ]
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": 2,
3
+ "name": "Sales",
4
+ "language": "en",
5
+ "agents": [
6
+ "john.doe@mycompany.com",
7
+ "jenny.doe@mycompany.com"
8
+ ],
9
+ "status": "accepting chats"
10
+ }
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "id": 0,
4
+ "name": "All operators",
5
+ "language": "en"
6
+ },
7
+ {
8
+ "id": 1,
9
+ "name": "Invoicing",
10
+ "language": "en",
11
+ "agents": [
12
+ "jane.doe@mycompany.com"
13
+ ]
14
+ },
15
+ {
16
+ "id": 2,
17
+ "name": "Sales",
18
+ "language": "en",
19
+ "agents": [
20
+ "john.doe@mycompany.com",
21
+ "jenny.doe@mycompany.com"
22
+ ]
23
+ },
24
+ {
25
+ "id": 3,
26
+ "name": "Technical Support",
27
+ "language": "en",
28
+ "agents": [
29
+ "john.doe@mycompany.com"
30
+ ]
31
+ }
32
+ ]
@@ -0,0 +1,91 @@
1
+ [
2
+ {
3
+ "browser": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14",
4
+ "chat_id": "MH0H3V3XO3",
5
+ "chat_start_time": "2013-01-31 15:51:03",
6
+ "city": "Greenville",
7
+ "country": "United States",
8
+ "host": "152.27.26.254",
9
+ "id": "S1355415390.49b8940793",
10
+ "ip": "152.27.26.254",
11
+ "language": "en",
12
+ "last_visit": "2013-01-31 15:43:05",
13
+ "latitude": "35.6127",
14
+ "longitude": "-77.3663",
15
+ "operators": [
16
+ {
17
+ "id": "john.doe@mycompany.com",
18
+ "display_name": "John Doe"
19
+ }
20
+ ],
21
+ "page_current": "http://www.mycompany.com/products/shoes",
22
+ "page_entered": "2013-01-31 15:49:17",
23
+ "page_time": "2013-01-31 15:49:17",
24
+ "prechat_survey": [
25
+ {
26
+ "key": "Name:",
27
+ "value": "Mark"
28
+ },
29
+ {
30
+ "key": "E-mail:",
31
+ "value": "mark.johnson@example.com"
32
+ }
33
+ ],
34
+ "queue_start_time": "",
35
+ "referrer": "",
36
+ "region": "North Carolina",
37
+ "state": "chatting",
38
+ "timezone": "America/New_York",
39
+ "custom_variables": [
40
+ {
41
+ "key": "empty_cart",
42
+ "value": "true"
43
+ }
44
+ ],
45
+ "chats": 27,
46
+ "group": 0,
47
+ "greetings_accepted": 9,
48
+ "greetings_all": 13,
49
+ "greetings_refused": 4,
50
+ "visits": 16,
51
+ "page_views": 59
52
+ },
53
+ {
54
+ "browser": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11",
55
+ "chat_id": "",
56
+ "chat_start_time": "",
57
+ "city": "Courbevoie",
58
+ "country": "France",
59
+ "host": "def92-2-87-91-13-226.dsl.sta.abo.bbox.fr",
60
+ "id": "S1359643767.a7904dd2f2",
61
+ "ip": "87.91.13.226",
62
+ "language": "en",
63
+ "last_visit": "2013-01-31 15:49:27",
64
+ "latitude": "48.897",
65
+ "longitude": "2.2564",
66
+ "operators": [
67
+ {
68
+ "id": "",
69
+ "display_name": ""
70
+ }
71
+ ],
72
+ "page_current": "http://www.mycompany.com/",
73
+ "page_entered": "2013-01-31 15:49:27",
74
+ "page_time": "2013-01-31 15:49:27",
75
+ "prechat_survey": [
76
+
77
+ ],
78
+ "queue_start_time": "",
79
+ "referrer": "",
80
+ "region": "Ile-de-France",
81
+ "state": "online",
82
+ "timezone": "Europe/Paris",
83
+ "chats": 0,
84
+ "group": 0,
85
+ "greetings_accepted": 0,
86
+ "greetings_all": 0,
87
+ "greetings_refused": 0,
88
+ "visits": 1,
89
+ "page_views": 1
90
+ }
91
+ ]
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ include WebMock::API
4
+
5
+
6
+ describe LiveChat::REST::Agents do
7
+
8
+ before do
9
+ @livechat = create_client
10
+
11
+ @john_id = 'john.doe@mycompany.com'
12
+ @jane_id = 'jane.doe@mycompany.com'
13
+ @alice_id = 'alice@mycompany.com'
14
+
15
+ stub_rest 'agents'
16
+
17
+ end
18
+
19
+ after do
20
+ WebMock.reset!
21
+ end
22
+
23
+ it "lists all agents" do
24
+ agents = @livechat.agents.list
25
+ expect(agents.length).to be(2)
26
+ end
27
+
28
+ it "gets a single agent details" do
29
+ agent = @livechat.agents(@john_id)
30
+ expect(agent.login).to eq(@john_id)
31
+ end
32
+
33
+ it "creates a new agent" do
34
+ agent = @livechat.agents.create do |a|
35
+ a[:login] = @alice_id
36
+ a[:name] = 'Alice'
37
+ end
38
+ end
39
+
40
+ #all properties are optional
41
+ it "updates an agent" do
42
+ @livechat.agents(@jane_id).update do |a|
43
+ a[:job_title] = 'Tester'
44
+ a[:status] = 'not accepting chats'
45
+ end
46
+ end
47
+
48
+ it "resets an API key" do
49
+ @livechat.agents(@alice_id).reset_api_key
50
+ end
51
+
52
+ it "removes an agent" do
53
+ @livechat.agents(@alice_id).delete
54
+ end
55
+
56
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ include WebMock::API
4
+
5
+
6
+ describe LiveChat::REST::CannedResponses do
7
+ before do
8
+ @livechat = create_client
9
+
10
+ stub_rest 'canned_responses'
11
+ end
12
+
13
+ after do
14
+ WebMock.reset!
15
+ end
16
+
17
+ it "lists all canned responses" do
18
+ @livechat.canned_responses
19
+ end
20
+
21
+ it "gets a single canned response" do
22
+ @livechat.canned_responses(0)
23
+ end
24
+
25
+ it "creates a new canned response" do
26
+ canned_response = @livechat.canned_responses.create do |r|
27
+ r[:text] = 'Have a great day, goodbye.'
28
+ r[:tags] = ['cu', 'bye']
29
+ end
30
+ end
31
+
32
+ it "updates a canned response" do
33
+ @livechat.canned_responses(0).update do |r|
34
+ r[:tags] = ['bye']
35
+ end
36
+ end
37
+
38
+ it "removes a canned response" do
39
+ @livechat.canned_responses(0).delete
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ include WebMock::API
4
+
5
+
6
+ describe LiveChat::REST::Chats do
7
+ before do
8
+ @livechat = create_client
9
+
10
+ stub_rest 'chats'
11
+ end
12
+
13
+ after do
14
+ WebMock.reset!
15
+ end
16
+
17
+
18
+ it "gets list of chats" do
19
+ chats = @livechat.chats
20
+ expect(chats.list.length).to be(1)
21
+ end
22
+
23
+ it "gets single chat" do
24
+ chat = @livechat.chats('MH022RD0K5')
25
+ expect(chat.visitor_name).to eq('Mary Brown')
26
+ end
27
+
28
+ it "sends chat transcript to e-mail" do
29
+ @livechat.chats('MH022RD0K5').send_transcript(:to => 'john.doe@mycompany.com')
30
+ expect(@livechat.last_request.path).to eq '/chats/MH022RD0K5/send_transcript'
31
+ expect(@livechat.last_request.method).to eq 'POST'
32
+ expect(@livechat.last_request.body).to eq 'to=john.doe%40mycompany.com'
33
+ end
34
+
35
+
36
+ end
37
+
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ include WebMock::API
4
+
5
+
6
+ describe LiveChat::REST::Goals do
7
+ before do
8
+ @livechat = create_client
9
+
10
+ stub_rest 'goals'
11
+ end
12
+
13
+ after do
14
+ WebMock.reset!
15
+ end
16
+
17
+
18
+ it "lists all goals" do
19
+ @livechat.goals
20
+ end
21
+
22
+ it "gets a single goal details" do
23
+ @livechat.goals(1181)
24
+ end
25
+
26
+ it "marks goal as successful" do
27
+ @livechat.goals(1181).mark_as_successful(:visitor_id => 1, :order_id => 'AP723HVCA721')
28
+ expect(@livechat.last_request.body).to eq 'visitor_id=1&order_id=AP723HVCA721'
29
+
30
+ end
31
+
32
+ it "adds a new goal" do
33
+ @livechat.goals.create do |goal|
34
+ goal[:name] = 'new goal'
35
+ goal[:type] = 'url'
36
+ end
37
+ end
38
+
39
+ it "updates a goal" do
40
+ @livechat.goals(2231).update do |goal|
41
+ goal[:name] = 'updated goal'
42
+ end
43
+ end
44
+
45
+ it "removes a goal" do
46
+ @livechat.goals(2231).delete
47
+ end
48
+
49
+ end
50
+