Class: Baidu::SEM::Base
- Inherits:
-
Object
- Object
- Baidu::SEM::Base
- Defined in:
- lib/baidu/sem/base.rb
Direct Known Subclasses
AccountService, AdgroupService, BulkJobService, CampaignService, CreativeService, KR, KeywordService, NewCreativeService, ReportService, SearchService
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #example(operation, with_header = false) ⇒ Object
-
#initialize(auth) ⇒ Base
constructor
A new instance of Base.
- #make_operation(operation_name) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
Savon.new(@base_uri+service_name+‘?wsdl’).
- #operation_header ⇒ Object
- #operations ⇒ Object
Constructor Details
#initialize(auth) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/baidu/sem/base.rb', line 7 def initialize(auth) classname = self.class.name.split('::').last @service_name = classname @port_name = classname @username = auth.username @password = auth.password @token = auth.token @client = Savon.new("https://api.baidu.com/sem/sms/v3/#{classname}?wsdl") # Savon.new(@base_uri+service_name+'?wsdl') end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Savon.new(@base_uri+service_name+‘?wsdl’)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/baidu/sem/base.rb', line 17 def method_missing(name, *args, &block) ,debug = args[0],args[1] = {} if .nil? name = name.to_s name_snake = name.snake_case # p name name_tmp = case name when 'getAllCampaign' 'GetAllCampaign' when 'getCampaignByCampaignId' 'GetCampaignByCampaignId' when 'addCampaign' 'AddCampaign' when 'updateCampaign' 'UpdateCampaign' when 'deleteCampaign' 'DeleteCampaign' when 'getCampaignByCampaignId' 'GetCampaignByCampaignId' else name end name_request_sym = (name_tmp+'Request').to_sym #if %w(getCampaignByCampaignId getAllCampaign addCampaign updateCampaign deleteCampaign).include?name # puts name_request_sym name_response_sym = (name+'Response').snake_case.to_sym operation = make_operation(name) operation.header = operation_header operation.body = { name_request_sym => } ap operation.body if debug puts operation.build if debug response = operation.call ap response if debug # ap response.failures if debug if response.failures raise response.failures.to_s else Baidu::Response.new(response,name_response_sym) end end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/baidu/sem/base.rb', line 5 def debug @debug end |
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/baidu/sem/base.rb', line 4 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/baidu/sem/base.rb', line 4 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
4 5 6 |
# File 'lib/baidu/sem/base.rb', line 4 def username @username end |
Instance Method Details
#example(operation, with_header = false) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/baidu/sem/base.rb', line 79 def example(operation,with_header=false) operation = make_operation(operation) if with_header { :example_header => operation.example_header, :example_body => operation.example_body } else operation.example_body end end |
#make_operation(operation_name) ⇒ Object
64 65 66 |
# File 'lib/baidu/sem/base.rb', line 64 def make_operation(operation_name) @client.operation(@service_name,@port_name,operation_name) end |
#operation_header ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/baidu/sem/base.rb', line 68 def operation_header { :AuthHeader=> { :username=>@username, :password=>@password, :token=>@token } } end |
#operations ⇒ Object
60 61 62 |
# File 'lib/baidu/sem/base.rb', line 60 def operations @client.operations(@service_name,@port_name) end |