Class: SimpleSpark::Endpoints::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_spark/endpoints/templates.rb

Overview

Note:

Sample Template { “id”=>“102293692714480130”, “name”=>“Summer Sale!”, “description”=>“”, “published”=>false, “options”=>{},

"last_update_time"=>"2016-03-02T22:49:23+00:00",
"content"=>{"from"=>"[email protected]", "subject"=>"Summer deals", "html"=>"<b>Check out these deals!</b>"} }

Provides access to the /templates endpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Templates

Returns a new instance of Templates.



12
13
14
# File 'lib/simple_spark/endpoints/templates.rb', line 12

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/simple_spark/endpoints/templates.rb', line 10

def client
  @client
end

Instance Method Details

#create(values) ⇒ boolean

Create a template by providing values for the template object.

Parameters:

  • values (Hash)

    containing the properties. At a minimum, the “name” and “content” fields are required, where content must contain the “from”, “subject”, and at least one of “html” or “text” fields.

Returns:

  • (boolean)

    true if success



29
30
31
# File 'lib/simple_spark/endpoints/templates.rb', line 29

def create(values)
  @client.call(method: :post, path: 'templates', body_values: values)
end

#delete(id) ⇒ Object

Delete a Template by its ID

Parameters:

  • id (String)

    the Unique Template ID to delete



75
76
77
# File 'lib/simple_spark/endpoints/templates.rb', line 75

def delete(id)
  @client.call(method: :delete, path: "templates/#{id}")
end

#listArray

Lists the most recent version of each template in your account.

Returns:

  • (Array)

    a list of Template hash objects



19
20
21
# File 'lib/simple_spark/endpoints/templates.rb', line 19

def list
  @client.call(method: :get, path: 'templates')
end

#preview(id, substitutions, draft = nil) ⇒ Object

Preview a Template by its ID

Parameters:

  • id (String)

    the Unique Template ID to preview

  • substitutions (Hash)

    the values to update the template with. Must contain a key ‘substitution_data’ { “substitution_data” => { “name” => “Natalie”, “age” => 35, “member” => true }

  • draft (boolean) (defaults to: nil)

    If true, returns the most recent draft template. If false, returns the most recent published template. If not provided, returns the most recent template version regardless of draft or published.



66
67
68
69
# File 'lib/simple_spark/endpoints/templates.rb', line 66

def preview(id, substitutions, draft = nil)
  query_params = draft.nil? ? {} : { draft: draft }
  @client.call(method: :post, path: "templates/#{id}/preview", body_values: substitutions, query_values: query_params)
end

#retrieve(id, draft = nil) ⇒ Hash

Parameters:

  • id (String)

    the Unique Template ID to retrieve

  • draft (boolean) (defaults to: nil)

    If true, returns the most recent draft template. If false, returns the most recent published template. If not provided, returns the most recent template version regardless of draft or published.

Returns:

  • (Hash)

    the Template object



40
41
42
43
44
# File 'lib/simple_spark/endpoints/templates.rb', line 40

def retrieve(id, draft = nil)
  path = "templates/#{id}"
  query_params = draft.nil? ? {} : { draft: draft }
  @client.call(method: :get, path: path, query_values: query_params)
end

#update(id, values, update_published = false) ⇒ Object

Update a Template by its ID

Parameters:

  • id (String)

    the Unique Template ID to update

  • values (Hash)

    the values to update the template with

  • update_published (boolean) (defaults to: false)

    If true, directly overwrite the existing published template. If false, create a new draft. If this template isn’t yet published, setting to ‘true’ will result in a NotFound error



53
54
55
# File 'lib/simple_spark/endpoints/templates.rb', line 53

def update(id, values, update_published = false)
  @client.call(method: :put, path: "templates/#{id}", body_values: values,  query_values: { update_published: update_published })
end