Class: RelayGrid::Resources::MessageTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/relaygrid/resources/message_templates.rb

Overview

Read access to the account's templates. notify takes a template name, so this is mostly for discovery -- listing what's available, or checking which attributes a template expects before sending.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ MessageTemplates

Returns a new instance of MessageTemplates.



9
10
11
# File 'lib/relaygrid/resources/message_templates.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#find_by_name(name) ⇒ Hash?

Look a template up by the same name notify takes.

Parameters:

  • name (String)

Returns:

  • (Hash, nil)


28
29
30
# File 'lib/relaygrid/resources/message_templates.rb', line 28

def find_by_name(name)
  list.find { |template| template["name"] == name.to_s }
end

#get(id) ⇒ Hash

Parameters:

  • id (Integer)

Returns:

  • (Hash)


20
21
22
# File 'lib/relaygrid/resources/message_templates.rb', line 20

def get(id)
  @client.get("/api/v1/message_templates/#{id}")["message_template"]
end

#listArray<Hash>

Returns every template in the account.

Returns:

  • (Array<Hash>)

    every template in the account



14
15
16
# File 'lib/relaygrid/resources/message_templates.rb', line 14

def list
  Array(@client.get("/api/v1/message_templates")["message_templates"])
end