repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.validate_array_arg
def validate_array_arg(arg, parent, key, arg_type) result = arg.map do |item| validate_arg(item, parent, key, arg_type) end return result end
ruby
def validate_array_arg(arg, parent, key, arg_type) result = arg.map do |item| validate_arg(item, parent, key, arg_type) end return result end
[ "def", "validate_array_arg", "(", "arg", ",", "parent", ",", "key", ",", "arg_type", ")", "result", "=", "arg", ".", "map", "do", "|", "item", "|", "validate_arg", "(", "item", ",", "parent", ",", "key", ",", "arg_type", ")", "end", "return", "result",...
Validates Array argument.
[ "Validates", "Array", "argument", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L221-L226
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.validate_hash_arg
def validate_hash_arg(arg, parent, key, arg_type) arg_type = handle_xsi_type(arg, parent, key, arg_type) validate_arguments(arg, arg_type[:fields], arg_type[:ns]) end
ruby
def validate_hash_arg(arg, parent, key, arg_type) arg_type = handle_xsi_type(arg, parent, key, arg_type) validate_arguments(arg, arg_type[:fields], arg_type[:ns]) end
[ "def", "validate_hash_arg", "(", "arg", ",", "parent", ",", "key", ",", "arg_type", ")", "arg_type", "=", "handle_xsi_type", "(", "arg", ",", "parent", ",", "key", ",", "arg_type", ")", "validate_arguments", "(", "arg", ",", "arg_type", "[", ":fields", "]"...
Validates Hash argument.
[ "Validates", "Hash", "argument", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L229-L232
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.validate_time_arg
def validate_time_arg(arg, parent, key) xml_value = time_to_xml_hash(arg) parent[key] = xml_value return xml_value end
ruby
def validate_time_arg(arg, parent, key) xml_value = time_to_xml_hash(arg) parent[key] = xml_value return xml_value end
[ "def", "validate_time_arg", "(", "arg", ",", "parent", ",", "key", ")", "xml_value", "=", "time_to_xml_hash", "(", "arg", ")", "parent", "[", "key", "]", "=", "xml_value", "return", "xml_value", "end" ]
Validates Time argument.
[ "Validates", "Time", "argument", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L235-L239
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.add_attribute
def add_attribute(node, key, name, value) node[:attributes!] ||= {} node[:attributes!][key] ||= {} if node[:attributes!][key].include?(name) node[:attributes!][key][name] = arrayize(node[:attributes!][key][name]) node[:attributes!][key][name] << value else node[:attributes!][key][name] = value end end
ruby
def add_attribute(node, key, name, value) node[:attributes!] ||= {} node[:attributes!][key] ||= {} if node[:attributes!][key].include?(name) node[:attributes!][key][name] = arrayize(node[:attributes!][key][name]) node[:attributes!][key][name] << value else node[:attributes!][key][name] = value end end
[ "def", "add_attribute", "(", "node", ",", "key", ",", "name", ",", "value", ")", "node", "[", ":attributes!", "]", "||=", "{", "}", "node", "[", ":attributes!", "]", "[", "key", "]", "||=", "{", "}", "if", "node", "[", ":attributes!", "]", "[", "ke...
Adds Savon attribute for given node, key, name and value.
[ "Adds", "Savon", "attribute", "for", "given", "node", "key", "name", "and", "value", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L279-L288
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.prefix_key_with_namespace
def prefix_key_with_namespace(key, ns_index = nil) namespace = (ns_index.nil?) ? DEFAULT_NAMESPACE : ("ns%d" % ns_index) return prefix_key(key, namespace) end
ruby
def prefix_key_with_namespace(key, ns_index = nil) namespace = (ns_index.nil?) ? DEFAULT_NAMESPACE : ("ns%d" % ns_index) return prefix_key(key, namespace) end
[ "def", "prefix_key_with_namespace", "(", "key", ",", "ns_index", "=", "nil", ")", "namespace", "=", "(", "ns_index", ".", "nil?", ")", "?", "DEFAULT_NAMESPACE", ":", "(", "\"ns%d\"", "%", "ns_index", ")", "return", "prefix_key", "(", "key", ",", "namespace",...
Prefixes a key with a given namespace index or default namespace.
[ "Prefixes", "a", "key", "with", "a", "given", "namespace", "index", "or", "default", "namespace", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L291-L294
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.get_full_type_signature
def get_full_type_signature(type_name) result = (type_name.nil?) ? nil : @registry.get_type_signature(type_name) result[:fields] = implode_parent(result) if result and result[:base] return result end
ruby
def get_full_type_signature(type_name) result = (type_name.nil?) ? nil : @registry.get_type_signature(type_name) result[:fields] = implode_parent(result) if result and result[:base] return result end
[ "def", "get_full_type_signature", "(", "type_name", ")", "result", "=", "(", "type_name", ".", "nil?", ")", "?", "nil", ":", "@registry", ".", "get_type_signature", "(", "type_name", ")", "result", "[", ":fields", "]", "=", "implode_parent", "(", "result", "...
Returns type signature with all inherited fields.
[ "Returns", "type", "signature", "with", "all", "inherited", "fields", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L312-L316
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.implode_parent
def implode_parent(data_type) result = [] if data_type[:base] parent_type = @registry.get_type_signature(data_type[:base]) result += implode_parent(parent_type) end data_type[:fields].each do |field| # If the parent type includes a field with the same name, overwrite it. result.reject! {|parent_field| parent_field[:name].eql?(field[:name])} # Storing field's namespace. field[:ns] = data_type[:ns] if data_type[:ns] result << field end return result end
ruby
def implode_parent(data_type) result = [] if data_type[:base] parent_type = @registry.get_type_signature(data_type[:base]) result += implode_parent(parent_type) end data_type[:fields].each do |field| # If the parent type includes a field with the same name, overwrite it. result.reject! {|parent_field| parent_field[:name].eql?(field[:name])} # Storing field's namespace. field[:ns] = data_type[:ns] if data_type[:ns] result << field end return result end
[ "def", "implode_parent", "(", "data_type", ")", "result", "=", "[", "]", "if", "data_type", "[", ":base", "]", "parent_type", "=", "@registry", ".", "get_type_signature", "(", "data_type", "[", ":base", "]", ")", "result", "+=", "implode_parent", "(", "paren...
Returns all inherited fields of superclasses for given type.
[ "Returns", "all", "inherited", "fields", "of", "superclasses", "for", "given", "type", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L319-L333
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/parameters_validator.rb
AdsCommon.ParametersValidator.time_to_xml_hash
def time_to_xml_hash(time) return { :hour => time.hour, :minute => time.min, :second => time.sec, :date => {:year => time.year, :month => time.month, :day => time.day} } end
ruby
def time_to_xml_hash(time) return { :hour => time.hour, :minute => time.min, :second => time.sec, :date => {:year => time.year, :month => time.month, :day => time.day} } end
[ "def", "time_to_xml_hash", "(", "time", ")", "return", "{", ":hour", "=>", "time", ".", "hour", ",", ":minute", "=>", "time", ".", "min", ",", ":second", "=>", "time", ".", "sec", ",", ":date", "=>", "{", ":year", "=>", "time", ".", "year", ",", ":...
Converts Time to a hash for XML marshalling.
[ "Converts", "Time", "to", "a", "hash", "for", "XML", "marshalling", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/parameters_validator.rb#L349-L354
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/config.rb
AdsCommon.Config.load
def load(filename) begin new_config = YAML::load_file(filename) if new_config.kind_of?(Hash) @config = new_config else raise AdsCommon::Errors::Error, "Incorrect configuration file: '%s'" % filename end rescue TypeError => e raise AdsCommon::Errors::Error, "Error parsing configuration file: '%s' (%s)" % [filename, e] end return nil end
ruby
def load(filename) begin new_config = YAML::load_file(filename) if new_config.kind_of?(Hash) @config = new_config else raise AdsCommon::Errors::Error, "Incorrect configuration file: '%s'" % filename end rescue TypeError => e raise AdsCommon::Errors::Error, "Error parsing configuration file: '%s' (%s)" % [filename, e] end return nil end
[ "def", "load", "(", "filename", ")", "begin", "new_config", "=", "YAML", "::", "load_file", "(", "filename", ")", "if", "new_config", ".", "kind_of?", "(", "Hash", ")", "@config", "=", "new_config", "else", "raise", "AdsCommon", "::", "Errors", "::", "Erro...
Reads a configuration file into instance variable as a Ruby structure with the complete set of keys and values. Args: - filename: config file to be read (*String*) Raises: - <b>Errno::ENOENT</b> if the file does not exist.
[ "Reads", "a", "configuration", "file", "into", "instance", "variable", "as", "a", "Ruby", "structure", "with", "the", "complete", "set", "of", "keys", "and", "values", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/config.rb#L79-L93
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/config.rb
AdsCommon.Config.process_hash_keys
def process_hash_keys(hash) return hash.inject({}) do |result, pair| key, value = pair result[key.to_sym] = value.is_a?(Hash) ? process_hash_keys(value) : value result end end
ruby
def process_hash_keys(hash) return hash.inject({}) do |result, pair| key, value = pair result[key.to_sym] = value.is_a?(Hash) ? process_hash_keys(value) : value result end end
[ "def", "process_hash_keys", "(", "hash", ")", "return", "hash", ".", "inject", "(", "{", "}", ")", "do", "|", "result", ",", "pair", "|", "key", ",", "value", "=", "pair", "result", "[", "key", ".", "to_sym", "]", "=", "value", ".", "is_a?", "(", ...
Auxiliary method to recurse through a hash and convert all the keys to symbols.
[ "Auxiliary", "method", "to", "recurse", "through", "a", "hash", "and", "convert", "all", "the", "keys", "to", "symbols", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/config.rb#L99-L106
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/config.rb
AdsCommon.Config.find_value
def find_value(data, path) return (path.nil? or data.nil?) ? nil : path.split('.').inject(data) do |node, section| break if node.nil? key = section.to_sym (node.is_a?(Hash) and node.include?(key)) ? node[key] : nil end end
ruby
def find_value(data, path) return (path.nil? or data.nil?) ? nil : path.split('.').inject(data) do |node, section| break if node.nil? key = section.to_sym (node.is_a?(Hash) and node.include?(key)) ? node[key] : nil end end
[ "def", "find_value", "(", "data", ",", "path", ")", "return", "(", "path", ".", "nil?", "or", "data", ".", "nil?", ")", "?", "nil", ":", "path", ".", "split", "(", "'.'", ")", ".", "inject", "(", "data", ")", "do", "|", "node", ",", "section", ...
Finds a value for string of format 'level1.level2.name' in a given hash.
[ "Finds", "a", "value", "for", "string", "of", "format", "level1", ".", "level2", ".", "name", "in", "a", "given", "hash", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/config.rb#L109-L116
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/batch_job_utils.rb
AdwordsApi.BatchJobUtils.initialize_url
def initialize_url(batch_job_url) headers = DEFAULT_HEADERS headers['Content-Length'] = 0 headers['x-goog-resumable'] = 'start' response = AdsCommon::Http.post_response( batch_job_url, '', @api.config, headers) return response.headers['Location'] end
ruby
def initialize_url(batch_job_url) headers = DEFAULT_HEADERS headers['Content-Length'] = 0 headers['x-goog-resumable'] = 'start' response = AdsCommon::Http.post_response( batch_job_url, '', @api.config, headers) return response.headers['Location'] end
[ "def", "initialize_url", "(", "batch_job_url", ")", "headers", "=", "DEFAULT_HEADERS", "headers", "[", "'Content-Length'", "]", "=", "0", "headers", "[", "'x-goog-resumable'", "]", "=", "'start'", "response", "=", "AdsCommon", "::", "Http", ".", "post_response", ...
Initializes an upload URL to get the actual URL to which to upload operations. Args: - batch_job_url: The UploadURL provided by BatchJobService Returns: - The URL that should actually be used to upload operations.
[ "Initializes", "an", "upload", "URL", "to", "get", "the", "actual", "URL", "to", "which", "to", "upload", "operations", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/batch_job_utils.rb#L85-L94
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/batch_job_utils.rb
AdwordsApi.BatchJobUtils.put_incremental_operations
def put_incremental_operations( operations, batch_job_url, total_content_length = 0, is_last_request = false) @api.utils_reporter.batch_job_utils_used() headers = DEFAULT_HEADERS soap_operations = generate_soap_operations(operations) request_body = soap_operations.join is_first_request = (total_content_length == 0) if is_first_request request_body = (UPLOAD_XML_PREFIX % [@version]) + request_body end if is_last_request request_body += UPLOAD_XML_SUFFIX end request_body = add_padding(request_body) content_length = request_body.bytesize headers['Content-Length'] = content_length lower_bound = total_content_length upper_bound = total_content_length + content_length - 1 total_bytes = is_last_request ? upper_bound + 1 : '*' content_range = "bytes %d-%d/%s" % [lower_bound, upper_bound, total_bytes] headers['Content-Range'] = content_range log_request(batch_job_url, headers, request_body) # The HTTPI library fails to handle the response when uploading # incremental requests. We're not interested in the response, so just # ignore the error. begin AdsCommon::Http.put_response( batch_job_url, request_body, @api.config, headers) rescue ArgumentError end total_content_length += content_length return total_content_length end
ruby
def put_incremental_operations( operations, batch_job_url, total_content_length = 0, is_last_request = false) @api.utils_reporter.batch_job_utils_used() headers = DEFAULT_HEADERS soap_operations = generate_soap_operations(operations) request_body = soap_operations.join is_first_request = (total_content_length == 0) if is_first_request request_body = (UPLOAD_XML_PREFIX % [@version]) + request_body end if is_last_request request_body += UPLOAD_XML_SUFFIX end request_body = add_padding(request_body) content_length = request_body.bytesize headers['Content-Length'] = content_length lower_bound = total_content_length upper_bound = total_content_length + content_length - 1 total_bytes = is_last_request ? upper_bound + 1 : '*' content_range = "bytes %d-%d/%s" % [lower_bound, upper_bound, total_bytes] headers['Content-Range'] = content_range log_request(batch_job_url, headers, request_body) # The HTTPI library fails to handle the response when uploading # incremental requests. We're not interested in the response, so just # ignore the error. begin AdsCommon::Http.put_response( batch_job_url, request_body, @api.config, headers) rescue ArgumentError end total_content_length += content_length return total_content_length end
[ "def", "put_incremental_operations", "(", "operations", ",", "batch_job_url", ",", "total_content_length", "=", "0", ",", "is_last_request", "=", "false", ")", "@api", ".", "utils_reporter", ".", "batch_job_utils_used", "(", ")", "headers", "=", "DEFAULT_HEADERS", "...
Puts the provided operations to the provided URL, allowing for incremental followup puts. Args: - soap_operations: An array including SOAP operations provided by generate_soap_operations - batch_job_url: The UploadURL provided by BatchJobService - total_content_length: The total number of bytes already uploaded incrementally. Set this to 0 the first time you call the method. - is_last_request: Whether or not this set of uploads will conclude the full request. Returns: - total content length, including what was just uploaded. Pass this back into this method on subsequent calls.
[ "Puts", "the", "provided", "operations", "to", "the", "provided", "URL", "allowing", "for", "incremental", "followup", "puts", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/batch_job_utils.rb#L111-L153
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/batch_job_utils.rb
AdwordsApi.BatchJobUtils.get_job_results
def get_job_results(batch_job_url) @api.utils_reporter.batch_job_utils_used() xml_response = AdsCommon::Http.get_response(batch_job_url, @api.config) begin return sanitize_result( get_nori().parse(xml_response.body)[:mutate_response][:rval]) rescue return nil end end
ruby
def get_job_results(batch_job_url) @api.utils_reporter.batch_job_utils_used() xml_response = AdsCommon::Http.get_response(batch_job_url, @api.config) begin return sanitize_result( get_nori().parse(xml_response.body)[:mutate_response][:rval]) rescue return nil end end
[ "def", "get_job_results", "(", "batch_job_url", ")", "@api", ".", "utils_reporter", ".", "batch_job_utils_used", "(", ")", "xml_response", "=", "AdsCommon", "::", "Http", ".", "get_response", "(", "batch_job_url", ",", "@api", ".", "config", ")", "begin", "retur...
Downloads the results of a batch job from the specified URL. Args: - batch_job_url: The URL provided by BatchJobService to fetch the results from Returns: - the results of the batch job, as a ruby hash, or nil if none yet exist
[ "Downloads", "the", "results", "of", "a", "batch", "job", "from", "the", "specified", "URL", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/batch_job_utils.rb#L164-L173
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/batch_job_utils.rb
AdwordsApi.BatchJobUtils.extract_soap_operations
def extract_soap_operations(full_soap_xml) doc = Nokogiri::XML(full_soap_xml) operations = doc.css('wsdl|operations') operations.attr('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') operations.each do |element| check_xsi_type(element) end return operations.to_s end
ruby
def extract_soap_operations(full_soap_xml) doc = Nokogiri::XML(full_soap_xml) operations = doc.css('wsdl|operations') operations.attr('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') operations.each do |element| check_xsi_type(element) end return operations.to_s end
[ "def", "extract_soap_operations", "(", "full_soap_xml", ")", "doc", "=", "Nokogiri", "::", "XML", "(", "full_soap_xml", ")", "operations", "=", "doc", ".", "css", "(", "'wsdl|operations'", ")", "operations", ".", "attr", "(", "'xmlns:xsi'", ",", "'http://www.w3....
Given a full SOAP xml string, extract just the operations element from the SOAP body as a string.
[ "Given", "a", "full", "SOAP", "xml", "string", "extract", "just", "the", "operations", "element", "from", "the", "SOAP", "body", "as", "a", "string", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/batch_job_utils.rb#L257-L265
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/batch_job_utils.rb
AdwordsApi.BatchJobUtils.sanitize_result
def sanitize_result(results) if results.is_a?(Array) ret = [] results.each do |result| ret << sanitize_result(result) end return ret end if results.is_a?(Hash) ret = {} results.each do |k, v| v = sanitize_result(v) if v.is_a?(Hash) ret[k] = v unless k.to_s.start_with?('@') end return ret end return results end
ruby
def sanitize_result(results) if results.is_a?(Array) ret = [] results.each do |result| ret << sanitize_result(result) end return ret end if results.is_a?(Hash) ret = {} results.each do |k, v| v = sanitize_result(v) if v.is_a?(Hash) ret[k] = v unless k.to_s.start_with?('@') end return ret end return results end
[ "def", "sanitize_result", "(", "results", ")", "if", "results", ".", "is_a?", "(", "Array", ")", "ret", "=", "[", "]", "results", ".", "each", "do", "|", "result", "|", "ret", "<<", "sanitize_result", "(", "result", ")", "end", "return", "ret", "end", ...
Removes extraneous XML information from return hash.
[ "Removes", "extraneous", "XML", "information", "from", "return", "hash", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/batch_job_utils.rb#L290-L309
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/query_utils/service_query.rb
AdwordsApi.ServiceQuery.has_next_landscape_page
def has_next_landscape_page(page) raise ArgumentError, 'Cannot page through query with no LIMIT clause.' if @start_index.nil? return false unless page[:entries] total_landscape_points_in_page = 0 page[:entries].each do |landscape| total_landscape_points_in_page += landscape[:landscape_points].size end return total_landscape_points_in_page >= @page_size end
ruby
def has_next_landscape_page(page) raise ArgumentError, 'Cannot page through query with no LIMIT clause.' if @start_index.nil? return false unless page[:entries] total_landscape_points_in_page = 0 page[:entries].each do |landscape| total_landscape_points_in_page += landscape[:landscape_points].size end return total_landscape_points_in_page >= @page_size end
[ "def", "has_next_landscape_page", "(", "page", ")", "raise", "ArgumentError", ",", "'Cannot page through query with no LIMIT clause.'", "if", "@start_index", ".", "nil?", "return", "false", "unless", "page", "[", ":entries", "]", "total_landscape_points_in_page", "=", "0"...
Determining whether another page exists when dealing with bid landscapes is different from other types of queries. Use this method for those cases.
[ "Determining", "whether", "another", "page", "exists", "when", "dealing", "with", "bid", "landscapes", "is", "different", "from", "other", "types", "of", "queries", ".", "Use", "this", "method", "for", "those", "cases", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/query_utils/service_query.rb#L36-L45
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api_config.rb
AdsCommon.ApiConfig.version_has_service
def version_has_service(version, service) return service_config.include?(version) && service_config[version].include?(service) end
ruby
def version_has_service(version, service) return service_config.include?(version) && service_config[version].include?(service) end
[ "def", "version_has_service", "(", "version", ",", "service", ")", "return", "service_config", ".", "include?", "(", "version", ")", "&&", "service_config", "[", "version", "]", ".", "include?", "(", "service", ")", "end" ]
Does the given version exist and contain the given service? Returns: Boolean indicating whether the given version exists and contains the given service
[ "Does", "the", "given", "version", "exist", "and", "contain", "the", "given", "service?" ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api_config.rb#L60-L63
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api_config.rb
AdsCommon.ApiConfig.endpoint
def endpoint(version, service) base = get_wsdl_base(version) if !subdir_config().nil? base = base.to_s + subdir_config()[[version, service]].to_s end return base.to_s + version.to_s + '/' + service.to_s end
ruby
def endpoint(version, service) base = get_wsdl_base(version) if !subdir_config().nil? base = base.to_s + subdir_config()[[version, service]].to_s end return base.to_s + version.to_s + '/' + service.to_s end
[ "def", "endpoint", "(", "version", ",", "service", ")", "base", "=", "get_wsdl_base", "(", "version", ")", "if", "!", "subdir_config", "(", ")", ".", "nil?", "base", "=", "base", ".", "to_s", "+", "subdir_config", "(", ")", "[", "[", "version", ",", ...
Get the endpoint for a service on a given API version. Args: - version: the API version - service: the name of the API service Returns: The endpoint URL
[ "Get", "the", "endpoint", "for", "a", "service", "on", "a", "given", "API", "version", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api_config.rb#L110-L116
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api_config.rb
AdsCommon.ApiConfig.do_require
def do_require(version, service) filename = [api_path, version.to_s, service.to_s.snakecase].join('/') require filename return filename end
ruby
def do_require(version, service) filename = [api_path, version.to_s, service.to_s.snakecase].join('/') require filename return filename end
[ "def", "do_require", "(", "version", ",", "service", ")", "filename", "=", "[", "api_path", ",", "version", ".", "to_s", ",", "service", ".", "to_s", ".", "snakecase", "]", ".", "join", "(", "'/'", ")", "require", "filename", "return", "filename", "end" ...
Perform the loading of the necessary source files for a version. Args: - version: the API version - service: service name Returns: The filename that was loaded
[ "Perform", "the", "loading", "of", "the", "necessary", "source", "files", "for", "a", "version", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api_config.rb#L141-L145
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api_config.rb
AdsCommon.ApiConfig.module_name
def module_name(version, service) return [api_name, version.to_s.upcase, service.to_s].join('::') end
ruby
def module_name(version, service) return [api_name, version.to_s.upcase, service.to_s].join('::') end
[ "def", "module_name", "(", "version", ",", "service", ")", "return", "[", "api_name", ",", "version", ".", "to_s", ".", "upcase", ",", "service", ".", "to_s", "]", ".", "join", "(", "'::'", ")", "end" ]
Returns the full module name for a given service. Args: - version: the API version - service: the service name Returns: The full module name for the given service
[ "Returns", "the", "full", "module", "name", "for", "a", "given", "service", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api_config.rb#L156-L158
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api_config.rb
AdsCommon.ApiConfig.get_wsdls
def get_wsdls(version) res = {} wsdl_base = get_wsdl_base(version) postfix = wsdl_base.start_with?('http') ? '?wsdl' : '.wsdl' services(version).each do |service| path = wsdl_base if (!subdir_config().nil?) subdir_name = subdir(version, service); path = path + subdir_name if subdir_name and !subdir_name.empty? end path = path + version.to_s + '/' + service.to_s + postfix res[service.to_s] = path end return res end
ruby
def get_wsdls(version) res = {} wsdl_base = get_wsdl_base(version) postfix = wsdl_base.start_with?('http') ? '?wsdl' : '.wsdl' services(version).each do |service| path = wsdl_base if (!subdir_config().nil?) subdir_name = subdir(version, service); path = path + subdir_name if subdir_name and !subdir_name.empty? end path = path + version.to_s + '/' + service.to_s + postfix res[service.to_s] = path end return res end
[ "def", "get_wsdls", "(", "version", ")", "res", "=", "{", "}", "wsdl_base", "=", "get_wsdl_base", "(", "version", ")", "postfix", "=", "wsdl_base", ".", "start_with?", "(", "'http'", ")", "?", "'?wsdl'", ":", "'.wsdl'", "services", "(", "version", ")", "...
Generates an array of WSDL URLs based on defined Services and version supplied. This method is used by generators to determine what service wrappers to generate. Args: - version: the API version. Returns hash of pairs Service => WSDL URL
[ "Generates", "an", "array", "of", "WSDL", "URLs", "based", "on", "defined", "Services", "and", "version", "supplied", ".", "This", "method", "is", "used", "by", "generators", "to", "determine", "what", "service", "wrappers", "to", "generate", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api_config.rb#L183-L197
valid
googleads/google-api-ads-ruby
ads_savon/lib/ads_savon/client.rb
GoogleAdsSavon.Client.process
def process(offset = 0, instance = self, &block) block.arity > 0 ? yield_objects(offset, instance, &block) : evaluate(instance, &block) end
ruby
def process(offset = 0, instance = self, &block) block.arity > 0 ? yield_objects(offset, instance, &block) : evaluate(instance, &block) end
[ "def", "process", "(", "offset", "=", "0", ",", "instance", "=", "self", ",", "&", "block", ")", "block", ".", "arity", ">", "0", "?", "yield_objects", "(", "offset", ",", "instance", ",", "&", "block", ")", ":", "evaluate", "(", "instance", ",", "...
Processes a given +block+. Yields objects if the block expects any arguments. Otherwise evaluates the block in the context of +instance+.
[ "Processes", "a", "given", "+", "block", "+", ".", "Yields", "objects", "if", "the", "block", "expects", "any", "arguments", ".", "Otherwise", "evaluates", "the", "block", "in", "the", "context", "of", "+", "instance", "+", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_savon/lib/ads_savon/client.rb#L121-L123
valid
googleads/google-api-ads-ruby
ads_savon/lib/ads_savon/client.rb
GoogleAdsSavon.Client.yield_objects
def yield_objects(offset, instance, &block) to_yield = [:soap, :wsdl, :http, :wsse] yield *(to_yield[offset, block.arity].map { |obj_name| instance.send(obj_name) }) end
ruby
def yield_objects(offset, instance, &block) to_yield = [:soap, :wsdl, :http, :wsse] yield *(to_yield[offset, block.arity].map { |obj_name| instance.send(obj_name) }) end
[ "def", "yield_objects", "(", "offset", ",", "instance", ",", "&", "block", ")", "to_yield", "=", "[", ":soap", ",", ":wsdl", ",", ":http", ",", ":wsse", "]", "yield", "*", "(", "to_yield", "[", "offset", ",", "block", ".", "arity", "]", ".", "map", ...
Yields a number of objects to a given +block+ depending on how many arguments the block is expecting.
[ "Yields", "a", "number", "of", "objects", "to", "a", "given", "+", "block", "+", "depending", "on", "how", "many", "arguments", "the", "block", "is", "expecting", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_savon/lib/ads_savon/client.rb#L127-L130
valid
googleads/google-api-ads-ruby
ads_savon/lib/ads_savon/client.rb
GoogleAdsSavon.Client.evaluate
def evaluate(instance, &block) original_self = eval "self", block.binding # A proxy that attemps to make method calls on +instance+. If a NoMethodError is # raised, the call will be made on +original_self+. proxy = Object.new proxy.instance_eval do class << self attr_accessor :original_self, :instance end def method_missing(method, *args, &block) instance.send(method, *args, &block) rescue NoMethodError original_self.send(method, *args, &block) end end proxy.instance = instance proxy.original_self = original_self proxy.instance_eval &block end
ruby
def evaluate(instance, &block) original_self = eval "self", block.binding # A proxy that attemps to make method calls on +instance+. If a NoMethodError is # raised, the call will be made on +original_self+. proxy = Object.new proxy.instance_eval do class << self attr_accessor :original_self, :instance end def method_missing(method, *args, &block) instance.send(method, *args, &block) rescue NoMethodError original_self.send(method, *args, &block) end end proxy.instance = instance proxy.original_self = original_self proxy.instance_eval &block end
[ "def", "evaluate", "(", "instance", ",", "&", "block", ")", "original_self", "=", "eval", "\"self\"", ",", "block", ".", "binding", "proxy", "=", "Object", ".", "new", "proxy", ".", "instance_eval", "do", "class", "<<", "self", "attr_accessor", ":original_se...
Evaluates a given +block+ inside +instance+. Stores the original block binding.
[ "Evaluates", "a", "given", "+", "block", "+", "inside", "+", "instance", "+", ".", "Stores", "the", "original", "block", "binding", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_savon/lib/ads_savon/client.rb#L133-L155
valid
googleads/google-api-ads-ruby
ads_savon/lib/ads_savon/client.rb
GoogleAdsSavon.Client.remove_blank_values
def remove_blank_values(hash) hash.delete_if { |_, value| value.respond_to?(:empty?) ? value.empty? : !value } end
ruby
def remove_blank_values(hash) hash.delete_if { |_, value| value.respond_to?(:empty?) ? value.empty? : !value } end
[ "def", "remove_blank_values", "(", "hash", ")", "hash", ".", "delete_if", "{", "|", "_", ",", "value", "|", "value", ".", "respond_to?", "(", ":empty?", ")", "?", "value", ".", "empty?", ":", "!", "value", "}", "end" ]
Removes all blank values from a given +hash+.
[ "Removes", "all", "blank", "values", "from", "a", "given", "+", "hash", "+", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_savon/lib/ads_savon/client.rb#L158-L160
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb
AdManagerApi.PQLValues.values
def values() # values_array is an Ad-Manager-compliant list of values of the following # form: [:key => ..., :value => {:xsi_type => ..., :value => ...}] values_array = @values.map do |key, value| raise 'Missing value in StatementBuilder.' if value.nil? raise 'Misconfigured value in StatementBuilder.' unless value.is_a? Hash raise 'Value cannot be nil on StatementBuilder.' if value[:value].nil? raise 'Missing value type for %s.' % key if value[:xsi_type].nil? unless VALUE_TYPES.values.include?(value[:xsi_type]) raise 'Unknown value type for %s.' % key end if value[:xsi_type] == 'SetValue' if value[:value].map {|v| v.class}.to_set.size > 1 raise 'Cannot pass more than one type in set variable, %s.' % key end end if value[:xsi_type] == 'DateTimeValue' unless value[:value][:time_zone_id] raise 'Missing timezone on DateTimeValue variable, %s.' %key end end {:key => key.to_s(), :value => value} end return values_array end
ruby
def values() # values_array is an Ad-Manager-compliant list of values of the following # form: [:key => ..., :value => {:xsi_type => ..., :value => ...}] values_array = @values.map do |key, value| raise 'Missing value in StatementBuilder.' if value.nil? raise 'Misconfigured value in StatementBuilder.' unless value.is_a? Hash raise 'Value cannot be nil on StatementBuilder.' if value[:value].nil? raise 'Missing value type for %s.' % key if value[:xsi_type].nil? unless VALUE_TYPES.values.include?(value[:xsi_type]) raise 'Unknown value type for %s.' % key end if value[:xsi_type] == 'SetValue' if value[:value].map {|v| v.class}.to_set.size > 1 raise 'Cannot pass more than one type in set variable, %s.' % key end end if value[:xsi_type] == 'DateTimeValue' unless value[:value][:time_zone_id] raise 'Missing timezone on DateTimeValue variable, %s.' %key end end {:key => key.to_s(), :value => value} end return values_array end
[ "def", "values", "(", ")", "values_array", "=", "@values", ".", "map", "do", "|", "key", ",", "value", "|", "raise", "'Missing value in StatementBuilder.'", "if", "value", ".", "nil?", "raise", "'Misconfigured value in StatementBuilder.'", "unless", "value", ".", ...
Get values as an array, the format the Ad Manager API expects.
[ "Get", "values", "as", "an", "array", "the", "format", "the", "Ad", "Manager", "API", "expects", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb#L65-L89
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb
AdManagerApi.PQLValues.generate_value_object
def generate_value_object(value) typeKeyValue = VALUE_TYPES.find {|key, val| value.is_a? key} dateTypes = [AdManagerApi::AdManagerDate, AdManagerApi::AdManagerDateTime] if dateTypes.include?(value.class) value = value.to_h end return value if typeKeyValue.nil? return {:xsi_type => typeKeyValue.last, :value => value} end
ruby
def generate_value_object(value) typeKeyValue = VALUE_TYPES.find {|key, val| value.is_a? key} dateTypes = [AdManagerApi::AdManagerDate, AdManagerApi::AdManagerDateTime] if dateTypes.include?(value.class) value = value.to_h end return value if typeKeyValue.nil? return {:xsi_type => typeKeyValue.last, :value => value} end
[ "def", "generate_value_object", "(", "value", ")", "typeKeyValue", "=", "VALUE_TYPES", ".", "find", "{", "|", "key", ",", "val", "|", "value", ".", "is_a?", "key", "}", "dateTypes", "=", "[", "AdManagerApi", "::", "AdManagerDate", ",", "AdManagerApi", "::", ...
Create an individual value object by inferring the xsi_type. If the value type isn't recognized, return the original value parameter.
[ "Create", "an", "individual", "value", "object", "by", "inferring", "the", "xsi_type", ".", "If", "the", "value", "type", "isn", "t", "recognized", "return", "the", "original", "value", "parameter", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb#L93-L101
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb
AdManagerApi.StatementBuilder.validate
def validate() if !@select.to_s.strip.empty? and @from.to_s.strip.empty? raise 'FROM clause is required with SELECT' end if !@from.to_s.strip.empty? and @select.to_s.strip.empty? raise 'SELECT clause is required with FROM' end if !@offset.nil? and @limit.nil? raise 'LIMIT clause is required with OFFSET' end unless @limit.is_a? Integer or @limit.nil? raise 'LIMIT must be an integer' end unless @offset.is_a? Integer or @offset.nil? raise 'OFFSET must be an integer' end end
ruby
def validate() if !@select.to_s.strip.empty? and @from.to_s.strip.empty? raise 'FROM clause is required with SELECT' end if !@from.to_s.strip.empty? and @select.to_s.strip.empty? raise 'SELECT clause is required with FROM' end if !@offset.nil? and @limit.nil? raise 'LIMIT clause is required with OFFSET' end unless @limit.is_a? Integer or @limit.nil? raise 'LIMIT must be an integer' end unless @offset.is_a? Integer or @offset.nil? raise 'OFFSET must be an integer' end end
[ "def", "validate", "(", ")", "if", "!", "@select", ".", "to_s", ".", "strip", ".", "empty?", "and", "@from", ".", "to_s", ".", "strip", ".", "empty?", "raise", "'FROM clause is required with SELECT'", "end", "if", "!", "@from", ".", "to_s", ".", "strip", ...
Return a list of validation errors.
[ "Return", "a", "list", "of", "validation", "errors", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb#L160-L176
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb
AdManagerApi.StatementBuilder.to_statement
def to_statement() @api.utils_reporter.statement_builder_used() validate() ordering = @ascending ? 'ASC' : 'DESC' pql_query = PQLQuery.new pql_query << SELECT % @select unless @select.to_s.empty? pql_query << FROM % @from unless @from.to_s.empty? pql_query << WHERE % @where unless @where.to_s.empty? pql_query << ORDER % [@order_by, ordering] unless @order_by.to_s.empty? pql_query << LIMIT % @limit unless @limit.nil? pql_query << OFFSET % @offset unless @offset.nil? return {:query => pql_query.to_s(), :values => @pql_values.values} end
ruby
def to_statement() @api.utils_reporter.statement_builder_used() validate() ordering = @ascending ? 'ASC' : 'DESC' pql_query = PQLQuery.new pql_query << SELECT % @select unless @select.to_s.empty? pql_query << FROM % @from unless @from.to_s.empty? pql_query << WHERE % @where unless @where.to_s.empty? pql_query << ORDER % [@order_by, ordering] unless @order_by.to_s.empty? pql_query << LIMIT % @limit unless @limit.nil? pql_query << OFFSET % @offset unless @offset.nil? return {:query => pql_query.to_s(), :values => @pql_values.values} end
[ "def", "to_statement", "(", ")", "@api", ".", "utils_reporter", ".", "statement_builder_used", "(", ")", "validate", "(", ")", "ordering", "=", "@ascending", "?", "'ASC'", ":", "'DESC'", "pql_query", "=", "PQLQuery", ".", "new", "pql_query", "<<", "SELECT", ...
Create a statement object that can be sent in a Ad Manager API request.
[ "Create", "a", "statement", "object", "that", "can", "be", "sent", "in", "a", "Ad", "Manager", "API", "request", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/pql_statement_utils.rb#L179-L191
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb
AdManagerApi.AdManagerDate.method_missing
def method_missing(name, *args, &block) result = @date.send(name, *args, &block) return self.class.new(@api, result) if result.is_a? Date return result end
ruby
def method_missing(name, *args, &block) result = @date.send(name, *args, &block) return self.class.new(@api, result) if result.is_a? Date return result end
[ "def", "method_missing", "(", "name", ",", "*", "args", ",", "&", "block", ")", "result", "=", "@date", ".", "send", "(", "name", ",", "*", "args", ",", "&", "block", ")", "return", "self", ".", "class", ".", "new", "(", "@api", ",", "result", ")...
When an unrecognized method is applied to AdManagerDate, pass it through to the internal ruby Date.
[ "When", "an", "unrecognized", "method", "is", "applied", "to", "AdManagerDate", "pass", "it", "through", "to", "the", "internal", "ruby", "Date", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb#L62-L66
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb
AdManagerApi.AdManagerDateTime.to_h
def to_h { :date => AdManagerApi::AdManagerDate.new( @api, @time.year, @time.month, @time.day ).to_h, :hour => @time.hour, :minute => @time.min, :second => @time.sec, :time_zone_id => @timezone.identifier } end
ruby
def to_h { :date => AdManagerApi::AdManagerDate.new( @api, @time.year, @time.month, @time.day ).to_h, :hour => @time.hour, :minute => @time.min, :second => @time.sec, :time_zone_id => @timezone.identifier } end
[ "def", "to_h", "{", ":date", "=>", "AdManagerApi", "::", "AdManagerDate", ".", "new", "(", "@api", ",", "@time", ".", "year", ",", "@time", ".", "month", ",", "@time", ".", "day", ")", ".", "to_h", ",", ":hour", "=>", "@time", ".", "hour", ",", ":m...
Convert AdManagerDateTime into a hash representation which can be consumed by the Ad Manager API. E.g., a hash that can be passed as PQL DateTime variables. Returns: - ad_manager_datetime_hash: a hash representation of an AdManagerDateTime
[ "Convert", "AdManagerDateTime", "into", "a", "hash", "representation", "which", "can", "be", "consumed", "by", "the", "Ad", "Manager", "API", ".", "E", ".", "g", ".", "a", "hash", "that", "can", "be", "passed", "as", "PQL", "DateTime", "variables", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb#L158-L168
valid
googleads/google-api-ads-ruby
ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb
AdManagerApi.AdManagerDateTime.method_missing
def method_missing(name, *args, &block) # Restrict time zone related functions from being passed to internal ruby # Time attribute, since AdManagerDateTime handles timezones its own way. restricted_functions = [:dst?, :getgm, :getlocal, :getutc, :gmt, :gmtime, :gmtoff, :isdst, :localtime, :utc] if restricted_functions.include? name raise NoMethodError, 'undefined method %s for %s' % [name, self] end result = @time.send(name, *args, &block) if result.is_a? Time return self.class.new(@api, result, @timezone.identifier) else return result end end
ruby
def method_missing(name, *args, &block) # Restrict time zone related functions from being passed to internal ruby # Time attribute, since AdManagerDateTime handles timezones its own way. restricted_functions = [:dst?, :getgm, :getlocal, :getutc, :gmt, :gmtime, :gmtoff, :isdst, :localtime, :utc] if restricted_functions.include? name raise NoMethodError, 'undefined method %s for %s' % [name, self] end result = @time.send(name, *args, &block) if result.is_a? Time return self.class.new(@api, result, @timezone.identifier) else return result end end
[ "def", "method_missing", "(", "name", ",", "*", "args", ",", "&", "block", ")", "restricted_functions", "=", "[", ":dst?", ",", ":getgm", ",", ":getlocal", ",", ":getutc", ",", ":gmt", ",", ":gmtime", ",", ":gmtoff", ",", ":isdst", ",", ":localtime", ","...
When an unrecognized method is applied to AdManagerDateTime, pass it through to the internal ruby Time.
[ "When", "an", "unrecognized", "method", "is", "applied", "to", "AdManagerDateTime", "pass", "it", "through", "to", "the", "internal", "ruby", "Time", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ad_manager_api/lib/ad_manager_api/ad_manager_api_datetime.rb#L172-L186
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.create_savon_client
def create_savon_client(endpoint, namespace) client = GoogleAdsSavon::Client.new do |wsdl, httpi| wsdl.endpoint = endpoint wsdl.namespace = namespace AdsCommon::Http.configure_httpi(@config, httpi) end client.config.raise_errors = false client.config.logger.subject = NoopLogger.new return client end
ruby
def create_savon_client(endpoint, namespace) client = GoogleAdsSavon::Client.new do |wsdl, httpi| wsdl.endpoint = endpoint wsdl.namespace = namespace AdsCommon::Http.configure_httpi(@config, httpi) end client.config.raise_errors = false client.config.logger.subject = NoopLogger.new return client end
[ "def", "create_savon_client", "(", "endpoint", ",", "namespace", ")", "client", "=", "GoogleAdsSavon", "::", "Client", ".", "new", "do", "|", "wsdl", ",", "httpi", "|", "wsdl", ".", "endpoint", "=", "endpoint", "wsdl", ".", "namespace", "=", "namespace", "...
Creates and sets up Savon client.
[ "Creates", "and", "sets", "up", "Savon", "client", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L66-L75
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.get_soap_xml
def get_soap_xml(action_name, args) registry = get_service_registry() validator = ParametersValidator.new(registry) args = validator.validate_args(action_name, args) return handle_soap_request( action_name.to_sym, true, args, validator.extra_namespaces) end
ruby
def get_soap_xml(action_name, args) registry = get_service_registry() validator = ParametersValidator.new(registry) args = validator.validate_args(action_name, args) return handle_soap_request( action_name.to_sym, true, args, validator.extra_namespaces) end
[ "def", "get_soap_xml", "(", "action_name", ",", "args", ")", "registry", "=", "get_service_registry", "(", ")", "validator", "=", "ParametersValidator", ".", "new", "(", "registry", ")", "args", "=", "validator", ".", "validate_args", "(", "action_name", ",", ...
Generates and returns SOAP XML for the specified action and args.
[ "Generates", "and", "returns", "SOAP", "XML", "for", "the", "specified", "action", "and", "args", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L78-L84
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.execute_action
def execute_action(action_name, args, &block) registry = get_service_registry() validator = ParametersValidator.new(registry) args = validator.validate_args(action_name, args) request_info, response = handle_soap_request( action_name.to_sym, false, args, validator.extra_namespaces) do_logging(action_name, request_info, response) handle_errors(response) extractor = ResultsExtractor.new(registry) result = extractor.extract_result(response, action_name, &block) run_user_block(extractor, response, result, &block) if block_given? return result end
ruby
def execute_action(action_name, args, &block) registry = get_service_registry() validator = ParametersValidator.new(registry) args = validator.validate_args(action_name, args) request_info, response = handle_soap_request( action_name.to_sym, false, args, validator.extra_namespaces) do_logging(action_name, request_info, response) handle_errors(response) extractor = ResultsExtractor.new(registry) result = extractor.extract_result(response, action_name, &block) run_user_block(extractor, response, result, &block) if block_given? return result end
[ "def", "execute_action", "(", "action_name", ",", "args", ",", "&", "block", ")", "registry", "=", "get_service_registry", "(", ")", "validator", "=", "ParametersValidator", ".", "new", "(", "registry", ")", "args", "=", "validator", ".", "validate_args", "(",...
Executes SOAP action specified as a string with given arguments.
[ "Executes", "SOAP", "action", "specified", "as", "a", "string", "with", "given", "arguments", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L87-L99
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.handle_soap_request
def handle_soap_request(action, xml_only, args, extra_namespaces) original_action_name = get_service_registry.get_method_signature(action)[:original_name] original_action_name = action if original_action_name.nil? request_info = nil response = @client.request(original_action_name) do |soap, wsdl, http| soap.body = args @header_handler.prepare_request(http, soap) soap.namespaces.merge!(extra_namespaces) unless extra_namespaces.nil? return soap.to_xml if xml_only request_info = RequestInfo.new(soap.to_xml, http.headers, http.url) end return request_info, response end
ruby
def handle_soap_request(action, xml_only, args, extra_namespaces) original_action_name = get_service_registry.get_method_signature(action)[:original_name] original_action_name = action if original_action_name.nil? request_info = nil response = @client.request(original_action_name) do |soap, wsdl, http| soap.body = args @header_handler.prepare_request(http, soap) soap.namespaces.merge!(extra_namespaces) unless extra_namespaces.nil? return soap.to_xml if xml_only request_info = RequestInfo.new(soap.to_xml, http.headers, http.url) end return request_info, response end
[ "def", "handle_soap_request", "(", "action", ",", "xml_only", ",", "args", ",", "extra_namespaces", ")", "original_action_name", "=", "get_service_registry", ".", "get_method_signature", "(", "action", ")", "[", ":original_name", "]", "original_action_name", "=", "act...
Executes the SOAP request with original SOAP name.
[ "Executes", "the", "SOAP", "request", "with", "original", "SOAP", "name", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L102-L115
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.handle_errors
def handle_errors(response) if response.soap_fault? exception = exception_for_soap_fault(response) raise exception end if response.http_error? raise AdsCommon::Errors::HttpError, "HTTP Error occurred: %s" % response.http_error end end
ruby
def handle_errors(response) if response.soap_fault? exception = exception_for_soap_fault(response) raise exception end if response.http_error? raise AdsCommon::Errors::HttpError, "HTTP Error occurred: %s" % response.http_error end end
[ "def", "handle_errors", "(", "response", ")", "if", "response", ".", "soap_fault?", "exception", "=", "exception_for_soap_fault", "(", "response", ")", "raise", "exception", "end", "if", "response", ".", "http_error?", "raise", "AdsCommon", "::", "Errors", "::", ...
Checks for errors in response and raises appropriate exception.
[ "Checks", "for", "errors", "in", "response", "and", "raises", "appropriate", "exception", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L118-L127
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.exception_for_soap_fault
def exception_for_soap_fault(response) begin fault = response[:fault] if fault[:detail] and fault[:detail][:api_exception_fault] exception_fault = fault[:detail][:api_exception_fault] exception_name = ( exception_fault[:application_exception_type] || FALLBACK_API_ERROR_EXCEPTION) exception_class = get_module().const_get(exception_name) return exception_class.new(exception_fault) elsif fault[:faultstring] fault_message = fault[:faultstring] return AdsCommon::Errors::ApiException.new( "Unknown exception with error: %s" % fault_message) else raise ArgumentError.new(fault.to_s) end rescue Exception => e return AdsCommon::Errors::ApiException.new( "Failed to resolve exception (%s), SOAP fault: %s" % [e.message, response.soap_fault]) end end
ruby
def exception_for_soap_fault(response) begin fault = response[:fault] if fault[:detail] and fault[:detail][:api_exception_fault] exception_fault = fault[:detail][:api_exception_fault] exception_name = ( exception_fault[:application_exception_type] || FALLBACK_API_ERROR_EXCEPTION) exception_class = get_module().const_get(exception_name) return exception_class.new(exception_fault) elsif fault[:faultstring] fault_message = fault[:faultstring] return AdsCommon::Errors::ApiException.new( "Unknown exception with error: %s" % fault_message) else raise ArgumentError.new(fault.to_s) end rescue Exception => e return AdsCommon::Errors::ApiException.new( "Failed to resolve exception (%s), SOAP fault: %s" % [e.message, response.soap_fault]) end end
[ "def", "exception_for_soap_fault", "(", "response", ")", "begin", "fault", "=", "response", "[", ":fault", "]", "if", "fault", "[", ":detail", "]", "and", "fault", "[", ":detail", "]", "[", ":api_exception_fault", "]", "exception_fault", "=", "fault", "[", "...
Finds an exception object for a given response.
[ "Finds", "an", "exception", "object", "for", "a", "given", "response", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L130-L152
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.run_user_block
def run_user_block(extractor, response, body, &block) header = extractor.extract_header_data(response) case block.arity when 1 then yield(header) when 2 then yield(header, body) else raise AdsCommon::Errors::ApiException, "Wrong number of block parameters: %d" % block.arity end return nil end
ruby
def run_user_block(extractor, response, body, &block) header = extractor.extract_header_data(response) case block.arity when 1 then yield(header) when 2 then yield(header, body) else raise AdsCommon::Errors::ApiException, "Wrong number of block parameters: %d" % block.arity end return nil end
[ "def", "run_user_block", "(", "extractor", ",", "response", ",", "body", ",", "&", "block", ")", "header", "=", "extractor", ".", "extract_header_data", "(", "response", ")", "case", "block", ".", "arity", "when", "1", "then", "yield", "(", "header", ")", ...
Yields to user-specified block with additional information such as headers.
[ "Yields", "to", "user", "-", "specified", "block", "with", "additional", "information", "such", "as", "headers", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L156-L166
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.do_logging
def do_logging(action, request, response) logger = get_logger() return unless should_log_summary(logger.level, response.soap_fault?) response_hash = response.hash soap_headers = {} begin soap_headers = response_hash[:envelope][:header][:response_header] rescue NoMethodError # If there are no headers, just ignore. We'll log what we know. end summary_message = ('ID: %s, URL: %s, Service: %s, Action: %s, Response ' + 'time: %sms, Request ID: %s') % [@header_handler.identifier, request.url, self.class.to_s.split("::").last, action, soap_headers[:response_time], soap_headers[:request_id]] if soap_headers[:operations] summary_message += ', Operations: %s' % soap_headers[:operations] end summary_message += ', Is fault: %s' % response.soap_fault? request_message = nil response_message = nil if should_log_payloads(logger.level, response.soap_fault?) request_message = 'Outgoing request: %s %s' % [format_headers(request.headers), sanitize_request(request.body)] response_message = 'Incoming response: %s %s' % [format_headers(response.http.headers), response.http.body] end if response.soap_fault? summary_message += ', Fault message: %s' % format_fault( response_hash[:envelope][:body][:fault][:faultstring]) logger.warn(summary_message) logger.info(request_message) unless request_message.nil? logger.info(response_message) unless response_message.nil? else logger.info(summary_message) logger.debug(request_message) unless request_message.nil? logger.debug(response_message) unless response_message.nil? end end
ruby
def do_logging(action, request, response) logger = get_logger() return unless should_log_summary(logger.level, response.soap_fault?) response_hash = response.hash soap_headers = {} begin soap_headers = response_hash[:envelope][:header][:response_header] rescue NoMethodError # If there are no headers, just ignore. We'll log what we know. end summary_message = ('ID: %s, URL: %s, Service: %s, Action: %s, Response ' + 'time: %sms, Request ID: %s') % [@header_handler.identifier, request.url, self.class.to_s.split("::").last, action, soap_headers[:response_time], soap_headers[:request_id]] if soap_headers[:operations] summary_message += ', Operations: %s' % soap_headers[:operations] end summary_message += ', Is fault: %s' % response.soap_fault? request_message = nil response_message = nil if should_log_payloads(logger.level, response.soap_fault?) request_message = 'Outgoing request: %s %s' % [format_headers(request.headers), sanitize_request(request.body)] response_message = 'Incoming response: %s %s' % [format_headers(response.http.headers), response.http.body] end if response.soap_fault? summary_message += ', Fault message: %s' % format_fault( response_hash[:envelope][:body][:fault][:faultstring]) logger.warn(summary_message) logger.info(request_message) unless request_message.nil? logger.info(response_message) unless response_message.nil? else logger.info(summary_message) logger.debug(request_message) unless request_message.nil? logger.debug(response_message) unless response_message.nil? end end
[ "def", "do_logging", "(", "action", ",", "request", ",", "response", ")", "logger", "=", "get_logger", "(", ")", "return", "unless", "should_log_summary", "(", "logger", ".", "level", ",", "response", ".", "soap_fault?", ")", "response_hash", "=", "response", ...
Log the request, response, and summary lines.
[ "Log", "the", "request", "response", "and", "summary", "lines", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L169-L212
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.format_headers
def format_headers(headers) return headers.map do |k, v| v = REDACTED_STR if k == 'Authorization' [k, v].join(': ') end.join(', ') end
ruby
def format_headers(headers) return headers.map do |k, v| v = REDACTED_STR if k == 'Authorization' [k, v].join(': ') end.join(', ') end
[ "def", "format_headers", "(", "headers", ")", "return", "headers", ".", "map", "do", "|", "k", ",", "v", "|", "v", "=", "REDACTED_STR", "if", "k", "==", "'Authorization'", "[", "k", ",", "v", "]", ".", "join", "(", "': '", ")", "end", ".", "join", ...
Format headers, redacting sensitive information.
[ "Format", "headers", "redacting", "sensitive", "information", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L215-L220
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.format_fault
def format_fault(message) if message.length > MAX_FAULT_LOG_LENGTH message = message[0, MAX_FAULT_LOG_LENGTH] end return message.gsub("\n", ' ') end
ruby
def format_fault(message) if message.length > MAX_FAULT_LOG_LENGTH message = message[0, MAX_FAULT_LOG_LENGTH] end return message.gsub("\n", ' ') end
[ "def", "format_fault", "(", "message", ")", "if", "message", ".", "length", ">", "MAX_FAULT_LOG_LENGTH", "message", "=", "message", "[", "0", ",", "MAX_FAULT_LOG_LENGTH", "]", "end", "return", "message", ".", "gsub", "(", "\"\\n\"", ",", "' '", ")", "end" ]
Format the fault message by capping length and removing newlines.
[ "Format", "the", "fault", "message", "by", "capping", "length", "and", "removing", "newlines", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L229-L234
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.should_log_summary
def should_log_summary(level, is_fault) # Fault summaries log at WARN. return level <= Logger::WARN if is_fault # Success summaries log at INFO. return level <= Logger::INFO end
ruby
def should_log_summary(level, is_fault) # Fault summaries log at WARN. return level <= Logger::WARN if is_fault # Success summaries log at INFO. return level <= Logger::INFO end
[ "def", "should_log_summary", "(", "level", ",", "is_fault", ")", "return", "level", "<=", "Logger", "::", "WARN", "if", "is_fault", "return", "level", "<=", "Logger", "::", "INFO", "end" ]
Check whether or not to log request summaries based on log level.
[ "Check", "whether", "or", "not", "to", "log", "request", "summaries", "based", "on", "log", "level", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L237-L242
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/savon_service.rb
AdsCommon.SavonService.should_log_payloads
def should_log_payloads(level, is_fault) # Fault payloads log at INFO. return level <= Logger::INFO if is_fault # Success payloads log at DEBUG. return level <= Logger::DEBUG end
ruby
def should_log_payloads(level, is_fault) # Fault payloads log at INFO. return level <= Logger::INFO if is_fault # Success payloads log at DEBUG. return level <= Logger::DEBUG end
[ "def", "should_log_payloads", "(", "level", ",", "is_fault", ")", "return", "level", "<=", "Logger", "::", "INFO", "if", "is_fault", "return", "level", "<=", "Logger", "::", "DEBUG", "end" ]
Check whether or not to log payloads based on log level.
[ "Check", "whether", "or", "not", "to", "log", "payloads", "based", "on", "log", "level", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/savon_service.rb#L245-L250
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.download_report_as_file
def download_report_as_file(report_definition, path, cid = nil) report_body = download_report(report_definition, cid) save_to_file(report_body, path) return nil end
ruby
def download_report_as_file(report_definition, path, cid = nil) report_body = download_report(report_definition, cid) save_to_file(report_body, path) return nil end
[ "def", "download_report_as_file", "(", "report_definition", ",", "path", ",", "cid", "=", "nil", ")", "report_body", "=", "download_report", "(", "report_definition", ",", "cid", ")", "save_to_file", "(", "report_body", ",", "path", ")", "return", "nil", "end" ]
Downloads a report and saves it to a file. Args: - report_definition: definition of the report in XML text or hash - path: path to save report to - cid: optional customer ID to run against Returns: - nil Raises: - AdwordsApi::Errors::InvalidReportDefinitionError if the report definition is invalid - AdwordsApi::Errors::ReportError if server-side error occurred
[ "Downloads", "a", "report", "and", "saves", "it", "to", "a", "file", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L74-L78
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.download_report_as_file_with_awql
def download_report_as_file_with_awql(report_query, format, path, cid = nil) report_body = download_report_with_awql(report_query, format, cid) save_to_file(report_body, path) return nil end
ruby
def download_report_as_file_with_awql(report_query, format, path, cid = nil) report_body = download_report_with_awql(report_query, format, cid) save_to_file(report_body, path) return nil end
[ "def", "download_report_as_file_with_awql", "(", "report_query", ",", "format", ",", "path", ",", "cid", "=", "nil", ")", "report_body", "=", "download_report_with_awql", "(", "report_query", ",", "format", ",", "cid", ")", "save_to_file", "(", "report_body", ",",...
Downloads a report with AWQL and saves it to a file. Args: - report_query: query for the report as string - format: format for the report as string - path: path to save report to - cid: optional customer ID to run report against Returns: - nil Raises: - AdwordsApi::Errors::ReportError if server-side error occurred
[ "Downloads", "a", "report", "with", "AWQL", "and", "saves", "it", "to", "a", "file", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L150-L154
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.download_report_as_stream_with_awql
def download_report_as_stream_with_awql( report_query, format, cid = nil, &block) return get_report_response_with_awql(report_query, format, cid, &block) end
ruby
def download_report_as_stream_with_awql( report_query, format, cid = nil, &block) return get_report_response_with_awql(report_query, format, cid, &block) end
[ "def", "download_report_as_stream_with_awql", "(", "report_query", ",", "format", ",", "cid", "=", "nil", ",", "&", "block", ")", "return", "get_report_response_with_awql", "(", "report_query", ",", "format", ",", "cid", ",", "&", "block", ")", "end" ]
Streams a report with AWQL as a string to the given block. This method will not do error checking on returned values. Args: - report_query: query for the report as string - format: format for the report as string - cid: optional customer ID to run report against Returns: - nil
[ "Streams", "a", "report", "with", "AWQL", "as", "a", "string", "to", "the", "given", "block", ".", "This", "method", "will", "not", "do", "error", "checking", "on", "returned", "values", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L167-L170
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.get_stream_helper_with_awql
def get_stream_helper_with_awql(report_query, format, cid = nil) return AdwordsApi::ReportStream.set_up_with_awql( self, report_query, format, cid) end
ruby
def get_stream_helper_with_awql(report_query, format, cid = nil) return AdwordsApi::ReportStream.set_up_with_awql( self, report_query, format, cid) end
[ "def", "get_stream_helper_with_awql", "(", "report_query", ",", "format", ",", "cid", "=", "nil", ")", "return", "AdwordsApi", "::", "ReportStream", ".", "set_up_with_awql", "(", "self", ",", "report_query", ",", "format", ",", "cid", ")", "end" ]
Returns a helper object that can manage breaking the streamed report results into individual lines. Args: - report_query: query for the report as string - format: format for the report as string - cid: optional customer ID to run report against Returns: - ReportStream object initialized to begin streaming.
[ "Returns", "a", "helper", "object", "that", "can", "manage", "breaking", "the", "streamed", "report", "results", "into", "individual", "lines", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L183-L186
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.get_report_response
def get_report_response(report_definition, cid, &block) definition_text = get_report_definition_text(report_definition) data = '__rdxml=%s' % CGI.escape(definition_text) return make_adhoc_request(data, cid, &block) end
ruby
def get_report_response(report_definition, cid, &block) definition_text = get_report_definition_text(report_definition) data = '__rdxml=%s' % CGI.escape(definition_text) return make_adhoc_request(data, cid, &block) end
[ "def", "get_report_response", "(", "report_definition", ",", "cid", ",", "&", "block", ")", "definition_text", "=", "get_report_definition_text", "(", "report_definition", ")", "data", "=", "'__rdxml=%s'", "%", "CGI", ".", "escape", "(", "definition_text", ")", "r...
Send POST request for a report and returns Response object.
[ "Send", "POST", "request", "for", "a", "report", "and", "returns", "Response", "object", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L206-L210
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.get_report_response_with_awql
def get_report_response_with_awql(report_query, format, cid, &block) data = '__rdquery=%s&__fmt=%s' % [CGI.escape(report_query), CGI.escape(format)] return make_adhoc_request(data, cid, &block) end
ruby
def get_report_response_with_awql(report_query, format, cid, &block) data = '__rdquery=%s&__fmt=%s' % [CGI.escape(report_query), CGI.escape(format)] return make_adhoc_request(data, cid, &block) end
[ "def", "get_report_response_with_awql", "(", "report_query", ",", "format", ",", "cid", ",", "&", "block", ")", "data", "=", "'__rdquery=%s&__fmt=%s'", "%", "[", "CGI", ".", "escape", "(", "report_query", ")", ",", "CGI", ".", "escape", "(", "format", ")", ...
Send POST request for a report with AWQL and returns Response object.
[ "Send", "POST", "request", "for", "a", "report", "with", "AWQL", "and", "returns", "Response", "object", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L213-L217
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.make_adhoc_request
def make_adhoc_request(data, cid, &block) @api.utils_reporter.report_utils_used() url = @api.api_config.adhoc_report_download_url(@version) headers = get_report_request_headers(url, cid) log_request(url, headers, data) # A given block indicates that we should make a stream request and yield # the results, rather than return a full response. if block_given? AdsCommon::Http.post_stream(url, data, @api.config, headers, &block) return nil else response = AdsCommon::Http.post_response( url, data, @api.config, headers) log_headers(response.headers) check_for_errors(response) return response end end
ruby
def make_adhoc_request(data, cid, &block) @api.utils_reporter.report_utils_used() url = @api.api_config.adhoc_report_download_url(@version) headers = get_report_request_headers(url, cid) log_request(url, headers, data) # A given block indicates that we should make a stream request and yield # the results, rather than return a full response. if block_given? AdsCommon::Http.post_stream(url, data, @api.config, headers, &block) return nil else response = AdsCommon::Http.post_response( url, data, @api.config, headers) log_headers(response.headers) check_for_errors(response) return response end end
[ "def", "make_adhoc_request", "(", "data", ",", "cid", ",", "&", "block", ")", "@api", ".", "utils_reporter", ".", "report_utils_used", "(", ")", "url", "=", "@api", ".", "api_config", ".", "adhoc_report_download_url", "(", "@version", ")", "headers", "=", "g...
Makes request and AdHoc service and returns response.
[ "Makes", "request", "and", "AdHoc", "service", "and", "returns", "response", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L220-L237
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.get_report_request_headers
def get_report_request_headers(url, cid) @header_handler ||= AdwordsApi::ReportHeaderHandler.new( @api.credential_handler, @api.get_auth_handler(), @api.config) return @header_handler.headers(url, cid) end
ruby
def get_report_request_headers(url, cid) @header_handler ||= AdwordsApi::ReportHeaderHandler.new( @api.credential_handler, @api.get_auth_handler(), @api.config) return @header_handler.headers(url, cid) end
[ "def", "get_report_request_headers", "(", "url", ",", "cid", ")", "@header_handler", "||=", "AdwordsApi", "::", "ReportHeaderHandler", ".", "new", "(", "@api", ".", "credential_handler", ",", "@api", ".", "get_auth_handler", "(", ")", ",", "@api", ".", "config",...
Prepares headers for report request.
[ "Prepares", "headers", "for", "report", "request", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L253-L257
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.save_to_file
def save_to_file(data, path) open(path, 'wb') { |file| file.write(data) } if path end
ruby
def save_to_file(data, path) open(path, 'wb') { |file| file.write(data) } if path end
[ "def", "save_to_file", "(", "data", ",", "path", ")", "open", "(", "path", ",", "'wb'", ")", "{", "|", "file", "|", "file", ".", "write", "(", "data", ")", "}", "if", "path", "end" ]
Saves raw data to a file.
[ "Saves", "raw", "data", "to", "a", "file", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L260-L262
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.log_headers
def log_headers(headers) @api.logger.debug('HTTP headers: [%s]' % (headers.map { |k, v| [k, v].join(': ') }.join(', '))) end
ruby
def log_headers(headers) @api.logger.debug('HTTP headers: [%s]' % (headers.map { |k, v| [k, v].join(': ') }.join(', '))) end
[ "def", "log_headers", "(", "headers", ")", "@api", ".", "logger", ".", "debug", "(", "'HTTP headers: [%s]'", "%", "(", "headers", ".", "map", "{", "|", "k", ",", "v", "|", "[", "k", ",", "v", "]", ".", "join", "(", "': '", ")", "}", ".", "join", ...
Logs HTTP headers on debug level.
[ "Logs", "HTTP", "headers", "on", "debug", "level", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L272-L275
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.check_for_errors
def check_for_errors(response) # Check for error code. if response.code != 200 # Check for error in body. report_body = response.body check_for_xml_error(report_body, response.code) # No XML error found nor raised, falling back to a default message. raise AdwordsApi::Errors::ReportError.new(response.code, 'HTTP code: %d, body: %s' % [response.code, response.body]) end return nil end
ruby
def check_for_errors(response) # Check for error code. if response.code != 200 # Check for error in body. report_body = response.body check_for_xml_error(report_body, response.code) # No XML error found nor raised, falling back to a default message. raise AdwordsApi::Errors::ReportError.new(response.code, 'HTTP code: %d, body: %s' % [response.code, response.body]) end return nil end
[ "def", "check_for_errors", "(", "response", ")", "if", "response", ".", "code", "!=", "200", "report_body", "=", "response", ".", "body", "check_for_xml_error", "(", "report_body", ",", "response", ".", "code", ")", "raise", "AdwordsApi", "::", "Errors", "::",...
Checks downloaded data for error signature. Raises ReportError if it detects an error.
[ "Checks", "downloaded", "data", "for", "error", "signature", ".", "Raises", "ReportError", "if", "it", "detects", "an", "error", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L279-L290
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.check_for_xml_error
def check_for_xml_error(report_body, response_code) unless report_body.nil? error_response = get_nori().parse(report_body) if error_response.include?(:report_download_error) and error_response[:report_download_error].include?(:api_error) api_error = error_response[:report_download_error][:api_error] raise AdwordsApi::Errors::ReportXmlError.new(response_code, api_error[:type], api_error[:trigger], api_error[:field_path]) end end end
ruby
def check_for_xml_error(report_body, response_code) unless report_body.nil? error_response = get_nori().parse(report_body) if error_response.include?(:report_download_error) and error_response[:report_download_error].include?(:api_error) api_error = error_response[:report_download_error][:api_error] raise AdwordsApi::Errors::ReportXmlError.new(response_code, api_error[:type], api_error[:trigger], api_error[:field_path]) end end end
[ "def", "check_for_xml_error", "(", "report_body", ",", "response_code", ")", "unless", "report_body", ".", "nil?", "error_response", "=", "get_nori", "(", ")", ".", "parse", "(", "report_body", ")", "if", "error_response", ".", "include?", "(", ":report_download_e...
Checks for an XML error in the response body and raises an exception if it was found.
[ "Checks", "for", "an", "XML", "error", "in", "the", "response", "body", "and", "raises", "an", "exception", "if", "it", "was", "found", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L294-L304
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.report_definition_to_xml
def report_definition_to_xml(report_definition) check_report_definition_hash(report_definition) add_report_definition_hash_order(report_definition) begin return Gyoku.xml({:report_definition => report_definition}) rescue ArgumentError => e if e.message.include?("order!") unknown_fields = e.message.slice(e.message.index('['), e.message.length) raise AdwordsApi::Errors::InvalidReportDefinitionError, "Unknown report definition field(s): %s" % unknown_fields end raise e end end
ruby
def report_definition_to_xml(report_definition) check_report_definition_hash(report_definition) add_report_definition_hash_order(report_definition) begin return Gyoku.xml({:report_definition => report_definition}) rescue ArgumentError => e if e.message.include?("order!") unknown_fields = e.message.slice(e.message.index('['), e.message.length) raise AdwordsApi::Errors::InvalidReportDefinitionError, "Unknown report definition field(s): %s" % unknown_fields end raise e end end
[ "def", "report_definition_to_xml", "(", "report_definition", ")", "check_report_definition_hash", "(", "report_definition", ")", "add_report_definition_hash_order", "(", "report_definition", ")", "begin", "return", "Gyoku", ".", "xml", "(", "{", ":report_definition", "=>", ...
Renders a report definition hash into XML text.
[ "Renders", "a", "report", "definition", "hash", "into", "XML", "text", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L307-L321
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.check_report_definition_hash
def check_report_definition_hash(report_definition) # Minimal set of fields required. REQUIRED_FIELDS.each do |field| unless report_definition.include?(field) raise AdwordsApi::Errors::InvalidReportDefinitionError, "Required field '%s' is missing in the definition" % field end end # Fields list is also required. unless report_definition[:selector].include?(:fields) raise AdwordsApi::Errors::InvalidReportDefinitionError, 'Fields list is required' end # 'Fields' must be an Array. unless report_definition[:selector][:fields].kind_of?(Array) raise AdwordsApi::Errors::InvalidReportDefinitionError, 'Fields list must be an array' end # We should request at least one field. if report_definition[:selector][:fields].empty? raise AdwordsApi::Errors::InvalidReportDefinitionError, 'At least one field needs to be requested' end end
ruby
def check_report_definition_hash(report_definition) # Minimal set of fields required. REQUIRED_FIELDS.each do |field| unless report_definition.include?(field) raise AdwordsApi::Errors::InvalidReportDefinitionError, "Required field '%s' is missing in the definition" % field end end # Fields list is also required. unless report_definition[:selector].include?(:fields) raise AdwordsApi::Errors::InvalidReportDefinitionError, 'Fields list is required' end # 'Fields' must be an Array. unless report_definition[:selector][:fields].kind_of?(Array) raise AdwordsApi::Errors::InvalidReportDefinitionError, 'Fields list must be an array' end # We should request at least one field. if report_definition[:selector][:fields].empty? raise AdwordsApi::Errors::InvalidReportDefinitionError, 'At least one field needs to be requested' end end
[ "def", "check_report_definition_hash", "(", "report_definition", ")", "REQUIRED_FIELDS", ".", "each", "do", "|", "field", "|", "unless", "report_definition", ".", "include?", "(", "field", ")", "raise", "AdwordsApi", "::", "Errors", "::", "InvalidReportDefinitionError...
Checks if the report definition looks correct.
[ "Checks", "if", "the", "report", "definition", "looks", "correct", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L324-L347
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_utils.rb
AdwordsApi.ReportUtils.add_report_definition_hash_order
def add_report_definition_hash_order(node, name = :root) def_order = REPORT_DEFINITION_ORDER[name] var_order = def_order.reject { |field| !node.include?(field) } node.keys.each do |key| if REPORT_DEFINITION_ORDER.include?(key) case node[key] when Hash add_report_definition_hash_order(node[key], key) when Array node[key].each do |item| add_report_definition_hash_order(item, key) end end end end node[:order!] = var_order return nil end
ruby
def add_report_definition_hash_order(node, name = :root) def_order = REPORT_DEFINITION_ORDER[name] var_order = def_order.reject { |field| !node.include?(field) } node.keys.each do |key| if REPORT_DEFINITION_ORDER.include?(key) case node[key] when Hash add_report_definition_hash_order(node[key], key) when Array node[key].each do |item| add_report_definition_hash_order(item, key) end end end end node[:order!] = var_order return nil end
[ "def", "add_report_definition_hash_order", "(", "node", ",", "name", "=", ":root", ")", "def_order", "=", "REPORT_DEFINITION_ORDER", "[", "name", "]", "var_order", "=", "def_order", ".", "reject", "{", "|", "field", "|", "!", "node", ".", "include?", "(", "f...
Adds fields order hint to generator based on specification.
[ "Adds", "fields", "order", "hint", "to", "generator", "based", "on", "specification", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_utils.rb#L350-L367
valid
googleads/google-api-ads-ruby
adwords_api/lib/adwords_api/report_header_handler.rb
AdwordsApi.ReportHeaderHandler.headers
def headers(url, cid) override = (cid.nil?) ? nil : {:client_customer_id => cid} credentials = @credential_handler.credentials(override) headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => @auth_handler.auth_string(credentials), 'User-Agent' => @credential_handler.generate_user_agent(), 'clientCustomerId' => credentials[:client_customer_id].to_s, 'developerToken' => credentials[:developer_token] } skip_report_header = @config.read('library.skip_report_header') unless skip_report_header.nil? headers['skipReportHeader'] = skip_report_header.to_s end skip_report_summary = @config.read('library.skip_report_summary') unless skip_report_summary.nil? headers['skipReportSummary'] = skip_report_summary.to_s end skip_column_header = @config.read('library.skip_column_header') unless skip_column_header.nil? headers['skipColumnHeader'] = skip_column_header.to_s end include_zero_impressions = @config.read('library.include_zero_impressions') unless include_zero_impressions.nil? headers['includeZeroImpressions'] = include_zero_impressions.to_s end use_raw_enum_values = @config.read('library.use_raw_enum_values') unless use_raw_enum_values.nil? headers['useRawEnumValues'] = use_raw_enum_values.to_s end return headers end
ruby
def headers(url, cid) override = (cid.nil?) ? nil : {:client_customer_id => cid} credentials = @credential_handler.credentials(override) headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => @auth_handler.auth_string(credentials), 'User-Agent' => @credential_handler.generate_user_agent(), 'clientCustomerId' => credentials[:client_customer_id].to_s, 'developerToken' => credentials[:developer_token] } skip_report_header = @config.read('library.skip_report_header') unless skip_report_header.nil? headers['skipReportHeader'] = skip_report_header.to_s end skip_report_summary = @config.read('library.skip_report_summary') unless skip_report_summary.nil? headers['skipReportSummary'] = skip_report_summary.to_s end skip_column_header = @config.read('library.skip_column_header') unless skip_column_header.nil? headers['skipColumnHeader'] = skip_column_header.to_s end include_zero_impressions = @config.read('library.include_zero_impressions') unless include_zero_impressions.nil? headers['includeZeroImpressions'] = include_zero_impressions.to_s end use_raw_enum_values = @config.read('library.use_raw_enum_values') unless use_raw_enum_values.nil? headers['useRawEnumValues'] = use_raw_enum_values.to_s end return headers end
[ "def", "headers", "(", "url", ",", "cid", ")", "override", "=", "(", "cid", ".", "nil?", ")", "?", "nil", ":", "{", ":client_customer_id", "=>", "cid", "}", "credentials", "=", "@credential_handler", ".", "credentials", "(", "override", ")", "headers", "...
Initializes a header handler. Args: - credential_handler: a header with credential data - auth_handler: a header with auth data - config: API config Returns the headers set for the report request. Args: - url: URL for the report requests - cid: clientCustomerId to use Returns: - a Hash with HTTP headers.
[ "Initializes", "a", "header", "handler", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/adwords_api/lib/adwords_api/report_header_handler.rb#L45-L78
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/credential_handler.rb
AdsCommon.CredentialHandler.credentials
def credentials(credentials_override = nil) credentials = @credentials.dup() credentials.merge!(credentials_override) unless credentials_override.nil? return credentials end
ruby
def credentials(credentials_override = nil) credentials = @credentials.dup() credentials.merge!(credentials_override) unless credentials_override.nil? return credentials end
[ "def", "credentials", "(", "credentials_override", "=", "nil", ")", "credentials", "=", "@credentials", ".", "dup", "(", ")", "credentials", ".", "merge!", "(", "credentials_override", ")", "unless", "credentials_override", ".", "nil?", "return", "credentials", "e...
Initializes CredentialHandler. Returns credentials set for the next call.
[ "Initializes", "CredentialHandler", ".", "Returns", "credentials", "set", "for", "the", "next", "call", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/credential_handler.rb#L36-L40
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/credential_handler.rb
AdsCommon.CredentialHandler.credentials=
def credentials=(new_credentials) # Find new and changed properties. diff = new_credentials.inject([]) do |result, (key, value)| result << [key, value] if value != @credentials[key] result end # Find removed properties. diff = @credentials.inject(diff) do |result, (key, _)| result << [key, nil] unless new_credentials.include?(key) result end # Set each property. diff.each { |entry| set_credential(entry[0], entry[1]) } return nil end
ruby
def credentials=(new_credentials) # Find new and changed properties. diff = new_credentials.inject([]) do |result, (key, value)| result << [key, value] if value != @credentials[key] result end # Find removed properties. diff = @credentials.inject(diff) do |result, (key, _)| result << [key, nil] unless new_credentials.include?(key) result end # Set each property. diff.each { |entry| set_credential(entry[0], entry[1]) } return nil end
[ "def", "credentials", "=", "(", "new_credentials", ")", "diff", "=", "new_credentials", ".", "inject", "(", "[", "]", ")", "do", "|", "result", ",", "(", "key", ",", "value", ")", "|", "result", "<<", "[", "key", ",", "value", "]", "if", "value", "...
Set the credentials hash to a new one. Calculate difference, and call the AuthHandler callback appropriately.
[ "Set", "the", "credentials", "hash", "to", "a", "new", "one", ".", "Calculate", "difference", "and", "call", "the", "AuthHandler", "callback", "appropriately", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/credential_handler.rb#L44-L61
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/credential_handler.rb
AdsCommon.CredentialHandler.generate_user_agent
def generate_user_agent(extra_ids = [], agent_app = nil) agent_app ||= File.basename($0) agent_data = extra_ids agent_data << 'Common-Ruby/%s' % AdsCommon::ApiConfig::CLIENT_LIB_VERSION agent_data << 'GoogleAdsSavon/%s' % GoogleAdsSavon::VERSION ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' agent_data << [ruby_engine, RUBY_VERSION].join('/') agent_data << 'HTTPI/%s' % HTTPI::VERSION agent_data << HTTPI::Adapter.use.to_s agent_data += get_extra_user_agents() return '%s (%s)' % [agent_app, agent_data.join(', ')] end
ruby
def generate_user_agent(extra_ids = [], agent_app = nil) agent_app ||= File.basename($0) agent_data = extra_ids agent_data << 'Common-Ruby/%s' % AdsCommon::ApiConfig::CLIENT_LIB_VERSION agent_data << 'GoogleAdsSavon/%s' % GoogleAdsSavon::VERSION ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' agent_data << [ruby_engine, RUBY_VERSION].join('/') agent_data << 'HTTPI/%s' % HTTPI::VERSION agent_data << HTTPI::Adapter.use.to_s agent_data += get_extra_user_agents() return '%s (%s)' % [agent_app, agent_data.join(', ')] end
[ "def", "generate_user_agent", "(", "extra_ids", "=", "[", "]", ",", "agent_app", "=", "nil", ")", "agent_app", "||=", "File", ".", "basename", "(", "$0", ")", "agent_data", "=", "extra_ids", "agent_data", "<<", "'Common-Ruby/%s'", "%", "AdsCommon", "::", "Ap...
Generates string for UserAgent to put into headers.
[ "Generates", "string", "for", "UserAgent", "to", "put", "into", "headers", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/credential_handler.rb#L83-L94
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/credential_handler.rb
AdsCommon.CredentialHandler.get_extra_user_agents
def get_extra_user_agents() @extra_user_agents_lock.synchronize do user_agents = @extra_user_agents.collect do |k, v| v.nil? ? k : '%s/%s' % [k, v] end @extra_user_agents.clear return user_agents end end
ruby
def get_extra_user_agents() @extra_user_agents_lock.synchronize do user_agents = @extra_user_agents.collect do |k, v| v.nil? ? k : '%s/%s' % [k, v] end @extra_user_agents.clear return user_agents end end
[ "def", "get_extra_user_agents", "(", ")", "@extra_user_agents_lock", ".", "synchronize", "do", "user_agents", "=", "@extra_user_agents", ".", "collect", "do", "|", "k", ",", "v", "|", "v", ".", "nil?", "?", "k", ":", "'%s/%s'", "%", "[", "k", ",", "v", "...
Generates an array of extra user agents to include in the user agent string.
[ "Generates", "an", "array", "of", "extra", "user", "agents", "to", "include", "in", "the", "user", "agent", "string", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/credential_handler.rb#L116-L124
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.extract_header_data
def extract_header_data(response) header_type = get_full_type_signature(:SoapResponseHeader) headers = response.header[:response_header].dup process_attributes(headers, false) headers = normalize_fields(headers, header_type[:fields]) return headers end
ruby
def extract_header_data(response) header_type = get_full_type_signature(:SoapResponseHeader) headers = response.header[:response_header].dup process_attributes(headers, false) headers = normalize_fields(headers, header_type[:fields]) return headers end
[ "def", "extract_header_data", "(", "response", ")", "header_type", "=", "get_full_type_signature", "(", ":SoapResponseHeader", ")", "headers", "=", "response", ".", "header", "[", ":response_header", "]", ".", "dup", "process_attributes", "(", "headers", ",", "false...
Extracts misc data from response header.
[ "Extracts", "misc", "data", "from", "response", "header", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L44-L50
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.extract_exception_data
def extract_exception_data(soap_fault, exception_name) exception_type = get_full_type_signature(exception_name) process_attributes(soap_fault, false) soap_fault = normalize_fields(soap_fault, exception_type[:fields]) return soap_fault end
ruby
def extract_exception_data(soap_fault, exception_name) exception_type = get_full_type_signature(exception_name) process_attributes(soap_fault, false) soap_fault = normalize_fields(soap_fault, exception_type[:fields]) return soap_fault end
[ "def", "extract_exception_data", "(", "soap_fault", ",", "exception_name", ")", "exception_type", "=", "get_full_type_signature", "(", "exception_name", ")", "process_attributes", "(", "soap_fault", ",", "false", ")", "soap_fault", "=", "normalize_fields", "(", "soap_fa...
Extracts misc data from SOAP fault.
[ "Extracts", "misc", "data", "from", "SOAP", "fault", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L53-L58
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.normalize_fields
def normalize_fields(data, fields) fields.each do |field| field_name = field[:name] if data.include?(field_name) field_data = data[field_name] field_data = normalize_output_field(field_data, field) field_data = check_array_collapse(field_data, field) data[field_name] = field_data unless field_data.nil? end end return data end
ruby
def normalize_fields(data, fields) fields.each do |field| field_name = field[:name] if data.include?(field_name) field_data = data[field_name] field_data = normalize_output_field(field_data, field) field_data = check_array_collapse(field_data, field) data[field_name] = field_data unless field_data.nil? end end return data end
[ "def", "normalize_fields", "(", "data", ",", "fields", ")", "fields", ".", "each", "do", "|", "field", "|", "field_name", "=", "field", "[", ":name", "]", "if", "data", ".", "include?", "(", "field_name", ")", "field_data", "=", "data", "[", "field_name"...
Normalizes all fields for the given data based on the fields list provided.
[ "Normalizes", "all", "fields", "for", "the", "given", "data", "based", "on", "the", "fields", "list", "provided", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L70-L81
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.normalize_output_field
def normalize_output_field(field_data, field_def) return case field_data when Array normalize_array_field(field_data, field_def) when Hash normalize_hash_field(field_data, field_def) else normalize_item(field_data, field_def) end end
ruby
def normalize_output_field(field_data, field_def) return case field_data when Array normalize_array_field(field_data, field_def) when Hash normalize_hash_field(field_data, field_def) else normalize_item(field_data, field_def) end end
[ "def", "normalize_output_field", "(", "field_data", ",", "field_def", ")", "return", "case", "field_data", "when", "Array", "normalize_array_field", "(", "field_data", ",", "field_def", ")", "when", "Hash", "normalize_hash_field", "(", "field_data", ",", "field_def", ...
Normalizes one field of a given data recursively. Args: - field_data: XML data to normalize - field_def: field type definition for the data
[ "Normalizes", "one", "field", "of", "a", "given", "data", "recursively", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L89-L98
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.normalize_array_field
def normalize_array_field(data, field_def) result = data # Convert a specific structure to a handy hash if detected. if check_key_value_struct(result) result = convert_key_value_to_hash(result).inject({}) do |s, (k,v)| s[k] = normalize_output_field(v, field_def) s end else result = data.map {|item| normalize_output_field(item, field_def)} end return result end
ruby
def normalize_array_field(data, field_def) result = data # Convert a specific structure to a handy hash if detected. if check_key_value_struct(result) result = convert_key_value_to_hash(result).inject({}) do |s, (k,v)| s[k] = normalize_output_field(v, field_def) s end else result = data.map {|item| normalize_output_field(item, field_def)} end return result end
[ "def", "normalize_array_field", "(", "data", ",", "field_def", ")", "result", "=", "data", "if", "check_key_value_struct", "(", "result", ")", "result", "=", "convert_key_value_to_hash", "(", "result", ")", ".", "inject", "(", "{", "}", ")", "do", "|", "s", ...
Normalizes every item of an Array.
[ "Normalizes", "every", "item", "of", "an", "Array", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L101-L113
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.normalize_hash_field
def normalize_hash_field(field, field_def) process_attributes(field, true) field_type = field_def[:type] field_def = get_full_type_signature(field_type) # First checking for xsi:type provided. xsi_type_override = determine_xsi_type_override(field, field_def) unless xsi_type_override.nil? field_def = get_full_type_signature(xsi_type_override) return (field_def.nil?) ? field : normalize_fields(field, field_def[:fields]) end result = field # Now checking for choice options from wsdl. choice_type_override = determine_choice_type_override(field, field_def) unless choice_type_override.nil? # For overrides we need to process sub-field and than return it # in the original structure. field_key = field.keys.first field_data = field[field_key] field_def = get_full_type_signature(choice_type_override) if !field_def.nil? and field_data.kind_of?(Hash) field_data = normalize_fields(field_data, field_def[:fields]) end result = {field_key => field_data} else # Otherwise using the best we have. unless field_def.nil? result = normalize_fields(field, field_def[:fields]) end end # Convert a single key-value hash to a proper hash if detected. if check_key_value_struct(result) result = convert_key_value_to_hash(result) end return result end
ruby
def normalize_hash_field(field, field_def) process_attributes(field, true) field_type = field_def[:type] field_def = get_full_type_signature(field_type) # First checking for xsi:type provided. xsi_type_override = determine_xsi_type_override(field, field_def) unless xsi_type_override.nil? field_def = get_full_type_signature(xsi_type_override) return (field_def.nil?) ? field : normalize_fields(field, field_def[:fields]) end result = field # Now checking for choice options from wsdl. choice_type_override = determine_choice_type_override(field, field_def) unless choice_type_override.nil? # For overrides we need to process sub-field and than return it # in the original structure. field_key = field.keys.first field_data = field[field_key] field_def = get_full_type_signature(choice_type_override) if !field_def.nil? and field_data.kind_of?(Hash) field_data = normalize_fields(field_data, field_def[:fields]) end result = {field_key => field_data} else # Otherwise using the best we have. unless field_def.nil? result = normalize_fields(field, field_def[:fields]) end end # Convert a single key-value hash to a proper hash if detected. if check_key_value_struct(result) result = convert_key_value_to_hash(result) end return result end
[ "def", "normalize_hash_field", "(", "field", ",", "field_def", ")", "process_attributes", "(", "field", ",", "true", ")", "field_type", "=", "field_def", "[", ":type", "]", "field_def", "=", "get_full_type_signature", "(", "field_type", ")", "xsi_type_override", "...
Normalizes every item of a Hash.
[ "Normalizes", "every", "item", "of", "a", "Hash", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L116-L156
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.determine_choice_type_override
def determine_choice_type_override(field_data, field_def) result = nil if field_data.kind_of?(Hash) and field_def.include?(:choices) result = determine_choice(field_data, field_def[:choices]) end return result end
ruby
def determine_choice_type_override(field_data, field_def) result = nil if field_data.kind_of?(Hash) and field_def.include?(:choices) result = determine_choice(field_data, field_def[:choices]) end return result end
[ "def", "determine_choice_type_override", "(", "field_data", ",", "field_def", ")", "result", "=", "nil", "if", "field_data", ".", "kind_of?", "(", "Hash", ")", "and", "field_def", ".", "include?", "(", ":choices", ")", "result", "=", "determine_choice", "(", "...
Determines a choice type override for for the field. Returns nil if no override found.
[ "Determines", "a", "choice", "type", "override", "for", "for", "the", "field", ".", "Returns", "nil", "if", "no", "override", "found", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L204-L210
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.determine_choice
def determine_choice(field_data, field_choices) result = nil key_name = field_data.keys.first unless key_name.nil? choice = find_named_entry(field_choices, key_name) result = choice[:type] unless choice.nil? end return result end
ruby
def determine_choice(field_data, field_choices) result = nil key_name = field_data.keys.first unless key_name.nil? choice = find_named_entry(field_choices, key_name) result = choice[:type] unless choice.nil? end return result end
[ "def", "determine_choice", "(", "field_data", ",", "field_choices", ")", "result", "=", "nil", "key_name", "=", "field_data", ".", "keys", ".", "first", "unless", "key_name", ".", "nil?", "choice", "=", "find_named_entry", "(", "field_choices", ",", "key_name", ...
Finds the choice option matching data provided.
[ "Finds", "the", "choice", "option", "matching", "data", "provided", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L213-L221
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.normalize_item
def normalize_item(item, field_def) return case field_def[:type] when 'long', 'int' then Integer(item) when 'double', 'float' then Float(item) when 'boolean' then item.kind_of?(String) ? item.casecmp('true') == 0 : item else item end end
ruby
def normalize_item(item, field_def) return case field_def[:type] when 'long', 'int' then Integer(item) when 'double', 'float' then Float(item) when 'boolean' then item.kind_of?(String) ? item.casecmp('true') == 0 : item else item end end
[ "def", "normalize_item", "(", "item", ",", "field_def", ")", "return", "case", "field_def", "[", ":type", "]", "when", "'long'", ",", "'int'", "then", "Integer", "(", "item", ")", "when", "'double'", ",", "'float'", "then", "Float", "(", "item", ")", "wh...
Converts one leaf item to a built-in type.
[ "Converts", "one", "leaf", "item", "to", "a", "built", "-", "in", "type", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L230-L238
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.check_array_collapse
def check_array_collapse(data, field_def) result = data if !field_def[:min_occurs].nil? && (field_def[:max_occurs] == :unbounded || (!field_def[:max_occurs].nil? && field_def[:max_occurs] > 1)) && !(field_def[:type] =~ /MapEntry$/) result = arrayize(result) end return result end
ruby
def check_array_collapse(data, field_def) result = data if !field_def[:min_occurs].nil? && (field_def[:max_occurs] == :unbounded || (!field_def[:max_occurs].nil? && field_def[:max_occurs] > 1)) && !(field_def[:type] =~ /MapEntry$/) result = arrayize(result) end return result end
[ "def", "check_array_collapse", "(", "data", ",", "field_def", ")", "result", "=", "data", "if", "!", "field_def", "[", ":min_occurs", "]", ".", "nil?", "&&", "(", "field_def", "[", ":max_occurs", "]", "==", ":unbounded", "||", "(", "!", "field_def", "[", ...
Checks if the field signature allows an array and forces array structure even for a signle item.
[ "Checks", "if", "the", "field", "signature", "allows", "an", "array", "and", "forces", "array", "structure", "even", "for", "a", "signle", "item", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L242-L251
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/results_extractor.rb
AdsCommon.ResultsExtractor.process_attributes
def process_attributes(data, keep_xsi_type = false) if keep_xsi_type xsi_type = data.delete(:"@xsi:type") data[:xsi_type] = xsi_type if xsi_type end data.reject! {|key, value| key.to_s.start_with?('@')} end
ruby
def process_attributes(data, keep_xsi_type = false) if keep_xsi_type xsi_type = data.delete(:"@xsi:type") data[:xsi_type] = xsi_type if xsi_type end data.reject! {|key, value| key.to_s.start_with?('@')} end
[ "def", "process_attributes", "(", "data", ",", "keep_xsi_type", "=", "false", ")", "if", "keep_xsi_type", "xsi_type", "=", "data", ".", "delete", "(", ":\"", "\"", ")", "data", "[", ":xsi_type", "]", "=", "xsi_type", "if", "xsi_type", "end", "data", ".", ...
Handles attributes received from Savon.
[ "Handles", "attributes", "received", "from", "Savon", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/results_extractor.rb#L282-L288
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.service
def service(name, version = nil) name = name.to_sym version = (version.nil?) ? api_config.default_version : version.to_sym # Check if the combination is available. validate_service_request(version, name) # Try to re-use the service for this version if it was requested before. wrapper = if @wrappers.include?(version) && @wrappers[version][name] @wrappers[version][name] else @wrappers[version] ||= {} @wrappers[version][name] = prepare_wrapper(version, name) end return wrapper end
ruby
def service(name, version = nil) name = name.to_sym version = (version.nil?) ? api_config.default_version : version.to_sym # Check if the combination is available. validate_service_request(version, name) # Try to re-use the service for this version if it was requested before. wrapper = if @wrappers.include?(version) && @wrappers[version][name] @wrappers[version][name] else @wrappers[version] ||= {} @wrappers[version][name] = prepare_wrapper(version, name) end return wrapper end
[ "def", "service", "(", "name", ",", "version", "=", "nil", ")", "name", "=", "name", ".", "to_sym", "version", "=", "(", "version", ".", "nil?", ")", "?", "api_config", ".", "default_version", ":", "version", ".", "to_sym", "validate_service_request", "(",...
Obtain an API service, given a version and its name. Args: - name: name for the intended service - version: intended API version. Returns: - the service wrapper for the intended service.
[ "Obtain", "an", "API", "service", "given", "a", "version", "and", "its", "name", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L70-L85
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.authorize
def authorize(parameters = {}, &block) parameters.each_pair do |key, value| @credential_handler.set_credential(key, value) end auth_handler = get_auth_handler() token = auth_handler.get_token() # If token is invalid ask for a new one. if token.nil? begin credentials = @credential_handler.credentials token = auth_handler.get_token(credentials) rescue AdsCommon::Errors::OAuth2VerificationRequired => e verification_code = (block_given?) ? yield(e.oauth_url) : nil # Retry with verification code if one provided. if verification_code @credential_handler.set_credential( :oauth2_verification_code, verification_code) retry else raise e end end end return token end
ruby
def authorize(parameters = {}, &block) parameters.each_pair do |key, value| @credential_handler.set_credential(key, value) end auth_handler = get_auth_handler() token = auth_handler.get_token() # If token is invalid ask for a new one. if token.nil? begin credentials = @credential_handler.credentials token = auth_handler.get_token(credentials) rescue AdsCommon::Errors::OAuth2VerificationRequired => e verification_code = (block_given?) ? yield(e.oauth_url) : nil # Retry with verification code if one provided. if verification_code @credential_handler.set_credential( :oauth2_verification_code, verification_code) retry else raise e end end end return token end
[ "def", "authorize", "(", "parameters", "=", "{", "}", ",", "&", "block", ")", "parameters", ".", "each_pair", "do", "|", "key", ",", "value", "|", "@credential_handler", ".", "set_credential", "(", "key", ",", "value", ")", "end", "auth_handler", "=", "g...
Authorize with specified authentication method. Args: - parameters - hash of credentials to add to configuration - block - code block to handle auth login url Returns: - Auth token for the method Throws: - AdsCommon::Errors::AuthError or derived if authetication error has occured
[ "Authorize", "with", "specified", "authentication", "method", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L100-L126
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.save_oauth2_token
def save_oauth2_token(token) raise AdsCommon::Errors::Error, "Can't save nil token" if token.nil? AdsCommon::Utils.save_oauth2_token( File.join(ENV['HOME'], api_config.default_config_filename), token) end
ruby
def save_oauth2_token(token) raise AdsCommon::Errors::Error, "Can't save nil token" if token.nil? AdsCommon::Utils.save_oauth2_token( File.join(ENV['HOME'], api_config.default_config_filename), token) end
[ "def", "save_oauth2_token", "(", "token", ")", "raise", "AdsCommon", "::", "Errors", "::", "Error", ",", "\"Can't save nil token\"", "if", "token", ".", "nil?", "AdsCommon", "::", "Utils", ".", "save_oauth2_token", "(", "File", ".", "join", "(", "ENV", "[", ...
Updates default configuration file to include OAuth2 token information.
[ "Updates", "default", "configuration", "file", "to", "include", "OAuth2", "token", "information", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L143-L147
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.validate_service_request
def validate_service_request(version, service) # Check if the current config supports the requested version. unless api_config.has_version(version) raise AdsCommon::Errors::Error, "Version '%s' not recognized" % version.to_s end # Check if the specified version has the requested service. unless api_config.version_has_service(version, service) raise AdsCommon::Errors::Error, "Version '%s' does not contain service '%s'" % [version.to_s, service.to_s] end end
ruby
def validate_service_request(version, service) # Check if the current config supports the requested version. unless api_config.has_version(version) raise AdsCommon::Errors::Error, "Version '%s' not recognized" % version.to_s end # Check if the specified version has the requested service. unless api_config.version_has_service(version, service) raise AdsCommon::Errors::Error, "Version '%s' does not contain service '%s'" % [version.to_s, service.to_s] end end
[ "def", "validate_service_request", "(", "version", ",", "service", ")", "unless", "api_config", ".", "has_version", "(", "version", ")", "raise", "AdsCommon", "::", "Errors", "::", "Error", ",", "\"Version '%s' not recognized\"", "%", "version", ".", "to_s", "end"...
Auxiliary method to test parameters correctness for the service request.
[ "Auxiliary", "method", "to", "test", "parameters", "correctness", "for", "the", "service", "request", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L152-L165
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.create_auth_handler
def create_auth_handler() auth_method = @config.read('authentication.method', :OAUTH2) return case auth_method when :OAUTH raise AdsCommon::Errors::Error, 'OAuth authorization method is deprecated, use OAuth2 instead.' when :OAUTH2 AdsCommon::Auth::OAuth2Handler.new( @config, api_config.config(:oauth_scope) ) when :OAUTH2_SERVICE_ACCOUNT AdsCommon::Auth::OAuth2ServiceAccountHandler.new( @config, api_config.config(:oauth_scope) ) else raise AdsCommon::Errors::Error, "Unknown authentication method '%s'" % auth_method end end
ruby
def create_auth_handler() auth_method = @config.read('authentication.method', :OAUTH2) return case auth_method when :OAUTH raise AdsCommon::Errors::Error, 'OAuth authorization method is deprecated, use OAuth2 instead.' when :OAUTH2 AdsCommon::Auth::OAuth2Handler.new( @config, api_config.config(:oauth_scope) ) when :OAUTH2_SERVICE_ACCOUNT AdsCommon::Auth::OAuth2ServiceAccountHandler.new( @config, api_config.config(:oauth_scope) ) else raise AdsCommon::Errors::Error, "Unknown authentication method '%s'" % auth_method end end
[ "def", "create_auth_handler", "(", ")", "auth_method", "=", "@config", ".", "read", "(", "'authentication.method'", ",", ":OAUTH2", ")", "return", "case", "auth_method", "when", ":OAUTH", "raise", "AdsCommon", "::", "Errors", "::", "Error", ",", "'OAuth authorizat...
Auxiliary method to create an authentication handler. Returns: - auth handler
[ "Auxiliary", "method", "to", "create", "an", "authentication", "handler", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L190-L210
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.prepare_wrapper
def prepare_wrapper(version, service) api_config.do_require(version, service) endpoint = api_config.endpoint(version, service) interface_class_name = api_config.interface_name(version, service) wrapper = class_for_path(interface_class_name).new(@config, endpoint) auth_handler = get_auth_handler() header_ns = api_config.config(:header_ns) + version.to_s soap_handler = soap_header_handler(auth_handler, version, header_ns, wrapper.namespace) wrapper.header_handler = soap_handler return wrapper end
ruby
def prepare_wrapper(version, service) api_config.do_require(version, service) endpoint = api_config.endpoint(version, service) interface_class_name = api_config.interface_name(version, service) wrapper = class_for_path(interface_class_name).new(@config, endpoint) auth_handler = get_auth_handler() header_ns = api_config.config(:header_ns) + version.to_s soap_handler = soap_header_handler(auth_handler, version, header_ns, wrapper.namespace) wrapper.header_handler = soap_handler return wrapper end
[ "def", "prepare_wrapper", "(", "version", ",", "service", ")", "api_config", ".", "do_require", "(", "version", ",", "service", ")", "endpoint", "=", "api_config", ".", "endpoint", "(", "version", ",", "service", ")", "interface_class_name", "=", "api_config", ...
Handle loading of a single service. Creates the wrapper, sets up handlers and creates an instance of it. Args: - version: intended API version, must be a symbol - service: name for the intended service Returns: - a simplified wrapper generated for the service
[ "Handle", "loading", "of", "a", "single", "service", ".", "Creates", "the", "wrapper", "sets", "up", "handlers", "and", "creates", "an", "instance", "of", "it", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L222-L235
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.create_default_logger
def create_default_logger() logger = Logger.new(STDOUT) logger.level = get_log_level_for_string( @config.read('library.log_level', 'INFO')) return logger end
ruby
def create_default_logger() logger = Logger.new(STDOUT) logger.level = get_log_level_for_string( @config.read('library.log_level', 'INFO')) return logger end
[ "def", "create_default_logger", "(", ")", "logger", "=", "Logger", ".", "new", "(", "STDOUT", ")", "logger", ".", "level", "=", "get_log_level_for_string", "(", "@config", ".", "read", "(", "'library.log_level'", ",", "'INFO'", ")", ")", "return", "logger", ...
Auxiliary method to create a default Logger.
[ "Auxiliary", "method", "to", "create", "a", "default", "Logger", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L238-L243
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.load_config
def load_config(provided_config = nil) @config = (provided_config.nil?) ? AdsCommon::Config.new( File.join(ENV['HOME'], api_config.default_config_filename)) : AdsCommon::Config.new(provided_config) init_config() end
ruby
def load_config(provided_config = nil) @config = (provided_config.nil?) ? AdsCommon::Config.new( File.join(ENV['HOME'], api_config.default_config_filename)) : AdsCommon::Config.new(provided_config) init_config() end
[ "def", "load_config", "(", "provided_config", "=", "nil", ")", "@config", "=", "(", "provided_config", ".", "nil?", ")", "?", "AdsCommon", "::", "Config", ".", "new", "(", "File", ".", "join", "(", "ENV", "[", "'HOME'", "]", ",", "api_config", ".", "de...
Helper method to load the default configuration file or a given config.
[ "Helper", "method", "to", "load", "the", "default", "configuration", "file", "or", "a", "given", "config", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L246-L252
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.init_config
def init_config() # Set up logger. provided_logger = @config.read('library.logger') self.logger = (provided_logger.nil?) ? create_default_logger() : provided_logger # Set up default HTTPI adapter. provided_adapter = @config.read('connection.adapter') @config.set('connection.adapter', :httpclient) if provided_adapter.nil? # Make sure Auth param is a symbol. symbolize_config_value('authentication.method') end
ruby
def init_config() # Set up logger. provided_logger = @config.read('library.logger') self.logger = (provided_logger.nil?) ? create_default_logger() : provided_logger # Set up default HTTPI adapter. provided_adapter = @config.read('connection.adapter') @config.set('connection.adapter', :httpclient) if provided_adapter.nil? # Make sure Auth param is a symbol. symbolize_config_value('authentication.method') end
[ "def", "init_config", "(", ")", "provided_logger", "=", "@config", ".", "read", "(", "'library.logger'", ")", "self", ".", "logger", "=", "(", "provided_logger", ".", "nil?", ")", "?", "create_default_logger", "(", ")", ":", "provided_logger", "provided_adapter"...
Initializes config with default values and converts existing if required.
[ "Initializes", "config", "with", "default", "values", "and", "converts", "existing", "if", "required", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L255-L267
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.symbolize_config_value
def symbolize_config_value(key) value_str = @config.read(key).to_s if !value_str.nil? and !value_str.empty? value = value_str.upcase.to_sym @config.set(key, value) end end
ruby
def symbolize_config_value(key) value_str = @config.read(key).to_s if !value_str.nil? and !value_str.empty? value = value_str.upcase.to_sym @config.set(key, value) end end
[ "def", "symbolize_config_value", "(", "key", ")", "value_str", "=", "@config", ".", "read", "(", "key", ")", ".", "to_s", "if", "!", "value_str", ".", "nil?", "and", "!", "value_str", ".", "empty?", "value", "=", "value_str", ".", "upcase", ".", "to_sym"...
Converts value of a config key to uppercase symbol.
[ "Converts", "value", "of", "a", "config", "key", "to", "uppercase", "symbol", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L270-L276
valid
googleads/google-api-ads-ruby
ads_common/lib/ads_common/api.rb
AdsCommon.Api.class_for_path
def class_for_path(path) path.split('::').inject(Kernel) do |scope, const_name| scope.const_get(const_name) end end
ruby
def class_for_path(path) path.split('::').inject(Kernel) do |scope, const_name| scope.const_get(const_name) end end
[ "def", "class_for_path", "(", "path", ")", "path", ".", "split", "(", "'::'", ")", ".", "inject", "(", "Kernel", ")", "do", "|", "scope", ",", "const_name", "|", "scope", ".", "const_get", "(", "const_name", ")", "end", "end" ]
Converts complete class path into class object.
[ "Converts", "complete", "class", "path", "into", "class", "object", "." ]
bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b
https://github.com/googleads/google-api-ads-ruby/blob/bf8ede5dda838bbd6161f4eb7d66b4654ae6e46b/ads_common/lib/ads_common/api.rb#L284-L288
valid
zold-io/zold
lib/zold/node/farm.rb
Zold.Farm.to_json
def to_json { threads: @threads.to_json, pipeline: @pipeline.size, best: best.map(&:to_mnemo).join(', '), farmer: @farmer.class.name } end
ruby
def to_json { threads: @threads.to_json, pipeline: @pipeline.size, best: best.map(&:to_mnemo).join(', '), farmer: @farmer.class.name } end
[ "def", "to_json", "{", "threads", ":", "@threads", ".", "to_json", ",", "pipeline", ":", "@pipeline", ".", "size", ",", "best", ":", "best", ".", "map", "(", "&", ":to_mnemo", ")", ".", "join", "(", "', '", ")", ",", "farmer", ":", "@farmer", ".", ...
Renders the Farm into JSON to show for the end-user in front.rb.
[ "Renders", "the", "Farm", "into", "JSON", "to", "show", "for", "the", "end", "-", "user", "in", "front", ".", "rb", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/node/farm.rb#L91-L98
valid
zold-io/zold
lib/zold/node/async_entrance.rb
Zold.AsyncEntrance.exists?
def exists?(id, body) DirItems.new(@dir).fetch.each do |f| next unless f.start_with?("#{id}-") return true if safe_read(File.join(@dir, f)) == body end false end
ruby
def exists?(id, body) DirItems.new(@dir).fetch.each do |f| next unless f.start_with?("#{id}-") return true if safe_read(File.join(@dir, f)) == body end false end
[ "def", "exists?", "(", "id", ",", "body", ")", "DirItems", ".", "new", "(", "@dir", ")", ".", "fetch", ".", "each", "do", "|", "f", "|", "next", "unless", "f", ".", "start_with?", "(", "\"#{id}-\"", ")", "return", "true", "if", "safe_read", "(", "F...
Returns TRUE if a file for this wallet is already in the queue.
[ "Returns", "TRUE", "if", "a", "file", "for", "this", "wallet", "is", "already", "in", "the", "queue", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/node/async_entrance.rb#L116-L122
valid
zold-io/zold
lib/zold/tax.rb
Zold.Tax.exists?
def exists?(details) !@wallet.txns.find { |t| t.details.start_with?("#{PREFIX} ") && t.details == details }.nil? end
ruby
def exists?(details) !@wallet.txns.find { |t| t.details.start_with?("#{PREFIX} ") && t.details == details }.nil? end
[ "def", "exists?", "(", "details", ")", "!", "@wallet", ".", "txns", ".", "find", "{", "|", "t", "|", "t", ".", "details", ".", "start_with?", "(", "\"#{PREFIX} \"", ")", "&&", "t", ".", "details", "==", "details", "}", ".", "nil?", "end" ]
Check whether this tax payment already exists in the wallet.
[ "Check", "whether", "this", "tax", "payment", "already", "exists", "in", "the", "wallet", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/tax.rb#L76-L78
valid
zold-io/zold
lib/zold/node/spread_entrance.rb
Zold.SpreadEntrance.push
def push(id, body) mods = @entrance.push(id, body) return mods if @remotes.all.empty? mods.each do |m| next if @seen.include?(m) @mutex.synchronize { @seen << m } @modified.push(m) @log.debug("Spread-push scheduled for #{m}, queue size is #{@modified.size}") end mods end
ruby
def push(id, body) mods = @entrance.push(id, body) return mods if @remotes.all.empty? mods.each do |m| next if @seen.include?(m) @mutex.synchronize { @seen << m } @modified.push(m) @log.debug("Spread-push scheduled for #{m}, queue size is #{@modified.size}") end mods end
[ "def", "push", "(", "id", ",", "body", ")", "mods", "=", "@entrance", ".", "push", "(", "id", ",", "body", ")", "return", "mods", "if", "@remotes", ".", "all", ".", "empty?", "mods", ".", "each", "do", "|", "m", "|", "next", "if", "@seen", ".", ...
This method is thread-safe
[ "This", "method", "is", "thread", "-", "safe" ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/node/spread_entrance.rb#L97-L107
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.init
def init(id, pubkey, overwrite: false, network: 'test') raise "File '#{path}' already exists" if File.exist?(path) && !overwrite raise "Invalid network name '#{network}'" unless network =~ /^[a-z]{4,16}$/ FileUtils.mkdir_p(File.dirname(path)) IO.write(path, "#{network}\n#{PROTOCOL}\n#{id}\n#{pubkey.to_pub}\n\n") @txns.flush @head.flush end
ruby
def init(id, pubkey, overwrite: false, network: 'test') raise "File '#{path}' already exists" if File.exist?(path) && !overwrite raise "Invalid network name '#{network}'" unless network =~ /^[a-z]{4,16}$/ FileUtils.mkdir_p(File.dirname(path)) IO.write(path, "#{network}\n#{PROTOCOL}\n#{id}\n#{pubkey.to_pub}\n\n") @txns.flush @head.flush end
[ "def", "init", "(", "id", ",", "pubkey", ",", "overwrite", ":", "false", ",", "network", ":", "'test'", ")", "raise", "\"File '#{path}' already exists\"", "if", "File", ".", "exist?", "(", "path", ")", "&&", "!", "overwrite", "raise", "\"Invalid network name '...
Creates an empty wallet with the specified ID and public key.
[ "Creates", "an", "empty", "wallet", "with", "the", "specified", "ID", "and", "public", "key", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L113-L120
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.balance
def balance txns.inject(Amount::ZERO) { |sum, t| sum + t.amount } end
ruby
def balance txns.inject(Amount::ZERO) { |sum, t| sum + t.amount } end
[ "def", "balance", "txns", ".", "inject", "(", "Amount", "::", "ZERO", ")", "{", "|", "sum", ",", "t", "|", "sum", "+", "t", ".", "amount", "}", "end" ]
Returns current wallet balance.
[ "Returns", "current", "wallet", "balance", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L133-L135
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.sub
def sub(amount, invoice, pvt, details = '-', time: Time.now) raise 'The amount has to be of type Amount' unless amount.is_a?(Amount) raise "The amount can't be negative: #{amount}" if amount.negative? raise 'The pvt has to be of type Key' unless pvt.is_a?(Key) prefix, target = invoice.split('@') tid = max + 1 raise 'Too many transactions already, can\'t add more' if max > 0xffff txn = Txn.new( tid, time, amount * -1, prefix, Id.new(target), details ) txn = txn.signed(pvt, id) raise "Invalid private key for the wallet #{id}" unless Signature.new(network).valid?(key, id, txn) add(txn) txn end
ruby
def sub(amount, invoice, pvt, details = '-', time: Time.now) raise 'The amount has to be of type Amount' unless amount.is_a?(Amount) raise "The amount can't be negative: #{amount}" if amount.negative? raise 'The pvt has to be of type Key' unless pvt.is_a?(Key) prefix, target = invoice.split('@') tid = max + 1 raise 'Too many transactions already, can\'t add more' if max > 0xffff txn = Txn.new( tid, time, amount * -1, prefix, Id.new(target), details ) txn = txn.signed(pvt, id) raise "Invalid private key for the wallet #{id}" unless Signature.new(network).valid?(key, id, txn) add(txn) txn end
[ "def", "sub", "(", "amount", ",", "invoice", ",", "pvt", ",", "details", "=", "'-'", ",", "time", ":", "Time", ".", "now", ")", "raise", "'The amount has to be of type Amount'", "unless", "amount", ".", "is_a?", "(", "Amount", ")", "raise", "\"The amount can...
Add a payment transaction to the wallet.
[ "Add", "a", "payment", "transaction", "to", "the", "wallet", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L138-L157
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.add
def add(txn) raise 'The txn has to be of type Txn' unless txn.is_a?(Txn) raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id raise "The amount can't be zero in #{id}: #{txn}" if txn.amount.zero? if txn.amount.negative? && includes_negative?(txn.id) raise "Negative transaction with the same ID #{txn.id} already exists in #{id}" end if txn.amount.positive? && includes_positive?(txn.id, txn.bnf) raise "Positive transaction with the same ID #{txn.id} and BNF #{txn.bnf} already exists in #{id}" end raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn.details) File.open(path, 'a') { |f| f.print "#{txn}\n" } @txns.flush end
ruby
def add(txn) raise 'The txn has to be of type Txn' unless txn.is_a?(Txn) raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id raise "The amount can't be zero in #{id}: #{txn}" if txn.amount.zero? if txn.amount.negative? && includes_negative?(txn.id) raise "Negative transaction with the same ID #{txn.id} already exists in #{id}" end if txn.amount.positive? && includes_positive?(txn.id, txn.bnf) raise "Positive transaction with the same ID #{txn.id} and BNF #{txn.bnf} already exists in #{id}" end raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn.details) File.open(path, 'a') { |f| f.print "#{txn}\n" } @txns.flush end
[ "def", "add", "(", "txn", ")", "raise", "'The txn has to be of type Txn'", "unless", "txn", ".", "is_a?", "(", "Txn", ")", "raise", "\"Wallet #{id} can't pay itself: #{txn}\"", "if", "txn", ".", "bnf", "==", "id", "raise", "\"The amount can't be zero in #{id}: #{txn}\""...
Add a transaction to the wallet.
[ "Add", "a", "transaction", "to", "the", "wallet", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L160-L173
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.includes_negative?
def includes_negative?(id, bnf = nil) raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer) !txns.find { |t| t.id == id && (bnf.nil? || t.bnf == bnf) && t.amount.negative? }.nil? end
ruby
def includes_negative?(id, bnf = nil) raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer) !txns.find { |t| t.id == id && (bnf.nil? || t.bnf == bnf) && t.amount.negative? }.nil? end
[ "def", "includes_negative?", "(", "id", ",", "bnf", "=", "nil", ")", "raise", "'The txn ID has to be of type Integer'", "unless", "id", ".", "is_a?", "(", "Integer", ")", "!", "txns", ".", "find", "{", "|", "t", "|", "t", ".", "id", "==", "id", "&&", "...
Returns TRUE if the wallet contains a payment sent with the specified ID, which was sent to the specified beneficiary.
[ "Returns", "TRUE", "if", "the", "wallet", "contains", "a", "payment", "sent", "with", "the", "specified", "ID", "which", "was", "sent", "to", "the", "specified", "beneficiary", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L177-L180
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.includes_positive?
def includes_positive?(id, bnf) raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer) raise 'The bnf has to be of type Id' unless bnf.is_a?(Id) !txns.find { |t| t.id == id && t.bnf == bnf && !t.amount.negative? }.nil? end
ruby
def includes_positive?(id, bnf) raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer) raise 'The bnf has to be of type Id' unless bnf.is_a?(Id) !txns.find { |t| t.id == id && t.bnf == bnf && !t.amount.negative? }.nil? end
[ "def", "includes_positive?", "(", "id", ",", "bnf", ")", "raise", "'The txn ID has to be of type Integer'", "unless", "id", ".", "is_a?", "(", "Integer", ")", "raise", "'The bnf has to be of type Id'", "unless", "bnf", ".", "is_a?", "(", "Id", ")", "!", "txns", ...
Returns TRUE if the wallet contains a payment received with the specified ID, which was sent by the specified beneficiary.
[ "Returns", "TRUE", "if", "the", "wallet", "contains", "a", "payment", "received", "with", "the", "specified", "ID", "which", "was", "sent", "by", "the", "specified", "beneficiary", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L184-L188
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.age
def age list = txns list.empty? ? 0 : (Time.now - list.min_by(&:date).date) / (60 * 60) end
ruby
def age list = txns list.empty? ? 0 : (Time.now - list.min_by(&:date).date) / (60 * 60) end
[ "def", "age", "list", "=", "txns", "list", ".", "empty?", "?", "0", ":", "(", "Time", ".", "now", "-", "list", ".", "min_by", "(", "&", ":date", ")", ".", "date", ")", "/", "(", "60", "*", "60", ")", "end" ]
Age of wallet in hours.
[ "Age", "of", "wallet", "in", "hours", "." ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L212-L215
valid
zold-io/zold
lib/zold/wallet.rb
Zold.Wallet.max
def max negative = txns.select { |t| t.amount.negative? } negative.empty? ? 0 : negative.max_by(&:id).id end
ruby
def max negative = txns.select { |t| t.amount.negative? } negative.empty? ? 0 : negative.max_by(&:id).id end
[ "def", "max", "negative", "=", "txns", ".", "select", "{", "|", "t", "|", "t", ".", "amount", ".", "negative?", "}", "negative", ".", "empty?", "?", "0", ":", "negative", ".", "max_by", "(", "&", ":id", ")", ".", "id", "end" ]
Calculate the maximum transaction ID visible currently in the wallet. We go through them all and find the largest number. If there are no transactions, zero is returned.
[ "Calculate", "the", "maximum", "transaction", "ID", "visible", "currently", "in", "the", "wallet", ".", "We", "go", "through", "them", "all", "and", "find", "the", "largest", "number", ".", "If", "there", "are", "no", "transactions", "zero", "is", "returned"...
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/wallet.rb#L250-L253
valid
zold-io/zold
lib/zold/commands/propagate.rb
Zold.Propagate.propagate
def propagate(id, _) start = Time.now modified = [] total = 0 network = @wallets.acq(id, &:network) @wallets.acq(id, &:txns).select { |t| t.amount.negative? }.each do |t| total += 1 if t.bnf == id @log.error("Paying itself in #{id}? #{t}") next end @wallets.acq(t.bnf, exclusive: true) do |target| unless target.exists? @log.debug("#{t.amount * -1} from #{id} to #{t.bnf}: wallet is absent") next end unless target.network == network @log.debug("#{t.amount * -1} to #{t.bnf}: network mismatch, '#{target.network}'!='#{network}'") next end next if target.includes_positive?(t.id, id) unless target.prefix?(t.prefix) @log.debug("#{t.amount * -1} from #{id} to #{t.bnf}: wrong prefix \"#{t.prefix}\" in \"#{t}\"") next end target.add(t.inverse(id)) @log.info("#{t.amount * -1} arrived to #{t.bnf}: #{t.details}") modified << t.bnf end end modified.uniq! @log.debug("Wallet #{id} propagated successfully, #{total} txns \ in #{Age.new(start, limit: 20 + total * 0.005)}, #{modified.count} wallets affected") modified.each do |w| @wallets.acq(w, &:refurbish) end modified end
ruby
def propagate(id, _) start = Time.now modified = [] total = 0 network = @wallets.acq(id, &:network) @wallets.acq(id, &:txns).select { |t| t.amount.negative? }.each do |t| total += 1 if t.bnf == id @log.error("Paying itself in #{id}? #{t}") next end @wallets.acq(t.bnf, exclusive: true) do |target| unless target.exists? @log.debug("#{t.amount * -1} from #{id} to #{t.bnf}: wallet is absent") next end unless target.network == network @log.debug("#{t.amount * -1} to #{t.bnf}: network mismatch, '#{target.network}'!='#{network}'") next end next if target.includes_positive?(t.id, id) unless target.prefix?(t.prefix) @log.debug("#{t.amount * -1} from #{id} to #{t.bnf}: wrong prefix \"#{t.prefix}\" in \"#{t}\"") next end target.add(t.inverse(id)) @log.info("#{t.amount * -1} arrived to #{t.bnf}: #{t.details}") modified << t.bnf end end modified.uniq! @log.debug("Wallet #{id} propagated successfully, #{total} txns \ in #{Age.new(start, limit: 20 + total * 0.005)}, #{modified.count} wallets affected") modified.each do |w| @wallets.acq(w, &:refurbish) end modified end
[ "def", "propagate", "(", "id", ",", "_", ")", "start", "=", "Time", ".", "now", "modified", "=", "[", "]", "total", "=", "0", "network", "=", "@wallets", ".", "acq", "(", "id", ",", "&", ":network", ")", "@wallets", ".", "acq", "(", "id", ",", ...
Returns list of Wallet IDs which were affected
[ "Returns", "list", "of", "Wallet", "IDs", "which", "were", "affected" ]
7e0f69307786846186bc3436dcc72d91d393ddd4
https://github.com/zold-io/zold/blob/7e0f69307786846186bc3436dcc72d91d393ddd4/lib/zold/commands/propagate.rb#L65-L102
valid