fastly 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +6 -5
  5. data/docs/EventsApi.md +8 -0
  6. data/docs/HistoricalDdos.md +13 -0
  7. data/docs/HistoricalDdosMeta.md +13 -0
  8. data/docs/HistoricalFieldResultsAttributes.md +9 -0
  9. data/docs/KvStoreApi.md +15 -15
  10. data/docs/LoggingLogentriesAdditional.md +1 -1
  11. data/docs/LoggingLogentriesApi.md +4 -4
  12. data/docs/LoggingLogentriesResponse.md +1 -1
  13. data/docs/PlatformDdosDataItems.md +10 -0
  14. data/docs/PlatformDdosEntry.md +10 -0
  15. data/docs/PlatformDdosResponse.md +13 -0
  16. data/docs/PlatformDdosResponseAllOf.md +10 -0
  17. data/docs/RealtimeEntryAggregated.md +9 -0
  18. data/docs/RealtimeMeasurements.md +9 -0
  19. data/docs/Results.md +9 -0
  20. data/docs/SchemasSnippetResponse.md +1 -1
  21. data/docs/SchemasSnippetResponseCommon.md +15 -0
  22. data/docs/Snippet.md +1 -1
  23. data/docs/SnippetAllOf.md +10 -0
  24. data/docs/SnippetApi.md +6 -6
  25. data/docs/SnippetCommon.md +13 -0
  26. data/docs/SnippetResponse.md +1 -1
  27. data/docs/SnippetResponseCommon.md +15 -0
  28. data/docs/{SnippetResponseAllOf.md → SnippetResponseCommonAllOf.md} +1 -1
  29. data/docs/SnippetResponsePost.md +20 -0
  30. data/docs/SnippetWithDynamicNumber.md +14 -0
  31. data/docs/SnippetWithDynamicNumberAllOf.md +10 -0
  32. data/docs/ValuesDdos.md +15 -0
  33. data/docs/WholePlatformDdosHistoricalApi.md +56 -0
  34. data/lib/fastly/api/events_api.rb +12 -0
  35. data/lib/fastly/api/kv_store_api.rb +14 -14
  36. data/lib/fastly/api/logging_logentries_api.rb +4 -4
  37. data/lib/fastly/api/snippet_api.rb +17 -17
  38. data/lib/fastly/api/whole_platform_ddos_historical_api.rb +89 -0
  39. data/lib/fastly/configuration.rb +6 -0
  40. data/lib/fastly/models/historical_ddos.rb +249 -0
  41. data/lib/fastly/models/historical_ddos_meta.rb +248 -0
  42. data/lib/fastly/models/historical_field_results_attributes.rb +91 -1
  43. data/lib/fastly/models/logging_logentries_additional.rb +1 -1
  44. data/lib/fastly/models/logging_logentries_response.rb +1 -1
  45. data/lib/fastly/models/platform_ddos_data_items.rb +216 -0
  46. data/lib/fastly/models/platform_ddos_entry.rb +219 -0
  47. data/lib/fastly/models/platform_ddos_response.rb +257 -0
  48. data/lib/fastly/models/platform_ddos_response_all_of.rb +219 -0
  49. data/lib/fastly/models/realtime_entry_aggregated.rb +94 -4
  50. data/lib/fastly/models/realtime_measurements.rb +94 -4
  51. data/lib/fastly/models/results.rb +94 -4
  52. data/lib/fastly/models/schemas_snippet_response.rb +25 -26
  53. data/lib/fastly/models/schemas_snippet_response_common.rb +276 -0
  54. data/lib/fastly/models/snippet.rb +34 -26
  55. data/lib/fastly/models/snippet_all_of.rb +251 -0
  56. data/lib/fastly/models/snippet_common.rb +283 -0
  57. data/lib/fastly/models/snippet_response.rb +24 -25
  58. data/lib/fastly/models/snippet_response_common.rb +276 -0
  59. data/lib/fastly/models/{snippet_response_all_of.rb → snippet_response_common_all_of.rb} +3 -3
  60. data/lib/fastly/models/snippet_response_post.rb +374 -0
  61. data/lib/fastly/models/snippet_with_dynamic_number.rb +313 -0
  62. data/lib/fastly/models/snippet_with_dynamic_number_all_of.rb +251 -0
  63. data/lib/fastly/models/values_ddos.rb +268 -0
  64. data/lib/fastly/version.rb +1 -1
  65. data/lib/fastly.rb +16 -1
  66. data/sig.json +1 -1
  67. metadata +34 -4
