class Hulaki::Core
Public Class Methods
new(config)
click to toggle source
# File lib/hulaki/core.rb, line 4 def initialize(config) @config = config end
Public Instance Methods
perform()
click to toggle source
# File lib/hulaki/core.rb, line 8 def perform if @config.search_keyword handle_search_and_clipboard else handle_messaging end rescue CSV::MalformedCSVError puts 'Your contact.csv file is invalid or has invalid/malformed UTF characters.'.red puts 'Please use a valid CSV file.'.red end
Private Instance Methods
get_sender()
click to toggle source
# File lib/hulaki/core.rb, line 73 def get_sender @config[:from] || Hulaki::Config['email']['from'] end
handle_email(recipient)
click to toggle source
# File lib/hulaki/core.rb, line 47 def handle_email(recipient) puts "Sending email to #{recipient}" email_handler = Hulaki::Mailer.new( { :to => recipient, :message => @config.message, :subject => @config.subject, :from => @config.from }).deliver puts "Email sent to `#{recipient}`. from `#{get_sender}`" end
handle_messaging()
click to toggle source
# File lib/hulaki/core.rb, line 20 def handle_messaging puts '~' * 100 puts 'Welcome to Hulaki : Your best companion! to make your day great.' puts '~' * 100 # It supports multiple recipients like two phonenumbers separated by commas `,` @config.to.each do |recipient| if is_phone?(recipient) handle_sms(recipient) elsif is_email?(recipient) handle_email(recipient) end end puts '~' * 100 puts @config.message puts '~' * 100 end
handle_search_and_clipboard()
click to toggle source
# File lib/hulaki/core.rb, line 77 def handle_search_and_clipboard puts response = Hulaki::SearchEngine.new.perform(@config.search_keyword) Hulaki::Presenter.new(response).display if response if @config.copy_phone_number number = response[0][0]['phone_1___value'].gsub(' ', '') Clipboard.copy number puts "Number '#{number.underline}' is copied to your clipboard" puts end end
handle_sms(recipient)
click to toggle source
# File lib/hulaki/core.rb, line 59 def handle_sms(recipient) puts "Sending SMS to #{recipient}" sms_handler = Hulaki::SmsHandler.new( { :to => recipient, :message => @config.message, :gateway => @config.gateway, :from => @config.from }) if sms_handler.send puts "SMS sent successfully to #{recipient} using `#{sms_handler.gateway.class}` gateway" end end
is_email?(email)
click to toggle source
# File lib/hulaki/core.rb, line 43 def is_email?(email) Hulaki::EmailValidator.is_email?(email) end
is_phone?(number)
click to toggle source
# File lib/hulaki/core.rb, line 39 def is_phone?(number) Hulaki::SmsValidator.is_phone_number?(number) end