Class: AlexaWebService::DisplayDirective
- Inherits:
-
Object
- Object
- AlexaWebService::DisplayDirective
- Defined in:
- lib/alexa_web_service/display_directive.rb
Instance Attribute Summary collapse
-
#directive ⇒ Object
Returns the value of attribute directive.
Instance Method Summary collapse
- #add_background_image(content_description, url, size = 'X_SMALL') ⇒ Object
- #add_image(content_description, url, size = 'X_SMALL') ⇒ Object
-
#add_list_item(token: '', image_object: {}, text_object: {}) ⇒ Object
To create Show lists, first create image and text objects and then add show list item.
- #add_text(primary_text:, secondary_text: nil, tertiary_text: nil) ⇒ Object
- #image_object(content_description = '', url = '', size = 'X_SMALL') ⇒ Object
-
#initialize(type: "BodyTemplate1", token: "", back_button: "VISIBLE", title: "") ⇒ DisplayDirective
constructor
A new instance of DisplayDirective.
- #text_object(primary_text: nil, secondary_text: nil, tertiary_text: nil) ⇒ Object
Constructor Details
#initialize(type: "BodyTemplate1", token: "", back_button: "VISIBLE", title: "") ⇒ DisplayDirective
Returns a new instance of DisplayDirective.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/alexa_web_service/display_directive.rb', line 6 def initialize(type: "BodyTemplate1", token: "", back_button: "VISIBLE", title: "") @directive = { "type": "Display.RenderTemplate", "template": { "type": type, "token": token, "backButton": , "backgroundImage": image_object, "title": title, "image": image_object, "textContent": {} } } end |
Instance Attribute Details
#directive ⇒ Object
Returns the value of attribute directive.
4 5 6 |
# File 'lib/alexa_web_service/display_directive.rb', line 4 def directive @directive end |
Instance Method Details
#add_background_image(content_description, url, size = 'X_SMALL') ⇒ Object
37 38 39 |
# File 'lib/alexa_web_service/display_directive.rb', line 37 def add_background_image(content_description, url, size = 'X_SMALL') @directive[:template][:backgroundImage] = image_object(content_description, url, size = 'X_SMALL') end |
#add_image(content_description, url, size = 'X_SMALL') ⇒ Object
33 34 35 |
# File 'lib/alexa_web_service/display_directive.rb', line 33 def add_image(content_description, url, size = 'X_SMALL') @directive[:template][:image] = image_object(content_description, url, size = 'X_SMALL') end |
#add_list_item(token: '', image_object: {}, text_object: {}) ⇒ Object
To create Show lists, first create image and text objects and then add show list item.
63 64 65 66 67 68 69 70 71 |
# File 'lib/alexa_web_service/display_directive.rb', line 63 def add_list_item(token: '', image_object: {}, text_object: {}) item = { "token": token, "image": image_object, "textContent": text_object } @directive[:template][:listItems] ||= [] @directive[:template][:listItems] << item end |
#add_text(primary_text:, secondary_text: nil, tertiary_text: nil) ⇒ Object
58 59 60 |
# File 'lib/alexa_web_service/display_directive.rb', line 58 def add_text(primary_text:, secondary_text: nil, tertiary_text: nil) @directive[:template][:textContent] = text_object(primary_text: primary_text, secondary_text: secondary_text, tertiary_text: tertiary_text) end |
#image_object(content_description = '', url = '', size = 'X_SMALL') ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/alexa_web_service/display_directive.rb', line 21 def image_object(content_description = '', url = '', size = 'X_SMALL') { "contentDescription": content_description, "sources": [ { "url": url, "size": size } ] } end |
#text_object(primary_text: nil, secondary_text: nil, tertiary_text: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/alexa_web_service/display_directive.rb', line 41 def text_object(primary_text: nil, secondary_text: nil, tertiary_text: nil) { "primaryText": { "text": primary_text, "type": "RichText" }, "secondaryText": { "text": secondary_text, "type": "RichText" }, "tertiaryText": { "text": tertiary_text, "type": "RichText" } } end |