Class: Urbanairship::Devices::StaticList
- Inherits:
-
Object
- Object
- Urbanairship::Devices::StaticList
show all
- Includes:
- Common, Loggable
- Defined in:
- lib/urbanairship/devices/static_lists.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')) ⇒ StaticList
Returns a new instance of StaticList.
11
12
13
14
|
# File 'lib/urbanairship/devices/static_lists.rb', line 11
def initialize(client: required('client'))
fail ArgumentError, 'Client cannot be set to nil' if client.nil?
@client = client
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/urbanairship/devices/static_lists.rb', line 10
def name
@name
end
|
Instance Method Details
#create(description: nil, extra: nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/urbanairship/devices/static_lists.rb', line 16
def create(description: nil, extra: nil)
fail ArgumentError, 'Name must be set' if name.nil?
payload = {'name': name}
payload['description'] = description unless description.nil?
payload['extra'] = unless .nil?
response = @client.send_request(
method: 'POST',
body: JSON.dump(payload),
path: lists_path,
content_type: 'application/json'
)
logger.info("Created static list for #{@name}")
response
end
|
#delete ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/urbanairship/devices/static_lists.rb', line 81
def delete
fail ArgumentError, 'Name must be set' if name.nil?
response = @client.send_request(
method: 'DELETE',
path: lists_path(@name)
)
logger.info("Deleted list #{@name}")
response
end
|
#lookup ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/urbanairship/devices/static_lists.rb', line 71
def lookup
fail ArgumentError, 'Name must be set' if name.nil?
response = @client.send_request(
method: 'GET',
path: lists_path(@name)
)
logger.info("Retrieving info for list #{@name}")
response
end
|
#update(description: nil, extra: nil) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/urbanairship/devices/static_lists.rb', line 54
def update(description: nil, extra: nil)
fail ArgumentError, 'Name must be set' if name.nil?
fail ArgumentError,
'Either description or extras must be set to a value' if description.nil? and .nil?
payload = {}
payload['description'] = description unless description.nil?
payload['extra'] = unless .nil?
response = @client.send_request(
method: 'PUT',
body: JSON.dump(payload),
path: lists_path(@name),
content_type: 'application/json'
)
logger.info("Updating the metadata for list #{@name}")
response
end
|
#upload(csv_file: required('csv_file'), gzip: false) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/urbanairship/devices/static_lists.rb', line 32
def upload(csv_file: required('csv_file'), gzip: false)
fail ArgumentError, 'Name must be set' if name.nil?
if gzip
response = @client.send_request(
method: 'PUT',
body: csv_file,
path: lists_path(@name + '/csv/'),
content_type: 'text/csv',
encoding: gzip
)
else
response = @client.send_request(
method: 'PUT',
body: csv_file,
path: lists_path(@name + '/csv/'),
content_type: 'text/csv'
)
end
logger.info("Uploading a list for #{@name}")
response
end
|