Class: Clockwork::MessageCollection

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

Overview

Use an instance of Clockwork::API#messages.build to create SMS messages.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MessageCollection

Create a new instance of Clockwork::MessageCollection.

Raises:

  • ArgumentError - if a valid instance of API is not passed as :api in options


20
21
22
23
24
25
# File 'lib/clockwork/message_collection.rb', line 20

def initialize options
  @api = options[:api]
  raise ArgumentError, "Clockwork::MessageCollection#new must include an instance of Clockwork::API as :api" unless @api.kind_of?(Clockwork::API)
  
  @messages = []
end

Instance Attribute Details

#apiClockwork::API

An instance of Clockwork::API.


10
11
12
# File 'lib/clockwork/message_collection.rb', line 10

def api
  @api
end

#messagesarray

An array of Clockwork::SMS messages.


15
16
17
# File 'lib/clockwork/message_collection.rb', line 15

def messages
  @messages
end

Instance Method Details

#build(params = {}) ⇒ Object

Create a new instance of Clockwork::SMS in this MessageCollection.

See Also:


30
31
32
33
34
35
# File 'lib/clockwork/message_collection.rb', line 30

def build params = {}
  sms = Clockwork::SMS.new({ :api => @api }.merge(params))
  sms.wrapper_id = @messages.count
  @messages << sms
  sms
end