Class: TextMe::JTJVerseExtractor
- Inherits:
-
Object
- Object
- TextMe::JTJVerseExtractor
- Defined in:
- lib/textme-jtj.rb
Overview
Helper class to extract Join The Journey’s (JTJ) daily devotion specific information
Instance Method Summary collapse
-
#extract_data(entry_id) ⇒ Object
What: Called from Core class to get the verse name and image link for specific JTJ Input: id of the JTJ entry Output: Hash containing the verse name and verse lock screen image.
-
#get_verse(entry_id) ⇒ Object
Helper method What: Makes a HTTP Get request to the JTJ API Input: id of the JTJ entry Output: the API response in JSON format.
Instance Method Details
#extract_data(entry_id) ⇒ Object
What: Called from Core class to get the verse name and image link for specific JTJ Input: id of the JTJ entry Output: Hash containing the verse name and verse lock screen image
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/textme-jtj.rb', line 296 def extract_data(entry_id) #Getting the HTTP response in JSON format of the given JTJ entry data = get_verse(entry_id) result = Hash.new #Empty result hash #Get the lock screen image from the JSON if data["entry"]["links"]["lock_screen"] image_link = data["entry"]["links"]["lock_screen"] result["image"] = image_link end #Get the verse name from JSON if data["entry"]["memory_verse"]["reference"] verse_name = data["entry"]["memory_verse"]["reference"] result["verse"] = verse_name end return result end |
#get_verse(entry_id) ⇒ Object
Helper method What: Makes a HTTP Get request to the JTJ API Input: id of the JTJ entry Output: the API response in JSON format
287 288 289 290 291 |
# File 'lib/textme-jtj.rb', line 287 def get_verse(entry_id) url = 'https://jtj.watermark.org/api/entries/' + entry_id.to_s result = Net::HTTP.get(URI.parse(url)) return JSON.parse(result) end |