gitlab_support_readiness 1.0.117 → 1.0.118

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cf9fab733d81a7aa5c5c5d9e471a0f227c8d18a054c8dc0c9da5f968697a107
4
- data.tar.gz: c0203eb2c3522b57969e8ec42b85115e994ebbe619de02024e832e0f9e349e7b
3
+ metadata.gz: 9f0bcf366ba1eb4cf4cb4db3bd2c12f1813d2cfcb1354e270f4ad06e4597bfe5
4
+ data.tar.gz: 3fb6cafe83120494ba4dae58e319ef2f76631ec3160ea119dfd42d75bd4f21aa
5
5
  SHA512:
6
- metadata.gz: 41579e75455d37c9139d7df45f2a413cdf5629469e51977af063e1bea5b28c024ce7c8222d4ab6da3a5aa0a4c8f12cf6a11e6fe399fe51702c931be1362465f5
7
- data.tar.gz: 1931b9f5d11cf0fdab299ea3a73c31256d73d309510c996a176f598d7bebe1d4df201ef23b3da8b2b45ba61afe5a070fe26b041c81593562b633124351844d3a
6
+ metadata.gz: d660ad4f9ec5cc6d97a44dd816a53784f8a786bde8c7a53cbe69f9d0d009784c2315544ff38ade8fb7f3aa5fdbdbe52604f2ff9a5ca2e6b1ac84501e52e1f0b6
7
+ data.tar.gz: 825c5a0c2e0cc70024f0991a9ca5fcc2ce65602c226b662a2a4aeb449a49c25e61d4dbcfe0f443bc361bf328d4fb1d547a5eee73fde23c236a728eac40b71622
@@ -439,5 +439,82 @@ module Readiness
439
439
  end
440
440
  object
441
441
  end
442
+
443
+ ##
444
+ # Convert user friendly Strings into Zendesk values for ticket form objects
445
+ #
446
+ # @author Jason Colyer
447
+ # @since 1.0.118
448
+ # @param object [Object] The object to parse
449
+ def self.convert_ticket_form_names_to_ids(object)
450
+ new_object = covert_ticket_form_field_ids(object)
451
+ new_object = convert_ticket_form_end_user_conditions(new_object)
452
+ new_object = convert_ticket_form_agent_conditions(new_object)
453
+ convert_ticket_form_brands(new_object)
454
+ end
455
+
456
+ ##
457
+ # Convert user friendly Strings into Zendesk values for ticket form field IDs
458
+ #
459
+ # @author Jason Colyer
460
+ # @since 1.0.118
461
+ # @param object [Object] The ticket form to parse
462
+ def self.covert_ticket_form_field_ids(object)
463
+ object['ticket_field_ids'] = object['ticket_field_ids'].map do |f|
464
+ field = Readiness::Zendesk::TicketFields.find_by_name(@zendesk_client, f, @ticket_fields)
465
+ field.nil? ? f : field.id
466
+ end
467
+ object
468
+ end
469
+
470
+ ##
471
+ # Convert user friendly Strings into Zendesk values for ticket form end_user conditions
472
+ #
473
+ # @author Jason Colyer
474
+ # @since 1.0.118
475
+ # @param object [Object] The ticket form to parse
476
+ def self.convert_ticket_form_end_user_conditions(object)
477
+ object['end_user_conditions'].each_with_index do |c, ci|
478
+ parent_field = Readiness::Zendesk::TicketFields.find_by_name(@zendesk_client, c['parent_field_id'], @ticket_fields)
479
+ object['end_user_conditions'][ci]['parent_field_id'] = parent_field.id unless parent_field.nil?
480
+ c['child_fields'].each_with_index do |cf, cfi|
481
+ child_field = Readiness::Zendesk::TicketFields.find_by_name(@zendesk_client, cf['id'], @ticket_fields)
482
+ object['end_user_conditions'][ci]['child_fields'][cfi]['id'] = child_field.id unless child_field.nil?
483
+ end
484
+ end
485
+ object
486
+ end
487
+
488
+ ##
489
+ # Convert user friendly Strings into Zendesk values for ticket form agent conditions
490
+ #
491
+ # @author Jason Colyer
492
+ # @since 1.0.118
493
+ # @param object [Object] The ticket form to parse
494
+ def self.convert_ticket_form_agent_conditions(object)
495
+ object['agent_conditions'].each_with_index do |c, ci|
496
+ parent_field = Readiness::Zendesk::TicketFields.find_by_name(@zendesk_client, c['parent_field_id'], @ticket_fields)
497
+ object['agent_conditions'][ci]['parent_field_id'] = parent_field.id unless parent_field.nil?
498
+ c['child_fields'].each_with_index do |cf, cfi|
499
+ child_field = Readiness::Zendesk::TicketFields.find_by_name(@zendesk_client, cf['id'], @ticket_fields)
500
+ object['agent_conditions'][ci]['child_fields'][cfi]['id'] = child_field.id unless child_field.nil?
501
+ end
502
+ end
503
+ object
504
+ end
505
+
506
+ ##
507
+ # Convert user friendly Strings into Zendesk values for ticket form brands
508
+ #
509
+ # @author Jason Colyer
510
+ # @since 1.0.118
511
+ # @param object [Object] The ticket form to parse
512
+ def self.convert_ticket_form_brands(object)
513
+ object['restricted_brand_ids'] = object['restricted_brand_ids'].map do |b|
514
+ brand = Readiness::Zendesk::Brands.find_by_name(@zendesk_client, b, @brands)
515
+ brand.nil? ? b : brand.id
516
+ end
517
+ object
518
+ end
442
519
  end
443
520
  end
@@ -48,6 +48,7 @@ module Readiness
48
48
  # pp diffs[:updates.count]
49
49
  # # => 1
