- Use undocumented but valid .count method to prevent more than one API request for gathering the count ob objects.
- Use .all! instead of .all to get possible errors raised insted of silently capturing them.
This commit is contained in:
parent
de2f2bf20b
commit
edd9b42fdf
1 changed files with 11 additions and 16 deletions
|
@ -163,13 +163,7 @@ module Import::Zendesk
|
||||||
}
|
}
|
||||||
|
|
||||||
result.each { |object, _score|
|
result.each { |object, _score|
|
||||||
|
result[ object ] = @client.send( object.underscore.to_sym ).count!
|
||||||
counter = 0
|
|
||||||
@client.send( object.underscore.to_sym ).all do |_resource|
|
|
||||||
counter += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
result[ object ] = counter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if result
|
if result
|
||||||
|
@ -317,7 +311,7 @@ module Import::Zendesk
|
||||||
|
|
||||||
local_fields = local_object.constantize.column_names
|
local_fields = local_object.constantize.column_names
|
||||||
|
|
||||||
@client.send("#{local_object.downcase}_fields").all { |zendesk_object_field|
|
@client.send("#{local_object.downcase}_fields").all! { |zendesk_object_field|
|
||||||
|
|
||||||
if local_object == 'Ticket'
|
if local_object == 'Ticket'
|
||||||
mapped_object_field = method("mapping_#{local_object.downcase}_field").call( zendesk_object_field.type )
|
mapped_object_field = method("mapping_#{local_object.downcase}_field").call( zendesk_object_field.type )
|
||||||
|
@ -467,7 +461,7 @@ module Import::Zendesk
|
||||||
def import_groups
|
def import_groups
|
||||||
|
|
||||||
@zendesk_group_mapping = {}
|
@zendesk_group_mapping = {}
|
||||||
@client.groups.all { |zendesk_group|
|
@client.groups.all! { |zendesk_group|
|
||||||
local_group = Group.create_if_not_exists(
|
local_group = Group.create_if_not_exists(
|
||||||
name: zendesk_group.name,
|
name: zendesk_group.name,
|
||||||
active: !zendesk_group.deleted,
|
active: !zendesk_group.deleted,
|
||||||
|
@ -515,7 +509,7 @@ module Import::Zendesk
|
||||||
role_agent = Role.lookup(name: 'Agent')
|
role_agent = Role.lookup(name: 'Agent')
|
||||||
role_customer = Role.lookup(name: 'Customer')
|
role_customer = Role.lookup(name: 'Customer')
|
||||||
|
|
||||||
@client.users.all { |zendesk_user|
|
@client.users.all! { |zendesk_user|
|
||||||
|
|
||||||
local_user_fields = {
|
local_user_fields = {
|
||||||
login: zendesk_user.id.to_s, # Zendesk users may have no other identifier than the ID, e.g. twitter users
|
login: zendesk_user.id.to_s, # Zendesk users may have no other identifier than the ID, e.g. twitter users
|
||||||
|
@ -586,7 +580,7 @@ module Import::Zendesk
|
||||||
|
|
||||||
@zendesk_user_group_mapping = {}
|
@zendesk_user_group_mapping = {}
|
||||||
|
|
||||||
@client.group_memberships.all { |zendesk_group_membership|
|
@client.group_memberships.all! { |zendesk_group_membership|
|
||||||
|
|
||||||
@zendesk_user_group_mapping[ zendesk_group_membership.user_id ] ||= []
|
@zendesk_user_group_mapping[ zendesk_group_membership.user_id ] ||= []
|
||||||
@zendesk_user_group_mapping[ zendesk_group_membership.user_id ].push( zendesk_group_membership.group_id )
|
@zendesk_user_group_mapping[ zendesk_group_membership.user_id ].push( zendesk_group_membership.group_id )
|
||||||
|
@ -620,7 +614,7 @@ module Import::Zendesk
|
||||||
article_type_facebook_feed_post = Ticket::Article::Type.lookup(name: 'facebook feed post')
|
article_type_facebook_feed_post = Ticket::Article::Type.lookup(name: 'facebook feed post')
|
||||||
article_type_facebook_feed_comment = Ticket::Article::Type.lookup(name: 'facebook feed comment')
|
article_type_facebook_feed_comment = Ticket::Article::Type.lookup(name: 'facebook feed comment')
|
||||||
|
|
||||||
@client.tickets.all { |zendesk_ticket|
|
@client.tickets.all! { |zendesk_ticket|
|
||||||
|
|
||||||
zendesk_ticket_fields = {}
|
zendesk_ticket_fields = {}
|
||||||
zendesk_ticket.custom_fields.each { |zendesk_ticket_field|
|
zendesk_ticket.custom_fields.each { |zendesk_ticket_field|
|
||||||
|
@ -635,6 +629,7 @@ module Import::Zendesk
|
||||||
}
|
}
|
||||||
|
|
||||||
local_ticket_fields = {
|
local_ticket_fields = {
|
||||||
|
id: zendesk_ticket.id,
|
||||||
title: zendesk_ticket.subject,
|
title: zendesk_ticket.subject,
|
||||||
note: zendesk_ticket.description,
|
note: zendesk_ticket.description,
|
||||||
group_id: @zendesk_group_mapping[ zendesk_ticket.group_id ] || 1,
|
group_id: @zendesk_group_mapping[ zendesk_ticket.group_id ] || 1,
|
||||||
|
@ -682,7 +677,7 @@ module Import::Zendesk
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local_ticket = Ticket.create( local_ticket_fields )
|
local_ticket = Ticket.create_or_update( local_ticket_fields )
|
||||||
|
|
||||||
zendesk_ticket_tags = []
|
zendesk_ticket_tags = []
|
||||||
zendesk_ticket.tags.each { |tag|
|
zendesk_ticket.tags.each { |tag|
|
||||||
|
@ -814,7 +809,7 @@ module Import::Zendesk
|
||||||
# https://developer.zendesk.com/rest_api/docs/core/macros
|
# https://developer.zendesk.com/rest_api/docs/core/macros
|
||||||
def import_macros
|
def import_macros
|
||||||
|
|
||||||
@client.macros.all { |zendesk_macro|
|
@client.macros.all! { |zendesk_macro|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
next if !zendesk_macro.active
|
next if !zendesk_macro.active
|
||||||
|
@ -866,7 +861,7 @@ module Import::Zendesk
|
||||||
# https://developer.zendesk.com/rest_api/docs/core/views
|
# https://developer.zendesk.com/rest_api/docs/core/views
|
||||||
def import_views
|
def import_views
|
||||||
|
|
||||||
@client.views.all { |zendesk_view|
|
@client.views.all! { |zendesk_view|
|
||||||
|
|
||||||
# "url" => "https://example.zendesk.com/api/v2/views/59511071.json"
|
# "url" => "https://example.zendesk.com/api/v2/views/59511071.json"
|
||||||
# "id" => 59511071
|
# "id" => 59511071
|
||||||
|
@ -995,7 +990,7 @@ module Import::Zendesk
|
||||||
# https://developer.zendesk.com/rest_api/docs/core/automations
|
# https://developer.zendesk.com/rest_api/docs/core/automations
|
||||||
def import_automations
|
def import_automations
|
||||||
|
|
||||||
@client.automations.all { |zendesk_automation|
|
@client.automations.all! { |zendesk_automation|
|
||||||
|
|
||||||
# "url" => "https://example.zendesk.com/api/v2/automations/60037892.json"
|
# "url" => "https://example.zendesk.com/api/v2/automations/60037892.json"
|
||||||
# "id" => 60037892
|
# "id" => 60037892
|
||||||
|
|
Loading…
Reference in a new issue