Class: Urbanairship::AbTests::AbTest

Inherits:
Object
  • Object
show all
Includes:
Common, Loggable
Defined in:
lib/urbanairship/ab_tests/ab_test.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')) ⇒ AbTest

Returns a new instance of AbTest.



15
16
17
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 15

def initialize(client: required('client'))
    @client = client
end

Instance Attribute Details

#experiment_idObject

Returns the value of attribute experiment_id.



10
11
12
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 10

def experiment_id
  @experiment_id
end

#experiment_objectObject

Returns the value of attribute experiment_object.



10
11
12
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 10

def experiment_object
  @experiment_object
end

#limitObject

Returns the value of attribute limit.



10
11
12
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 10

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



10
11
12
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 10

def offset
  @offset
end

Instance Method Details

#create_ab_testObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 28

def create_ab_test
    response = @client.send_request(
        method: 'POST',
        body: JSON.dump(experiment_object),
        path: experiments_path,
        content_type: 'application/json'
    )
    logger.info("Created A/B Test")
    response
end

#delete_ab_testObject



48
49
50
51
52
53
54
55
56
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 48

def delete_ab_test
    fail ArgumentError, 'experiment_id must be set to delete individual A/B test' if @experiment_id.nil?
    response = @client.send_request(
        method: 'DELETE',
        path: experiments_path('scheduled/' + experiment_id)
    )
    logger.info("Deleting A/B test with ID #{experiment_id}")
    response
end

#format_url_with_paramsObject



79
80
81
82
83
84
85
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 79

def format_url_with_params
    params = []
    params << ['limit', limit] if limit
    params << ['offset', offset] if offset
    query = URI.encode_www_form(params)
    '?' + query
end

#list_ab_testObject



19
20
21
22
23
24
25
26
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 19

def list_ab_test
    response = @client.send_request(
        method: 'GET',
        path: experiments_path(format_url_with_params)
    )
    logger.info("Looking up A/B Tests for project")
    response
end

#list_scheduled_ab_testObject



39
40
41
42
43
44
45
46
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 39

def list_scheduled_ab_test
    response = @client.send_request(
        method: 'GET',
        path: experiments_path('scheduled' + format_url_with_params)
    )
    logger.info("Looking up scheduled A/B Tests for project")
    response
end

#lookup_ab_testObject



69
70
71
72
73
74
75
76
77
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 69

def lookup_ab_test
    fail ArgumentError, 'experiment_id must be set to lookup individual A/B Test' if @experiment_id.nil?
    response = @client.send_request(
        method: 'GET',
        path: experiments_path(experiment_id)
    )
    logger.info("Looking up A/B test with ID #{experiment_id}")
    response
end

#validate_ab_testObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/urbanairship/ab_tests/ab_test.rb', line 58

def validate_ab_test
    response = @client.send_request(
        method: 'POST',
        body: JSON.dump(experiment_object),
        path: experiments_path('validate'),
        content_type: 'application/json'
    )
    logger.info("Validating A/B Test")
    response
end