lib/ppc/baidu/account.rb in ppc-1.0.6 vs lib/ppc/baidu/account.rb in ppc-1.3.0
- old
+ new
@@ -4,21 +4,46 @@
def initialize(params = {})
params[:service] = 'Account'
super(params)
end
+ def info
+ response = request('getAccountInfo')["accountInfoType"]
+ end
+
def all(params = {})
download(params)
end
+ def update( params = {} )
+ """
+ update account info
+ @ params : account_info_type
+ @return : account info_type
+ """
+ info = {
+ accountInfoType: {
+ budgetType: params[:budget_type] ,
+ budget: params[:budget],
+ regionTarget: params[:region],
+ excludeIp: params[:excludeip] ,
+ isDynamicCreative: params[:isdynamic],
+ dynamicCreativeParam: params[:creativeparam]
+ }
+ }
+ # delete null symbol
+ info[:accountInfoType].each{
+ |pair|
+ key, value = pair
+ info[:accountInfoType].delete(key) if value == nil
+ }
+
+ request('updateAccountInfo', info)["accountInfoType"]
+ end
+
def query_report(params = {})
- report = ::PPC::Baidu::Report.new({
- username: @username,
- password: @password,
- token: @token,
- debug: @debug
- })
+ report = ::PPC::Baidu::Report.new({username: @username, password: @password, token: @token, debug: @debug})
begin
@file_id = report.file_id_of_query(params)
print_debug(@file_id,'file_id') if @debug
@@ -28,33 +53,36 @@
break if state == '3'
print_debug(state,'file_id.state') if @debug
sleep 3
end
-
- return report.path(@file_id)
+ url = report.path(@file_id)
+ open(url).read.force_encoding('gb18030').encode('utf-8')
rescue Exception => e
- # @header = bulk.header
- # @oprs = bulk.oprs
- # @oprtime = bulk.oprtime
- # @quota = bulk.quota
- # @rquota = bulk.rquota
- # @status = bulk.status
+ raise ReportException.new(@file_id,report,e)
+ end
+ end
- # @desc = bulk.desc
+ def cost_report(params = {})
+ report = ::PPC::Baidu::Report.new({username: @username, password: @password, token: @token, debug: @debug})
+ begin
+ @file_id = report.file_id_of_cost(params)
+ print_debug(@file_id,'file_id') if @debug
- # case @desc
- # when 'success'
- # when 'failure'
- # @code = bulk.code
- # @message = bulk.message
- # when 'system failure'
- # @code = bulk.code
- # @message = bulk.message
- # else
- raise ReportException.new(@file_id,report,e)#,"unknown desc from baidu: #{@desc}"
- # end
+ loop do
+ state = report.state(@file_id)
+ raise "invalid file state: #{state}" unless %w(1 2 3 null).include? state
+ break if state == '3'
+ print_debug(state,'file_id.state') if @debug
+ sleep 3
+ end
+
+ url = report.path(@file_id)
+ open(url).read.force_encoding('gb18030').encode('utf-8')
+ rescue Exception => e
+ raise ReportException.new(@file_id,report,e)
end
end
+
end
end
end