Module: Jung::Drivers::Infobip::Campaign

Defined in:
lib/jung/drivers/infobip/campaign.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



3
4
5
# File 'lib/jung/drivers/infobip/campaign.rb', line 3

def api_url
  @api_url
end

#app_idObject

Warning: Infobip limitation: app_id should not be more than 30 chars



4
5
6
# File 'lib/jung/drivers/infobip/campaign.rb', line 4

def app_id
  @app_id
end

#deliver_atObject

Returns the value of attribute deliver_at.



7
8
9
# File 'lib/jung/drivers/infobip/campaign.rb', line 7

def deliver_at
  @deliver_at
end

#messages_idsObject

Returns the value of attribute messages_ids.



3
4
5
# File 'lib/jung/drivers/infobip/campaign.rb', line 3

def messages_ids
  @messages_ids
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/jung/drivers/infobip/campaign.rb', line 3

def password
  @password
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/jung/drivers/infobip/campaign.rb', line 3

def username
  @username
end

#webhookObject

Returns the value of attribute webhook.



5
6
7
# File 'lib/jung/drivers/infobip/campaign.rb', line 5

def webhook
  @webhook
end

Instance Method Details

#deliver(recipients = self.recipients) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/jung/drivers/infobip/campaign.rb', line 42

def deliver(recipients = self.recipients)
  messages_ids = recipients.map do | recipient |
    address = recipient.is_a?(Jung::Recipient) ? recipient.address : recipient
    deliver_recipient address, message
  end
  delivery_success? messages_ids
end

#deliver_inObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jung/drivers/infobip/campaign.rb', line 13

def deliver_in
  return @deliver_in = nil unless deliver_at.respond_to?(:to_time)

  @deliver_in ||= begin

    time = deliver_at.to_time
    seconds_from_now = (Time.now - time) * -1

    unless seconds_from_now < 0
      minutes_from_now, seconds_from_now = seconds_from_now.divmod(60)
      hours_from_now, minutes_from_now = minutes_from_now.divmod(60)
      days_from_now, hours_from_now = hours_from_now.divmod(24)
      seconds_from_now = seconds_from_now.to_i

      time_from_now = { 
        :d => days_from_now,
        :h => hours_from_now,
        :m => minutes_from_now,
        :s => seconds_from_now
      }.reject { |k,v| v == 0 }.map { |(k,v)| "#{v}#{k}" }.join
    else
      time_from_now = nil
    end

    time_from_now
  end
end

#deliver_test(recipients) ⇒ Object



50
51
52
# File 'lib/jung/drivers/infobip/campaign.rb', line 50

def deliver_test(recipients)
  deliver(recipients)
end

#schedule(time) ⇒ Object



54
55
56
57
# File 'lib/jung/drivers/infobip/campaign.rb', line 54

def schedule time
  self.deliver_at = time
  deliver
end