Module: PPC::Operation
- Included in:
- Account, Creative, Group, Keyword, Plan, Sublink
- Defined in:
- lib/ppc/operation.rb,
lib/ppc/operation/plan.rb,
lib/ppc/operation/group.rb,
lib/ppc/operation/report.rb,
lib/ppc/operation/account.rb,
lib/ppc/operation/keyword.rb,
lib/ppc/operation/sublink.rb,
lib/ppc/operation/creative.rb
Defined Under Namespace
Modules: Creative_operation, Group_operation, Keyword_operation, Plan_operation, Report, Sublink_operation
Classes: Account, Creative, Group, Keyword, Plan, Sublink
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# 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
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
4
5
6
|
# File 'lib/ppc/operation.rb', line 4
def id
@id
end
|
Instance Method Details
#call(service) ⇒ Object
53
54
55
|
# File 'lib/ppc/operation.rb', line 53
def call(service)
eval "::PPC::API::#{@se.capitalize}::#{service.capitalize}"
end
|
#download(param = nil) ⇒ Object
46
47
48
49
50
51
|
# 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
|
#initialize(params) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 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],
token: params[:token],
target: params[:target]
}
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
|
#qihu_refresh_token ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# 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
|