class PPC::API::Sm::Bulk

Constants

Service

Public Class Methods

do_download(auth, id) click to toggle source
# File lib/ppc/api/sm/bulk.rb, line 30
def self.do_download(auth, id)
  request(auth, 'file', 'download',{fileId: id})
end
download( auth, params = {} ) click to toggle source

interface for operation #

# File lib/ppc/api/sm/bulk.rb, line 37
def self.download( auth, params = {} )
  """
  """
  begin
    result = get_all_object( auth, params )
    if result[:succ]
      task_id = result[:result]
    else
      raise "获取task id 失败"
    end

    puts "task_id: #{task_id}" if ENV["DEBUG"]

    loop do
      file_id = get_file_id( auth, task_id )[:result]
      if file_id.nil?
        sleep 15
        next
      end
      File.open("sm_#{file_id}.zip", "w") do |f|
        f.puts do_download(auth, file_id)
      end
      return
    end
  rescue => e
    p "Error encounter:#{e.to_s}"
  end  
end
get_all_object( auth,params = {}) click to toggle source
# File lib/ppc/api/sm/bulk.rb, line 7
def self.get_all_object( auth,params = {})
  
  plan_ids = params[:plan_ids]

  unless plan_ids.nil?
    plan_ids = plan_ids.class == Array ? plan_ids : [plan_ids]
  end

  options = {
    bulkJobRequestType: {
      campaignIds:              plan_ids              || []      
    }
  }
  response = request( auth, Service, 'getAllObjects',options )
  process( response, 'taskId'){ |x| x }
end
get_file_id( auth, id) click to toggle source
# File lib/ppc/api/sm/bulk.rb, line 24
def self.get_file_id( auth, id)
  raise "empty id" if id.nil?
  response = request(auth, 'task', 'getTaskState',{taskId: id})
  process( response, 'fileId'){ |x| x }
end