@@ -16,9 +16,6 @@ module Fastly
16
16
  # The name for the snippet.
17
17
  attr_accessor :name
18
18
 
19
- # Sets the snippet version.
20
- attr_accessor :dynamic
21
-
22
19
  # The location in generated VCL where the snippet should be placed.
23
20
  attr_accessor :type
24
21
 
@@ -28,6 +25,9 @@ module Fastly
28
25
  # Priority determines execution order. Lower numbers execute first.
29
26
  attr_accessor :priority
30
27
 
28
+ # Sets the snippet version.
29
+ attr_accessor :dynamic
30
+
31
31
  class EnumAttributeValidator
32
32
  attr_reader :datatype
33
33
  attr_reader :allowable_values
@@ -54,10 +54,10 @@ module Fastly
54
54
  def self.attribute_map
55
55
  {
56
56
  :'name' => :'name',
57
- :'dynamic' => :'dynamic',
58
57
  :'type' => :'type',
59
58
  :'content' => :'content',
60
- :'priority' => :'priority'
59
+ :'priority' => :'priority',
60
+ :'dynamic' => :'dynamic'
61
61
  }
62
62
  end
63
63
 
@@ -70,10 +70,10 @@ module Fastly
70
70
  def self.fastly_types
71
71
  {
72
72
  :'name' => :'String',
73
- :'dynamic' => :'String',
74
73
  :'type' => :'String',
75
74
  :'content' => :'String',
76
- :'priority' => :'String'
75
+ :'priority' => :'String',
76
+ :'dynamic' => :'String'
77
77
  }
78
78
  end
79
79
 
@@ -83,6 +83,14 @@ module Fastly
83
83
  ])
84
84
  end
85
85
 
86
+ # List of class defined in allOf (OpenAPI v3)
87
+ def self.fastly_all_of
88
+ [
89
+ :'SnippetAllOf',
90
+ :'SnippetCommon'
91
+ ]
92
+ end
93
+
86
94
  # Initializes the object
87
95
  # @param [Hash] attributes Model attributes in the form of hash
88
96
  def initialize(attributes = {})
@@ -102,10 +110,6 @@ module Fastly
102
110
  self.name = attributes[:'name']
103
111
  end
104
112
 
105
- if attributes.key?(:'dynamic')
106
- self.dynamic = attributes[:'dynamic']
107
- end
108
-
109
113
  if attributes.key?(:'type')
110
114
  self.type = attributes[:'type']
111
115
  end
@@ -119,6 +123,10 @@ module Fastly
119
123
  else
120
124
  self.priority = '100'
121
125
  end
126
+
127
+ if attributes.key?(:'dynamic')
128
+ self.dynamic = attributes[:'dynamic']
129
+ end
122
130
  end
123
131
 
124
132
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -131,23 +139,13 @@ module Fastly
131
139
  # Check to see if the all the properties in the model are valid
132
140
  # @return true if the model is valid
133
141
  def valid?
134
- dynamic_validator = EnumAttributeValidator.new('String', ["0", "1"])
135
- return false unless dynamic_validator.valid?(@dynamic)
136
142
  type_validator = EnumAttributeValidator.new('String', ["init", "recv", "hash", "hit", "miss", "pass", "fetch", "error", "deliver", "log", "none"])
