lib/howitzer/gmail_api/client.rb in howitzer-2.2.0 vs lib/howitzer/gmail_api/client.rb in howitzer-2.3.0

- old
+ new

@@ -1,22 +1,31 @@ -require 'gmail' - module Howitzer module GmailApi # A GmailApi::Client object is used to communicate with the Gmail API. class Client + def self.load_gmail_gem! + require 'gmail' + rescue LoadError + raise LoadError, "Unable to load `gmail` library, please add following code to your Gemfile:\n\ngem 'gmail'" + end + load_gmail_gem! + def initialize - @client = Gmail.connect(Howitzer.gmail_login, Howitzer.gmail_password) + self.client = Gmail.connect(Howitzer.gmail_login, Howitzer.gmail_password) end # 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 [Gmail::Message] gmail message object def find_message(recipient, subject) - @client.inbox.emails(to: recipient, subject: subject).last + client.inbox.emails(to: recipient, subject: subject).last end + + private + + attr_accessor :client end end end