module PPC::Operation
Attributes
id[RW]
Public Class Methods
new( params )
click to toggle source
# File lib/ppc/operation.rb, line 6 def initialize( params ) raise 'please specific a search engine' if params[:se].nil? @se = params[:se] @id = params[:id] @auth = { username: params[:username], password: params[:password], # 在qihu360的api中,apikey就是auth[:token] token: params[:token], target: params[:target] } # add support for qihu360 if @se == 'qihu' raise "you are using qihu service, please enter api_key" if params[:api_key].nil? raise "you are using qihu service, please enter api_secret" if params[:api_secret].nil? @auth[:api_key] = params[:api_key] @auth[:api_secret] = params[:api_secret] @auth[:token] = qihu_refresh_token if params[:token].nil? end end
Public Instance Methods
call(service)
click to toggle source
# File lib/ppc/operation.rb, line 53 def call(service) eval "::PPC::API::#{@se.capitalize}::#{service.capitalize}" end
download( param = nil )
click to toggle source
# File lib/ppc/operation.rb, line 46 def download( param = nil ) """ download all objs of an account """ eval("::PPC::API::#{@se.capitalize}::Bulk").download( @auth, param ) end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/ppc/operation.rb, line 57 def method_missing(method_name, *args, &block) method = method_name.to_s unit = self.class.to_s.downcase[/(account|plan|group|keyword|creative|sublink)/] case method when "info" unit == "account" ? call( unit ).send( method, @auth ) : call( unit ).send( method, @auth, [@id].flatten ) when "get", "delete", "enable", "pause", "status", "quality" call( unit ).send( method, @auth, [@id].flatten ) when "update" call( unit ).send( method, @auth, [args[0].merge(id: @id)].flatten ) when "activate" call( unit ).enable( @auth, [@id].flatten ) else super end end
qihu_refresh_token()
click to toggle source
# File lib/ppc/operation.rb, line 28 def qihu_refresh_token cipher_aes = OpenSSL::Cipher::AES.new(128, :CBC) cipher_aes.encrypt cipher_aes.key = @auth[:api_secret][0,16] cipher_aes.iv = @auth[:api_secret][16,16] encrypted = (cipher_aes.update(Digest::MD5.hexdigest( @auth[:password])) + cipher_aes.final).unpack('H*').join url = "https://api.e.360.cn/account/clientLogin" response = HTTParty.post(url, :body => { :username => @auth[:username], :passwd => encrypted[0,64] }, :headers => {'apiKey' => @auth[:api_key] } ) data = response.parsed_response data["account_clientLogin_response"]["accessToken"] end