desk_api_v2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +0 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +24 -0
  6. data/README.md +27 -0
  7. data/Rakefile +39 -0
  8. data/desk_api_v2.gemspec +27 -0
  9. data/lib/desk.rb +11 -0
  10. data/lib/desk/api/articles.rb +34 -0
  11. data/lib/desk/api/cases.rb +47 -0
  12. data/lib/desk/api/customers.rb +36 -0
  13. data/lib/desk/api/groups.rb +30 -0
  14. data/lib/desk/api/modules/creatable.rb +15 -0
  15. data/lib/desk/api/modules/deletable.rb +11 -0
  16. data/lib/desk/api/modules/listable.rb +16 -0
  17. data/lib/desk/api/modules/searchable.rb +13 -0
  18. data/lib/desk/api/topics.rb +25 -0
  19. data/lib/desk/api/translations.rb +24 -0
  20. data/lib/desk/article.rb +7 -0
  21. data/lib/desk/case.rb +7 -0
  22. data/lib/desk/client.rb +39 -0
  23. data/lib/desk/collection.rb +17 -0
  24. data/lib/desk/connection.rb +71 -0
  25. data/lib/desk/customer.rb +7 -0
  26. data/lib/desk/entity.rb +7 -0
  27. data/lib/desk/error.rb +17 -0
  28. data/lib/desk/filter.rb +7 -0
  29. data/lib/desk/group.rb +7 -0
  30. data/lib/desk/message.rb +7 -0
  31. data/lib/desk/response/error_handling.rb +30 -0
  32. data/lib/desk/topic.rb +7 -0
  33. data/lib/desk/translation.rb +7 -0
  34. data/lib/desk/user.rb +7 -0
  35. data/spec/desk/api/articles_spec.rb +135 -0
  36. data/spec/desk/api/cases_spec.rb +181 -0
  37. data/spec/desk/api/customers_spec.rb +135 -0
  38. data/spec/desk/api/groups_spec.rb +98 -0
  39. data/spec/desk/api/topics_spec.rb +98 -0
  40. data/spec/desk/api/translations_spec.rb +92 -0
  41. data/spec/desk/collection_spec.rb +22 -0
  42. data/spec/desk/connection_spec.rb +95 -0
  43. data/spec/fixtures/article.json +39 -0
  44. data/spec/fixtures/articles.json +101 -0
  45. data/spec/fixtures/case.json +40 -0
  46. data/spec/fixtures/cases.json +105 -0
  47. data/spec/fixtures/customer.json +60 -0
  48. data/spec/fixtures/customers.json +143 -0
  49. data/spec/fixtures/group.json +9 -0
  50. data/spec/fixtures/group_filters.json +53 -0
  51. data/spec/fixtures/group_users.json +71 -0
  52. data/spec/fixtures/groups.json +42 -0
  53. data/spec/fixtures/message.json +26 -0
  54. data/spec/fixtures/topic.json +23 -0
  55. data/spec/fixtures/topics.json +69 -0
  56. data/spec/fixtures/translation.json +28 -0
  57. data/spec/fixtures/translations.json +79 -0
  58. data/spec/spec_helper.rb +17 -0
  59. metadata +200 -0
