class Ralyxa::ResponseEntities::Card
Constants
- LINK_ACCOUNT_CARD_TYPE
- SIMPLE_CARD_TYPE
- STANDARD_CARD_TYPE
Public Class Methods
as_hash(title, body, small_image_url = nil, large_image_url = small_image_url)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 14 def self.as_hash(title, body, small_image_url = nil, large_image_url = small_image_url) new(title: title, body: body, small_image_url: small_image_url, large_image_url: large_image_url).to_h end
link_account()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 18 def self.link_account new(link_account: true).to_h end
new(options)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 10 def initialize(options) @options = options end
Public Instance Methods
to_h()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 22 def to_h {}.tap do |card| add_type(card) add_title(card) if @options[:title] add_body(card) if @options[:body] add_image(card) if standard? end end
Private Instance Methods
add_body(card)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 43 def add_body(card) card[:content] = @options[:body] if simple? card[:text] = @options[:body] if standard? end
add_image(card)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 48 def add_image(card) raise Ralyxa::UnsecureUrlError, "Card images must be available at an SSL-enabled (HTTPS) endpoint. Your current image urls are: (small: #{@options[:small_image_url]}, large: #{@options[:large_image_url]}" unless secure_images? card[:image] = {} small_image = @options[:small_image_url] || @options[:large_image_url] large_image = @options[:large_image_url] || @options[:small_image_url] card[:image][:smallImageUrl] = small_image if small_image card[:image][:largeImageUrl] = large_image if large_image end
add_title(card)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 39 def add_title(card) card[:title] = @options[:title] end
add_type(card)
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 33 def add_type(card) return card[:type] = LINK_ACCOUNT_CARD_TYPE if link_account? card[:type] = SIMPLE_CARD_TYPE if simple? card[:type] = STANDARD_CARD_TYPE if standard? end
link_account?()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 59 def link_account? !@options[:link_account].nil? end
secure_images?()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 71 def secure_images? small_secure = secure_uri?(@options[:small_image_url]) large_secure = secure_uri?(@options[:large_image_url]) small_secure && large_secure end
secure_uri?(uri_string)
click to toggle source
Given a uri string, retutrn true if:
* the scheme is https * or if we are not interested in the uri being secure * or if the value that has been passed is nil
# File lib/ralyxa/response_entities/card.rb, line 82 def secure_uri?(uri_string) return true if uri_string.nil? (URI.parse(uri_string).scheme == 'https' || !Ralyxa.require_secure_urls?) end
simple?()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 63 def simple? !@options[:small_image_url] && !@options[:large_image_url] end
standard?()
click to toggle source
# File lib/ralyxa/response_entities/card.rb, line 67 def standard? @options[:small_image_url] || @options[:large_image_url] end