Module: SendGrid4r::REST::TransactionalTemplates::Versions

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/transactional_templates/versions.rb

Overview

SendGrid Web API v3 Template Engine - Versions

Defined Under Namespace

Classes: Version

Constant Summary

Constants included from Request

Request::BASE_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put

Class Method Details

.create_version(resp) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 18

def self.create_version(resp)
  return resp if resp.nil?
  Version.new(
    resp['id'],
    resp['user_id'],
    resp['template_id'],
    resp['active'],
    resp['name'],
    resp['html_content'],
    resp['plain_content'],
    resp['subject'],
    resp['updated_at'])
end

.url(temp_id, ver_id = nil) ⇒ Object



32
33
34
35
36
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 32

def self.url(temp_id, ver_id = nil)
  url = "#{BASE_URL}/templates/#{temp_id}/versions"
  url = "#{url}/#{ver_id}" unless ver_id.nil?
  url
end

Instance Method Details

#activate_version(template_id:, version_id:, &block) ⇒ Object



48
49
50
51
52
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 48

def activate_version(template_id:, version_id:, &block)
  url = Versions.url(template_id, version_id)
  resp = post(@auth, "#{url}/activate", &block)
  finish(resp, @raw_resp) { |r| Versions.create_version(r) }
end

#delete_version(template_id:, version_id:, &block) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 73

def delete_version(template_id:, version_id:, &block)
  delete(
    @auth,
    Versions.url(template_id, version_id),
    &block
  )
end

#get_version(template_id:, version_id:, &block) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 54

def get_version(template_id:, version_id:, &block)
  resp = get(
    @auth,
    Versions.url(template_id, version_id),
    &block
  )
  finish(resp, @raw_resp) { |r| Versions.create_version(r) }
end

#patch_version(template_id:, version_id:, version:, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 63

def patch_version(template_id:, version_id:, version:, &block)
  resp = patch(
    @auth,
    Versions.url(template_id, version_id),
    remove_uneditable_keys(version.to_h),
    &block
  )
  finish(resp, @raw_resp) { |r| Versions.create_version(r) }
end

#post_version(template_id:, version:, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/sendgrid4r/rest/transactional_templates/versions.rb', line 38

def post_version(template_id:, version:, &block)
  resp = post(
    @auth,
    Versions.url(template_id),
    remove_uneditable_keys(version.to_h),
    &block
  )
  finish(resp, @raw_resp) { |r| Versions.create_version(r) }
end