Class: TextMe::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/textme.rb

Instance Method Summary collapse

Constructor Details

#initialize(account_sid, auth_token, sender_number, reciever_number) ⇒ Core

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



18
19
20
21
22
23
24
25
# File 'lib/textme.rb', line 18

def initialize(, auth_token, sender_number, reciever_number)
	#Initialize the twilio client
	@client = Twilio::REST::Client.new , auth_token

	#Save the 'from' and 'to' number as private variable
	@sender_number = sender_number
	@reciever_number = reciever_number
end

Instance Method Details

#meta_extractor(verse_name) ⇒ Object

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/textme.rb', line 32

def meta_extractor(verse_name)
	extractor = TextMe::BibleExtractor.new
	url = extractor.verse_url_generator(verse_name)
	#Use a Hash to store the verse and image url
	 = Hash.new

	page = MetaInspector.new(url)
	
	#Get the verse name and the verse
	['verse'] = page.meta['og:title']
	
	#If the page contains an opengraph image
	if page.meta['og:image']
		if page.meta['og:image'].include? "http"
			['image_url'] = page.meta['og:image']
		end
	end

	return 
end

#send_message(verse_name) ⇒ Object

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/textme.rb', line 56

def send_message(verse_name)
	#A call to the meta_extractor to get the verse name, verse text and verse image(optional)
	verse_data = meta_extractor(verse_name)

	#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..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..messages.create(
			from: @sender_number,
			to: @reciever_number,
			body: verse_data['verse']
		)

	end
end