Class: Mosaic::Lyris::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaic/lyris/upload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

callback_url, configuration, configuration=, default_list_id, default_trigger_id, get_array_data, get_boolean_data, get_data, get_date_data, get_demographic_data, get_element, get_integer_data, get_integer_element, get_time_data, get_time_element, get_time_offset_data, get_xml_time_data, #initialize, load_configuration, logger, logger=, password, post, put_array_data, put_data, put_demographic_data, put_extra_data, server, site_id, #to_param, triggers

Constructor Details

This class inherits a constructor from Mosaic::Lyris::Object

Instance Attribute Details

#bytes_processedObject (readonly)

Returns the value of attribute bytes_processed.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def bytes_processed
  @bytes_processed
end

#completed_atObject (readonly)

Returns the value of attribute completed_at.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def completed_at
  @completed_at
end

#estimated_complete_atObject (readonly)

Returns the value of attribute estimated_complete_at.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def estimated_complete_at
  @estimated_complete_at
end

#list_idObject (readonly)

Returns the value of attribute list_id.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def list_id
  @list_id
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def size
  @size
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def status
  @status
end

#time_elapsedObject (readonly)

Returns the value of attribute time_elapsed.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def time_elapsed
  @time_elapsed
end

#time_remainingObject (readonly)

Returns the value of attribute time_remaining.



4
5
6
# File 'lib/mosaic/lyris/upload.rb', line 4

def time_remaining
  @time_remaining
end

Class Method Details

.add(email, file, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mosaic/lyris/upload.rb', line 38

def add(email, file, options = {})
  validate_options!(options)
  reply = post('record', 'upload') do |request|
    request.MLID options[:list_id] || ''
    put_data(request, 'email', email)
    put_extra_data(request, 'file', file)
    put_extra_data(request, 'type', options[:type] || 'active')
    put_extra_data(request, 'trigger', 'yes') if options[:trigger]
    if options[:update]
      put_extra_data(request, 'update', options[:update].to_s == 'only' ? 'only' : 'on')
      put_extra_data(request, 'delete_blank', 'on') if options[:blank]
      put_extra_data(request, 'untrash', 'on') if options[:untrash]
    end
    put_extra_data(request, 'validate', 'on') if options[:validate]
  end
  new(options.merge(:id => reply.at('/DATASET/DATA').inner_html, :email => options[:email], :file => file, :type => options[:type] || 'active'))
end

.build(record, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mosaic/lyris/upload.rb', line 56

def build(record, options = {})
  new :list_id => options[:list_id],
      :file => get_element(record, 'FILE'),
      :status => get_element(record, 'STATUS'),
      :size => get_integer_element(record, 'SIZE'),
      :bytes_processed => get_integer_element(record, 'PROCESSED'),
      :time_elapsed => get_integer_element(record, 'ELAPSED'),
      :time_remaining => get_integer_element(record, 'TIMELEFT'),
      :estimated_complete_at => get_time_element(record, 'ETC'),
      :completed_at => get_time_element(record, 'TIME')
end

.query(what, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mosaic/lyris/upload.rb', line 68

def query(what, options = {})
  reply = post('record', 'upload-status') do |request|
    request.MLID options[:list_id] || ''
    put_extra_data(request, 'file', what) unless what.to_s == 'all'
  end
  if what.to_s == 'all'
    reply.search('/DATASET/*').collect do |record|
      build record, options
    end
  else
    build reply.at('/DATASET/DATASET_1'), options
  end
end

.validate_options!(options) ⇒ Object

Raises:

  • (ArgumentError)


82
83
84
85
# File 'lib/mosaic/lyris/upload.rb', line 82

def validate_options!(options)
  raise ArgumentError, "expected type of :active, :proof, :unsubscribed, :bounced, :trashed or :globalunsubscribe; got #{options[:type]}" unless %w(active proof unsubscribed bounced trashed globalunsubscribe).include?(options[:type].to_s) if options[:type]
  raise ArgumentError, "expected update value of true or :only; for #{options[:update]}" unless %w(true only).include?(options[:update].to_s) if options[:update]
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mosaic/lyris/upload.rb', line 21

def active?
  status =~ /^[0-9]+%$/
end

#done?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mosaic/lyris/upload.rb', line 13

def done?
  status == 'done'
end

#fatal?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mosaic/lyris/upload.rb', line 17

def fatal?
  status == 'fatal'
end

#incomplete?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mosaic/lyris/upload.rb', line 25

def incomplete?
  pending? || active?
end

#pending?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mosaic/lyris/upload.rb', line 29

def pending?
  status == 'pending'
end

#retry?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/mosaic/lyris/upload.rb', line 33

def retry?
  status == 'retry'
end