zendesk2 0.4.4 → 0.4.5
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.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/zendesk2/client/models/categories.rb +1 -1
- data/lib/zendesk2/client/models/forums.rb +1 -1
- data/lib/zendesk2/client/models/groups.rb +1 -1
- data/lib/zendesk2/client/models/membership.rb +1 -1
- data/lib/zendesk2/client/models/organization.rb +2 -0
- data/lib/zendesk2/client/models/organizations.rb +1 -1
- data/lib/zendesk2/client/models/ticket_audits.rb +1 -1
- data/lib/zendesk2/client/models/ticket_comments.rb +1 -1
- data/lib/zendesk2/client/models/ticket_metrics.rb +1 -1
- data/lib/zendesk2/client/models/tickets.rb +1 -1
- data/lib/zendesk2/client/models/topic_comments.rb +1 -1
- data/lib/zendesk2/client/models/topics.rb +1 -1
- data/lib/zendesk2/client/models/user_field.rb +59 -0
- data/lib/zendesk2/client/models/user_fields.rb +11 -0
- data/lib/zendesk2/client/models/user_identity.rb +1 -1
- data/lib/zendesk2/client/models/users.rb +1 -1
- data/lib/zendesk2/client/requests/create_membership.rb +10 -0
- data/lib/zendesk2/client/requests/create_user.rb +2 -12
- data/lib/zendesk2/client/requests/create_user_field.rb +44 -0
- data/lib/zendesk2/client/requests/destroy_user.rb +1 -0
- data/lib/zendesk2/client/requests/destroy_user_field.rb +27 -0
- data/lib/zendesk2/client/requests/get_category.rb +7 -14
- data/lib/zendesk2/client/requests/get_group.rb +6 -14
- data/lib/zendesk2/client/requests/get_membership.rb +6 -14
- data/lib/zendesk2/client/requests/get_organization.rb +7 -14
- data/lib/zendesk2/client/requests/get_organization_memberships.rb +1 -1
- data/lib/zendesk2/client/requests/get_ticket.rb +6 -14
- data/lib/zendesk2/client/requests/get_ticket_audit.rb +7 -18
- data/lib/zendesk2/client/requests/get_ticket_field.rb +6 -15
- data/lib/zendesk2/client/requests/get_ticket_fields.rb +1 -1
- data/lib/zendesk2/client/requests/get_ticket_metric.rb +6 -17
- data/lib/zendesk2/client/requests/get_topic_comment.rb +3 -6
- data/lib/zendesk2/client/requests/get_topic_comments.rb +1 -1
- data/lib/zendesk2/client/requests/get_user.rb +9 -13
- data/lib/zendesk2/client/requests/get_user_field.rb +25 -0
- data/lib/zendesk2/client/requests/get_user_fields.rb +18 -0
- data/lib/zendesk2/client/requests/get_user_identity.rb +6 -15
- data/lib/zendesk2/client/requests/get_user_memberships.rb +1 -1
- data/lib/zendesk2/client/requests/mark_membership_default.rb +2 -6
- data/lib/zendesk2/client/requests/mark_user_identity_primary.rb +3 -6
- data/lib/zendesk2/client/requests/update_group.rb +8 -14
- data/lib/zendesk2/client/requests/update_topic_comment.rb +2 -2
- data/lib/zendesk2/client/requests/update_user_field.rb +28 -0
- data/lib/zendesk2/client.rb +79 -15
- data/lib/zendesk2/collection.rb +1 -18
- data/lib/zendesk2/paged_collection.rb +100 -0
- data/lib/zendesk2/version.rb +1 -1
- data/lib/zendesk2.rb +9 -7
- data/spec/categories_spec.rb +6 -4
- data/spec/forums_spec.rb +7 -4
- data/spec/groups_spec.rb +6 -3
- data/spec/memberships_spec.rb +31 -5
- data/spec/organizations_spec.rb +6 -3
- data/spec/shared/zendesk_resource.rb +66 -48
- data/spec/ticket_fields_spec.rb +6 -3
- data/spec/tickets_spec.rb +6 -3
- data/spec/topic_comments_spec.rb +6 -5
- data/spec/topics_spec.rb +7 -5
- data/spec/user_fields_spec.rb +12 -0
- data/spec/user_identities_spec.rb +7 -7
- data/spec/users_spec.rb +7 -4
- metadata +12 -6
- data/spec/config_spec.rb +0 -17
- data/spec/shared/resource.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d128511e7f57cbba27856d2f6802def8372e72
|
4
|
+
data.tar.gz: 6f8a606ef092869b312359ea713464a5cbdf930e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30155530e6086ef765851f134129bcf22baaa95e4b8561a685df15c828e4f852f9482ffd24083158682f16b512831e661feefdd07e5c16a61b857b94335c2d19
|
7
|
+
data.tar.gz: a94bccf5ecce5fbc6230fc8c158c2a43c8fb96d545c93108c0207e7e7195c3f08ec7fe44f9dc949d9a9786a0b0e7111ec695e9c545d1b76004f1e05d40757d28
|
data/README.md
CHANGED
@@ -19,6 +19,18 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
### Mock it!
|
23
|
+
|
24
|
+
All support resources have basic mocks. Error conditions and messaging are constantly changing. Please contribute updates or fixes to the mock if you encounter inconsistencies.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Zendesk2::Client.mock!
|
28
|
+
|
29
|
+
client = Zendesk2::Client.new(...) # Zendesk2::Client::Mock
|
30
|
+
client.organizations.create!(name: "foo") # Zendesk2::Client::Organization
|
31
|
+
client.organizations.create!(name: "foo") # Zendesk2::Error => Name has already been taken
|
32
|
+
```
|
33
|
+
|
22
34
|
### Defaults
|
23
35
|
|
24
36
|
Default credentials will be read in from `~/.zendesk2` file in YAML format.
|
@@ -57,6 +69,7 @@ Currently support resources
|
|
57
69
|
* Categories
|
58
70
|
* Forums
|
59
71
|
* Groups
|
72
|
+
* Memberships
|
60
73
|
* Organization
|
61
74
|
* Ticket Audits
|
62
75
|
* Ticket Fields
|
@@ -64,6 +77,7 @@ Currently support resources
|
|
64
77
|
* Topic Comments
|
65
78
|
* Topics
|
66
79
|
* User Identities
|
80
|
+
* User Fields
|
67
81
|
* Users
|
68
82
|
|
69
83
|
All collection are accessed like so:
|
@@ -40,9 +40,11 @@ class Zendesk2::Client::Organization < Zendesk2::Model
|
|
40
40
|
def save!
|
41
41
|
data = if new_record?
|
42
42
|
requires :name
|
43
|
+
|
43
44
|
connection.create_organization(params).body["organization"]
|
44
45
|
else
|
45
46
|
requires :identity
|
47
|
+
|
46
48
|
connection.update_organization(params).body["organization"]
|
47
49
|
end
|
48
50
|
merge_attributes(data)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Zendesk2::Client::UserField < Zendesk2::Model
|
2
|
+
extend Zendesk2::Attributes
|
3
|
+
|
4
|
+
PARAMS = %w[key type title description position active, regexp_for_validation tag custom_field_options]
|
5
|
+
|
6
|
+
# @return [Integer] Automatically assigned upon creation
|
7
|
+
identity :id, type: :integer
|
8
|
+
|
9
|
+
# @return [Boolean] If true, this field is available for use
|
10
|
+
attribute :active, type: :boolean
|
11
|
+
# @return [Time] The time the ticket field was created
|
12
|
+
attribute :created_at, type: :time
|
13
|
+
# @return [Array] Required and presented for a custom field of type "tagger"
|
14
|
+
attribute :custom_field_options, type: :array
|
15
|
+
# @return [String] User-defined description of this field's purpose
|
16
|
+
attribute :description, type: :string
|
17
|
+
# @return [String] create A unique key that identifies this custom field. This is used for updating the field and referencing in placeholders.
|
18
|
+
attribute :key, type: :string
|
19
|
+
# @return [Integer] Ordering of the field relative to other fields
|
20
|
+
attribute :position, type: :integer
|
21
|
+
# @return [String] Regular expression field only. The validation pattern for a field value to be deemed valid.
|
22
|
+
attribute :regexp_for_validation, type: :string
|
23
|
+
# @return [String] Optional for custom field of type "checkbox"; not presented otherwise.
|
24
|
+
attribute :tag, type: :string
|
25
|
+
# @return [String] The title of the custom field
|
26
|
+
attribute :title, type: :string
|
27
|
+
# @return [String] Supported types: "text", "textarea", "checkbox", "date", "integer", "decimal", "regexp", "tagger" (custom dropdown)
|
28
|
+
attribute :type, type: :string
|
29
|
+
# @return [Time] The time of the last update of the ticket field
|
30
|
+
attribute :updated_at, type: :time
|
31
|
+
# @return [String] The URL for this resource
|
32
|
+
attribute :url, type: :string
|
33
|
+
|
34
|
+
def save!
|
35
|
+
data = if new_record?
|
36
|
+
requires :type, :title, :key
|
37
|
+
|
38
|
+
connection.create_user_field(params).body["user_field"]
|
39
|
+
else
|
40
|
+
requires :identity
|
41
|
+
|
42
|
+
connection.update_user_field(params.merge("id" => self.identity)).body["user_field"]
|
43
|
+
end
|
44
|
+
|
45
|
+
merge_attributes(data)
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy!
|
49
|
+
requires :identity
|
50
|
+
|
51
|
+
connection.destroy_user_field("id" => self.identity)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def params
|
57
|
+
Cistern::Hash.slice(Zendesk2.stringify_keys(attributes), *PARAMS)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Zendesk2::Client::UserFields < Zendesk2::Collection
|
2
|
+
include Zendesk2::Searchable
|
3
|
+
|
4
|
+
model Zendesk2::Client::UserField
|
5
|
+
|
6
|
+
self.collection_method = :get_user_fields
|
7
|
+
self.collection_root = "user_fields"
|
8
|
+
self.model_method = :get_user_field
|
9
|
+
self.model_root = "user_field"
|
10
|
+
self.search_type = "user_field"
|
11
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class Zendesk2::Client
|
2
2
|
class Real
|
3
3
|
def create_membership(params={})
|
4
|
+
require_parameters(params, "user_id", "organization_id")
|
5
|
+
|
4
6
|
user_id = params["user_id"]
|
5
7
|
|
6
8
|
request(
|
@@ -13,9 +15,17 @@ class Zendesk2::Client
|
|
13
15
|
|
14
16
|
class Mock
|
15
17
|
def create_membership(params={})
|
18
|
+
require_parameters(params, "user_id", "organization_id")
|
19
|
+
|
16
20
|
user_id = params["user_id"]
|
17
21
|
organization_id = params["organization_id"]
|
18
22
|
|
23
|
+
find!(:users, user_id)
|
24
|
+
find!(:organizations, organization_id, error: :invalid, details: { "organization" => [ { "description" => "Organization cannot be blank" } ] })
|
25
|
+
if self.data[:memberships].values.find { |m| m["user_id"] == user_id && m["organization_id"] == organization_id }
|
26
|
+
error!(:invalid, description: { "user_id" => [ { "description" => "User has already been taken" } ] })
|
27
|
+
end
|
28
|
+
|
19
29
|
resource_id = self.class.new_id
|
20
30
|
|
21
31
|
default_membership = false # !self.data[:memberships].values.find { |m| m["user_id"] == user_id && m["default"] }
|
@@ -23,20 +23,10 @@ class Zendesk2::Client
|
|
23
23
|
}.merge(params)
|
24
24
|
|
25
25
|
if (email = record["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
|
26
|
-
|
27
|
-
:method => :put,
|
28
|
-
:path => path,
|
29
|
-
:status => 422,
|
30
|
-
:body => {
|
31
|
-
"error" => "RecordInvalid",
|
32
|
-
"description" => "Record validation errors",
|
33
|
-
"details" => {
|
26
|
+
error!(:invalid, :details => {
|
34
27
|
"email" => [ {
|
35
28
|
"description" => "Email #{email} is already being used by another user"
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
)
|
29
|
+
}]})
|
40
30
|
else
|
41
31
|
user_identity_id = self.class.new_id # ugh
|
42
32
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def create_user_field(params={})
|
4
|
+
request(
|
5
|
+
:body => {"user_field" => params},
|
6
|
+
:method => :post,
|
7
|
+
:path => "/user_fields.json",
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end # Real
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
def create_user_field(params={})
|
14
|
+
identity = self.class.new_id
|
15
|
+
|
16
|
+
record = {
|
17
|
+
"active" => true,
|
18
|
+
"collapsed_for_agents" => false,
|
19
|
+
"created_at" => Time.now.iso8601,
|
20
|
+
"description" => params["title"],
|
21
|
+
"editable_in_portal" => false,
|
22
|
+
"id" => identity,
|
23
|
+
"position" => 9999,
|
24
|
+
"regexp_for_validation" => "",
|
25
|
+
"removable" => true,
|
26
|
+
"required" => false,
|
27
|
+
"required_in_portal" => false,
|
28
|
+
"tag" => "",
|
29
|
+
"title_in_portal" => params["title"],
|
30
|
+
"updated_at" => Time.now.iso8601,
|
31
|
+
"url" => url_for("/user_fields/#{identity}.json"),
|
32
|
+
"visible_in_portal" => false,
|
33
|
+
}.merge(params)
|
34
|
+
|
35
|
+
self.data[:user_fields][identity] = record
|
36
|
+
|
37
|
+
response(
|
38
|
+
:method => :post,
|
39
|
+
:body => {"user_field" => record},
|
40
|
+
:path => "/user_fields.json"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end # Mock
|
44
|
+
end # Zendesk2::Client
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Zendesk2::Client
|
2
|
+
class Real
|
3
|
+
def destroy_user_field(params={})
|
4
|
+
id = params["id"]
|
5
|
+
|
6
|
+
request(
|
7
|
+
:method => :delete,
|
8
|
+
:path => "/user_fields/#{id}.json"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def destroy_user_field(params={})
|
15
|
+
id = params["id"]
|
16
|
+
body = self.data[:user_fields].delete(id)
|
17
|
+
|
18
|
+
response(
|
19
|
+
:method => :delete,
|
20
|
+
:path => "/user_fields/#{id}.json",
|
21
|
+
:body => {
|
22
|
+
"user_field" => body,
|
23
|
+
},
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -12,21 +12,14 @@ class Zendesk2::Client
|
|
12
12
|
|
13
13
|
class Mock
|
14
14
|
def get_category(params={})
|
15
|
-
id
|
16
|
-
if body = self.data[:categories][id]
|
15
|
+
id = params["id"]
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
response(
|
26
|
-
:path => "/categories/#{id}.json",
|
27
|
-
:status => 404
|
28
|
-
)
|
29
|
-
end
|
17
|
+
response(
|
18
|
+
:path => "/categories/#{id}.json",
|
19
|
+
:body => {
|
20
|
+
"category" => find!(:categories, id)
|
21
|
+
},
|
22
|
+
)
|
30
23
|
end
|
31
24
|
end # Mock
|
32
25
|
end
|
@@ -15,20 +15,12 @@ class Zendesk2::Client
|
|
15
15
|
id = params["id"]
|
16
16
|
path = "/groups/#{id}.json"
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
25
|
-
else
|
26
|
-
response(
|
27
|
-
:path => path,
|
28
|
-
:status => 404,
|
29
|
-
:body => {"error" => "RecordNotFound", "description" => "Not found"},
|
30
|
-
)
|
31
|
-
end
|
18
|
+
response(
|
19
|
+
:path => path,
|
20
|
+
:body => {
|
21
|
+
"group" => find!(:groups, id),
|
22
|
+
},
|
23
|
+
)
|
32
24
|
end
|
33
25
|
end # Mock
|
34
26
|
end
|
@@ -16,20 +16,12 @@ class Zendesk2::Client
|
|
16
16
|
|
17
17
|
path = "/organization_memberships/#{membership_id}.json"
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
)
|
26
|
-
else
|
27
|
-
response(
|
28
|
-
:path => path,
|
29
|
-
:status => 404,
|
30
|
-
:body => {"error" => "RecordNotFound", "description" => "Not found"},
|
31
|
-
)
|
32
|
-
end
|
19
|
+
response(
|
20
|
+
:path => path,
|
21
|
+
:body => {
|
22
|
+
"organization_membership" => find!(:memberships, membership_id)
|
23
|
+
},
|
24
|
+
)
|
33
25
|
end
|
34
26
|
end # Mock
|
35
27
|
end
|