Class: Broadcast::Resources::OptInForms

Inherits:
Base
  • Object
show all
Defined in:
lib/broadcast/resources/opt_in_forms.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Broadcast::Resources::Base

Instance Method Details

#analytics(id, start_date: nil, end_date: nil) ⇒ Object

Performance analytics for the form. start_date/end_date accept Date, Time, or ISO-8601 strings (default: last 30 days).



41
42
43
44
45
46
# File 'lib/broadcast/resources/opt_in_forms.rb', line 41

def analytics(id, start_date: nil, end_date: nil)
  params = {}
  params[:start_date] = coerce_date(start_date) if start_date
  params[:end_date] = coerce_date(end_date) if end_date
  get("/api/v1/opt_in_forms/#{id}/analytics", params)
end

#create(**attrs) ⇒ Object

Create an opt-in form. Attrs are wrapped under ‘opt_in_form:` on the wire. Nested settings hashes (theme_settings, automation_settings, security_settings, trigger_settings, widget_settings) and arrays (opt_in_form_blocks_attributes, opt_in_post_submission_blocks_attributes) are passed through verbatim.



27
28
29
# File 'lib/broadcast/resources/opt_in_forms.rb', line 27

def create(**attrs)
  post('/api/v1/opt_in_forms', { opt_in_form: attrs })
end

#create_variant(id, name: nil, weight: nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/broadcast/resources/opt_in_forms.rb', line 48

def create_variant(id, name: nil, weight: nil)
  body = {}
  body[:name] = name unless name.nil?
  body[:weight] = weight unless weight.nil?
  post("/api/v1/opt_in_forms/#{id}/variants", body)
end

#delete(id) ⇒ Object



35
36
37
# File 'lib/broadcast/resources/opt_in_forms.rb', line 35

def delete(id)
  @client.request(:delete, "/api/v1/opt_in_forms/#{id}")
end

#duplicate(id, label: nil) ⇒ Object



55
56
57
58
59
# File 'lib/broadcast/resources/opt_in_forms.rb', line 55

def duplicate(id, label: nil)
  body = {}
  body[:label] = label unless label.nil?
  post("/api/v1/opt_in_forms/#{id}/duplicate", body)
end

#get_opt_in_form(id) ⇒ Object



19
20
21
# File 'lib/broadcast/resources/opt_in_forms.rb', line 19

def get_opt_in_form(id)
  get("/api/v1/opt_in_forms/#{id}")
end

#list(**params) ⇒ Object

List opt-in forms.

NOTE: returns up to 250 results per page along with ‘pagination` metadata. Variants are excluded (only main forms are returned). Pass `page:` to advance.

Optional filters: filter: (label substring), widget_type:, enabled: ‘true’



15
16
17
# File 'lib/broadcast/resources/opt_in_forms.rb', line 15

def list(**params)
  get('/api/v1/opt_in_forms', params)
end

#update(id, **attrs) ⇒ Object



31
32
33
# File 'lib/broadcast/resources/opt_in_forms.rb', line 31

def update(id, **attrs)
  patch("/api/v1/opt_in_forms/#{id}", { opt_in_form: attrs })
end