Class: Urbanairship::AbTests::Experiment

Inherits:
Object
  • Object
show all
Includes:
Common, Loggable
Defined in:
lib/urbanairship/ab_tests/experiment.rb

Constant Summary

Constants included from Common

Common::CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

create_logger, logger, #logger

Methods included from Common

#apid_path, #channel_path, #compact_helper, #create_and_send_path, #custom_events_path, #device_token_path, #experiments_path, #lists_path, #named_users_path, #open_channel_path, #pipelines_path, #push_path, #reports_path, #required, #schedules_path, #segments_path, #tag_lists_path, #try_helper

Constructor Details

#initialize(client: required('client')) ⇒ Experiment

Returns a new instance of Experiment.



19
20
21
22
# File 'lib/urbanairship/ab_tests/experiment.rb', line 19

def initialize(client: required('client'))
    @client = client
    @variants = []
end

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def audience
  @audience
end

#campaignsObject

Returns the value of attribute campaigns.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def campaigns
  @campaigns
end

#controlObject

Returns the value of attribute control.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def control
  @control
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def description
  @description
end

#device_typesObject

Returns the value of attribute device_types.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def device_types
  @device_types
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def name
  @name
end

#push_idObject

Returns the value of attribute push_id.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def push_id
  @push_id
end

#variantsObject

Returns the value of attribute variants.



8
9
10
# File 'lib/urbanairship/ab_tests/experiment.rb', line 8

def variants
  @variants
end

Instance Method Details

#payloadObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/urbanairship/ab_tests/experiment.rb', line 24

def payload
    fail ArgumentError, 'audience is required for experiment' if @audience.nil?
    fail ArgumentError, 'device_types is required for experiment' if @device_types.nil?
    fail ArgumentError, 'variant cannot be empty for experiment' if @variants.empty?

    {
        'name': name,
        'description': description,
        'control': control,
        'audience': audience,
        'device_types': device_types,
        'campaigns': campaigns,
        'variants': variants,
        'id': id,
        'created_at': created_at,
        'push_id': push_id
    }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
end