class TextMe::Core
Public Class Methods
new(account_sid, auth_token, sender_number, reciever_number)
click to toggle source
Constructor What: Initialize Twilio with credentials and save the from number Input: account_sid, auth_token => From twilio dashbaord
'from' number, 'to' number => from your twilio settings
Output: No output
# File lib/textme-jtj.rb, line 18 def initialize(account_sid, auth_token, sender_number, reciever_number) #Initialize the twilio client @client = Twilio::REST::Client.new account_sid, auth_token #Save the 'from' and 'to' number as private variable @sender_number = sender_number @reciever_number = reciever_number end
Public Instance Methods
meta_extractor(verse_id)
click to toggle source
Helper Method What: Take a youversion url and return the verse and the verse image from the open graph data Input: You version url of the verse Output: A hash with the (always) 'verse' => (verse name + verse text),
(optional) 'image_url' => image verse
# File lib/textme-jtj.rb, line 32 def meta_extractor(verse_id) jtj = TextMe::JTJVerseExtractor.new raw_data = jtj.extract_data(verse_id) bible_extractor = TextMe::BibleExtractor.new url = bible_extractor.verse_url_generator(raw_data["verse"]) #Use a Hash to store the verse and image url metadata = Hash.new page = MetaInspector.new(url) #Get the verse name and the verse metadata['verse'] = page.meta['og:title'] #If the page contains an opengraph image if not raw_data['image'] if page.meta['og:image'] if page.meta['og:image'].include? 'http' metadata['image_url'] = page.meta['og:image'] end end else metadata['image_url'] = raw_data["image"] end return metadata end
send_message(verse_id)
click to toggle source
What: Take the recievers number and the verse url. Calls the meta_extractor
helper method Input: 'To' number, You version url of the verse Output: No actual output. Send's a text containing verse name(always), verse text(always) and verse image(optional) to the 'To' number
# File lib/textme-jtj.rb, line 63 def send_message(verse_id) #A call to the meta_extractor to get the verse name, verse text and verse image(optional) verse_data = meta_extractor(verse_id) #If: There is a verse image for the verse #Else: There is no image if verse_data['image_url'] #Sending a text with the twilio client @client.api.account.messages.create( from: @sender_number, to: @reciever_number, body: verse_data['verse'], media_url: verse_data['image_url'] ) else #Sending a text with the twilio client @client.api.account.messages.create( from: @sender_number, to: @reciever_number, body: verse_data['verse'] ) end end