Class: Txbr::EmailTemplatesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/txbr/email_templates_api.rb

Constant Summary collapse

TEMPLATE_BATCH_SIZE =
35
TEMPLATE_LIST_PATH =
'templates/email/list'.freeze
TEMPLATE_DETAILS_PATH =
'templates/email/info'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(braze_api) ⇒ EmailTemplatesApi

Returns a new instance of EmailTemplatesApi.



9
10
11
# File 'lib/txbr/email_templates_api.rb', line 9

def initialize(braze_api)
  @braze_api = braze_api
end

Instance Attribute Details

#braze_apiObject (readonly)

Returns the value of attribute braze_api.



7
8
9
# File 'lib/txbr/email_templates_api.rb', line 7

def braze_api
  @braze_api
end

Instance Method Details

#details(email_template_id:) ⇒ Object



29
30
31
# File 'lib/txbr/email_templates_api.rb', line 29

def details(email_template_id:)
  braze_api.get_json(TEMPLATE_DETAILS_PATH, email_template_id: email_template_id)
end

#each(offset: 1, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/txbr/email_templates_api.rb', line 13

def each(offset: 1, &block)
  return to_enum(__method__, offset: offset) unless block_given?

  loop do
    templates = braze_api.get_json(
      TEMPLATE_LIST_PATH,
      offset: offset,
      limit: TEMPLATE_BATCH_SIZE
    )

    templates['templates'].each(&block)
    offset += templates['templates'].size
    break if templates['templates'].size < TEMPLATE_BATCH_SIZE
  end
end