Class: Leash::GmailClient

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

Overview

Client for Gmail operations via the Leash platform proxy.

Not instantiated directly – use Integrations#gmail instead.

Constant Summary collapse

PROVIDER =
"gmail"

Instance Method Summary collapse

Constructor Details

#initialize(call_fn) ⇒ GmailClient

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of GmailClient.



11
12
13
# File 'lib/leash/gmail.rb', line 11

def initialize(call_fn)
  @call = call_fn
end

Instance Method Details

#get_message(message_id, format: "full") ⇒ Hash

Get a single message by ID.

Parameters:

  • message_id (String)

    the message ID

  • format (String) (defaults to: "full")

    response format (“full”, “metadata”, “minimal”, “raw”)

Returns:

  • (Hash)

    the full message object



35
36
37
# File 'lib/leash/gmail.rb', line 35

def get_message(message_id, format: "full")
  @call.call(PROVIDER, "get-message", { "messageId" => message_id, "format" => format })
end

#list_labelsHash

List all labels in the user’s mailbox.

Returns:

  • (Hash)

    hash with “labels” list



66
67
68
# File 'lib/leash/gmail.rb', line 66

def list_labels
  @call.call(PROVIDER, "list-labels", {})
end

#list_messages(query: nil, max_results: 20, label_ids: nil, page_token: nil) ⇒ Hash

List messages in the user’s mailbox.

Parameters:

  • query (String, nil) (defaults to: nil)

    Gmail search query (e.g. “from:user@example.com”)

  • max_results (Integer) (defaults to: 20)

    maximum number of messages to return

  • label_ids (Array<String>, nil) (defaults to: nil)

    filter by label IDs (e.g. [“INBOX”])

  • page_token (String, nil) (defaults to: nil)

    token for fetching the next page of results

Returns:

  • (Hash)

    hash with “messages”, “nextPageToken”, and “resultSizeEstimate”



22
23
24
25
26
27
28
# File 'lib/leash/gmail.rb', line 22

def list_messages(query: nil, max_results: 20, label_ids: nil, page_token: nil)
  params = { "maxResults" => max_results }
  params["query"] = query if query
  params["labelIds"] = label_ids if label_ids
  params["pageToken"] = page_token if page_token
  @call.call(PROVIDER, "list-messages", params)
end

#search_messages(query, max_results: 20) ⇒ Hash

Search messages using a Gmail query string.

Parameters:

  • query (String)

    Gmail search query

  • max_results (Integer) (defaults to: 20)

    maximum number of results to return

Returns:

  • (Hash)

    hash with “messages”, “nextPageToken”, and “resultSizeEstimate”



59
60
61
# File 'lib/leash/gmail.rb', line 59

def search_messages(query, max_results: 20)
  @call.call(PROVIDER, "search-messages", { "query" => query, "maxResults" => max_results })
end

#send_message(to:, subject:, body:, cc: nil, bcc: nil) ⇒ Hash

Send an email message.

Parameters:

  • to (String)

    recipient email address

  • subject (String)

    email subject line

  • body (String)

    email body text

  • cc (String, nil) (defaults to: nil)

    CC recipient(s)

  • bcc (String, nil) (defaults to: nil)

    BCC recipient(s)

Returns:

  • (Hash)

    the sent message metadata



47
48
49
50
51
52
# File 'lib/leash/gmail.rb', line 47

def send_message(to:, subject:, body:, cc: nil, bcc: nil)
  params = { "to" => to, "subject" => subject, "body" => body }
  params["cc"] = cc if cc
  params["bcc"] = bcc if bcc
  @call.call(PROVIDER, "send-message", params)
end