Class: PortaText::Command::Api::Campaigns

Inherits:
Base
  • Object
show all
Defined in:
lib/portatext/command/api/campaigns.rb

Overview

The campaigns endpoint. github.com/PortaText/docs/wiki/REST-API#api_campaigns

Author

Marcelo Gornstein ([email protected])

Copyright

Copyright © 2015 PortaText

License

Apache-2.0

Direct Known Subclasses

SmsCampaign, TelCampaign

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#accept_content_type, #body, #content_type, #delete, #get, #initialize, #patch, #post, #put, #set

Constructor Details

This class inherits a constructor from PortaText::Command::Base

Instance Method Details

#all_subscribersObject



35
36
37
# File 'lib/portatext/command/api/campaigns.rb', line 35

def all_subscribers
  set :all_subscribers, true
end

#contact(contact) ⇒ Object



51
52
53
# File 'lib/portatext/command/api/campaigns.rb', line 51

def contact(contact)
  set :contact, contact
end

#contactsObject



47
48
49
# File 'lib/portatext/command/api/campaigns.rb', line 47

def contacts
  set :contacts, true
end

#csv(file) ⇒ Object



31
32
33
# File 'lib/portatext/command/api/campaigns.rb', line 31

def csv(file)
  set :file, file
end

#description(description) ⇒ Object



19
20
21
# File 'lib/portatext/command/api/campaigns.rb', line 19

def description(description)
  set :description, description
end

#endpoint(_method) ⇒ Object

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/portatext/command/api/campaigns.rb', line 71

def endpoint(_method)
  unless @args[:file].nil?
    settings = @args.clone
    settings.delete :file
    settings = settings.to_json
    settings = URI.encode_www_form('settings' => settings)
    return "campaigns?#{settings}"
  end
  qs = {}
  unless @args[:page].nil?
    qs['page'] = @args[:page]
    @args.delete :page
  end
  qs = URI.encode_www_form qs
  unless @args[:id].nil?
    id = @args[:id]
    contacts = @args[:contacts]
    contact = @args[:contact]
    @args.delete :type
    @args.delete :id
    @args.delete :contacts
    @args.delete :contact
    return "campaigns/#{id}/contacts/#{contact}" if contact
    return "campaigns/#{id}/contacts?#{qs}" if contacts
    return "campaigns/#{id}"
  end
  return "campaigns?#{qs}" unless qs.empty?
  'campaigns'
end

#from(from) ⇒ Object



23
24
25
# File 'lib/portatext/command/api/campaigns.rb', line 23

def from(from)
  set :from, from
end

#id(id) ⇒ Object



11
12
13
# File 'lib/portatext/command/api/campaigns.rb', line 11

def id(id)
  set :id, id
end

#name(name) ⇒ Object



15
16
17
# File 'lib/portatext/command/api/campaigns.rb', line 15

def name(name)
  set :name, name
end

#page(page) ⇒ Object



39
40
41
# File 'lib/portatext/command/api/campaigns.rb', line 39

def page(page)
  set :page, page
end

#save_to(file) ⇒ Object



43
44
45
# File 'lib/portatext/command/api/campaigns.rb', line 43

def save_to(file)
  set :accept_file, file
end

#schedule(type, details) ⇒ Object



55
56
57
58
59
# File 'lib/portatext/command/api/campaigns.rb', line 55

def schedule(type, details)
  schedule = {}
  schedule[type] = details
  set :schedule, schedule
end

#set_setting(name, value) ⇒ Object



61
62
63
64
65
66
# File 'lib/portatext/command/api/campaigns.rb', line 61

def set_setting(name, value)
  args = @args[:settings]
  args ||= {}
  args[name] = value
  set :settings, args
end

#to_contact_lists(contact_lists) ⇒ Object



27
28
29
# File 'lib/portatext/command/api/campaigns.rb', line 27

def to_contact_lists(contact_lists)
  set :contact_list_ids, contact_lists
end