Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RED-1886] Add more CBP endpoints #556

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions lib/zendesk_api/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def to_param

class Topic < Resource
class << self
def cbp_path_regexes
[%r{^community/topics$}]
end

def resource_path
"community/topics"
end
Expand Down Expand Up @@ -83,6 +87,10 @@ def _save(method = :save)
def attributes_for_save
{ self.class.resource_name => [id] }
end

def self.cbp_path_regexes
[/^tags$/]
end
end

class Attachment < ReadResource
Expand Down Expand Up @@ -154,7 +162,7 @@ def self.incremental_export(client, start_time)
end

def self.cbp_path_regexes
[/organizations$/]
[/^organizations$/]
end
end

Expand Down Expand Up @@ -186,7 +194,7 @@ class OrganizationSubscription < ReadResource
has Organization

def self.cbp_path_regexes
[%r{organizations/\d+/subscriptions$}]
[%r{^organizations/\d+/subscriptions$}]
end
end

Expand Down Expand Up @@ -275,6 +283,10 @@ class Topic < Resource
class Activity < Resource
has User
has :actor, :class => User

def self.cbp_path_regexes
[/^activities$/]
end
end

class Setting < UpdateResource
Expand Down Expand Up @@ -357,10 +369,18 @@ def self.singular_resource_name
namespace 'portal'
end

class TicketField < Resource; end
class TicketField < Resource
def self.cbp_path_regexes
[/^ticket_fields$/]
end
end

class TicketMetric < DataResource
include Read

def self.cbp_path_regexes
[/^ticket_metrics$/]
end
end

class TicketRelated < DataResource; end
Expand All @@ -387,7 +407,7 @@ class Ticket < Resource
extend DestroyMany

def self.cbp_path_regexes
[/tickets$/]
[/^tickets$/]
end

# Unlike other attributes, "comment" is not a property of the ticket,
Expand Down Expand Up @@ -498,6 +518,10 @@ class SuspendedTicket < ReadResource

# Recovers this suspended ticket to an actual ticket
put :recover

def self.cbp_path_regexes
[/^suspended_tickets$/]
end
end

class DeletedTicket < ReadResource
Expand All @@ -507,6 +531,10 @@ class DeletedTicket < ReadResource
# Restores this previously deleted ticket to an actual ticket
put :restore
put :restore_many

def self.cbp_path_regexes
[/^deleted_tickets$/]
end
end

class UserViewRow < DataResource
Expand Down Expand Up @@ -604,6 +632,10 @@ def columns=(columns)
def self.preview(client, options = {})
Collection.new(client, ViewRow, options.merge(:path => "views/preview", :verb => :post))
end

def self.cbp_path_regexes
[/^views$/]
end
end

class Trigger < Rule
Expand All @@ -613,7 +645,7 @@ class Trigger < Rule
has :execution, :class => RuleExecution

def self.cbp_path_regexes
[/triggers$/, %r{triggers/active$}]
[/^triggers$/, %r{^triggers/active$}]
end
end

Expand All @@ -622,13 +654,21 @@ class Automation < Rule
include Actions

has :execution, :class => RuleExecution

def self.cbp_path_regexes
[/^automations$/]
end
end

class Macro < Rule
include Actions

has :execution, :class => RuleExecution

def self.cbp_path_regexes
[/^macros$/]
end

# Returns the update to a ticket that happens when a macro will be applied.
# @param [Ticket] ticket Optional {Ticket} to apply this macro to.
# @raise [Faraday::ClientError] Raised for any non-200 response.
Expand Down Expand Up @@ -666,15 +706,15 @@ class GroupMembership < Resource
has Group

def self.cbp_path_regexes
[%r{groups/\d+/memberships$}]
[%r{^groups/\d+/memberships$}]
end
end

class Group < Resource
has_many :memberships, class: GroupMembership, path: "memberships"

def self.cbp_path_regexes
[/groups$/, %r{groups/assignable$}]
[/^groups$/, %r{^groups/assignable$}]
end
end

Expand Down Expand Up @@ -817,6 +857,10 @@ class OauthClient < Resource
def self.singular_resource_name
"client"
end

def self.cbp_path_regexes
[%r{^oauth/clients$}]
end
end

class OauthToken < ReadResource
Expand Down
106 changes: 106 additions & 0 deletions spec/live/cbp_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,110 @@
end
end
end

describe ZendeskAPI::TicketField do
describe '/ticket_fields' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.ticket_fields }
end
end
end

describe ZendeskAPI::Topic do
describe '/community/topics' do
let(:collection_fetched) do
VCR.use_cassette("cbp_#{described_class}_collection_fetch") do
client.topics.fetch
client.topics
end
end

let(:response_body) { collection_fetched.response.body }
let(:collection_fetched_results) { collection_fetched.to_a }

it 'returns a CBP response with all the correct keys' do
expect(response_body).to have_key('meta')
expect(response_body).to have_key('links')
expect(response_body['meta'].keys).to match_array(%w[has_more after_cursor before_cursor])
# expect(response_body['links'].keys).to match_array(%w[prev next]) this implementation omits prev and next keys
# instead of giving them a nil value
end

it "returns a list of #{described_class} objects" do
expect(collection_fetched_results).to all(be_a(described_class))
end
end
end

describe ZendeskAPI::View do
describe '/views' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.views }
end
end
end

describe ZendeskAPI::TicketMetric do
describe '/ticket_metrics' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.ticket_metrics }
end
end
end

describe ZendeskAPI::Tag do
describe '/tags' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.tags }
end
end
end

describe ZendeskAPI::SuspendedTicket do
describe '/suspended_tickets' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.suspended_tickets }
end
end
end

describe ZendeskAPI::Activity do
describe '/activities' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.activities }
end
end
end

describe ZendeskAPI::Automation do
describe '/automations' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.automations }
end
end
end

describe ZendeskAPI::DeletedTicket do
describe '/deleted_tickets' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.deleted_tickets }
end
end
end

describe ZendeskAPI::Macro do
describe '/macros' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.macros }
end
end
end

describe ZendeskAPI::OauthClient do
describe '/oauth/client' do
it_behaves_like 'an endpoint that supports CBP' do
let(:collection) { client.oauth_clients }
end
end
end
end
Loading