137
143
  return false unless type_validator.valid?(@type)
144
+ dynamic_validator = EnumAttributeValidator.new('String', ["0", "1"])
145
+ return false unless dynamic_validator.valid?(@dynamic)
138
146
  true
139
147
  end
140
148
 
141
- # Custom attribute writer method checking allowed values (enum).
142
- # @param [Object] dynamic Object to be assigned
143
- def dynamic=(dynamic)
144
- validator = EnumAttributeValidator.new('String', ["0", "1"])
145
- unless validator.valid?(dynamic)
146
- fail ArgumentError, "invalid value for \"dynamic\", must be one of #{validator.allowable_values}."
147
- end
148
- @dynamic = dynamic
149
- end
150
-
151
149
  # Custom attribute writer method checking allowed values (enum).
152
150
  # @param [Object] type Object to be assigned
153
151
  def type=(type)
@@ -158,16 +156,26 @@ module Fastly
158
156
  @type = type
159
157
  end
160
158
 
159
+ # Custom attribute writer method checking allowed values (enum).
160
+ # @param [Object] dynamic Object to be assigned
161
+ def dynamic=(dynamic)
162
+ validator = EnumAttributeValidator.new('String', ["0", "1"])
163
+ unless validator.valid?(dynamic)
164
+ fail ArgumentError, "invalid value for \"dynamic\", must be one of #{validator.allowable_values}."
165
+ end
166
+ @dynamic = dynamic
167
+ end
168
+
161
169
  # Checks equality by comparing each attribute.
162
170
  # @param [Object] Object to be compared
163
171
  def ==(o)
164
172
  return true if self.equal?(o)
165
173
  self.class == o.class &&
166
174
  name == o.name &&
167
- dynamic == o.dynamic &&
168
175
  type == o.type &&
169
176
  content == o.content &&
170
- priority == o.priority
177
+ priority == o.priority &&
178
+ dynamic == o.dynamic
171
179
  end
172
180
 
173
181
  # @see the `==` method
@@ -179,7 +187,7 @@ module Fastly
179
187
  # Calculates hash code according to all attributes.
180
188
  # @return [Integer] Hash code
181
189
  def hash
182
- [name, dynamic, type, content, priority].hash
190
+ [name, type, content, priority, dynamic].hash
183
191
  end
184
192
 
185
193
  # Builds the object from hash
