Class: GmailApiJp::Draft

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail_api_jp.rb

Constant Summary collapse

CONFIG =
YAML.load_file("gmail_draft.yml")
OOB_URI =
'urn:ietf:wg:oauth:2.0:oob'
APPLICATION_NAME =
CONFIG["application_name"]
CLIENT_SECRETS_PATH =
CONFIG["client_secrets_path"] || "client_secret.json"
CREDENTIALS_PATH =
CONFIG["stored_credential_path"] || File.join(Dir.home, '.credentials',
"gmail-draft-jp.yaml")
SCOPE =
CONFIG["scope"] || "https://mail.google.com/"

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Draft

the argument text should be like:

Subject: Hello

Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


27
28
29
30
31
32
# File 'lib/gmail_api_jp.rb', line 27

def initialize(text)
  @service = Google::Apis::GmailV1::GmailService.new
  @service.client_options.application_name = APPLICATION_NAME
  @service.authorization = authorize
  @text = text.encode("ISO-2022-JP")
end

Instance Method Details

#create_draftObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gmail_api_jp.rb', line 34

def create_draft
  user_id = 'me'

  draft = Google::Apis::GmailV1::Draft.new
  message = Google::Apis::GmailV1::Message.new
  message.raw = @text
  draft.message = message

  @service.create_user_draft(user_id, draft)
  puts "====== Draft created ====="
end