azure-storage-table 1.0.1 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,116 +1,116 @@
1
- # frozen_string_literal: true
2
-
3
- #-------------------------------------------------------------------------
4
- # # Copyright (c) Microsoft and contributors. All rights reserved.
5
- #
6
- # The MIT License(MIT)
7
-
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files(the "Software"), to deal
10
- # in the Software without restriction, including without limitation the rights
11
- # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
- # copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions :
14
-
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
-
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- # THE SOFTWARE.
25
- #--------------------------------------------------------------------------
26
- require "time"
27
- require "date"
28
- require "json"
29
-
30
- module Azure
31
- module Storage
32
- module Table
33
- # This is a class that serializes the request/response body for table
34
- # service.
35
- module Serialization
36
- include Azure::Storage::Common::Service::Serialization
37
-
38
- def self.hash_to_json(h)
39
- newhash = {}
40
- h.map do |key, val|
41
- type = Table::EdmType.property_type(val)
42
- type_key = key.is_a?(Symbol) ? key.to_s + TableConstants::ODATA_TYPE_SUFFIX : key + TableConstants::ODATA_TYPE_SUFFIX
43
- newhash[key] = EdmType::serialize_value(type, val)
44
- newhash[type_key] = type unless type.nil? || type.empty? || h.key?(type_key)
45
- end
46
- JSON newhash
47
- end
48
-
49
- def self.table_entries_from_json(json)
50
- table_entries_from_hash(hash_from_json(json))
51
- end
52
-
53
- def self.hash_from_json(json)
54
- JSON.parse(json)
55
- end
56
-
57
- def self.table_entries_from_hash(h)
58
- values = []
59
- if h["value"]
60
- h["value"].each do |name|
61
- values.push(name)
62
- end
63
- elsif h["TableName"]
64
- values = h
65
- end
66
- values
67
- end
68
-
69
- def self.entity_from_json(json)
70
- entity_from_hash(hash_from_json(json))
71
- end
72
-
73
- def self.entities_from_json(json)
74
- entities_hash = hash_from_json(json)
75
- entities_hash["value"].nil? ? [entity_from_hash(entities_hash)] : entities_from_hash(entities_hash)
76
- end
77
-
78
- def self.entities_from_hash(h)
79
- entities = []
80
- h["value"].each { |entity_hash|
81
- entities.push(entity_from_hash(entity_hash))
82
- }
83
- entities
84
- end
85
-
86
- def self.entity_from_hash(h)
87
- Entity.new do |entity|
88
- entity.etag = h.delete(TableConstants::ODATA_ETAG)
89
- properties = {}
90
- h.each do |k, v|
91
- next if k.end_with? TableConstants::ODATA_TYPE_SUFFIX
92
- type = h[k + TableConstants::ODATA_TYPE_SUFFIX]
93
- properties[k] = EdmType::deserialize_value(v, type.nil? ? EdmType::property_type(v) : type)
94
- end
95
- entity.properties = properties
96
- end
97
- end
98
-
99
- def self.get_accept_string(accept_type = :min_meta)
100
- case accept_type
101
- when :no_meta
102
- Azure::Storage::Common::HeaderConstants::ODATA_NO_META
103
- when :min_meta
104
- Azure::Storage::Common::HeaderConstants::ODATA_MIN_META
105
- when :full_meta
106
- Azure::Storage::Common::HeaderConstants::ODATA_FULL_META
107
- when nil
108
- Azure::Storage::Common::HeaderConstants::ODATA_MIN_META
109
- else
110
- accept_type
111
- end
112
- end
113
- end
114
- end
115
- end
116
- end
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+ require "time"
27
+ require "date"
28
+ require "json"
29
+
30
+ module Azure
31
+ module Storage
32
+ module Table
33
+ # This is a class that serializes the request/response body for table
34
+ # service.
35
+ module Serialization
36
+ include Azure::Storage::Common::Service::Serialization
37
+
38
+ def self.hash_to_json(h)
39
+ newhash = {}
40
+ h.map do |key, val|
41
+ type = Table::EdmType.property_type(val)
42
+ type_key = key.is_a?(Symbol) ? key.to_s + TableConstants::ODATA_TYPE_SUFFIX : key + TableConstants::ODATA_TYPE_SUFFIX
43
+ newhash[key] = EdmType::serialize_value(type, val)
44
+ newhash[type_key] = type unless type.nil? || type.empty? || h.key?(type_key)
45
+ end
46
+ JSON newhash
47
+ end
48
+
49
+ def self.table_entries_from_json(json)
50
+ table_entries_from_hash(hash_from_json(json))
51
+ end
52
+
53
+ def self.hash_from_json(json)
54
+ JSON.parse(json)
55
+ end
56
+
57
+ def self.table_entries_from_hash(h)
58
+ values = []
59
+ if h["value"]
60
+ h["value"].each do |name|
61
+ values.push(name)
62
+ end
63
+ elsif h["TableName"]
64
+ values = h
65
+ end
66
+ values
67
+ end
68
+
69
+ def self.entity_from_json(json)
70
+ entity_from_hash(hash_from_json(json))
71
+ end
72
+
73
+ def self.entities_from_json(json)
74
+ entities_hash = hash_from_json(json)
75
+ entities_hash["value"].nil? ? [entity_from_hash(entities_hash)] : entities_from_hash(entities_hash)
76
+ end
77
+
78
+ def self.entities_from_hash(h)
79
+ entities = []
80
+ h["value"].each { |entity_hash|
81
+ entities.push(entity_from_hash(entity_hash))
82
+ }
83
+ entities
84
+ end
85
+
86
+ def self.entity_from_hash(h)
87
+ Entity.new do |entity|
88
+ entity.etag = h.delete(TableConstants::ODATA_ETAG)
89
+ properties = {}
90
+ h.each do |k, v|
91
+ next if k.end_with? TableConstants::ODATA_TYPE_SUFFIX
92
+ type = h[k + TableConstants::ODATA_TYPE_SUFFIX]
93
+ properties[k] = EdmType::deserialize_value(v, type.nil? ? EdmType::property_type(v) : type)
94
+ end
95
+ entity.properties = properties
96
+ end
97
+ end
98
+
99
+ def self.get_accept_string(accept_type = :min_meta)
100
+ case accept_type
101
+ when :no_meta
102
+ Azure::Storage::Common::HeaderConstants::ODATA_NO_META
103
+ when :min_meta
104
+ Azure::Storage::Common::HeaderConstants::ODATA_MIN_META
105
+ when :full_meta
106
+ Azure::Storage::Common::HeaderConstants::ODATA_FULL_META
107
+ when nil
108
+ Azure::Storage::Common::HeaderConstants::ODATA_MIN_META
109
+ else
110
+ accept_type
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end