@@ -0,0 +1,251 @@
1
+ =begin
2
+ #Fastly API
3
+
4
+ #Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://developer.fastly.com/reference/api/)
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: oss@fastly.com
8
+
9
+ =end
10
+
11
+ require 'date'
12
+ require 'time'
13
+
14
+ module Fastly
15
+ class SnippetAllOf
16
+ # Sets the snippet version.
17
+ attr_accessor :dynamic
18
+
19
+ class EnumAttributeValidator
20
+ attr_reader :datatype
21
+ attr_reader :allowable_values
22
+
23
+ def initialize(datatype, allowable_values)
24
+ @allowable_values = allowable_values.map do |value|
25
+ case datatype.to_s
26
+ when /Integer/i
27
+ value.to_i
28
+ when /Float/i
29
+ value.to_f
30
+ else
31
+ value
32
+ end
33
+ end
34
+ end
35
+
36
+ def valid?(value)
37
+ !value || allowable_values.include?(value)
38
+ end
39
+ end
40
+
41
+ # Attribute mapping from ruby-style variable name to JSON key.
42
+ def self.attribute_map
43
+ {
44
+ :'dynamic' => :'dynamic'
45
+ }
46
+ end
47
+
48
+ # Returns all the JSON keys this model knows about
49
+ def self.acceptable_attributes
50
+ attribute_map.values
51
+ end
52
+
53
+ # Attribute type mapping.
54
+ def self.fastly_types
55
+ {
56
+ :'dynamic' => :'String'
57
+ }
58
+ end
59
+
60
+ # List of attributes with nullable: true
61
+ def self.fastly_nullable
62
+ Set.new([
63
+ ])
64
+ end
65
+
66
+ # Initializes the object
67
+ # @param [Hash] attributes Model attributes in the form of hash
68
+ def initialize(attributes = {})
69
+ if (!attributes.is_a?(Hash))
70
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Fastly::SnippetAllOf` initialize method"
71
+ end
72
+
73
+ # check to see if the attribute exists and convert string to symbol for hash key
74
+ attributes = attributes.each_with_object({}) { |(k, v), h|
75
+ if (!self.class.attribute_map.key?(k.to_sym))
76
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Fastly::SnippetAllOf`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
77
+ end
78
+ h[k.to_sym] = v
79
+ }
80
+
81
+ if attributes.key?(:'dynamic')
82
+ self.dynamic = attributes[:'dynamic']
83
+ end
84
+ end
85
+
86
+ # Show invalid properties with the reasons. Usually used together with valid?
87
+ # @return Array for valid properties with the reasons
88
+ def list_invalid_properties
89
+ invalid_properties = Array.new
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ dynamic_validator = EnumAttributeValidator.new('String', ["0", "1"])
97
+ return false unless dynamic_validator.valid?(@dynamic)
98
+ true
99
+ end
100
+
101
+ # Custom attribute writer method checking allowed values (enum).
102
+ # @param [Object] dynamic Object to be assigned
103
+ def dynamic=(dynamic)
104
+ validator = EnumAttributeValidator.new('String', ["0", "1"])
105
+ unless validator.valid?(dynamic)
106
+ fail ArgumentError, "invalid value for \"dynamic\", must be one of #{validator.allowable_values}."
107
+ end
108
+ @dynamic = dynamic
109
+ end
110
+
111
+ # Checks equality by comparing each attribute.
112
+ # @param [Object] Object to be compared
113
+ def ==(o)
114
+ return true if self.equal?(o)
115
+ self.class == o.class &&
116
+ dynamic == o.dynamic
117
+ end
118
+
119
+ # @see the `==` method
120
+ # @param [Object] Object to be compared
121
+ def eql?(o)
122
+ self == o
123
+ end
124
+
125
+ # Calculates hash code according to all attributes.
126
+ # @return [Integer] Hash code
127
+ def hash
128
+ [dynamic].hash
129
+ end
130
+
131
+ # Builds the object from hash
132
+ # @param [Hash] attributes Model attributes in the form of hash
133
+ # @return [Object] Returns the model itself
134
+ def self.build_from_hash(attributes)
135
+ new.build_from_hash(attributes)
136
+ end
137
+
138
+ # Builds the object from hash
139
+ # @param [Hash] attributes Model attributes in the form of hash
140
+ # @return [Object] Returns the model itself
141
+ def build_from_hash(attributes)
142
+ return nil unless attributes.is_a?(Hash)
143
+ self.class.fastly_types.each_pair do |key, type|
144
+ if attributes[self.class.attribute_map[key]].nil? && self.class.fastly_nullable.include?(key)
145
+ self.send("#{key}=", nil)
146
+ elsif type =~ /\AArray<(.*)>/i
147
+ # check to ensure the input is an array given that the attribute
148
+ # is documented as an array but the input is not
149
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
150
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
151
+ end
152
+ elsif !attributes[self.class.attribute_map[key]].nil?
153
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
154
+ end
155
+ end
156
+
157
+ self
158
+ end
159
+
160
+ # Deserializes the data based on type
161
+ # @param string type Data type
162
+ # @param string value Value to be deserialized
163
+ # @return [Object] Deserialized data
164
+ def _deserialize(type, value)
165
+ case type.to_sym
166
+ when :Time
167
+ Time.parse(value)
168
+ when :Date
169
+ Date.parse(value)
170
+ when :String
171
+ value.to_s
172
+ when :Integer
173
+ value.to_i
174
+ when :Float
175
+ value.to_f
176
+ when :Boolean
177
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
178
+ true
179
+ else
180
+ false
181
+ end
182
+ when :Object
183
+ # generic object (usually a Hash), return directly
184
+ value
185
+ when /\AArray<(?<inner_type>.+)>\z/
186
+ inner_type = Regexp.last_match[:inner_type]
187
+ value.map { |v| _deserialize(inner_type, v) }
188
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
189
+ k_type = Regexp.last_match[:k_type]
190
+ v_type = Regexp.last_match[:v_type]
191
+ {}.tap do |hash|
192
+ value.each do |k, v|
193
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
194
+ end
195
+ end
196
+ else # model
197
+ # models (e.g. Pet) or oneOf
198
+ klass = Fastly.const_get(type)
199
+ klass.respond_to?(:fastly_one_of) ? klass.build(value) : klass.build_from_hash(value)
200
+ end
201
+ end
202
+
203
+ # Returns the string representation of the object
204
+ # @return [String] String presentation of the object
205
+ def to_s
206
+ to_hash.to_s
207
+ end
208
+
209
+ # to_body is an alias to to_hash (backward compatibility)
210
+ # @return [Hash] Returns the object in the form of hash
211
+ def to_body
212
+ to_hash
213
+ end
214
+
215
+ # Returns the object in the form of hash
216
+ # @return [Hash] Returns the object in the form of hash
217
+ def to_hash
218
+ hash = {}
219
+ self.class.attribute_map.each_pair do |attr, param|
220
+ value = self.send(attr)
221
+ if value.nil?
222
+ is_nullable = self.class.fastly_nullable.include?(attr)
223
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
224
+ end
225
+
226
+ hash[param] = _to_hash(value)
227
+ end
228
+ hash
229
+ end
230
+
231
+ # Outputs non-array value in the form of hash
232
+ # For object, use to_hash. Otherwise, just return the value
233
+ # @param [Object] value Any valid value
234
+ # @return [Hash] Returns the value in the form of hash
235
+ def _to_hash(value)
236
+ if value.is_a?(Array)
237
+ value.compact.map { |v| _to_hash(v) }
238
+ elsif value.is_a?(Hash)
239
+ {}.tap do |hash|
240
+ value.each { |k, v| hash[k] = _to_hash(v) }
241
+ end
242
+ elsif value.respond_to? :to_hash
243
+ value.to_hash
244
+ else
245
+ value
246
+ end
247
+ end
248
+
249
+ end
250
+
251
+ end
@@ -0,0 +1,283 @@
1
+ =begin
2
+ #Fastly API
3
+
4
+ #Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://developer.fastly.com/reference/api/)
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: oss@fastly.com
8
+
9
+ =end
10
+
11
+ require 'date'
12
+ require 'time'
13
+
14
+ module Fastly
15
+ class SnippetCommon
16
+ # The name for the snippet.
17
+ attr_accessor :name
18
+
19
+ # The location in generated VCL where the snippet should be placed.
20
+ attr_accessor :type
21
+
22
+ # The VCL code that specifies exactly what the snippet does.
23
+ attr_accessor :content
24
+
25
+ # Priority determines execution order. Lower numbers execute first.
26
+ attr_accessor :priority
27
+
28
+ class EnumAttributeValidator
29
+ attr_reader :datatype
30
+ attr_reader :allowable_values
31
+
32
+ def initialize(datatype, allowable_values)
33
+ @allowable_values = allowable_values.map do |value|
34
+ case datatype.to_s
35
+ when /Integer/i
36
+ value.to_i
37
+ when /Float/i
38
+ value.to_f
39
+ else
40
+ value
41
+ end
42
+ end
43
+ end
44
+
45
+ def valid?(value)
46
+ !value || allowable_values.include?(value)
47
+ end
48
+ end
49
+
50
+ # Attribute mapping from ruby-style variable name to JSON key.
51
+ def self.attribute_map
52
+ {
53
+ :'name' => :'name',
54
+ :'type' => :'type',
55
+ :'content' => :'content',
56
+ :'priority' => :'priority'
57
+ }
58
+ end
59
+
60
+ # Returns all the JSON keys this model knows about
61
+ def self.acceptable_attributes
62
+ attribute_map.values
63
+ end
64
+
65
+ # Attribute type mapping.
66
+ def self.fastly_types
67
+ {
68
+ :'name' => :'String',
69
+ :'type' => :'String',
70
+ :'content' => :'String',
71
+ :'priority' => :'String'
72
+ }
73
+ end
74
+
75
+ # List of attributes with nullable: true
76
+ def self.fastly_nullable
77
+ Set.new([
78
+ ])
79
+ end
80
+
81
+ # Initializes the object
82
+ # @param [Hash] attributes Model attributes in the form of hash
83
+ def initialize(attributes = {})
84
+ if (!attributes.is_a?(Hash))
85
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Fastly::SnippetCommon` initialize method"
86
+ end
87
+
88
+ # check to see if the attribute exists and convert string to symbol for hash key
89
+ attributes = attributes.each_with_object({}) { |(k, v), h|
90
+ if (!self.class.attribute_map.key?(k.to_sym))
91
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Fastly::SnippetCommon`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
92
+ end
93
+ h[k.to_sym] = v
94
+ }
95
+
96
+ if attributes.key?(:'name')
97
+ self.name = attributes[:'name']
98
+ end
99
+
100
+ if attributes.key?(:'type')
101
+ self.type = attributes[:'type']
102
+ end
103
+
104
+ if attributes.key?(:'content')
105
+ self.content = attributes[:'content']
106
+ end
107
+
108
+ if attributes.key?(:'priority')
109
+ self.priority = attributes[:'priority']
110
+ else
111
+ self.priority = '100'
112
+ end
113
+ end
114
+
115
+ # Show invalid properties with the reasons. Usually used together with valid?
116
+ # @return Array for valid properties with the reasons
117
+ def list_invalid_properties
118
+ invalid_properties = Array.new
119
+ invalid_properties
120
+ end
121
+
122
+ # Check to see if the all the properties in the model are valid
123
+ # @return true if the model is valid
124
+ def valid?
125
+ type_validator = EnumAttributeValidator.new('String', ["init", "recv", "hash", "hit", "miss", "pass", "fetch", "error", "deliver", "log", "none"])
126
+ return false unless type_validator.valid?(@type)
127
+ true
128
+ end
129
+
130
+ # Custom attribute writer method checking allowed values (enum).
131
+ # @param [Object] type Object to be assigned
132
+ def type=(type)
133
+ validator = EnumAttributeValidator.new('String', ["init", "recv", "hash", "hit", "miss", "pass", "fetch", "error", "deliver", "log", "none"])
134
+ unless validator.valid?(type)
135
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
136
+ end
137
+ @type = type
138
+ end
139
+
140
+ # Checks equality by comparing each attribute.
141
+ # @param [Object] Object to be compared
142
+ def ==(o)
143
+ return true if self.equal?(o)
144
+ self.class == o.class &&
145
+ name == o.name &&
146
+ type == o.type &&
147
+ content == o.content &&
148
+ priority == o.priority
149
+ end
150
+
151
+ # @see the `==` method
152
+ # @param [Object] Object to be compared
153
+ def eql?(o)
154
+ self == o
155
+ end
156
+
157
+ # Calculates hash code according to all attributes.
158
+ # @return [Integer] Hash code
159
+ def hash
160
+ [name, type, content, priority].hash
161
+ end
162
+
163
+ # Builds the object from hash
164
+ # @param [Hash] attributes Model attributes in the form of hash
165
+ # @return [Object] Returns the model itself
166
+ def self.build_from_hash(attributes)
167
+ new.build_from_hash(attributes)
168
+ end
169
+
170
+ # Builds the object from hash
171
+ # @param [Hash] attributes Model attributes in the form of hash
172
+ # @return [Object] Returns the model itself
173
+ def build_from_hash(attributes)
174
+ return nil unless attributes.is_a?(Hash)
175
+ self.class.fastly_types.each_pair do |key, type|
176
+ if attributes[self.class.attribute_map[key]].nil? && self.class.fastly_nullable.include?(key)
177
+ self.send("#{key}=", nil)
178
+ elsif type =~ /\AArray<(.*)>/i
179
+ # check to ensure the input is an array given that the attribute
180
+ # is documented as an array but the input is not
181
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
182
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
183
+ end
184
+ elsif !attributes[self.class.attribute_map[key]].nil?
185
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
186
+ end
187
+ end
188
+
189
+ self
190
+ end
191
+
192
+ # Deserializes the data based on type
193
+ # @param string type Data type
194
+ # @param string value Value to be deserialized
195
+ # @return [Object] Deserialized data
196
+ def _deserialize(type, value)
197
+ case type.to_sym
198
+ when :Time
199
+ Time.parse(value)
200
+ when :Date
201
+ Date.parse(value)
202
+ when :String
203
+ value.to_s
204
+ when :Integer
205
+ value.to_i
206
+ when :Float
207
+ value.to_f
208
+ when :Boolean
209
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
210
+ true
211
+ else
212
+ false
213
+ end
214
+ when :Object
215
+ # generic object (usually a Hash), return directly
216
+ value
217
+ when /\AArray<(?<inner_type>.+)>\z/
218
+ inner_type = Regexp.last_match[:inner_type]
219
+ value.map { |v| _deserialize(inner_type, v) }
220
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
221
+ k_type = Regexp.last_match[:k_type]
222
+ v_type = Regexp.last_match[:v_type]
223
+ {}.tap do |hash|
224
+ value.each do |k, v|
225
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
226
+ end
227
+ end
228
+ else # model
229
+ # models (e.g. Pet) or oneOf
230
+ klass = Fastly.const_get(type)
231
+ klass.respond_to?(:fastly_one_of) ? klass.build(value) : klass.build_from_hash(value)
232
+ end
233
+ end
234
+
235
+ # Returns the string representation of the object
236
+ # @return [String] String presentation of the object
237
+ def to_s
238
+ to_hash.to_s
239
+ end
240
+
241
+ # to_body is an alias to to_hash (backward compatibility)
242
+ # @return [Hash] Returns the object in the form of hash
243
+ def to_body
244
+ to_hash
245
+ end
246
+
247
+ # Returns the object in the form of hash
248
+ # @return [Hash] Returns the object in the form of hash
249
+ def to_hash
250
+ hash = {}
251
+ self.class.attribute_map.each_pair do |attr, param|
252
+ value = self.send(attr)
253
+ if value.nil?
254
+ is_nullable = self.class.fastly_nullable.include?(attr)
255
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
256
+ end
257
+
258
+ hash[param] = _to_hash(value)
259
+ end
260
+ hash
261
+ end
262
+
263
+ # Outputs non-array value in the form of hash
264
+ # For object, use to_hash. Otherwise, just return the value
265
+ # @param [Object] value Any valid value
266
+ # @return [Hash] Returns the value in the form of hash
267
+ def _to_hash(value)
268
+ if value.is_a?(Array)
269
+ value.compact.map { |v| _to_hash(v) }
270
+ elsif value.is_a?(Hash)
271
+ {}.tap do |hash|
272
+ value.each { |k, v| hash[k] = _to_hash(v) }
273
+ end
274
+ elsif value.respond_to? :to_hash
275
+ value.to_hash
276
+ else
277
+ value
278
+ end
279
+ end
280
+
281
+ end
282
+
283
+ end