module SendGrid4r::REST::TransactionalTemplates::Versions

SendGrid Web API v3 Template Engine - Versions

Constants

Version

Public Class Methods

create_version(resp) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 17
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) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 31
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

Public Instance Methods

activate_version(template_id:, version_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 47
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) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 72
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) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 53
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) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 62
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) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 37
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

Private Instance Methods

remove_uneditable_keys(hash_value) click to toggle source
# File lib/sendgrid4r/rest/transactional_templates/versions.rb, line 82
def remove_uneditable_keys(hash_value)
  hash_value.delete(:id) if hash_value.key?(:id)
  hash_value.delete(:template_id) if hash_value.key?(:template_id)
  hash_value
end