Module: Gmail

Defined in:
lib/gmail.rb,
lib/gmail/client.rb,
lib/gmail/labels.rb,
lib/gmail/message.rb,
lib/gmail/mailbox.rb,
lib/gmail/version.rb,
lib/gmail/client/base.rb,
lib/gmail/client/plain.rb,
lib/gmail/client/xoauth.rb,
lib/gmail/client/xoauth2.rb,
lib/gmail/imap_extensions.rb

Defined Under Namespace

Modules: Client, ImapExtensions Classes: Labels, Mailbox, Message

Constant Summary collapse

VERSION =
"0.6.0"

Class Method Summary collapse

Class Method Details

.new(*args, &block) ⇒ Object Also known as: connect

Creates new Gmail connection using given authorization options.

Examples

Gmail.new(:plain, "[email protected]", "password")
Gmail.new(:xoauth, "[email protected]",
  :consumer_key => "",
  :consumer_secret => "",
  :token => "",
  :secret => "")

To use plain authentication mehod you can also call:

Gmail.new("[email protected]", "password")

You can also use block-style call:

Gmail.new("[email protected]", "password") do |client|
  # ...
end

48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gmail.rb', line 48

def new(*args, &block)
  args.unshift(:plain) unless args.first.is_a?(Symbol)
  client = Gmail::Client.new(*args)
  client.connect
  client.

  if block_given?
    yield client
    client.logout
  end

  client
end

.new!(*args, &block) ⇒ Object Also known as: connect!


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gmail.rb', line 63

def new!(*args, &block)
  args.unshift(:plain) unless args.first.is_a?(Symbol)
  client = Gmail::Client.new(*args)
  client.connect!
  client.login!

  if block_given?
    yield client
    client.logout
  end

  client
end