livechat_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,116 @@
1
+ module LiveChat
2
+ module REST
3
+ class Reports < ListResource
4
+
5
+ #http://developers.livechatinc.com/rest-api/#get-dashboard-data
6
+ def dashboard(*arg)
7
+ params = Hash[*arg]
8
+ if params.has_key? :agent
9
+ return dashboard_agent params[:agent]
10
+
11
+ elsif params.has_key? :group
12
+ return dashboard_group params[:group]
13
+ end
14
+
15
+ @client.get "#{@path}/dashboard"
16
+ end
17
+
18
+ #http://developers.livechatinc.com/rest-api/#get-dashboard-data-for-agent
19
+ def dashboard_agent(login)
20
+ @client.get "#{@path}/dashboard/agent/#{login}"
21
+ end
22
+
23
+ #http://developers.livechatinc.com/rest-api/#get-dashboard-data-for-group
24
+ def dashboard_group(group_id)
25
+ @client.get "#{@path}/dashboard/group/#{group_id}"
26
+ end
27
+
28
+ #http://developers.livechatinc.com/rest-api/#get-chats-report
29
+ #optional arguments:
30
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
31
+ # date_to - YYYY-MM-DD, defaults to today.
32
+ # group - id of the group, not set by default, returns statistics for the specified group.
33
+ # agent - agent's login, not set by default, return statistics for the specified agent.
34
+ # group_by - defaults to day (or hour when date_from equals date_to), can be set to month or hour.
35
+ def chats(*args)
36
+ @client.get "#{@path}/chats", Hash[*args]
37
+ end
38
+
39
+ #http://developers.livechatinc.com/rest-api/#get-ratings-report
40
+ #optional arguments
41
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
42
+ # date_to - YYYY-MM-DD, defaults to today.
43
+ # group - id of the group, not set by default, returns statistics for the specified group.
44
+ # agent - agent's login, not set by default, return statistics for the specified agent.
45
+ # group_by – defaults to day (or hour when date_from equals date_to), can be set to month or hour.
46
+ def ratings(*args)
47
+ @client.get "#{@path}/ratings", Hash[*args]
48
+ end
49
+
50
+ #http://developers.livechatinc.com/rest-api/#get-ratings-ranking
51
+ #optional arguments
52
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
53
+ # date_to - YYYY-MM-DD, defaults to today.
54
+ # group - id of the group, not set by default, returns statistics for the specified group.
55
+ def ratings_ranking(*args)
56
+ @client.get "#{@path}/ratings/ranking", Hash[*args]
57
+ end
58
+
59
+ #http://developers.livechatinc.com/rest-api/#get-queued-visitors-report
60
+ #optional arguments
61
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
62
+ # date_to - YYYY-MM-DD, defaults to today.
63
+ # group - id of the group, not set by default, returns statistics for the specified group.
64
+ # group_by - defaults to day (or hour when date_from equals date_to), can be set to month or hour.
65
+ def queued_visitors(*args)
66
+ @client.get "#{@path}/queued_visitors", Hash[*args]
67
+ end
68
+
69
+ #http://developers.livechatinc.com/rest-api/#get-queue-waiting-times-report
70
+ #optional arguments
71
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
72
+ # date_to - YYYY-MM-DD, defaults to today.
73
+ # group - id of the group, not set by default, returns statistics for the specified group.
74
+ # group_by - defaults to day (or hour when date_from equals date_to), can be set to month or hour.
75
+ def queued_visitors_waiting_times(*args)
76
+ @client.get "#{@path}/queued_visitors/waiting_times", Hash[*args]
77
+ end
78
+
79
+ #http://developers.livechatinc.com/rest-api/#get-availability-report
80
+ #optional arguments
81
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
82
+ # date_to - YYYY-MM-DD, defaults to today.
83
+ # group - id of the group, not set by default, returns statistics for the specified group.
84
+ # agent - agent's login, not set by default, return statistics for the specified agent.
85
+ def availability(*args)
86
+ @client.get "#{@path}/availability", Hash[*args]
87
+ end
88
+
89
+ #http://developers.livechatinc.com/rest-api/#get-chatting-time-report
90
+ #optional arguments
91
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
92
+ # date_to - YYYY-MM-DD, defaults to today.
93
+ # group - id of the group, not set by default, returns statistics for the specified group.
94
+ # agent - agent's login, not set by default, returns statistics for the specified agent
95
+ def chatting_time(*args)
96
+ @client.get "#{@path}/chatting_time", Hash[*args]
97
+ end
98
+
99
+ #http://developers.livechatinc.com/rest-api/#get-goals-report
100
+ #optional arguments:
101
+ # date_from - YYYY-MM-DD, defaults to the beginning of time.
102
+ # date_to - YYYY-MM-DD, defaults to today.
103
+ # group - id of the group, not set by default, returns statistics for the specified group.
104
+ # goal - id of the goal, not set by default.
105
+ # agent - agent's login, not set by default, return statistics for the specified agent.
106
+ # group_by - defaults to day (or hour when date_from equals date_to), can be set to month or hour.
107
+ def goals(*args)
108
+ @client.get "#{@path}/goals", Hash[*args]
109
+ end
110
+
111
+ end
112
+
113
+ class Report < InstanceResource
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,13 @@
1
+ module LiveChat
2
+ module REST
3
+ class Status
4
+ def initialize(path, client)
5
+ @path, @client = path, client
6
+ end
7
+
8
+ def get(params={})
9
+ @client.get "#{@path}/#{params[:group]}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ module LiveChat
2
+ module REST
3
+ module Utils
4
+
5
+ def restify(something)
6
+ if something.is_a? Hash
7
+ Hash[*something.to_a.map {|a| [restify(a[0]).to_sym, a[1]]}.flatten]
8
+ else
9
+ something.to_s.split('_').map do |s|
10
+ [s[0,1].capitalize, s[1..-1]].join
11
+ end.join
12
+ end
13
+ end
14
+
15
+ def unrestify(something)
16
+ if something.is_a? Hash
17
+ Hash[*something.to_a.map {|pair| [unrestify(pair[0]).to_sym, pair[1]]}.flatten]
18
+ else
19
+ something.to_s.gsub(/[A-Z][a-z]*/) {|s| "_#{s.downcase}"}.gsub(/^_/, '')
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module LiveChat
2
+ module REST
3
+ class Visitors < ListResource
4
+ def chatting
5
+ list
6
+ end
7
+ end
8
+
9
+ class Visitor < InstanceResource
10
+ def add_details(params={})
11
+ yield params if block_given?
12
+ @client.post(@path, params)
13
+ self
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module LiveChat
2
+ module Util
3
+ def url_encode(hash)
4
+ hash.to_a.map {|p| p.map {|e| CGI.escape e.to_s}.join '='}.join '&'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module LiveChat
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'livechat/version'
6
+
7
+ Gem::Specification.new do |g|
8
+ g.name = "livechat_client"
9
+ g.version = LiveChat::VERSION.dup
10
+ g.platform = Gem::Platform::RUBY
11
+ g.authors = ["Alexandre Maia"]
12
+ g.email = ["alexandre.maia@gmail.com"]
13
+ g.homepage = "https://github.com/cxz/livechat_client"
14
+ g.summary = %q|LiveChat REST API Client|
15
+ g.description = %q|Ruby wrapper for the REST API at http://developers.livechatinc.com/rest-api/|
16
+ g.license = %q|MIT|
17
+
18
+ g.required_ruby_version = ">= 1.8.7"
19
+ g.required_rubygems_version = ">= 1.3.6"
20
+
21
+ g.add_development_dependency "rake"
22
+ g.add_development_dependency "rspec"
23
+ g.add_development_dependency "webmock", "~> 1.9.0"
24
+
25
+ g.add_runtime_dependency "hashie", ">= 1.2"
26
+ g.add_runtime_dependency "multi_json"
27
+
28
+ g.files = `git ls-files`.split("\n") rescue ''
29
+ g.require_paths = ["lib"]
30
+ g.test_files = Dir['spec/**/*.rb']
31
+ g.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'livechat', '--main', 'README.md']
32
+
33
+ end
@@ -0,0 +1,30 @@
1
+ {
2
+ "login": "john.doe@mycompany.com",
3
+ "name": "John Doe",
4
+ "login_status": "accepting chats",
5
+ "permission": "owner",
6
+ "daily_summary": 1,
7
+ "job_title": "Support Agent",
8
+ "avatar": "livechat.s3.amazonaws.com/1011121/all/avatars/bdd8924fcbcdbddbeaf60c19b238b0b0.jpg",
9
+ "notifications": {
10
+ "new_visitor": 1,
11
+ "returning_visitor": 1,
12
+ "queued_visitor": 1,
13
+ "visitor_is_typing": 0,
14
+ "new_goal": 1
15
+ },
16
+ "max_chats_count": 6,
17
+ "groups": [
18
+ {
19
+ "id": 1,
20
+ "name": "Sales"
21
+ },
22
+ {
23
+ "id": 2,
24
+ "name": "Technical Support"
25
+ }
26
+ ],
27
+ "status": "accepting chats",
28
+ "last_logout": 1358427204,
29
+ "api_key": "6ed8580f2cc160ce98d16389a0ede2c0"
30
+ }
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "name": "John Doe",
4
+ "permission": "owner",
5
+ "avatar": "livechat.s3.amazonaws.com/1011121/all/avatars/bdd8924fcbcdbddbeaf60c19b238b0b0.jpg",
6
+ "login": "john.doe@mycompany.com",
7
+ "status": "accepting chats"
8
+ },
9
+ {
10
+ "name": "Jane Doe",
11
+ "permission": "normal",
12
+ "avatar": "livechat.s3.amazonaws.com/1011121/all/avatars/a557c601619878e28343cddb9a1b8445.jpg",
13
+ "login": "jane.doe@mycompany.com",
14
+ "status": "offline"
15
+ }
16
+ ]
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": 3181,
3
+ "group": 0,
4
+ "text": "Have a great day, goodbye.",
5
+ "creation_date": 1358866421,
6
+ "created_by": "john.doe@mycompany.com",
7
+ "modification_date": 1358866813,
8
+ "modified_by": "john.doe@mycompany.com",
9
+ "tags": [
10
+ "bye"
11
+ ]
12
+ }
@@ -0,0 +1,37 @@
1
+ [
2
+ {
3
+ "id": 3151,
4
+ "group": 1,
5
+ "text": "Can I help you with anything else?",
6
+ "creation_date": 1358257181,
7
+ "created_by": "john.doe@mycompany.com",
8
+ "tags": [
9
+ "help",
10
+ "else"
11
+ ]
12
+ },
13
+ {
14
+ "id": 3161,
15
+ "group": 1,
16
+ "text": "What product are you interested in?",
17
+ "creation_date": 1358257229,
18
+ "created_by": "john.doe@mycompany.com",
19
+ "modification_date": 1358864338,
20
+ "modified_by": "jenny.doe@mycompany.com",
21
+ "tags": [
22
+ "product",
23
+ "interest"
24
+ ]
25
+ },
26
+ {
27
+ "id": 3171,
28
+ "group": 1,
29
+ "text": "I will transfer you to the agent responsible for this matter.",
30
+ "creation_date": 1358864376,
31
+ "created_by": "jenny.doe@mycompany.com",
32
+ "tags": [
33
+ "transfer",
34
+ "matter"
35
+ ]
36
+ }
37
+ ]
@@ -0,0 +1,129 @@
1
+ {
2
+ "type": "chat",
3
+ "id": "MH022RD0K5",
4
+ "visitor_name": "Mary Brown",
5
+ "visitor_id": "S1355415390.49b8940793",
6
+ "agents": [
7
+ {
8
+ "display_name": "John Doe",
9
+ "email": "john.doe@mycompany.com"
10
+ }
11
+ ],
12
+ "supervisors": [
13
+ {
14
+ "display_name": "Jane Doe",
15
+ "email": "jane.doe@mycompany.com"
16
+ }
17
+ ],
18
+ "rate": "not_rated",
19
+ "duration": 1456, // in seconds
20
+ "group": [
21
+ 0
22
+ ],
23
+ "started": "Wed, 01/23/13 11:40:53 am",
24
+ "prechat_survey": [
25
+ {
26
+ "key": "Name:",
27
+ "value": "",
28
+ "id": "13589376348060238"
29
+ },
30
+ {
31
+ "key": "E-mail:",
32
+ "value": "",
33
+ "id": "135893763480606511"
34
+ }
35
+ ],
36
+ "postchat_survey": [
37
+ {
38
+ "key": "How would you rate the quality of support?",
39
+ "value": "Good",
40
+ "id": "137164167769201638"
41
+ }
42
+ ],
43
+ "custom_variables": [
44
+ {
45
+ "key": "customer_login",
46
+ "value": "mary_brown"
47
+ }
48
+ ],
49
+ "integration_variables": [
50
+ {
51
+ "key": "facebook.id",
52
+ "value": "123456789"
53
+ },
54
+ {
55
+ "key": "facebook.name",
56
+ "value": "Mary Brown"
57
+ },
58
+ {
59
+ "key": "facebook.first_name",
60
+ "value": "Mary"
61
+ },
62
+ {
63
+ "key": "facebook.last_name",
64
+ "value": "Brown"
65
+ },
66
+ {
67
+ "key": "facebook.gender",
68
+ "value": "female"
69
+ },
70
+ {
71
+ "key": "facebook.locale",
72
+ "value": "en_US"
73
+ },
74
+ {
75
+ "key": "facebook.link",
76
+ "value": "http://www.facebook.com/mary.brown"
77
+ },
78
+ {
79
+ "key": "facebook.username",
80
+ "value": "mary.brown"
81
+ },
82
+ {
83
+ "key": "facebook.email",
84
+ "value": "mary.brown@email.com"
85
+ }
86
+ ],
87
+ "goals": [
88
+ {
89
+ "id": 71,
90
+ "name": "goal_name"
91
+ }
92
+ ],
93
+ "messages": [
94
+ {
95
+ "author_name": "John Doe",
96
+ "text": "Hello",
97
+ "date": "Wed, 01/23/13 11:40:53 am",
98
+ "timestamp": 1358937653,
99
+ "user_type": "agent",
100
+ "agent_id": "john.doe@mycompany.com"
101
+ },
102
+ {
103
+ "author_name": "Mary Brown",
104
+ "text": "How are you?",
105
+ "date": "Wed, 01/23/13 11:41:01 am",
106
+ "timestamp": 1358937661,
107
+ "user_type": "visitor"
108
+ },
109
+ {
110
+ "author_name": "John Doe",
111
+ "text": "Thanks, fine :)",
112
+ "date": "Wed, 01/23/13 11:41:05 am",
113
+ "timestamp": 1358937665,
114
+ "user_type": "agent",
115
+ "agent_id": "john.doe@mycompany.com"
116
+ },
117
+ {
118
+ "author_name": "Jane Doe",
119
+ "text": "Message from supervisor.",
120
+ "date": "Wed, 01/23/13 11:57:13 am",
121
+ "timestamp": 1358938633,
122
+ "user_type": "supervisor",
123
+ "agent_id": "jane.doe@mycompany.com"
124
+ }
125
+ ],
126
+ "started_timestamp": 1358937653,
127
+ "ended_timestamp": 1358939109,
128
+ "ended": "Wed, 01/23/13 12:05:09 pm"
129
+ }