Class: SendGrid4r::CLI::Campaign::Contact::Segment
- Defined in:
- lib/sendgrid4r/cli/campaign/contact/segment.rb
Overview
SendGrid Web API v3 Marketing Campaigns - Segment
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(*args) ⇒ Segment
constructor
A new instance of Segment.
- #list ⇒ Object
- #recipient(action) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(*args) ⇒ Segment
Returns a new instance of Segment.
8 9 10 11 12 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 8 def initialize(*args) super @condition_factory = SendGrid4r::Factory::ConditionFactory.new @segment_factory = SendGrid4r::Factory::SegmentFactory.new end |
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 18 def create conditions = [:conditions].map do |c| array = c.delete(' ').split(/[:,]/) hash = array.each_slice(2).map do |k, v| [k.to_sym, v.nil? ? '' : v] end.to_h @condition_factory.create(hash) end params = @segment_factory.create( name: [:name], list_id: [:list_id], conditions: conditions ) puts @client.post_segment(params: params) rescue RestClient::ExceptionWithResponse => e puts e.inspect end |
#delete ⇒ Object
77 78 79 80 81 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 77 def delete puts @client.delete_segment(parameterise()) rescue RestClient::ExceptionWithResponse => e puts e.inspect end |
#get ⇒ Object
45 46 47 48 49 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 45 def get puts @client.get_segment(parameterise()) rescue RestClient::ExceptionWithResponse => e puts e.inspect end |
#list ⇒ Object
37 38 39 40 41 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 37 def list puts @client.get_segments rescue RestClient::ExceptionWithResponse => e puts e.inspect end |
#recipient(action) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 85 def recipient(action) case action when 'list' puts @client.get_recipients_on_segment(parameterise()) else puts "error: #{action} is not supported in action parameter" end end |
#update ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sendgrid4r/cli/campaign/contact/segment.rb', line 55 def update conditions = [:conditions].map do |c| array = c.delete(' ').split(/[:,]/) hash = array.each_slice(2).map do |k, v| [k.to_sym, v.nil? ? '' : v] end.to_h @condition_factory.create(hash) end params = @segment_factory.create( name: [:name], conditions: conditions ) puts @client.patch_segment( segment_id: [:segment_id], params: params ) rescue RestClient::ExceptionWithResponse => e puts e.inspect end |