Class: Urbanairship::Automations::Automation

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

Returns a new instance of Automation.



17
18
19
# File 'lib/urbanairship/automations/automation.rb', line 17

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

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def enabled
  @enabled
end

#limitObject

Returns the value of attribute limit.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def offset
  @offset
end

#pipeline_idObject

Returns the value of attribute pipeline_id.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def pipeline_id
  @pipeline_id
end

#pipeline_objectObject

Returns the value of attribute pipeline_object.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def pipeline_object
  @pipeline_object
end

#startObject

Returns the value of attribute start.



10
11
12
# File 'lib/urbanairship/automations/automation.rb', line 10

def start
  @start
end

Instance Method Details

#create_automationObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/urbanairship/automations/automation.rb', line 21

def create_automation
    response = @client.send_request(
        method: 'POST',
        body: JSON.dump(pipeline_object),
        path: pipelines_path,
        content_type: 'application/json'
    )
    logger.info("Created Automation")
    response
end

#delete_automationObject



84
85
86
87
88
89
90
91
92
# File 'lib/urbanairship/automations/automation.rb', line 84

def delete_automation
    fail ArgumentError, 'pipeline_id must be set to delete individual automation' if @pipeline_id.nil?
    response = @client.send_request(
        method: 'DELETE',
        path: pipelines_path(pipeline_id)
    )
    logger.info("Deleting automation with id #{pipeline_id}")
    response
end

#format_url_with_paramsObject



94
95
96
97
98
99
100
101
102
# File 'lib/urbanairship/automations/automation.rb', line 94

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

#list_automationsObject



32
33
34
35
36
37
38
39
# File 'lib/urbanairship/automations/automation.rb', line 32

def list_automations
    response = @client.send_request(
        method: 'GET',
        path: pipelines_path(format_url_with_params)
    )
    logger.info("Looking up automations for project")
    response
end

#list_deleted_automationsObject



41
42
43
44
45
46
47
48
# File 'lib/urbanairship/automations/automation.rb', line 41

def list_deleted_automations
    response = @client.send_request(
        method: 'GET',
        path: pipelines_path('deleted' + format_url_with_params)
    )
    logger.info("Looking up deleted automations for project")
    response
end

#lookup_automationObject



61
62
63
64
65
66
67
68
69
# File 'lib/urbanairship/automations/automation.rb', line 61

def lookup_automation
    fail ArgumentError, 'pipeline_id must be set to lookup individual automation' if @pipeline_id.nil?
    response = @client.send_request(
        method: 'GET',
        path: pipelines_path(pipeline_id)
    )
    logger.info("Looking up automation with id #{pipeline_id}")
    response
end

#update_automationObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/urbanairship/automations/automation.rb', line 71

def update_automation
    fail ArgumentError, 'pipeline_id must be set to update individual automation' if @pipeline_id.nil?

    response = @client.send_request(
        method: 'PUT',
        body: JSON.dump(pipeline_object),
        path: pipelines_path(pipeline_id),
        content_type: 'application/json'
    )
    logger.info("Validating Automation")
    response
end

#validate_automationObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/urbanairship/automations/automation.rb', line 50

def validate_automation
    response = @client.send_request(
        method: 'POST',
        body: JSON.dump(pipeline_object),
        path: pipelines_path('validate'),
        content_type: 'application/json'
    )
    logger.info("Validating Automation")
    response
end