Class: SendgridTemplate::Version
- Inherits:
-
Struct
- Object
- Struct
- SendgridTemplate::Version
- Defined in:
- lib/sendgrid_template/version.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#editor ⇒ Object
Returns the value of attribute editor.
-
#generate_plain_content ⇒ Object
Returns the value of attribute generate_plain_content.
-
#html_content ⇒ Object
Returns the value of attribute html_content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plain_content ⇒ Object
Returns the value of attribute plain_content.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attrs) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(attrs = {}) ⇒ Version
constructor
A new instance of Version.
- #save ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Version
Returns a new instance of Version.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sendgrid_template/version.rb', line 12 def initialize(attrs = {}) super(attrs['id'], attrs['template_id'], attrs['active'], attrs['name'], attrs['subject'], attrs['updated_at'], attrs['html_content'], attrs['plain_content'], attrs['user_id'], attrs['generate_plain_content'], attrs['editor'], attrs['thumbnail_url'] ) end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def active @active end |
#editor ⇒ Object
Returns the value of attribute editor
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def editor @editor end |
#generate_plain_content ⇒ Object
Returns the value of attribute generate_plain_content
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def generate_plain_content @generate_plain_content end |
#html_content ⇒ Object
Returns the value of attribute html_content
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def html_content @html_content end |
#id ⇒ Object
Returns the value of attribute id
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def name @name end |
#plain_content ⇒ Object
Returns the value of attribute plain_content
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def plain_content @plain_content end |
#subject ⇒ Object
Returns the value of attribute subject
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def subject @subject end |
#template_id ⇒ Object
Returns the value of attribute template_id
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def template_id @template_id end |
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def thumbnail_url @thumbnail_url end |
#updated_at ⇒ Object
Returns the value of attribute updated_at
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def updated_at @updated_at end |
#user_id ⇒ Object
Returns the value of attribute user_id
6 7 8 |
# File 'lib/sendgrid_template/version.rb', line 6 def user_id @user_id end |
Class Method Details
.activate(template_id, _version_id) ⇒ Object
74 75 76 77 |
# File 'lib/sendgrid_template/version.rb', line 74 def activate(template_id, _version_id) response = SendgridTemplate.configuration.connect.get("/v3/templates/#{template_id}/versions/#{id}/activate") new(response.body) if response.success? end |
.find(template_id, _version_id) ⇒ Object
69 70 71 72 |
# File 'lib/sendgrid_template/version.rb', line 69 def find(template_id, _version_id) response = SendgridTemplate.configuration.connect.get("/v3/templates/#{template_id}/versions/#{id}") new(response.body) if response.success? end |
Instance Method Details
#attributes ⇒ Object
28 29 30 |
# File 'lib/sendgrid_template/version.rb', line 28 def attributes Hash[each_pair.to_a] end |
#attributes=(attrs) ⇒ Object
32 33 34 35 36 |
# File 'lib/sendgrid_template/version.rb', line 32 def attributes=(attrs) attrs.each do |k, v| self[k.to_sym] = v if respond_to?(k) end end |
#create ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/sendgrid_template/version.rb', line 55 def create # create response = SendgridTemplate.configuration.connect.post("/v3/templates/#{template_id}/versions") do |req| req.headers[:content_type] = 'application/json' req.body = JSON.generate(attributes.reject { |k, v| v.nil? || k.to_s[/id|_id\Z/] }) end self.attributes = response.body if response.success? end |
#delete ⇒ Object
64 65 66 |
# File 'lib/sendgrid_template/version.rb', line 64 def delete SendgridTemplate.configuration.connect.delete("/v3/templates/#{template_id}/versions/#{id}").success? end |
#save ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/sendgrid_template/version.rb', line 38 def save if id.nil? create else update end end |
#update ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/sendgrid_template/version.rb', line 46 def update # update response = SendgridTemplate.configuration.connect.patch("/v3/templates/#{v.template_id}/versions/#{v.id}") do |req| req.headers[:content_type] = 'application/json' req.body = JSON.generate(v.attributes.reject { |k, v| v.nil? || k.to_s[/id|_id\Z/] }) end self.attributes = response.body if response.success? end |