Class: SparkPost::Template
- Defined in:
- lib/sparkpost/template.rb
Instance Method Summary collapse
- #create(id, from = nil, subject = nil, html = nil, **options) ⇒ Object
- #delete(id) ⇒ Object
- #get(id, draft = nil) ⇒ Object
-
#initialize(api_key, api_host) ⇒ Template
constructor
A new instance of Template.
- #list ⇒ Object
- #preview(id, substitution_data, draft = nil) ⇒ Object
- #update(id, from = nil, subject = nil, html = nil, **options) ⇒ Object
Methods included from Helpers
Methods included from Request
configure_http, configure_request, #endpoint, process_response, request
Constructor Details
#initialize(api_key, api_host) ⇒ Template
Returns a new instance of Template.
12 13 14 15 16 |
# File 'lib/sparkpost/template.rb', line 12 def initialize(api_key, api_host) @api_key = api_key @api_host = api_host @base_endpoint = "#{@api_host}/api/v1/templates" end |
Instance Method Details
#create(id, from = nil, subject = nil, html = nil, **options) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sparkpost/template.rb', line 18 def create(id, from = nil, subject = nil, html = nil, **) data = deep_merge( payload_from_args(id, from, subject, html), () ) request(endpoint, @api_key, data, 'POST') end |
#delete(id) ⇒ Object
36 37 38 |
# File 'lib/sparkpost/template.rb', line 36 def delete(id) request(endpoint(id), @api_key, nil, 'DELETE') end |
#get(id, draft = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/sparkpost/template.rb', line 40 def get(id, draft = nil) params = {} params[:draft] = draft unless draft.nil? request(endpoint(id, params), @api_key, nil, 'GET') end |
#list ⇒ Object
46 47 48 |
# File 'lib/sparkpost/template.rb', line 46 def list request(endpoint, @api_key, nil, 'GET') end |
#preview(id, substitution_data, draft = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sparkpost/template.rb', line 50 def preview(id, substitution_data, draft = nil) params = {} params[:draft] = draft unless draft.nil? request( endpoint("#{id}/preview", params), @api_key, { substitution_data: substitution_data }, 'POST' ) end |
#update(id, from = nil, subject = nil, html = nil, **options) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/sparkpost/template.rb', line 26 def update(id, from = nil, subject = nil, html = nil, **) params = {} copy_value(, :update_published, params, :update_published) data = deep_merge( payload_from_args(nil, from, subject, html), () ) request(endpoint(id, params), @api_key, data, 'PUT') end |