Class: AdwordsApi::V201101::GeoLocationService::GeoLocationServiceWrapper
- Inherits:
-
Object
- Object
- AdwordsApi::V201101::GeoLocationService::GeoLocationServiceWrapper
- Defined in:
- lib/adwords_api/v201101/GeoLocationServiceWrapper.rb
Overview
Wrapper class for the v201101 GeoLocationService service. This class is automatically generated.
Constant Summary collapse
- REGISTRY =
AdwordsApi::V201101::GeoLocationService::DefaultMappingRegistry::LiteralRegistry
- NAMESPACE =
This takes advantage of the code generated by soap4r to get the correct namespace for a given service. It accesses one of the fields in the description of the service’s methods, which indicates the namespace. Since we’re using a fixed version of soap4r (1.5.8), and this is automatically generated as part of the stub generation, it will always point to what we want.
'https://adwords.google.com/api/adwords/cm/v201101'
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Holds the API object to which the wrapper belongs.
-
#module ⇒ Object
readonly
Holds a shortcut to the parent module.
-
#service ⇒ Object
readonly
Version and service utility fields.
-
#version ⇒ Object
readonly
Version and service utility fields.
Instance Method Summary collapse
-
#convert_from_object(object) ⇒ Object
Converts real soap4r objects into dynamic ones (property hashes).
-
#convert_to_object(object, parent_class = nil, property = nil) ⇒ Object
Converts dynamic objects (property hashes) into real soap4r objects.
-
#get(selector) ⇒ Object
Raises: Error::ApiError (or a subclass thereof) if a SOAP fault occurs.
-
#initialize(driver, api) ⇒ GeoLocationServiceWrapper
constructor
Constructor for GeoLocationServiceWrapper.
-
#namespace ⇒ Object
Returns the namespace for this service.
Constructor Details
#initialize(driver, api) ⇒ GeoLocationServiceWrapper
Constructor for GeoLocationServiceWrapper.
Args:
-
driver: SOAP::RPC::Driver object with the remote SOAP methods for this service
-
api: the API object to which the wrapper belongs
47 48 49 50 51 52 53 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 47 def initialize(driver, api) @driver = driver @api = api @module = AdwordsApi::V201101::GeoLocationService @version = :v201101 @service = :GeoLocationService end |
Instance Attribute Details
#api ⇒ Object (readonly)
Holds the API object to which the wrapper belongs.
14 15 16 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 14 def api @api end |
#module ⇒ Object (readonly)
Holds a shortcut to the parent module. Use this to avoid typing the full class name when creating classes belonging to this service, e.g.
service_object.module::ClassName
instead of
AdwordsApi::V201101::GeoLocationService::ClassName
This will make it easier to migrate your code between API versions.
36 37 38 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 36 def module @module end |
#service ⇒ Object (readonly)
Version and service utility fields.
17 18 19 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 17 def service @service end |
#version ⇒ Object (readonly)
Version and service utility fields.
17 18 19 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 17 def version @version end |
Instance Method Details
#convert_from_object(object) ⇒ Object
Converts real soap4r objects into dynamic ones (property hashes). This is meant to be called for return objects of remote calls.
Args:
-
object: the object being converted
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 227 def convert_from_object(object) if object.class.name =~ /AdwordsApi::V201101::\w+::\w+/ # Handle soap4r object object_class = REGISTRY.schema_definition_from_class(object.class) if object_class.elements and !object_class.elements.entries.empty? # Process complex object. hash = {} hash[:xsi_type] = object.class.name.split('::').last object_class.elements.entries.each do |entry| property = entry.varname.to_s if object.respond_to? property and !property.include?('_Type') value = object.send(property) property_name = nil if @api.config.read('service.use_ruby_names', true) property_name = underscore(property).to_sym else property_name = property.to_sym end # Recurse. hash[property_name] = convert_from_object(value) if value end end return hash else # Process simple object. parent = object.class.superclass return parent.new(object) end elsif object.is_a? Array # Handle arrays return object.map do |entry| # Recurse. convert_from_object(entry) end else # Handle native objects return object end end |
#convert_to_object(object, parent_class = nil, property = nil) ⇒ Object
Converts dynamic objects (property hashes) into real soap4r objects. This is meant to be called when setting properties on a class, so the method receives an optional parameter specifying the class and property. This way, it’s possible to determine the default type for the object if none is provided.
Args:
-
object: the object being converted
-
parent_class: the class whose property is being set
-
property: the property being set
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 162 def convert_to_object(object, parent_class = nil, property = nil) property = camel_case(property.to_s) if property if object.is_a? Hash # Process a hash. specified_class = object[:xsi_type] or object['xsi_type'] default_class = nil # Determine default class for this object, given the property # being set. if parent_class and property parent = REGISTRY.schema_definition_from_class(parent_class) element = parent.elements.entries.find do |entry| entry.varname.to_s == property.to_s end default_class = element.mapped_class if element end validate_object(object, default_class) real_class = nil if specified_class real_class = @module.class_eval(specified_class) else real_class = default_class end # Instance real object. real_object = real_class.new # Set each of its properties. object.each do |entry, value| entry = entry.to_s unless entry == 'xsi_type' if @api.config.read('service.use_ruby_names', true) entry = camel_case(entry) end if value.is_a? Hash # Recurse. set_object_property(real_object, entry, convert_to_object(value, real_class, entry)) elsif value.is_a? Array set_object_property(real_object, entry, value.map do |item| # Recurse. convert_to_object(item, real_class, entry) end ) else set_object_property(real_object, entry, value) end end end return real_object elsif object.is_a? Array # Process an array return object.map do |entry| # Recurse. convert_to_object(entry, parent_class, property) end else return object end end |
#get(selector) ⇒ Object
Raises: Error::ApiError (or a subclass thereof) if a SOAP fault occurs.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 283 def get(selector) begin arg_array = [] validate_object(selector, AdwordsApi::V201101::GeoLocationService::GeoLocationSelector) arg_array << convert_to_object(selector, AdwordsApi::V201101::GeoLocationService::Get, 'selector') # Construct request object and make API call obj = AdwordsApi::V201101::GeoLocationService::Get.new(*arg_array) reply = convert_from_object(@driver.get(obj)) reply = reply[:rval] if reply.include?(:rval) return reply rescue SOAP::FaultError => fault raise AdwordsApi::Errors.create_api_exception(fault, self) end end |
#namespace ⇒ Object
Returns the namespace for this service.
56 57 58 |
# File 'lib/adwords_api/v201101/GeoLocationServiceWrapper.rb', line 56 def namespace return NAMESPACE end |