Class: Zendesk2::CreateHelpCenterTranslation

Inherits:
Object
  • Object
show all
Includes:
HelpCenter::TranslationSource::Request, Request
Defined in:
lib/zendesk2/help_center/create_help_center_translation.rb

Instance Attribute Summary

Attributes included from Request

#params

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HelpCenter::TranslationSource::Request

#locale, #mock_translation_key, #source_id, #source_type, #source_type_url

Methods included from Request

#call, cistern_included, #data, #delete!, #error!, #find!, #html_url_for, included, #mock_response, #page, #page_params!, #page_params?, #pluralize, #real, #real_request, #request_body, #request_params, #request_path, #resources, #response, #timestamp, #url_for

Class Method Details

.accepted_attributesObject



10
11
12
# File 'lib/zendesk2/help_center/create_help_center_translation.rb', line 10

def self.accepted_attributes
  %w(locale title body outdated draft)
end

Instance Method Details

#mockObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zendesk2/help_center/create_help_center_translation.rb', line 18

def mock
  identity = cistern.serial_id

  record = {
    'id'                => identity,
    'url'               => url_for("/help_center/#{source_type_url}/#{source_id}/translation/#{locale}.json"),
    'html_url'          => html_url_for("/hc/#{locale}/#{source_type_url}/#{source_id}"),
    'created_at'        => timestamp,
    'updated_at'        => timestamp,
    'title'             => params.fetch('translation').fetch('title'),
    'body'              => (params.fetch('translation')['body'] || ''),
    'outdated'          => false,
    'draft'             => false,
    'locale'            => locale,
  }.merge(translation_params)

  cistern.data[:help_center_translations][mock_translation_key] = record

  mock_response('translation' => record)
end

#translation_paramsObject



14
15
16
# File 'lib/zendesk2/help_center/create_help_center_translation.rb', line 14

def translation_params
  Cistern::Hash.slice(params.fetch('translation'), *self.class.accepted_attributes)
end