Class: Txbr::BrazeApi

Inherits:
Object
  • Object
show all
Includes:
RequestMethods
Defined in:
lib/txbr/braze_api.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_url, connection: nil) ⇒ BrazeApi

Returns a new instance of BrazeApi.



14
15
16
17
18
# File 'lib/txbr/braze_api.rb', line 14

def initialize(api_key, api_url, connection: nil)
  @api_key = api_key
  @api_url = api_url
  @connection = connection
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/txbr/braze_api.rb', line 12

def api_key
  @api_key
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



12
13
14
# File 'lib/txbr/braze_api.rb', line 12

def api_url
  @api_url
end

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/txbr/braze_api.rb', line 20

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

  loop do
    templates = 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

#get_email_template_details(email_template_id:) ⇒ Object



36
37
38
# File 'lib/txbr/braze_api.rb', line 36

def get_email_template_details(email_template_id:)
  get_json(TEMPLATE_INFO_PATH, email_template_id: email_template_id)
end