zendesk_api 0.0.9
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.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +19 -0
- data/Rakefile +49 -0
- data/Readme.md +178 -0
- data/lib/zendesk_api.rb +10 -0
- data/lib/zendesk_api/actions.rb +176 -0
- data/lib/zendesk_api/association.rb +267 -0
- data/lib/zendesk_api/client.rb +150 -0
- data/lib/zendesk_api/collection.rb +233 -0
- data/lib/zendesk_api/configuration.rb +52 -0
- data/lib/zendesk_api/core_ext/inflection.rb +13 -0
- data/lib/zendesk_api/core_ext/modulize.rb +10 -0
- data/lib/zendesk_api/core_ext/snakecase.rb +12 -0
- data/lib/zendesk_api/lru_cache.rb +38 -0
- data/lib/zendesk_api/middleware/request/etag_cache.rb +38 -0
- data/lib/zendesk_api/middleware/request/retry.rb +39 -0
- data/lib/zendesk_api/middleware/request/upload.rb +32 -0
- data/lib/zendesk_api/middleware/response/callback.rb +19 -0
- data/lib/zendesk_api/middleware/response/deflate.rb +18 -0
- data/lib/zendesk_api/middleware/response/gzip.rb +18 -0
- data/lib/zendesk_api/middleware/response/parse_iso_dates.rb +29 -0
- data/lib/zendesk_api/rescue.rb +44 -0
- data/lib/zendesk_api/resource.rb +133 -0
- data/lib/zendesk_api/resources/forum.rb +51 -0
- data/lib/zendesk_api/resources/misc.rb +66 -0
- data/lib/zendesk_api/resources/playlist.rb +64 -0
- data/lib/zendesk_api/resources/ticket.rb +76 -0
- data/lib/zendesk_api/resources/user.rb +44 -0
- data/lib/zendesk_api/track_changes.rb +72 -0
- data/lib/zendesk_api/trackie.rb +8 -0
- data/lib/zendesk_api/verbs.rb +43 -0
- data/lib/zendesk_api/version.rb +3 -0
- data/live/Readme.md +4 -0
- data/live/activity_spec.rb +5 -0
- data/live/audit_spec.rb +5 -0
- data/live/bookmark_spec.rb +11 -0
- data/live/category_spec.rb +12 -0
- data/live/collection_spec.rb +68 -0
- data/live/crm_spec.rb +11 -0
- data/live/custom_role_spec.rb +5 -0
- data/live/forum_spec.rb +14 -0
- data/live/forum_subscription_spec.rb +12 -0
- data/live/group_membership_spec.rb +18 -0
- data/live/group_spec.rb +14 -0
- data/live/identity_spec.rb +14 -0
- data/live/locale_spec.rb +11 -0
- data/live/macro_spec.rb +5 -0
- data/live/mobile_device_spec.rb +11 -0
- data/live/organization_spec.rb +12 -0
- data/live/satisfaction_rating_spec.rb +6 -0
- data/live/setting_spec.rb +5 -0
- data/live/suspended_ticket_spec.rb +8 -0
- data/live/ticket_field_spec.rb +12 -0
- data/live/ticket_metrics_spec.rb +6 -0
- data/live/ticket_spec.rb +88 -0
- data/live/topic_comment_spec.rb +13 -0
- data/live/topic_spec.rb +18 -0
- data/live/topic_subscription_spec.rb +12 -0
- data/live/topic_vote_spec.rb +13 -0
- data/live/upload_spec.rb +9 -0
- data/live/user_spec.rb +13 -0
- data/live/view_spec.rb +6 -0
- data/spec/association_spec.rb +210 -0
- data/spec/client_spec.rb +149 -0
- data/spec/collection_spec.rb +302 -0
- data/spec/configuration_spec.rb +24 -0
- data/spec/create_resource_spec.rb +39 -0
- data/spec/data_resource_spec.rb +229 -0
- data/spec/fixtures/Argentina.gif +0 -0
- data/spec/fixtures/Argentina2.gif +0 -0
- data/spec/fixtures/credentials.yml.example +3 -0
- data/spec/fixtures/test_resources.rb +8 -0
- data/spec/fixtures/zendesk.rb +88 -0
- data/spec/lru_cache_spec.rb +26 -0
- data/spec/macros/resource_macros.rb +157 -0
- data/spec/middleware/request/etag_cache_spec.rb +17 -0
- data/spec/middleware/request/retry_spec.rb +47 -0
- data/spec/middleware/request/test.jpg +0 -0
- data/spec/middleware/request/upload_spec.rb +74 -0
- data/spec/middleware/response/callback_spec.rb +17 -0
- data/spec/middleware/response/deflate_spec.rb +15 -0
- data/spec/middleware/response/gzip_spec.rb +19 -0
- data/spec/middleware/response/parse_iso_dates_spec.rb +44 -0
- data/spec/playlist_spec.rb +95 -0
- data/spec/read_resource_spec.rb +37 -0
- data/spec/rescue_spec.rb +94 -0
- data/spec/resource_spec.rb +332 -0
- data/spec/spec_helper.rb +120 -0
- data/spec/string_spec.rb +7 -0
- data/spec/trackie_spec.rb +39 -0
- data/zendesk_api.gemspec +38 -0
- metadata +364 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module ZendeskAPI
|
2
|
+
class ForumSubscription < Resource
|
3
|
+
only_send_unnested_params
|
4
|
+
has :forum
|
5
|
+
has :user
|
6
|
+
end
|
7
|
+
|
8
|
+
class Forum < Resource
|
9
|
+
has :category
|
10
|
+
has :organization
|
11
|
+
has :locale
|
12
|
+
|
13
|
+
has_many :topics
|
14
|
+
has_many :subscriptions, :class => :forum_subscription
|
15
|
+
end
|
16
|
+
|
17
|
+
class Category < Resource
|
18
|
+
has_many :forums
|
19
|
+
end
|
20
|
+
|
21
|
+
class TopicSubscription < Resource
|
22
|
+
only_send_unnested_params
|
23
|
+
has :topic
|
24
|
+
has :user
|
25
|
+
end
|
26
|
+
|
27
|
+
class Topic < Resource
|
28
|
+
class TopicComment < Resource
|
29
|
+
has :topic
|
30
|
+
has :user
|
31
|
+
has_many :attachments
|
32
|
+
end
|
33
|
+
|
34
|
+
class TopicVote < SingularResource
|
35
|
+
only_send_unnested_params
|
36
|
+
has :topic
|
37
|
+
has :user
|
38
|
+
end
|
39
|
+
|
40
|
+
has_many :comments, :class => :topic_comment
|
41
|
+
has_many :subscriptions, :class => :topic_subscription
|
42
|
+
has :vote, :class => :topic_vote
|
43
|
+
|
44
|
+
def votes(opts = {})
|
45
|
+
return @votes if @votes && !opts[:reload]
|
46
|
+
|
47
|
+
association = ZendeskAPI::Association.new(:class => Topic::TopicVote, :parent => self, :path => 'votes')
|
48
|
+
@votes = ZendeskAPI::Collection.new(@client, Topic::TopicVote, opts.merge(:association => association))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module ZendeskAPI
|
2
|
+
class Activity < Resource
|
3
|
+
has :user
|
4
|
+
has :actor, :class => :user
|
5
|
+
end
|
6
|
+
|
7
|
+
class Setting < DataResource
|
8
|
+
attr_reader :on
|
9
|
+
|
10
|
+
def initialize(client, attributes = {})
|
11
|
+
@on = attributes.first
|
12
|
+
super(client, attributes[1])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MobileDevice < Resource
|
17
|
+
put :clear_badge
|
18
|
+
end
|
19
|
+
|
20
|
+
class SatisfactionRating < ReadResource
|
21
|
+
has :assignee, :class => :user
|
22
|
+
has :requester, :class => :user
|
23
|
+
has :ticket
|
24
|
+
has :group
|
25
|
+
end
|
26
|
+
|
27
|
+
class Attachment < Data
|
28
|
+
def initialize(client, attributes)
|
29
|
+
if attributes.is_a?(Hash)
|
30
|
+
super
|
31
|
+
else
|
32
|
+
super(client, :file => attributes)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def save
|
37
|
+
upload = Upload.create!(client, :file => file)
|
38
|
+
self.token = upload.token
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_param
|
42
|
+
token
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Upload < Data
|
47
|
+
include Create
|
48
|
+
|
49
|
+
only_send_unnested_params
|
50
|
+
has_many :attachments
|
51
|
+
end
|
52
|
+
|
53
|
+
class Locale < ReadResource; end
|
54
|
+
class Bookmark < Resource; end
|
55
|
+
class Macro < DataResource; end
|
56
|
+
|
57
|
+
class Search < DataResource
|
58
|
+
def self.resource_name
|
59
|
+
"search"
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.model_key
|
63
|
+
"results"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module ZendeskAPI
|
2
|
+
class Playlist
|
3
|
+
include Rescue
|
4
|
+
|
5
|
+
attr_reader :ticket
|
6
|
+
attr_accessor :id
|
7
|
+
|
8
|
+
def initialize(client, id)
|
9
|
+
@client, @id = client, id
|
10
|
+
@ticket = nil
|
11
|
+
|
12
|
+
@initialized = false
|
13
|
+
@destroyed = false
|
14
|
+
|
15
|
+
init_playlist
|
16
|
+
end
|
17
|
+
|
18
|
+
def each
|
19
|
+
init_playlist unless initialized?
|
20
|
+
|
21
|
+
while initialized? && !destroyed? && (n = self.next)
|
22
|
+
yield n
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def next
|
27
|
+
init_playlist unless initialized?
|
28
|
+
return false if !initialized? || destroyed?
|
29
|
+
|
30
|
+
response = @client.connection.get("play/next")
|
31
|
+
|
32
|
+
if response.status == 200
|
33
|
+
@ticket = Ticket.new(@client, response.body["ticket"])
|
34
|
+
@ticket
|
35
|
+
else
|
36
|
+
@destroyed = (response.status == 204)
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
response = @client.connection.delete("play")
|
43
|
+
@destroyed = response.status == 204
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroyed?
|
47
|
+
@destroyed
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialized?
|
51
|
+
@initialized
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def init_playlist
|
57
|
+
response = @client.connection.get("views/#{id}/play")
|
58
|
+
@initialized = response.status == 302
|
59
|
+
end
|
60
|
+
|
61
|
+
rescue_client_error :next, :init_playlist
|
62
|
+
rescue_client_error :destroy, :with => false
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ZendeskAPI
|
2
|
+
class TicketField < Resource; end
|
3
|
+
class TicketComment < Data; end
|
4
|
+
class TicketMetric < ReadResource; end
|
5
|
+
|
6
|
+
class Ticket < Resource
|
7
|
+
class Audit < DataResource; end
|
8
|
+
|
9
|
+
has :requester, :class => :user
|
10
|
+
has :submitter, :class => :user
|
11
|
+
has :assignee, :class => :user
|
12
|
+
has :recipient, :class => :user
|
13
|
+
has_many :collaborators, :class => :user
|
14
|
+
has_many :audits
|
15
|
+
has :metrics, :class => :ticket_metric
|
16
|
+
has :group
|
17
|
+
has :forum_topic, :class => :topic
|
18
|
+
has :organization
|
19
|
+
|
20
|
+
has_many :uploads, :class => :attachment, :inline => true
|
21
|
+
has :comment, :class => :ticket_comment, :inline => true
|
22
|
+
|
23
|
+
# Gets a incremental export of tickets from the start_time until now.
|
24
|
+
# @param [Client] client The {Client} object to be used
|
25
|
+
# @param [Integer] start_time The start_time parameter
|
26
|
+
# @return [Collection] Collection of {Ticket}
|
27
|
+
def self.incremental_export(client, start_time)
|
28
|
+
ZendeskAPI::Collection.new(client, self, :path => "exports/tickets?start_time=#{start_time.to_i}")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Imports a ticket through the imports/tickets endpoint
|
32
|
+
# @param [Client] client The {Client} object to be used
|
33
|
+
# @param [Hash] attributes The attributes to create.
|
34
|
+
# @return [Ticket] Created object or nil
|
35
|
+
def self.import(client, attributes)
|
36
|
+
ticket = new(client, attributes)
|
37
|
+
return unless ticket.save(:path => "imports/tickets")
|
38
|
+
ticket
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class SuspendedTicket < ReadResource
|
43
|
+
include Destroy
|
44
|
+
put :recover
|
45
|
+
end
|
46
|
+
|
47
|
+
class ViewRow < DataResource
|
48
|
+
has :ticket
|
49
|
+
|
50
|
+
# Optional columns
|
51
|
+
has :group
|
52
|
+
has :assignee, :class => :user
|
53
|
+
has :requester, :class => :user
|
54
|
+
has :submitter, :class => :user
|
55
|
+
has :organization
|
56
|
+
|
57
|
+
def self.model_key
|
58
|
+
"rows"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class ViewExecution < Data
|
63
|
+
has_many :custom_fields, :class => :ticket_field
|
64
|
+
end
|
65
|
+
|
66
|
+
class View < ReadResource
|
67
|
+
has_many :rows, :class => :view_row, :path => "execute"
|
68
|
+
has :execution, :class => :view_execution
|
69
|
+
|
70
|
+
def self.preview(client, options = {})
|
71
|
+
Zendesk::Collection.new(client, ViewRow, options.merge(:path => "views/preview"))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'zendesk_api/resources/forum'
|
2
|
+
|
3
|
+
module ZendeskAPI
|
4
|
+
class CRMData < DataResource; end
|
5
|
+
class CRMDataStatus < DataResource; end
|
6
|
+
class CustomRole < DataResource; end
|
7
|
+
|
8
|
+
class GroupMembership < Resource
|
9
|
+
has :user
|
10
|
+
has :group
|
11
|
+
end
|
12
|
+
|
13
|
+
class User < Resource
|
14
|
+
class Identity < Resource
|
15
|
+
put :make_primary
|
16
|
+
put :verify
|
17
|
+
put :request_verification
|
18
|
+
end
|
19
|
+
|
20
|
+
has :organization
|
21
|
+
has :custom_role
|
22
|
+
has_many :identities
|
23
|
+
has_many :requested_tickets, :class => :ticket, :path => 'tickets/requested'
|
24
|
+
has_many :ccd_tickets, :class => :ticket, :path => 'tickets/ccd'
|
25
|
+
|
26
|
+
has_many :groups
|
27
|
+
has_many :group_memberships
|
28
|
+
has_many :topics
|
29
|
+
|
30
|
+
has_many :forum_subscriptions, :class => "forum/forum_subscription"
|
31
|
+
has_many :topic_subscriptions, :class => "topic/topic_subscription"
|
32
|
+
has_many :topic_comments, :class => "topic/topic_comment"
|
33
|
+
has_many :topic_votes, :class => "topic/vote"
|
34
|
+
|
35
|
+
has :crm_data
|
36
|
+
has :crm_data_status, :path => 'crm_data/status'
|
37
|
+
end
|
38
|
+
|
39
|
+
class Organization < Resource
|
40
|
+
has :group
|
41
|
+
has_many :tickets
|
42
|
+
has_many :users
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Shamelessly stolen and modified from https://github.com/archan937/dirty_hashy
|
2
|
+
|
3
|
+
module ZendeskAPI
|
4
|
+
module TrackChanges
|
5
|
+
def self.included(base)
|
6
|
+
base.method_defined?(:regular_writer).tap do |defined|
|
7
|
+
base.send :include, InstanceMethods
|
8
|
+
unless defined
|
9
|
+
base.send :alias_method, :_store, :store
|
10
|
+
base.send :alias_method, :store, :regular_writer
|
11
|
+
base.send :alias_method, :[]=, :store
|
12
|
+
base.send :define_method, :update do |other|
|
13
|
+
other.each{|key, value| store key, value}
|
14
|
+
end
|
15
|
+
base.send :alias_method, :merge!, :update
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
def clear_changes
|
22
|
+
each do |k, v|
|
23
|
+
v.clear_changes if v.respond_to?(:clear_changes)
|
24
|
+
end
|
25
|
+
|
26
|
+
changes.clear
|
27
|
+
end
|
28
|
+
|
29
|
+
def replace(other)
|
30
|
+
clear
|
31
|
+
merge! other
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
keys.each{|key| delete key}
|
36
|
+
end
|
37
|
+
|
38
|
+
def [](key)
|
39
|
+
super(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def regular_writer(key, value)
|
43
|
+
changes[key] = value
|
44
|
+
defined?(_store) ? _store(key, value) : super(key, value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete(key)
|
48
|
+
self[key] = nil
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def changes
|
53
|
+
(@changes ||= self.class.superclass.new).tap do |changes|
|
54
|
+
each do |k, v|
|
55
|
+
if v.respond_to?(:changed?) && v.changed?
|
56
|
+
changes[k] = v.changes
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def changed?(key = nil)
|
63
|
+
if key.nil?
|
64
|
+
!changes.empty? || any? {|_, v| v.respond_to?(:changed?) && v.changed?}
|
65
|
+
else
|
66
|
+
changes.key?(key)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias :dirty? :changed?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ZendeskAPI
|
2
|
+
# Creates put, post, delete class methods for custom resource methods.
|
3
|
+
module Verbs
|
4
|
+
include Rescue
|
5
|
+
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
# @macro [attach] container.create_verb
|
10
|
+
# @method $1(method)
|
11
|
+
# Executes a $1 using the passed in method as a path.
|
12
|
+
# Reloads the resource's attributes if any are in the response body.
|
13
|
+
#
|
14
|
+
# Created method takes an optional options hash. Valid options to be passed in to the created method: reload (for caching, default: false)
|
15
|
+
def create_verb(verb)
|
16
|
+
define_method verb do |method|
|
17
|
+
define_method method do |*method_args|
|
18
|
+
opts = method_args.last.is_a?(Hash) ? method_args.pop : {}
|
19
|
+
return instance_variable_get("@#{method}") if instance_variable_defined?("@#{verb}") && !opts[:reload]
|
20
|
+
|
21
|
+
response = @client.connection.send(verb, "#{path}/#{method}") do |req|
|
22
|
+
req.body = opts
|
23
|
+
end
|
24
|
+
|
25
|
+
if (resources = response.body[self.class.resource_name]) &&
|
26
|
+
(res = resources.find {|res| res["id"] == id})
|
27
|
+
@attributes = ZendeskAPI::Trackie.new(res)
|
28
|
+
@attributes.clear_changes
|
29
|
+
end
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
rescue_client_error method, :with => false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
create_verb :put
|
40
|
+
create_verb :post
|
41
|
+
create_verb :delete
|
42
|
+
end
|
43
|
+
end
|
data/live/Readme.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
- Make an empty account (company name Z3N, email <something>@zendesk.com, so it can be filtered)
|
2
|
+
- add credentials into spec/fixtures/credentials.yml
|
3
|
+
- mark 1 ticket as solved, change end-users email to on your can receive, copy ticket url, login as end-user (do not just assume identity), rate it
|
4
|
+
- create a new ticket and cc "zendesk-api-client-ruby-end-user-#{client.config.username}" (run tests once to create this user)
|