Class: Sendly::Campaign

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

Constant Summary collapse

STATUSES =
%w[draft scheduled sending sent paused cancelled failed].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Campaign

Returns a new instance of Campaign.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sendly/campaigns_resource.rb', line 12

def initialize(data)
  @id = data["id"]
  @name = data["name"]
  @text = data["text"]
  @template_id = data["template_id"] || data["templateId"]
  @contact_list_ids = data["contact_list_ids"] || data["contactListIds"] || []
  @status = data["status"]
  @recipient_count = data["recipient_count"] || data["recipientCount"] || 0
  @sent_count = data["sent_count"] || data["sentCount"] || 0
  @delivered_count = data["delivered_count"] || data["deliveredCount"] || 0
  @failed_count = data["failed_count"] || data["failedCount"] || 0
  @estimated_credits = data["estimated_credits"] || data["estimatedCredits"] || 0
  @credits_used = data["credits_used"] || data["creditsUsed"] || 0
  @scheduled_at = parse_time(data["scheduled_at"] || data["scheduledAt"])
  @timezone = data["timezone"]
  @started_at = parse_time(data["started_at"] || data["startedAt"])
  @completed_at = parse_time(data["completed_at"] || data["completedAt"])
  @created_at = parse_time(data["created_at"] || data["createdAt"])
  @updated_at = parse_time(data["updated_at"] || data["updatedAt"])
end

Instance Attribute Details

#completed_atObject (readonly)

Returns the value of attribute completed_at.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def completed_at
  @completed_at
end

#contact_list_idsObject (readonly)

Returns the value of attribute contact_list_ids.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def contact_list_ids
  @contact_list_ids
end

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def created_at
  @created_at
end

#credits_usedObject (readonly)

Returns the value of attribute credits_used.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def credits_used
  @credits_used
end

#delivered_countObject (readonly)

Returns the value of attribute delivered_count.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def delivered_count
  @delivered_count
end

#estimated_creditsObject (readonly)

Returns the value of attribute estimated_credits.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def estimated_credits
  @estimated_credits
end

#failed_countObject (readonly)

Returns the value of attribute failed_count.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def failed_count
  @failed_count
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def name
  @name
end

#recipient_countObject (readonly)

Returns the value of attribute recipient_count.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def recipient_count
  @recipient_count
end

#scheduled_atObject (readonly)

Returns the value of attribute scheduled_at.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def scheduled_at
  @scheduled_at
end

#sent_countObject (readonly)

Returns the value of attribute sent_count.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def sent_count
  @sent_count
end

#started_atObject (readonly)

Returns the value of attribute started_at.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def started_at
  @started_at
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def status
  @status
end

#template_idObject (readonly)

Returns the value of attribute template_id.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def template_id
  @template_id
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def text
  @text
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def timezone
  @timezone
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



5
6
7
# File 'lib/sendly/campaigns_resource.rb', line 5

def updated_at
  @updated_at
end

Instance Method Details

#cancelled?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sendly/campaigns_resource.rb', line 49

def cancelled?
  status == "cancelled"
end

#draft?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/sendly/campaigns_resource.rb', line 33

def draft?
  status == "draft"
end

#scheduled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/sendly/campaigns_resource.rb', line 37

def scheduled?
  status == "scheduled"
end

#sending?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sendly/campaigns_resource.rb', line 41

def sending?
  status == "sending"
end

#sent?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/sendly/campaigns_resource.rb', line 45

def sent?
  status == "sent"
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sendly/campaigns_resource.rb', line 53

def to_h
  {
    id: id, name: name, text: text, template_id: template_id,
    contact_list_ids: contact_list_ids, status: status,
    recipient_count: recipient_count, sent_count: sent_count,
    delivered_count: delivered_count, failed_count: failed_count,
    estimated_credits: estimated_credits, credits_used: credits_used,
    scheduled_at: scheduled_at&.iso8601, timezone: timezone,
    started_at: started_at&.iso8601, completed_at: completed_at&.iso8601,
    created_at: created_at&.iso8601, updated_at: updated_at&.iso8601
  }.compact
end