Sha256: d101311674c871b14cc5058d1a407275eb2f22664fadab21924989b8b265e3c6
Contents?: true
Size: 1.43 KB
Versions: 3
Compression:
Stored size: 1.43 KB
Contents
require 'json' require 'rest-client' module Howitzer module OnesecmailApi # A Onesecmail::Client object is used to communicate with the 1secMail API. class Client BASE_URL = 'https://www.1secmail.com/api/v1/'.freeze # :nodoc: # Finds message according to given parameters # # @param recipient [String] this is recipient mail address for message filtering # @param subject [String] this is subject of the message to filter particular message # @return [Hash] json message parsed to ruby hash def find_message(recipient, subject) messages = filter_by_subject(recipient[/[^@]+/], subject) latest_message(messages) end private def messages(recipient_name) JSON.parse(RestClient.get("#{BASE_URL}?action=getMessages&login=#{recipient_name}" \ "&domain=#{Howitzer.onesecmail_domain}")) end def latest_message(messages) messages[0] end def filter_by_subject(recipient_name, subject) result_messages = [] messages(recipient_name).each do |msg| if msg['subject'] == subject result_messages << JSON.parse(RestClient.get("#{BASE_URL}?action=readMessage&login=#{recipient_name}" \ "&domain=#{Howitzer.onesecmail_domain}&id=#{msg['id']}")) end end result_messages end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
howitzer-2.6.1 | lib/howitzer/onesecmail_api/client.rb |
howitzer-2.6.0 | lib/howitzer/onesecmail_api/client.rb |
howitzer-2.5.0 | lib/howitzer/onesecmail_api/client.rb |