Class: Zendesk2::CreateHelpCenterSubscription

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

Instance Attribute Summary

Attributes included from Request

#params

Instance Method Summary collapse

Methods included from HelpCenter::SubscriptionRequest

#content_id, #content_type, included, #plural_content_type, #route_prefix, #subscription, #subscription_id

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

Instance Method Details

#mockObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zendesk2/help_center/create_help_center_subscription.rb', line 19

def mock
  identity = cistern.serial_id

  url = url_for("/help_center/#{plural_content_type}/#{content_id}/subscription.json")

  content_collection = "help_center_#{plural_content_type}".to_sym
  find!(content_collection, content_id)

  if subscription_params.empty?
    mock_response('Required parameter missing: subscription', status: 400)
  end

  record = subscription_params.merge(
    'id'           => identity,
    'url'          => url,
    'created_at'   => timestamp, # @todo create #timestamp helper
    'updated_at'   => timestamp,
    'content_id'   => content_id,
    'content_type' => content_type,
  )

  record['locale'] = record.delete('source_locale') if record['source_locale']

  cistern.data[:help_center_subscriptions][identity] = record

  mock_response('subscription' => record)
end

#subscription_paramsObject



12
13
14
15
16
17
# File 'lib/zendesk2/help_center/create_help_center_subscription.rb', line 12

def subscription_params
  return @subscription_params if @subscription_params
  body = Cistern::Hash.slice(subscription, *self.class.accepted_attributes(content_type))
  body['source_locale'] = body.delete('locale') if body['locale']
  @subscription_params = body
end