Class: EmailVision::Member

Inherits:
BaseClient show all
Defined in:
lib/email_vision/member.rb

Constant Summary collapse

JOB_STATUS =
{
  :finished => 'Job_Done_Or_Does_Not_Exist',
  :error => 'Error'
}

Constants inherited from BaseClient

BaseClient::SESSION_TIMEOUT

Instance Attribute Summary

Attributes inherited from BaseClient

#options

Instance Method Summary collapse

Methods inherited from BaseClient

#api_namespaced, #check_server_status!, #client, #connect!, #connected?, #connection, #execute, #initialize, #request_without_protection

Constructor Details

This class inherits a constructor from EmailVision::BaseClient

Instance Method Details

#columnsObject



55
56
57
58
59
60
# File 'lib/email_vision/member.rb', line 55

def columns
  result = execute(:desc_member_table)
  result = convert_to_hash(result[:fields], :name, :type)
  result.each{|k,v| result[k] = to_ruby_style(v)}
  result
end

#create(attributes) ⇒ Object



28
29
30
# File 'lib/email_vision/member.rb', line 28

def create(attributes)
  execute_by_obj(:insert_member_by_obj, attributes)
end

#create_or_update(attributes) ⇒ Object



32
33
34
# File 'lib/email_vision/member.rb', line 32

def create_or_update(attributes)
  execute_by_obj(:insert_or_update_member_by_obj, attributes)
end

#find(email_or_id) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/email_vision/member.rb', line 8

def find(email_or_id)
  result = execute_by_email_or_id(:get_member, email_or_id)
  result = result.first if result.is_a?(Array) # may return multiple users if they have the same email -> return first
  return unless result.is_a?(Hash)
  result = convert_to_hash(result[:attributes][:entry], :key, :value)
  result.reject{|k,v| v.nil? }
end

#job_status(job_id) ⇒ Object

should be one of: Insert, Processing, Processed, Error, Job_Done_Or_Does_Not_Exist



37
38
39
# File 'lib/email_vision/member.rb', line 37

def job_status(job_id)
  execute(:get_member_job_status, :synchro_id => job_id)[:status]
end

#rejoin(email_or_id) ⇒ Object



20
21
22
# File 'lib/email_vision/member.rb', line 20

def rejoin(email_or_id)
  execute_by_email_or_id(:rejoin_member, email_or_id)
end

#unjoin(email_or_id) ⇒ Object



16
17
18
# File 'lib/email_vision/member.rb', line 16

def unjoin(email_or_id)
  execute_by_email_or_id(:unjoin_member, email_or_id)
end

#update(attributes) ⇒ Object



24
25
26
# File 'lib/email_vision/member.rb', line 24

def update(attributes)
  execute_by_obj(:update_member_by_obj, attributes)
end

#wait_for_job_to_finish(job_id, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/email_vision/member.rb', line 41

def wait_for_job_to_finish(job_id, options={})
  interval = options[:interval] || 5
  times = options[:times] || 20

  times.times do
    current_status = job_status(job_id)
    raise "Job failed" if current_status == JOB_STATUS[:error]
    return true if current_status == JOB_STATUS[:finished]
    sleep interval
  end

  raise "Job not finished in time! #{current_status}"
end