@@ -0,0 +1,95 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Desk::Connection do
4
+
5
+ subject { Desk::Connection.new(site: "yoursite", email: "user@example.com", password: "foo") }
6
+
7
+ describe "#get" do
8
+ it "will send a proper get request" do
9
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases"
10
+ stub_request(:get, url).with(headers: { accept: 'application/json' } )
11
+
12
+ subject.get("cases")
13
+
14
+ assert_requested :get, url
15
+ end
16
+
17
+ it "will convert the response to a hash" do
18
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases"
19
+ stub_request(:get, url).to_return(body: '{"foo":"bar"}', status: 200)
20
+
21
+ result = subject.get("cases")
22
+ expected = { "foo" => "bar" }
23
+ assert_equal expected, result
24
+ end
25
+
26
+ it "will pass hash arguments as params" do
27
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/search?foo=bar"
28
+ stub_request(:get, url).with(headers: { accept: 'application/json' } )
29
+
30
+ result = subject.get("search", foo: "bar")
31
+ assert_requested :get, url
32
+ end
33
+
34
+ it "will url encode hash arguments" do
35
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/search?foo=bar%26baz"
36
+ stub_request(:get, url).with(headers: { accept: 'application/json' } )
37
+
38
+ result = subject.get("search", foo: "bar&baz")
39
+ assert_requested :get, url
40
+ end
41
+
42
+ it "will join arrays" do
43
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/search?foo=bar,baz"
44
+ stub_request(:get, url).with(headers: { accept: 'application/json' } )
45
+
46
+ result = subject.get("search", foo: ["bar","baz"])
47
+ assert_requested :get, url
48
+ end
49
+ end
50
+
51
+ describe "#post" do
52
+ it "will send a proper post request" do
53
+ data = {foo: "bar", bar: ["foo", "bar", "baz"]}
54
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases"
55
+ stub_request(:post, url).with(data: data, headers: { accept: 'application/json' })
56
+
57
+ subject.post("cases", data)
58
+
59
+ assert_requested :post, url
60
+ end
61
+ end
62
+
63
+ describe "#patch" do
64
+ it "will send a proper patch request" do
65
+ data = {foo: "bar"}
66
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases"
67
+ stub_request(:patch, url).with(data: data, headers: { accept: 'application/json' })
68
+
69
+ subject.patch("cases", data)
70
+
71
+ assert_requested :patch, url
72
+ end
73
+ end
74
+
75
+ describe "#delete" do
76
+ it "will send a proper delete request" do
77
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases/1234"
78
+ stub_request(:delete, url).with(headers: { accept: 'application/json' })
79
+
80
+ subject.delete("cases/1234")
81
+
82
+ assert_requested :delete, url
83
+ end
84
+
85
+ it "returns true if delete is successful" do
86
+ url = "https://user@example.com:foo@yoursite.desk.com/api/v2/cases/1234"
87
+ stub_request(:delete, url).with(headers: { accept: 'application/json' })
88
+ .to_return(status: 204)
89
+
90
+ assert_equal true, subject.delete("cases/1234")
91
+ end
92
+ end
93
+
94
+
95
+ end
@@ -0,0 +1,39 @@
1
+ {
2
+ "subject": "Awesome Subject",
3
+ "body": "<p>Awesome apples</p>",
4
+ "body_email": "Email for Awesome apples",
5
+ "body_email_auto": false,
6
+ "body_chat": "Awesome apples",
7
+ "body_chat_auto": true,
8
+ "body_web_callback": "<p>Awesome Apples</p>",
9
+ "body_web_callback_auto": false,
10
+ "body_twitter": "Awesome apples",
11
+ "body_twitter_auto": true,
12
+ "body_qna": "Awesome apples",
13
+ "body_qna_auto": true,
14
+ "body_phone": "Awesome apples",
15
+ "body_phone_auto": true,
16
+ "body_facebook": "Awesome apples",
17
+ "body_facebook_auto": true,
18
+ "position": 1,
19
+ "quickcode": "AWESOME",
20
+ "in_support_center": true,
21
+ "internal_notes": "Notes to the agent here",
22
+ "publish_at": "2013-08-05T14:40:36Z",
23
+ "created_at": "2013-08-05T14:35:36Z",
24
+ "updated_at": "2013-08-05T14:40:36Z",
25
+ "_links": {
26
+ "self": {
27
+ "href": "/api/v2/articles/1",
28
+ "class": "article"
29
+ },
30
+ "topic": {
31
+ "href": "/api/v2/topics/1",
32
+ "class": "topic"
33
+ },
34
+ "translations": {
35
+ "href": "/api/v2/articles/1/translations",
36
+ "class": "article_translation"
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,101 @@
1
+ {
2
+ "total_entries": 2,
3
+ "_links": {
4
+ "self": {
5
+ "href": "/api/v2/articles?page=1&per_page=30",
6
+ "class": "page"
7
+ },
8
+ "first": {
9
+ "href": "/api/v2/articles?page=1&per_page=30",
10
+ "class": "page"
11
+ },
12
+ "last": {
13
+ "href": "/api/v2/articles?page=1&per_page=30",
14
+ "class": "page"
15
+ },
16
+ "next": null,
17
+ "previous": null
18
+ },
19
+ "_embedded": {
20
+ "entries": [
21
+ {
22
+ "subject": "Awesome Subject",
23
+ "body": "<p>Awesome apples</p>",
24
+ "body_email": "Email for Awesome apples",
25
+ "body_email_auto": false,
26
+ "body_chat": "Awesome apples",
27
+ "body_chat_auto": true,
28
+ "body_web_callback": "<p>Awesome Apples</p>",
29
+ "body_web_callback_auto": false,
30
+ "body_twitter": "Awesome apples",
31
+ "body_twitter_auto": true,
32
+ "body_qna": "Awesome apples",
33
+ "body_qna_auto": true,
34
+ "body_phone": "Awesome apples",
35
+ "body_phone_auto": true,
36
+ "body_facebook": "Awesome apples",
37
+ "body_facebook_auto": true,
38
+ "position": 1,
39
+ "quickcode": "AWESOME",
40
+ "in_support_center": true,
41
+ "internal_notes": "Notes to the agent here",
42
+ "publish_at": "2013-08-05T14:40:36Z",
43
+ "created_at": "2013-08-05T14:35:36Z",
44
+ "updated_at": "2013-08-05T14:40:36Z",
45
+ "_links": {
46
+ "self": {
47
+ "href": "/api/v2/articles/1",
48
+ "class": "article"
49
+ },
50
+ "topic": {
51
+ "href": "/api/v2/topics/1",
52
+ "class": "topic"
53
+ },
54
+ "translations": {
55
+ "href": "/api/v2/articles/1/translations",
56
+ "class": "article_translation"
57
+ }
58
+ }
59
+ },
60
+ {
61
+ "subject": "How to make your customers happy",
62
+ "body": "<strong>Use Desk.com</strong>",
63
+ "body_email": "Email just doesn't cut it",
64
+ "body_email_auto": false,
65
+ "body_chat": "Use Desk.com",
66
+ "body_chat_auto": true,
67
+ "body_web_callback": "<strong>Use Desk.com</strong>",
68
+ "body_web_callback_auto": false,
69
+ "body_twitter": "Use Desk.com in 140 chars or less",
70
+ "body_twitter_auto": false,
71
+ "body_qna": "Use Desk.com",
72
+ "body_qna_auto": true,
73
+ "body_phone": "Use Desk.com",
74
+ "body_phone_auto": true,
75
+ "body_facebook": "Use Desk.com",
76
+ "body_facebook_auto": true,
77
+ "position": 1,
78
+ "quickcode": "AWESOME",
79
+ "in_support_center": true,
80
+ "internal_notes": "Notes to the agent here",
81
+ "publish_at": "2013-08-05T14:40:36Z",
82
+ "created_at": "2013-08-05T14:35:36Z",
83
+ "updated_at": "2013-08-05T14:40:36Z",
84
+ "_links": {
85
+ "self": {
86
+ "href": "/api/v2/articles/2",
87
+ "class": "article"
88
+ },
89
+ "topic": {
90
+ "href": "/api/v2/topics/1",
91
+ "class": "topic"
92
+ },
93
+ "translations": {
94
+ "href": "/api/v2/articles/2/translations",
95
+ "class": "article_translation"
96
+ }
97
+ }
98
+ }
99
+ ]
100
+ }
101
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "external_id": null,
3
+ "subject": "Welcome",
4
+ "priority": 5,
5
+ "locked_until": null,
6
+ "description": null,
7
+ "status": "new",
8
+ "type": "email",
9
+ "language": "en_us",
10
+ "created_at": "2013-08-05T14:35:36Z",
11
+ "updated_at": "2013-08-05T14:35:36Z",
12
+ "active_at": null,
13
+ "received_at": "2012-05-02T21:38:48Z",
14
+ "custom_fields": {
15
+ "level": "vip"
16
+ },
17
+ "_links": {
18
+ "self": {
19
+ "href": "/api/v2/cases/1",
20
+ "class": "case"
21
+ },
22
+ "message": {
23
+ "href": "/api/v2/cases/1/message",
24
+ "class": "message"
25
+ },
26
+ "customer": {
27
+ "href": "/api/v2/customers/1",
28
+ "class": "customer"
29
+ },
30
+ "assigned_user": {
31
+ "href": "/api/v2/users/2",
32
+ "class": "user"
33
+ },
34
+ "assigned_group": {
35
+ "href": "/api/v2/groups/1",
36
+ "class": "group"
37
+ },
38
+ "locked_by": null
39
+ }
40
+ }
@@ -0,0 +1,105 @@
1
+ {
2
+ "total_entries": 4,
3
+ "_links": {
4
+ "self": {
5
+ "href": "/api/v2/cases/search?subject=please+help&name=jimmy&page=1&per_page=2",
6
+ "class": "page"
7
+ },
8
+ "first": {
9
+ "href": "/api/v2/cases/search?subject=please+help&name=jimmy&page=1&per_page=2",
10
+ "class": "page"
11
+ },
12
+ "last": {
13
+ "href": "/api/v2/cases/search?subject=please+help&name=jimmy&page=2&per_page=2",
14
+ "class": "page"
15
+ },
16
+ "next": {
17
+ "href": "/api/v2/cases/search?subject=please+help&name=jimmy&page=2&per_page=2"
18
+ },
19
+ "previous": null
20
+ },
21
+ "_embedded": {
22
+ "entries": [
23
+ {
24
+ "external_id": null,
25
+ "subject": "Welcome",
26
+ "priority": 5,
27
+ "locked_until": null,
28
+ "description": null,
29
+ "status": "new",
30
+ "type": "email",
31
+ "language": "en_us",
32
+ "created_at": "2013-07-31T20:39:34Z",
33
+ "updated_at": "2013-07-31T20:39:34Z",
34
+ "active_at": null,
35
+ "received_at": "2012-05-02T21:38:48Z",
36
+ "custom_fields": {
37
+ "level": "vip"
38
+ },
39
+ "_links": {
40
+ "self": {
41
+ "href": "/api/v2/cases/1",
42
+ "class": "case"
43
+ },
44
+ "message": {
45
+ "href": "/api/v2/cases/1/message",
46
+ "class": "message"
47
+ },
48
+ "customer": {
49
+ "href": "/api/v2/customers/1",
50
+ "class": "customer"
51
+ },
52
+ "assigned_user": {
53
+ "href": "/api/v2/users/2",
54
+ "class": "user"
55
+ },
56
+ "assigned_group": {
57
+ "href": "/api/v2/groups/1",
58
+ "class": "group"
59
+ },
60
+ "locked_by": null
61
+ }
62
+ },
63
+ {
64
+ "external_id": null,
65
+ "subject": "Help Please!",
66
+ "priority": 5,
67
+ "locked_until": null,
68
+ "description": null,
69
+ "status": "new",
70
+ "type": "email",
71
+ "language": "en_us",
72
+ "created_at": "2013-07-31T20:39:34Z",
73
+ "updated_at": "2013-07-31T20:39:34Z",
74
+ "active_at": null,
75
+ "received_at": "2012-05-02T21:38:48Z",
76
+ "custom_fields": {
77
+ "level": "vip"
78
+ },
79
+ "_links": {
80
+ "self": {
81
+ "href": "/api/v2/cases/2",
82
+ "class": "case"
83
+ },
84
+ "message": {
85
+ "href": "/api/v2/cases/1/message",
86
+ "class": "message"
87
+ },
88
+ "customer": {
89
+ "href": "/api/v2/customers/1",
90
+ "class": "customer"
91
+ },
92
+ "assigned_user": {
93
+ "href": "/api/v2/users/2",
94
+ "class": "user"
95
+ },
96
+ "assigned_group": {
97
+ "href": "/api/v2/groups/1",
98
+ "class": "group"
99
+ },
100
+ "locked_by": null
101
+ }
102
+ }
103
+ ]
104
+ }
105
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "first_name": "John",
3
+ "last_name": "Doe",
4
+ "company": "ACME, Inc",
5
+ "title": "Senior Ninja",
6
+ "external_id": null,
7
+ "background": "This guy can be a challenge to work with",
8
+ "language": "en_us",
9
+ "locked_until": null,
10
+ "created_at": "2013-11-01T19:54:21Z",
11
+ "updated_at": "2013-11-01T19:54:21Z",
12
+ "custom_fields": {
13
+ "level": "vip"
14
+ },
15
+ "emails": [
16
+ {
17
+ "type": "work",
18
+ "value": "john@acme.com"
19
+ },
20
+ {
21
+ "type": "home",
22
+ "value": "john@home.com"
23
+ }
24
+ ],
25
+ "phone_numbers": [
26
+ {
27
+ "type": "work",
28
+ "value": "123-456-7890"
29
+ }
30
+ ],
31
+ "addresses": [
32
+ {
33
+ "type": "work",
34
+ "value": "123 Main St, San Francisco, CA 94105"
35
+ }
36
+ ],
37
+ "_links": {
38
+ "self": {
39
+ "href": "/api/v2/customers/1",
40
+ "class": "customer"
41
+ },
42
+ "cases": {
43
+ "href": "/api/v2/customers/1/cases",
44
+ "class": "case"
45
+ },
46
+ "company": {
47
+ "href": "/api/v2/companies/1",
48
+ "class": "company"
49
+ },
50
+ "facebook_user": {
51
+ "href": "/api/v2/facebook_users/1",
52
+ "class": "facebook_user"
53
+ },
54
+ "twitter_user": {
55
+ "href": "/api/v2/twitter_users/1",
56
+ "class": "twitter_user"
57
+ },
58
+ "locked_by": null
59
+ }
60
+ }
@@ -0,0 +1,143 @@
1
+ {
2
+ "total_entries": 2,
3
+ "_links": {
4
+ "self": {
5
+ "href": "/api/v2/customers?page=1&per_page=30",
6
+ "class": "page"
7
+ },
8
+ "first": {
9
+ "href": "/api/v2/customers?page=1&per_page=30",
10
+ "class": "page"
11
+ },
12
+ "last": {
13
+ "href": "/api/v2/customers?page=1&per_page=30",
14
+ "class": "page"
15
+ },
16
+ "next": null,
17
+ "previous": null
18
+ },
19
+ "_embedded": {
20
+ "entries": [
21
+ {
22
+ "first_name": "John",
23
+ "last_name": "Doe",
24
+ "company": "ACME, Inc",
25
+ "title": "Senior Ninja",
26
+ "external_id": null,
27
+ "background": "This guy can be a challenge to work with",
28
+ "language": "en_us",
29
+ "locked_until": null,
30
+ "created_at": "2013-11-01T19:54:21Z",
31
+ "updated_at": "2013-11-01T19:54:21Z",
32
+ "custom_fields": {
33
+ "level": "vip"
34
+ },
35
+ "emails": [
36
+ {
37
+ "type": "work",
38
+ "value": "john@acme.com"
39
+ },
40
+ {
41
+ "type": "home",
42
+ "value": "john@home.com"
43
+ }
44
+ ],
45
+ "phone_numbers": [
46
+ {
47
+ "type": "work",
48
+ "value": "123-456-7890"
49
+ }
50
+ ],
51
+ "addresses": [
52
+ {
53
+ "type": "work",
54
+ "value": "123 Main St, San Francisco, CA 94105"
55
+ }
56
+ ],
57
+ "_links": {
58
+ "self": {
59
+ "href": "/api/v2/customers/1",
60
+ "class": "customer"
61
+ },
62
+ "cases": {
63
+ "href": "/api/v2/customers/1/cases",
64
+ "class": "case"
65
+ },
66
+ "company": {
67
+ "href": "/api/v2/companies/1",
68
+ "class": "company"
69
+ },
70
+ "facebook_user": {
71
+ "href": "/api/v2/facebook_users/1",
72
+ "class": "facebook_user"
73
+ },
74
+ "twitter_user": {
75
+ "href": "/api/v2/twitter_users/1",
76
+ "class": "twitter_user"
77
+ },
78
+ "locked_by": null
79
+ }
80
+ },
81
+ {
82
+ "first_name": "Bob",
83
+ "last_name": "Doe",
84
+ "company": "ACME, Inc",
85
+ "title": "Senior Ninja",
86
+ "external_id": null,
87
+ "background": "Easy to work with",
88
+ "language": "en_us",
89
+ "locked_until": null,
90
+ "created_at": "2013-11-01T19:54:21Z",
91
+ "updated_at": "2013-11-01T19:54:21Z",
92
+ "custom_fields": {
93
+ "level": "vip"
94
+ },
95
+ "emails": [
96
+ {
97
+ "type": "work",
98
+ "value": "bob@acme.com"
99
+ },
100
+ {
101
+ "type": "home",
102
+ "value": "bob@home.com"
103
+ }
104
+ ],
105
+ "phone_numbers": [
106
+ {
107
+ "type": "work",
108
+ "value": "123-456-7890"
109
+ }
110
+ ],
111
+ "addresses": [
112
+ {
113
+ "type": "work",
114
+ "value": "123 Main St, San Francisco, CA 94105"
115
+ }
116
+ ],
117
+ "_links": {
118
+ "self": {
119
+ "href": "/api/v2/customers/2",
120
+ "class": "customer"
121
+ },
122
+ "cases": {
123
+ "href": "/api/v2/customers/1/cases",
124
+ "class": "case"
125
+ },
126
+ "company": {
127
+ "href": "/api/v2/companies/1",
128
+ "class": "company"
129
+ },
130
+ "facebook_user": {
131
+ "href": "/api/v2/facebook_users/1",
132
+ "class": "facebook_user"
133
+ },
134
+ "twitter_user": {
135
+ "href": "/api/v2/twitter_users/1",
136
+ "class": "twitter_user"
137
+ },
138
+ "locked_by": null
139
+ }
140
+ }
141
+ ]
142
+ }
143
+ }