50
50
  def self.compare(zendesk_client, location = 'data', verbose = false)
51
+ @zendesk_client = zendesk_client
51
52
  diffs = {
52
53
  updates: [],
53
54
  creates: []
@@ -138,11 +139,14 @@ module Readiness
138
139
  # pp repo.count
139
140
  # # => 35
140
141
  def self.gather(location = 'data')
142
+ @brands = Readiness::Zendesk::Brands.list(@zendesk_client)
143
+ @ticket_fields = Readiness::Zendesk::TicketFields.list(@zendesk_client)
141
144
  @errors = []
142
145
  @location = location
143
146
  array = []
144
147
  Dir["#{@location}/**/*.yaml"].each do |f|
145
148
  object = YAML.safe_load_file(f)
149
+ object = convert_ticket_form_names_to_ids(object)
146
150
  validity_check(f, object)
147
151
  object['id'] = nil
148
152
  array.push(Zendesk::TicketForms.new(object))
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Brands within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.118
12
+ # @todo find
13
+ # @todo find!
14
+ # @todo Create
15
+ # @todo Update
16
+ # @todo Delete
17
+ # @todo Check Host Mapping Validity
18
+ # @todo Check Host Mapping Validity for an Existing Brand
19
+ class Brands < Readiness::Client
20
+ attr_accessor :active, :brand_url, :created_at, :default, :has_help_center, :help_center_state, :host_mapping, :id, :logo, :name, :signature_template, :subdomain, :ticket_form_ids, :updated_at
21
+
22
+ ##
23
+ # Creates a new {Readiness::Zendesk::Brands} instance
24
+ #
25
+ # @author Jason Colyer
26
+ # @since 1.0.118
27
+ # @param object [Object] An instance of {Readiness::Zendesk::Brands}
28
+ # @example
29
+ # require 'support_readiness'
30
+ # Readiness::Zendesk::Brands.new
31
+ def initialize(object = {})
32
+ @active = object['active']
33
+ @brand_url = object['brand_url']
34
+ @created_at = object['created_at']
35
+ @default = object['default']
36
+ @has_help_center = object['has_help_center']
37
+ @help_center_state = object['help_center_state']
38
+ @host_mapping = object['host_mapping']
39
+ @id = object['id']
40
+ @logo = object['logo']
41
+ @name = object['name']
42
+ @signature_template = object['signature_template']
43
+ @subdomain = object['subdomain']
44
+ @ticket_form_ids = object['ticket_form_ids']
45
+ @updated_at = object['updated_at']
46
+ end
47
+
48
+ ##
49
+ # Lists all brands.
50
+ #
51
+ # @author Jason Colyer
52
+ # @since 1.0.118
53
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
54
+ # @return [Array]
55
+ # @see https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#list-brands Zendesk API > Brands > List Brands
56
+ # @example
57
+ # require 'support_readiness'
58
+ # config = Readiness::Zendesk::Configuration.new
59
+ # config.username = 'alice@example.com'
60
+ # config.token = 'test123abc'
61
+ # config.url = 'https://example.zendesk.com/api/v2'
62
+ # client = Readiness::Zendesk::Client.new(config)
63
+ # brands = Readiness::Zendesk::Brands.list(client)
64
+ # pp brands.count
65
+ # # => 2
66
+ def self.list(client)
67
+ response = client.connection.get 'brands'
68
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
69
+ body = Oj.load(response.body)
70
+ body['brands'].map { |b| Brands.new(b) }
71
+ end
72
+
73
+ ##
74
+ # Locates a brand within Zendesk by name. Can utilize a cacheh for quicker results
75
+ #
76
+ # @author Jason Colyer
77
+ # @since 1.0.118
78
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
79
+ # @param name [String] The brand name to look for
80
+ # @param cache [Array] The results of {Readiness::Zendesk::Brands#list}
81
+ # @return [Object] An instance of {Readiness::Zendesk::Brands}
82
+ # @example
83
+ # require 'support_readiness'
84
+ # config = Readiness::Zendesk::Configuration.new
85
+ # config.username = 'alice@example.com'
86
+ # config.token = 'test123abc'
87
+ # config.url = 'https://example.zendesk.com/api/v2'
88
+ # client = Readiness::Zendesk::Client.new(config)
89
+ # brand = Readiness::Zendesk::Brands.find_by_name(client, 'Brand 1')
90
+ # pp brand.id
91
+ # # => 360002783572
92
+ def self.find_by_name(client, name, cache = nil)
93
+ brands = if cache.nil?
94
+ Brands.list(client)
95
+ else
96
+ cache
97
+ end
98
+ brands.detect { |f| f.name == name }
99
+ end
100
+ end
101
+ end
102
+ end
@@ -11,6 +11,7 @@ module Readiness
11
11
  require "#{__dir__}/zendesk/apps"
12
12
  require "#{__dir__}/zendesk/articles"
13
13
  require "#{__dir__}/zendesk/automations"
14
+ require "#{__dir__}/zendesk/brands"
14
15
  require "#{__dir__}/zendesk/client"
15
16
  require "#{__dir__}/zendesk/configuration"
16
17
  require "#{__dir__}/zendesk/dynamic_content"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_support_readiness
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.117
4
+ version: 1.0.118
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Colyer
@@ -405,6 +405,7 @@ files:
405
405
  - lib/support_readiness/zendesk/apps.rb
406
406
  - lib/support_readiness/zendesk/articles.rb
407
407
  - lib/support_readiness/zendesk/automations.rb
408
+ - lib/support_readiness/zendesk/brands.rb
408
409
  - lib/support_readiness/zendesk/client.rb
409
410
  - lib/support_readiness/zendesk/configuration.rb
410
411
  - lib/support_readiness/zendesk/dynamic_content.rb