module Azure::Storage::Table::Serialization
This is a class that serializes the request/response body for table service.
Public Class Methods
entities_from_hash(h)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 78 def self.entities_from_hash(h) entities = [] h["value"].each { |entity_hash| entities.push(entity_from_hash(entity_hash)) } entities end
entities_from_json(json)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 73 def self.entities_from_json(json) entities_hash = hash_from_json(json) entities_hash["value"].nil? ? [entity_from_hash(entities_hash)] : entities_from_hash(entities_hash) end
entity_from_hash(h)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 86 def self.entity_from_hash(h) Entity.new do |entity| entity.etag = h.delete(TableConstants::ODATA_ETAG) properties = {} h.each do |k, v| next if k.end_with? TableConstants::ODATA_TYPE_SUFFIX type = h[k + TableConstants::ODATA_TYPE_SUFFIX] properties[k] = EdmType::deserialize_value(v, type.nil? ? EdmType::property_type(v) : type) end entity.properties = properties end end
entity_from_json(json)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 69 def self.entity_from_json(json) entity_from_hash(hash_from_json(json)) end
get_accept_string(accept_type = :min_meta)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 99 def self.get_accept_string(accept_type = :min_meta) case accept_type when :no_meta Azure::Storage::Common::HeaderConstants::ODATA_NO_META when :min_meta Azure::Storage::Common::HeaderConstants::ODATA_MIN_META when :full_meta Azure::Storage::Common::HeaderConstants::ODATA_FULL_META when nil Azure::Storage::Common::HeaderConstants::ODATA_MIN_META else accept_type end end
hash_from_json(json)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 53 def self.hash_from_json(json) JSON.parse(json) end
hash_to_json(h)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 38 def self.hash_to_json(h) newhash = {} h.map do |key, val| type = Table::EdmType.property_type(val) type_key = key.is_a?(Symbol) ? key.to_s + TableConstants::ODATA_TYPE_SUFFIX : key + TableConstants::ODATA_TYPE_SUFFIX newhash[key] = EdmType::serialize_value(type, val) newhash[type_key] = type unless type.nil? || type.empty? || h.key?(type_key) end JSON newhash end
table_entries_from_hash(h)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 57 def self.table_entries_from_hash(h) values = [] if h["value"] h["value"].each do |name| values.push(name) end elsif h["TableName"] values = h end values end
table_entries_from_json(json)
click to toggle source
# File lib/azure/storage/table/serialization.rb, line 49 def self.table_entries_from_json(json) table_entries_from_hash(hash_from_json(json)) end