desk_api_v2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +3 -0
- data/LICENSE +24 -0
- data/README.md +27 -0
- data/Rakefile +39 -0
- data/desk_api_v2.gemspec +27 -0
- data/lib/desk.rb +11 -0
- data/lib/desk/api/articles.rb +34 -0
- data/lib/desk/api/cases.rb +47 -0
- data/lib/desk/api/customers.rb +36 -0
- data/lib/desk/api/groups.rb +30 -0
- data/lib/desk/api/modules/creatable.rb +15 -0
- data/lib/desk/api/modules/deletable.rb +11 -0
- data/lib/desk/api/modules/listable.rb +16 -0
- data/lib/desk/api/modules/searchable.rb +13 -0
- data/lib/desk/api/topics.rb +25 -0
- data/lib/desk/api/translations.rb +24 -0
- data/lib/desk/article.rb +7 -0
- data/lib/desk/case.rb +7 -0
- data/lib/desk/client.rb +39 -0
- data/lib/desk/collection.rb +17 -0
- data/lib/desk/connection.rb +71 -0
- data/lib/desk/customer.rb +7 -0
- data/lib/desk/entity.rb +7 -0
- data/lib/desk/error.rb +17 -0
- data/lib/desk/filter.rb +7 -0
- data/lib/desk/group.rb +7 -0
- data/lib/desk/message.rb +7 -0
- data/lib/desk/response/error_handling.rb +30 -0
- data/lib/desk/topic.rb +7 -0
- data/lib/desk/translation.rb +7 -0
- data/lib/desk/user.rb +7 -0
- data/spec/desk/api/articles_spec.rb +135 -0
- data/spec/desk/api/cases_spec.rb +181 -0
- data/spec/desk/api/customers_spec.rb +135 -0
- data/spec/desk/api/groups_spec.rb +98 -0
- data/spec/desk/api/topics_spec.rb +98 -0
- data/spec/desk/api/translations_spec.rb +92 -0
- data/spec/desk/collection_spec.rb +22 -0
- data/spec/desk/connection_spec.rb +95 -0
- data/spec/fixtures/article.json +39 -0
- data/spec/fixtures/articles.json +101 -0
- data/spec/fixtures/case.json +40 -0
- data/spec/fixtures/cases.json +105 -0
- data/spec/fixtures/customer.json +60 -0
- data/spec/fixtures/customers.json +143 -0
- data/spec/fixtures/group.json +9 -0
- data/spec/fixtures/group_filters.json +53 -0
- data/spec/fixtures/group_users.json +71 -0
- data/spec/fixtures/groups.json +42 -0
- data/spec/fixtures/message.json +26 -0
- data/spec/fixtures/topic.json +23 -0
- data/spec/fixtures/topics.json +69 -0
- data/spec/fixtures/translation.json +28 -0
- data/spec/fixtures/translations.json +79 -0
- data/spec/spec_helper.rb +17 -0
- metadata +200 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../spec_helper'
|
3
|
+
|
4
|
+
describe Desk::Api::Customers do
|
5
|
+
|
6
|
+
before { @connection = Minitest::Mock.new }
|
7
|
+
|
8
|
+
subject { Desk::Api::Customers.new(@connection) }
|
9
|
+
|
10
|
+
describe "#all" do
|
11
|
+
|
12
|
+
before { @connection.expect(:get, customers_fixture, ["customers"]) }
|
13
|
+
|
14
|
+
it "will connect to the customers endpoint" do
|
15
|
+
subject.all
|
16
|
+
end
|
17
|
+
|
18
|
+
it "will return an array of customers" do
|
19
|
+
result = subject.all
|
20
|
+
|
21
|
+
assert result.is_a? Array
|
22
|
+
assert result.first.is_a? Desk::Customer
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#show" do
|
27
|
+
|
28
|
+
before { @connection.expect(:get, customer_fixture, ["customers/1234"]) }
|
29
|
+
|
30
|
+
it "will connect to the customer show endpoint" do
|
31
|
+
subject.show(1234)
|
32
|
+
|
33
|
+
@connection.verify
|
34
|
+
end
|
35
|
+
|
36
|
+
it "will return a single customer object" do
|
37
|
+
result = subject.show(1234)
|
38
|
+
|
39
|
+
assert result.is_a? Desk::Customer
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#create" do
|
44
|
+
|
45
|
+
before do
|
46
|
+
@data = {
|
47
|
+
first_name: "Johnny",
|
48
|
+
last_name: "Bravo",
|
49
|
+
emails: [
|
50
|
+
{
|
51
|
+
type: "work",
|
52
|
+
value: "johnny@acme.com"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
type: "other",
|
56
|
+
value: "johnny@other.com"
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
60
|
+
|
61
|
+
@connection.expect(:post, customer_fixture, ["customers", @data])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "will connect to the customer creation endpoint" do
|
65
|
+
subject.create(@data)
|
66
|
+
|
67
|
+
@connection.verify
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#update" do
|
72
|
+
before do
|
73
|
+
@data = {
|
74
|
+
first_name: "Johnny",
|
75
|
+
emails: [
|
76
|
+
{
|
77
|
+
type: "work",
|
78
|
+
value: "johnny@acme.com"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
type: "other",
|
82
|
+
value: "johnny@other.com"
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
|
87
|
+
@connection.expect(:patch, customer_fixture, ["customers/1234", @data])
|
88
|
+
end
|
89
|
+
|
90
|
+
it "will connect to the customer update endpoint" do
|
91
|
+
subject.update(1234, @data)
|
92
|
+
|
93
|
+
@connection.verify
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#delete" do
|
98
|
+
|
99
|
+
before { @connection.expect(:delete, true, ["customers/1234"]) }
|
100
|
+
|
101
|
+
it "will connect to the customer delete endpoint" do
|
102
|
+
subject.delete(1234)
|
103
|
+
|
104
|
+
@connection.verify
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#search" do
|
109
|
+
|
110
|
+
it "will connect to the customer search endpoint" do
|
111
|
+
@connection.expect(:get, customers_fixture, ["customers/search", {first_name: "Johnny"}])
|
112
|
+
|
113
|
+
subject.search(first_name: "Johnny")
|
114
|
+
|
115
|
+
@connection.verify
|
116
|
+
end
|
117
|
+
|
118
|
+
it "will pass last name into the search query" do
|
119
|
+
@connection.expect(:get, customers_fixture, ["customers/search", {first_name: "Johhny", last_name: "Bravo"}])
|
120
|
+
|
121
|
+
subject.search(first_name: "Johhny", last_name: "Bravo")
|
122
|
+
|
123
|
+
@connection.verify
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
def customers_fixture
|
129
|
+
JSON.load(fixture("customers.json"))
|
130
|
+
end
|
131
|
+
|
132
|
+
def customer_fixture
|
133
|
+
JSON.load(fixture("customer.json"))
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../spec_helper'
|
3
|
+
|
4
|
+
class GroupsSpec
|
5
|
+
describe Desk::Api::Groups do
|
6
|
+
|
7
|
+
before { @connection = Minitest::Mock.new }
|
8
|
+
|
9
|
+
subject { Desk::Api::Groups.new(@connection) }
|
10
|
+
|
11
|
+
describe "#all" do
|
12
|
+
|
13
|
+
before { @connection.expect(:get, groups_fixture, ["groups"]) }
|
14
|
+
|
15
|
+
it "will connect to the groups endpoint" do
|
16
|
+
subject.all
|
17
|
+
|
18
|
+
@connection.verify
|
19
|
+
end
|
20
|
+
|
21
|
+
it "will return an array of groups" do
|
22
|
+
result = subject.all
|
23
|
+
|
24
|
+
assert result.is_a? Array
|
25
|
+
assert result.first.is_a? Desk::Group
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#show" do
|
30
|
+
|
31
|
+
before { @connection.expect(:get, group_fixture, ["groups/1234"]) }
|
32
|
+
|
33
|
+
it "will connect to the group show endpoint" do
|
34
|
+
subject.show(1234)
|
35
|
+
|
36
|
+
@connection.verify
|
37
|
+
end
|
38
|
+
|
39
|
+
it "will return a single group object" do
|
40
|
+
result = subject.show(1234)
|
41
|
+
|
42
|
+
assert result.is_a? Desk::Group
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#filters" do
|
47
|
+
|
48
|
+
before { @connection.expect(:get, filters_fixture, ["groups/1234/filters"]) }
|
49
|
+
|
50
|
+
it "will connect to the case filters endpoint" do
|
51
|
+
subject.filters(1234)
|
52
|
+
|
53
|
+
@connection.verify
|
54
|
+
end
|
55
|
+
|
56
|
+
it "will return an array of filters object" do
|
57
|
+
result = subject.filters(1234)
|
58
|
+
|
59
|
+
assert result.is_a? Array
|
60
|
+
assert result.first.is_a? Desk::Filter
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#users" do
|
65
|
+
|
66
|
+
before { @connection.expect(:get, users_fixture, ["groups/1234/users"]) }
|
67
|
+
|
68
|
+
it "will connect to the case users endpoint" do
|
69
|
+
subject.users(1234)
|
70
|
+
|
71
|
+
@connection.verify
|
72
|
+
end
|
73
|
+
|
74
|
+
it "will return an array of users object" do
|
75
|
+
result = subject.users(1234)
|
76
|
+
|
77
|
+
assert result.is_a? Array
|
78
|
+
assert result.first.is_a? Desk::User
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def groups_fixture
|
83
|
+
JSON.load(fixture("groups.json"))
|
84
|
+
end
|
85
|
+
|
86
|
+
def group_fixture
|
87
|
+
JSON.load(fixture("group.json"))
|
88
|
+
end
|
89
|
+
|
90
|
+
def filters_fixture
|
91
|
+
JSON.load(fixture("group_filters.json"))
|
92
|
+
end
|
93
|
+
|
94
|
+
def users_fixture
|
95
|
+
JSON.load(fixture("group_users.json"))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../spec_helper'
|
3
|
+
|
4
|
+
describe Desk::Api::Topics do
|
5
|
+
|
6
|
+
before { @connection = Minitest::Mock.new }
|
7
|
+
|
8
|
+
subject { Desk::Api::Topics.new(@connection) }
|
9
|
+
|
10
|
+
describe "#all" do
|
11
|
+
|
12
|
+
before { @connection.expect(:get, topics_fixture, ["topics"]) }
|
13
|
+
|
14
|
+
it "will connect to the topics endpoint" do
|
15
|
+
subject.all
|
16
|
+
end
|
17
|
+
|
18
|
+
it "will return an array of topics" do
|
19
|
+
result = subject.all
|
20
|
+
|
21
|
+
assert result.is_a? Array
|
22
|
+
assert result.first.is_a? Desk::Topic
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#show" do
|
27
|
+
|
28
|
+
before { @connection.expect(:get, topic_fixture, ["topics/1234"]) }
|
29
|
+
|
30
|
+
it "will connect to the topic show endpoint" do
|
31
|
+
subject.show(1234)
|
32
|
+
|
33
|
+
@connection.verify
|
34
|
+
end
|
35
|
+
|
36
|
+
it "will return a single topic object" do
|
37
|
+
result = subject.show(1234)
|
38
|
+
|
39
|
+
assert result.is_a? Desk::Topic
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#create" do
|
44
|
+
|
45
|
+
before do
|
46
|
+
@data = {
|
47
|
+
name: "Social Media",
|
48
|
+
allow_questions: true,
|
49
|
+
in_support_center: true
|
50
|
+
}
|
51
|
+
|
52
|
+
@connection.expect(:post, topic_fixture, ["topics", @data])
|
53
|
+
end
|
54
|
+
|
55
|
+
it "will connect to the topic creation endpoint" do
|
56
|
+
subject.create(@data)
|
57
|
+
|
58
|
+
@connection.verify
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#update" do
|
63
|
+
before do
|
64
|
+
@data = {
|
65
|
+
name: "New Name",
|
66
|
+
allow_questions: false,
|
67
|
+
in_support_center: true
|
68
|
+
}
|
69
|
+
|
70
|
+
@connection.expect(:patch, topic_fixture, ["topics/1234", @data])
|
71
|
+
end
|
72
|
+
|
73
|
+
it "will connect to the topic update endpoint" do
|
74
|
+
subject.update(1234, @data)
|
75
|
+
|
76
|
+
@connection.verify
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#delete" do
|
81
|
+
|
82
|
+
before { @connection.expect(:delete, true, ["topics/1234"]) }
|
83
|
+
|
84
|
+
it "will connect to the topic delete endpoint" do
|
85
|
+
subject.delete(1234)
|
86
|
+
|
87
|
+
@connection.verify
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def topics_fixture
|
92
|
+
JSON.load(fixture("topics.json"))
|
93
|
+
end
|
94
|
+
|
95
|
+
def topic_fixture
|
96
|
+
JSON.load(fixture("topic.json"))
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative '../../spec_helper'
|
3
|
+
|
4
|
+
describe Desk::Api::Translations do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@connection = Minitest::Mock.new
|
8
|
+
@parent = Minitest::Mock.new
|
9
|
+
@parent.expect(:endpoint, "articles/1234")
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { Desk::Api::Translations.new(@connection, @parent) }
|
13
|
+
|
14
|
+
describe "#all" do
|
15
|
+
|
16
|
+
before { @connection.expect(:get, translations_fixture, ["articles/1234/translations"]) }
|
17
|
+
|
18
|
+
it "will connect to the translations endpoint" do
|
19
|
+
subject.all
|
20
|
+
|
21
|
+
@connection.verify
|
22
|
+
end
|
23
|
+
|
24
|
+
it "will return an array of Translations" do
|
25
|
+
result = subject.all
|
26
|
+
|
27
|
+
assert result.is_a? Array
|
28
|
+
assert result.first.is_a? Desk::Translation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#show" do
|
33
|
+
|
34
|
+
before { @connection.expect(:get, translation_fixture, ["articles/1234/translations/es"]) }
|
35
|
+
|
36
|
+
it "will connect to the translation show endpoint" do
|
37
|
+
subject.show(:es)
|
38
|
+
|
39
|
+
@connection.verify
|
40
|
+
end
|
41
|
+
|
42
|
+
it "will return a single translation object" do
|
43
|
+
result = subject.show(:es)
|
44
|
+
|
45
|
+
assert result.is_a? Desk::Translation
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#create" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
@data = {
|
53
|
+
locale: "es",
|
54
|
+
subject: "Yo quiero Desk.com API v2",
|
55
|
+
body: "No hablo engles? Lea este."
|
56
|
+
}
|
57
|
+
|
58
|
+
@connection.expect(:post, translation_fixture, ["articles/1234/translations", @data])
|
59
|
+
end
|
60
|
+
|
61
|
+
it "will connect to the translations creation endpoint" do
|
62
|
+
subject.create(@data)
|
63
|
+
|
64
|
+
@connection.verify
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#update" do
|
69
|
+
before do
|
70
|
+
@data = {
|
71
|
+
subject: "Updated Spanish Translation"
|
72
|
+
}
|
73
|
+
|
74
|
+
@connection.expect(:patch, translation_fixture, ["articles/1234/translations/es", @data])
|
75
|
+
end
|
76
|
+
|
77
|
+
it "will connect to the article update endpoint" do
|
78
|
+
subject.update(:es, @data)
|
79
|
+
|
80
|
+
@connection.verify
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def translations_fixture
|
85
|
+
JSON.load(fixture("translations.json"))
|
86
|
+
end
|
87
|
+
|
88
|
+
def translation_fixture
|
89
|
+
JSON.load(fixture("translation.json"))
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Desk::Collection do
|
4
|
+
|
5
|
+
subject { Desk::Collection.new(@response, Desk::Entity) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@obj_1 = {foo: "bar"}
|
9
|
+
@obj_2 = {baz: "foo"}
|
10
|
+
@response = {"_embedded" => {"entries" => [@obj_1, @obj_2] }}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "acts like an enumerable" do
|
14
|
+
assert subject.respond_to? :first
|
15
|
+
assert subject.respond_to? :last
|
16
|
+
end
|
17
|
+
|
18
|
+
it "coerces the objects into the provided class" do
|
19
|
+
assert subject.last.is_a? Desk::Entity
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|