fastly 10.0.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +2 -5
  5. data/docs/AutomationToken.md +1 -1
  6. data/docs/AutomationTokenCreateRequestAttributes.md +1 -1
  7. data/docs/AutomationTokenCreateResponse.md +4 -6
  8. data/docs/AutomationTokenCreateResponseAllOf.md +3 -3
  9. data/docs/AutomationTokenResponse.md +4 -6
  10. data/docs/AutomationTokenResponseAllOf.md +4 -4
  11. data/docs/BillingUsageMetricsApi.md +11 -9
  12. data/docs/ComputeAclListEntriesMeta.md +1 -1
  13. data/docs/Header.md +2 -0
  14. data/docs/HeaderApi.md +8 -8
  15. data/docs/KvStoreItemApi.md +4 -4
  16. data/docs/LoggingAzureblobAdditional.md +1 -1
  17. data/docs/LoggingAzureblobApi.md +4 -4
  18. data/docs/LoggingAzureblobResponse.md +1 -1
  19. data/docs/Results.md +7 -0
  20. data/docs/SnippetApi.md +2 -2
  21. data/docs/{SnippetResponseCommonAllOf.md → SnippetResponseAllOf.md} +1 -1
  22. data/docs/TlsBulkCertificatesApi.md +4 -0
  23. data/lib/fastly/api/automation_tokens_api.rb +6 -6
  24. data/lib/fastly/api/billing_usage_metrics_api.rb +11 -8
  25. data/lib/fastly/api/header_api.rb +8 -8
  26. data/lib/fastly/api/kv_store_item_api.rb +5 -5
  27. data/lib/fastly/api/logging_azureblob_api.rb +4 -4
  28. data/lib/fastly/api/snippet_api.rb +3 -3
  29. data/lib/fastly/api/tls_bulk_certificates_api.rb +6 -0
  30. data/lib/fastly/configuration.rb +0 -18
  31. data/lib/fastly/models/automation_token.rb +1 -1
  32. data/lib/fastly/models/automation_token_create_request_attributes.rb +1 -1
  33. data/lib/fastly/models/automation_token_create_response.rb +21 -43
  34. data/lib/fastly/models/automation_token_create_response_all_of.rb +13 -12
  35. data/lib/fastly/models/automation_token_response.rb +24 -46
  36. data/lib/fastly/models/automation_token_response_all_of.rb +11 -10
  37. data/lib/fastly/models/compute_acl_list_entries_meta.rb +1 -1
  38. data/lib/fastly/models/header.rb +26 -4
  39. data/lib/fastly/models/header_response.rb +0 -1
  40. data/lib/fastly/models/logging_azureblob_additional.rb +1 -1
  41. data/lib/fastly/models/logging_azureblob_response.rb +1 -1
  42. data/lib/fastly/models/results.rb +71 -1
  43. data/lib/fastly/models/schemas_snippet_response.rb +3 -2
  44. data/lib/fastly/models/snippet.rb +0 -8
  45. data/lib/fastly/models/snippet_response.rb +2 -1
  46. data/lib/fastly/models/{snippet_response_common_all_of.rb → snippet_response_all_of.rb} +3 -3
  47. data/lib/fastly/version.rb +1 -1
  48. data/lib/fastly.rb +1 -26
  49. data/sig.json +1 -1
  50. metadata +4 -54
  51. data/docs/Billing.md +0 -16
  52. data/docs/BillingApi.md +0 -139
  53. data/docs/BillingBandwidth.md +0 -11
  54. data/docs/BillingBandwidthTiers.md +0 -14
  55. data/docs/BillingEstimateInvoiceId.md +0 -10
  56. data/docs/BillingEstimateLines.md +0 -10
  57. data/docs/BillingEstimateLinesLineItems.md +0 -18
  58. data/docs/BillingEstimateResponse.md +0 -18
  59. data/docs/BillingInvoiceId.md +0 -10
  60. data/docs/BillingRegions.md +0 -13
  61. data/docs/BillingResponse.md +0 -18
  62. data/docs/BillingResponseItemItemsData.md +0 -10
  63. data/docs/BillingResponseLineItem.md +0 -29
  64. data/docs/BillingStatus.md +0 -11
  65. data/docs/BillingTotal.md +0 -25
  66. data/docs/BillingTotalExtras.md +0 -12
  67. data/docs/HeaderResponseAdditional.md +0 -11
  68. data/docs/LineItemData.md +0 -26
  69. data/docs/SchemasSnippetResponseCommon.md +0 -15
  70. data/docs/SnippetAllOf.md +0 -10
  71. data/docs/SnippetCommon.md +0 -13
  72. data/docs/SnippetResponseCommon.md +0 -15
  73. data/docs/SnippetResponsePost.md +0 -20
  74. data/docs/SnippetWithDynamicNumber.md +0 -14
  75. data/docs/SnippetWithDynamicNumberAllOf.md +0 -10
  76. data/lib/fastly/api/billing_api.rb +0 -229
  77. data/lib/fastly/models/billing.rb +0 -278
  78. data/lib/fastly/models/billing_bandwidth.rb +0 -227
  79. data/lib/fastly/models/billing_bandwidth_tiers.rb +0 -252
  80. data/lib/fastly/models/billing_estimate_invoice_id.rb +0 -216
  81. data/lib/fastly/models/billing_estimate_lines.rb +0 -218
  82. data/lib/fastly/models/billing_estimate_lines_line_items.rb +0 -288
  83. data/lib/fastly/models/billing_estimate_response.rb +0 -307
  84. data/lib/fastly/models/billing_invoice_id.rb +0 -216
  85. data/lib/fastly/models/billing_regions.rb +0 -243
  86. data/lib/fastly/models/billing_response.rb +0 -307
  87. data/lib/fastly/models/billing_response_item_items_data.rb +0 -218
  88. data/lib/fastly/models/billing_response_line_item.rb +0 -418
  89. data/lib/fastly/models/billing_status.rb +0 -262
  90. data/lib/fastly/models/billing_total.rb +0 -371
  91. data/lib/fastly/models/billing_total_extras.rb +0 -237
  92. data/lib/fastly/models/header_response_additional.rb +0 -229
  93. data/lib/fastly/models/line_item_data.rb +0 -377
  94. data/lib/fastly/models/schemas_snippet_response_common.rb +0 -276
  95. data/lib/fastly/models/snippet_all_of.rb +0 -251
  96. data/lib/fastly/models/snippet_common.rb +0 -284
  97. data/lib/fastly/models/snippet_response_common.rb +0 -276
  98. data/lib/fastly/models/snippet_response_post.rb +0 -375
  99. data/lib/fastly/models/snippet_with_dynamic_number.rb +0 -314
  100. data/lib/fastly/models/snippet_with_dynamic_number_all_of.rb +0 -251
@@ -1,262 +0,0 @@
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://www.fastly.com/documentation/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 BillingStatus
16
- # What the current status of this invoice can be.
17
- attr_accessor :status
18
-
19
- # Date and time in ISO 8601 format.
20
- attr_accessor :sent_at
21
-
22
- class EnumAttributeValidator
23
- attr_reader :datatype
24
- attr_reader :allowable_values
25
-
26
- def initialize(datatype, allowable_values)
27
- @allowable_values = allowable_values.map do |value|
28
- case datatype.to_s
29
- when /Integer/i
30
- value.to_i
31
- when /Float/i
32
- value.to_f
33
- else
34
- value
35
- end
36
- end
37
- end
38
-
39
- def valid?(value)
40
- !value || allowable_values.include?(value)
41
- end
42
- end
43
-
44
- # Attribute mapping from ruby-style variable name to JSON key.
45
- def self.attribute_map
46
- {
47
- :'status' => :'status',
48
- :'sent_at' => :'sent_at'
49
- }
50
- end
51
-
52
- # Returns all the JSON keys this model knows about
53
- def self.acceptable_attributes
54
- attribute_map.values
55
- end
56
-
57
- # Attribute type mapping.
58
- def self.fastly_types
59
- {
60
- :'status' => :'String',
61
- :'sent_at' => :'Time'
62
- }
63
- end
64
-
65
- # List of attributes with nullable: true
66
- def self.fastly_nullable
67
- Set.new([
68
- :'sent_at'
69
- ])
70
- end
71
-
72
- # Initializes the object
73
- # @param [Hash] attributes Model attributes in the form of hash
74
- def initialize(attributes = {})
75
- if (!attributes.is_a?(Hash))
76
- fail ArgumentError, "The input argument (attributes) must be a hash in `Fastly::BillingStatus` initialize method"
77
- end
78
-
79
- # check to see if the attribute exists and convert string to symbol for hash key
80
- attributes = attributes.each_with_object({}) { |(k, v), h|
81
- if (!self.class.attribute_map.key?(k.to_sym))
82
- fail ArgumentError, "`#{k}` is not a valid attribute in `Fastly::BillingStatus`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
83
- end
84
- h[k.to_sym] = v
85
- }
86
-
87
- if attributes.key?(:'status')
88
- self.status = attributes[:'status']
89
- end
90
-
91
- if attributes.key?(:'sent_at')
92
- self.sent_at = attributes[:'sent_at']
93
- end
94
- end
95
-
96
- # Show invalid properties with the reasons. Usually used together with valid?
97
- # @return Array for valid properties with the reasons
98
- def list_invalid_properties
99
- invalid_properties = Array.new
100
- invalid_properties
101
- end
102
-
103
- # Check to see if the all the properties in the model are valid
104
- # @return true if the model is valid
105
- def valid?
106
- status_validator = EnumAttributeValidator.new('String', ["Pending", "Outstanding", "Paid", "MTD"])
107
- return false unless status_validator.valid?(@status)
108
- true
109
- end
110
-
111
- # Custom attribute writer method checking allowed values (enum).
112
- # @param [Object] status Object to be assigned
113
- def status=(status)
114
- validator = EnumAttributeValidator.new('String', ["Pending", "Outstanding", "Paid", "MTD"])
115
- unless validator.valid?(status)
116
- fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
117
- end
118
- @status = status
119
- end
120
-
121
- # Checks equality by comparing each attribute.
122
- # @param [Object] Object to be compared
123
- def ==(o)
124
- return true if self.equal?(o)
125
- self.class == o.class &&
126
- status == o.status &&
127
- sent_at == o.sent_at
128
- end
129
-
130
- # @see the `==` method
131
- # @param [Object] Object to be compared
132
- def eql?(o)
133
- self == o
134
- end
135
-
136
- # Calculates hash code according to all attributes.
137
- # @return [Integer] Hash code
138
- def hash
139
- [status, sent_at].hash
140
- end
141
-
142
- # Builds the object from hash
143
- # @param [Hash] attributes Model attributes in the form of hash
144
- # @return [Object] Returns the model itself
145
- def self.build_from_hash(attributes)
146
- new.build_from_hash(attributes)
147
- end
148
-
149
- # Builds the object from hash
150
- # @param [Hash] attributes Model attributes in the form of hash
151
- # @return [Object] Returns the model itself
152
- def build_from_hash(attributes)
153
- return nil unless attributes.is_a?(Hash)
154
- self.class.fastly_types.each_pair do |key, type|
155
- if attributes[self.class.attribute_map[key]].nil? && self.class.fastly_nullable.include?(key)
156
- self.send("#{key}=", nil)
157
- elsif type =~ /\AArray<(.*)>/i
158
- # check to ensure the input is an array given that the attribute
159
- # is documented as an array but the input is not
160
- if attributes[self.class.attribute_map[key]].is_a?(Array)
161
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
162
- end
163
- elsif !attributes[self.class.attribute_map[key]].nil?
164
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
165
- end
166
- end
167
-
168
- self
169
- end
170
-
171
- # Deserializes the data based on type
172
- # @param string type Data type
173
- # @param string value Value to be deserialized
174
- # @return [Object] Deserialized data
175
- def _deserialize(type, value)
176
- case type.to_sym
177
- when :Time
178
- Time.parse(value)
179
- when :Date
180
- Date.parse(value)
181
- when :String
182
- value.to_s
183
- when :Integer
184
- value.to_i
185
- when :Float
186
- value.to_f
187
- when :Boolean
188
- if value.to_s =~ /\A(true|t|yes|y|1)\z/i
189
- true
190
- else
191
- false
192
- end
193
- when :Object
194
- # generic object (usually a Hash), return directly
195
- value
196
- when /\AArray<(?<inner_type>.+)>\z/
197
- inner_type = Regexp.last_match[:inner_type]
198
- value.map { |v| _deserialize(inner_type, v) }
199
- when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
200
- k_type = Regexp.last_match[:k_type]
201
- v_type = Regexp.last_match[:v_type]
202
- {}.tap do |hash|
203
- value.each do |k, v|
204
- hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
205
- end
206
- end
207
- else # model
208
- # models (e.g. Pet) or oneOf
209
- klass = Fastly.const_get(type)
210
- klass.respond_to?(:fastly_one_of) ? klass.build(value) : klass.build_from_hash(value)
211
- end
212
- end
213
-
214
- # Returns the string representation of the object
215
- # @return [String] String presentation of the object
216
- def to_s
217
- to_hash.to_s
218
- end
219
-
220
- # to_body is an alias to to_hash (backward compatibility)
221
- # @return [Hash] Returns the object in the form of hash
222
- def to_body
223
- to_hash
224
- end
225
-
226
- # Returns the object in the form of hash
227
- # @return [Hash] Returns the object in the form of hash
228
- def to_hash
229
- hash = {}
230
- self.class.attribute_map.each_pair do |attr, param|
231
- value = self.send(attr)
232
- if value.nil?
233
- is_nullable = self.class.fastly_nullable.include?(attr)
234
- next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
235
- end
236
-
237
- hash[param] = _to_hash(value)
238
- end
239
- hash
240
- end
241
-
242
- # Outputs non-array value in the form of hash
243
- # For object, use to_hash. Otherwise, just return the value
244
- # @param [Object] value Any valid value
245
- # @return [Hash] Returns the value in the form of hash
246
- def _to_hash(value)
247
- if value.is_a?(Array)
248
- value.compact.map { |v| _to_hash(v) }
249
- elsif value.is_a?(Hash)
250
- {}.tap do |hash|
251
- value.each { |k, v| hash[k] = _to_hash(v) }
252
- end
253
- elsif value.respond_to? :to_hash
254
- value.to_hash
255
- else
256
- value
257
- end
258
- end
259
-
260
- end
261
-
262
- end
@@ -1,371 +0,0 @@
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://www.fastly.com/documentation/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
- # Complete summary of the billing information.
16
- class BillingTotal
17
- # The total amount of bandwidth used this month (See bandwidth_units for measurement).
18
- attr_accessor :bandwidth
19
-
20
- # The cost of the bandwidth used this month in USD.
21
- attr_accessor :bandwidth_cost
22
-
23
- # Bandwidth measurement units based on billing plan.
24
- attr_accessor :bandwidth_units
25
-
26
- # The final amount to be paid.
27
- attr_accessor :cost
28
-
29
- # Total incurred cost plus extras cost.
30
- attr_accessor :cost_before_discount
31
-
32
- # Calculated discount rate.
33
- attr_accessor :discount
34
-
35
- # A list of any extras for this invoice.
36
- attr_accessor :extras
37
-
38
- # Total cost of all extras.
39
- attr_accessor :extras_cost
40
-
41
- # The total cost of bandwidth and requests used this month.
42
- attr_accessor :incurred_cost
43
-
44
- # How much over the plan minimum has been incurred.
45
- attr_accessor :overage
46
-
47
- # The short code the plan this invoice was generated under.
48
- attr_accessor :plan_code
49
-
50
- # The minimum cost of this plan.
51
- attr_accessor :plan_minimum
52
-
53
- # The name of the plan this invoice was generated under.
54
- attr_accessor :plan_name
55
-
56
- # The total number of requests used this month.
57
- attr_accessor :requests
58
-
59
- # The cost of the requests used this month.
60
- attr_accessor :requests_cost
61
-
62
- # Payment terms. Almost always Net15.
63
- attr_accessor :terms
64
-
65
- # Attribute mapping from ruby-style variable name to JSON key.
66
- def self.attribute_map
67
- {
68
- :'bandwidth' => :'bandwidth',
69
- :'bandwidth_cost' => :'bandwidth_cost',
70
- :'bandwidth_units' => :'bandwidth_units',
71
- :'cost' => :'cost',
72
- :'cost_before_discount' => :'cost_before_discount',
73
- :'discount' => :'discount',
74
- :'extras' => :'extras',
75
- :'extras_cost' => :'extras_cost',
76
- :'incurred_cost' => :'incurred_cost',
77
- :'overage' => :'overage',
78
- :'plan_code' => :'plan_code',
79
- :'plan_minimum' => :'plan_minimum',
80
- :'plan_name' => :'plan_name',
81
- :'requests' => :'requests',
82
- :'requests_cost' => :'requests_cost',
83
- :'terms' => :'terms'
84
- }
85
- end
86
-
87
- # Returns all the JSON keys this model knows about
88
- def self.acceptable_attributes
89
- attribute_map.values
90
- end
91
-
92
- # Attribute type mapping.
93
- def self.fastly_types
94
- {
95
- :'bandwidth' => :'Float',
96
- :'bandwidth_cost' => :'Float',
97
- :'bandwidth_units' => :'String',
98
- :'cost' => :'Float',
99
- :'cost_before_discount' => :'Float',
100
- :'discount' => :'Float',
101
- :'extras' => :'Array<BillingTotalExtras>',
102
- :'extras_cost' => :'Float',
103
- :'incurred_cost' => :'Float',
104
- :'overage' => :'Float',
105
- :'plan_code' => :'String',
106
- :'plan_minimum' => :'Float',
107
- :'plan_name' => :'String',
108
- :'requests' => :'Float',
109
- :'requests_cost' => :'Float',
110
- :'terms' => :'String'
111
- }
112
- end
113
-
114
- # List of attributes with nullable: true
115
- def self.fastly_nullable
116
- Set.new([
117
- :'bandwidth_units',
118
- ])
119
- end
120
-
121
- # Initializes the object
122
- # @param [Hash] attributes Model attributes in the form of hash
123
- def initialize(attributes = {})
124
- if (!attributes.is_a?(Hash))
125
- fail ArgumentError, "The input argument (attributes) must be a hash in `Fastly::BillingTotal` initialize method"
126
- end
127
-
128
- # check to see if the attribute exists and convert string to symbol for hash key
129
- attributes = attributes.each_with_object({}) { |(k, v), h|
130
- if (!self.class.attribute_map.key?(k.to_sym))
131
- fail ArgumentError, "`#{k}` is not a valid attribute in `Fastly::BillingTotal`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
132
- end
133
- h[k.to_sym] = v
134
- }
135
-
136
- if attributes.key?(:'bandwidth')
137
- self.bandwidth = attributes[:'bandwidth']
138
- end
139
-
140
- if attributes.key?(:'bandwidth_cost')
141
- self.bandwidth_cost = attributes[:'bandwidth_cost']
142
- end
143
-
144
- if attributes.key?(:'bandwidth_units')
145
- self.bandwidth_units = attributes[:'bandwidth_units']
146
- end
147
-
148
- if attributes.key?(:'cost')
149
- self.cost = attributes[:'cost']
150
- end
151
-
152
- if attributes.key?(:'cost_before_discount')
153
- self.cost_before_discount = attributes[:'cost_before_discount']
154
- end
155
-
156
- if attributes.key?(:'discount')
157
- self.discount = attributes[:'discount']
158
- end
159
-
160
- if attributes.key?(:'extras')
161
- if (value = attributes[:'extras']).is_a?(Array)
162
- self.extras = value
163
- end
164
- end
165
-
166
- if attributes.key?(:'extras_cost')
167
- self.extras_cost = attributes[:'extras_cost']
168
- end
169
-
170
- if attributes.key?(:'incurred_cost')
171
- self.incurred_cost = attributes[:'incurred_cost']
172
- end
173
-
174
- if attributes.key?(:'overage')
175
- self.overage = attributes[:'overage']
176
- end
177
-
178
- if attributes.key?(:'plan_code')
179
- self.plan_code = attributes[:'plan_code']
180
- end
181
-
182
- if attributes.key?(:'plan_minimum')
183
- self.plan_minimum = attributes[:'plan_minimum']
184
- end
185
-
186
- if attributes.key?(:'plan_name')
187
- self.plan_name = attributes[:'plan_name']
188
- end
189
-
190
- if attributes.key?(:'requests')
191
- self.requests = attributes[:'requests']
192
- end
193
-
194
- if attributes.key?(:'requests_cost')
195
- self.requests_cost = attributes[:'requests_cost']
196
- end
197
-
198
- if attributes.key?(:'terms')
199
- self.terms = attributes[:'terms']
200
- end
201
- end
202
-
203
- # Show invalid properties with the reasons. Usually used together with valid?
204
- # @return Array for valid properties with the reasons
205
- def list_invalid_properties
206
- invalid_properties = Array.new
207
- invalid_properties
208
- end
209
-
210
- # Check to see if the all the properties in the model are valid
211
- # @return true if the model is valid
212
- def valid?
213
- true
214
- end
215
-
216
- # Checks equality by comparing each attribute.
217
- # @param [Object] Object to be compared
218
- def ==(o)
219
- return true if self.equal?(o)
220
- self.class == o.class &&
221
- bandwidth == o.bandwidth &&
222
- bandwidth_cost == o.bandwidth_cost &&
223
- bandwidth_units == o.bandwidth_units &&
224
- cost == o.cost &&
225
- cost_before_discount == o.cost_before_discount &&
226
- discount == o.discount &&
227
- extras == o.extras &&
228
- extras_cost == o.extras_cost &&
229
- incurred_cost == o.incurred_cost &&
230
- overage == o.overage &&
231
- plan_code == o.plan_code &&
232
- plan_minimum == o.plan_minimum &&
233
- plan_name == o.plan_name &&
234
- requests == o.requests &&
235
- requests_cost == o.requests_cost &&
236
- terms == o.terms
237
- end
238
-
239
- # @see the `==` method
240
- # @param [Object] Object to be compared
241
- def eql?(o)
242
- self == o
243
- end
244
-
245
- # Calculates hash code according to all attributes.
246
- # @return [Integer] Hash code
247
- def hash
248
- [bandwidth, bandwidth_cost, bandwidth_units, cost, cost_before_discount, discount, extras, extras_cost, incurred_cost, overage, plan_code, plan_minimum, plan_name, requests, requests_cost, terms].hash
249
- end
250
-
251
- # Builds the object from hash
252
- # @param [Hash] attributes Model attributes in the form of hash
253
- # @return [Object] Returns the model itself
254
- def self.build_from_hash(attributes)
255
- new.build_from_hash(attributes)
256
- end
257
-
258
- # Builds the object from hash
259
- # @param [Hash] attributes Model attributes in the form of hash
260
- # @return [Object] Returns the model itself
261
- def build_from_hash(attributes)
262
- return nil unless attributes.is_a?(Hash)
263
- self.class.fastly_types.each_pair do |key, type|
264
- if attributes[self.class.attribute_map[key]].nil? && self.class.fastly_nullable.include?(key)
265
- self.send("#{key}=", nil)
266
- elsif type =~ /\AArray<(.*)>/i
267
- # check to ensure the input is an array given that the attribute
268
- # is documented as an array but the input is not
269
- if attributes[self.class.attribute_map[key]].is_a?(Array)
270
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
271
- end
272
- elsif !attributes[self.class.attribute_map[key]].nil?
273
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
274
- end
275
- end
276
-
277
- self
278
- end
279
-
280
- # Deserializes the data based on type
281
- # @param string type Data type
282
- # @param string value Value to be deserialized
283
- # @return [Object] Deserialized data
284
- def _deserialize(type, value)
285
- case type.to_sym
286
- when :Time
287
- Time.parse(value)
288
- when :Date
289
- Date.parse(value)
290
- when :String
291
- value.to_s
292
- when :Integer
293
- value.to_i
294
- when :Float
295
- value.to_f
296
- when :Boolean
297
- if value.to_s =~ /\A(true|t|yes|y|1)\z/i
298
- true
299
- else
300
- false
301
- end
302
- when :Object
303
- # generic object (usually a Hash), return directly
304
- value
305
- when /\AArray<(?<inner_type>.+)>\z/
306
- inner_type = Regexp.last_match[:inner_type]
307
- value.map { |v| _deserialize(inner_type, v) }
308
- when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
309
- k_type = Regexp.last_match[:k_type]
310
- v_type = Regexp.last_match[:v_type]
311
- {}.tap do |hash|
312
- value.each do |k, v|
313
- hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
314
- end
315
- end
316
- else # model
317
- # models (e.g. Pet) or oneOf
318
- klass = Fastly.const_get(type)
319
- klass.respond_to?(:fastly_one_of) ? klass.build(value) : klass.build_from_hash(value)
320
- end
321
- end
322
-
323
- # Returns the string representation of the object
324
- # @return [String] String presentation of the object
325
- def to_s
326
- to_hash.to_s
327
- end
328
-
329
- # to_body is an alias to to_hash (backward compatibility)
330
- # @return [Hash] Returns the object in the form of hash
331
- def to_body
332
- to_hash
333
- end
334
-
335
- # Returns the object in the form of hash
336
- # @return [Hash] Returns the object in the form of hash
337
- def to_hash
338
- hash = {}
339
- self.class.attribute_map.each_pair do |attr, param|
340
- value = self.send(attr)
341
- if value.nil?
342
- is_nullable = self.class.fastly_nullable.include?(attr)
343
- next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
344
- end
345
-
346
- hash[param] = _to_hash(value)
347
- end
348
- hash
349
- end
350
-
351
- # Outputs non-array value in the form of hash
352
- # For object, use to_hash. Otherwise, just return the value
353
- # @param [Object] value Any valid value
354
- # @return [Hash] Returns the value in the form of hash
355
- def _to_hash(value)
356
- if value.is_a?(Array)
357
- value.compact.map { |v| _to_hash(v) }
358
- elsif value.is_a?(Hash)
359
- {}.tap do |hash|
360
- value.each { |k, v| hash[k] = _to_hash(v) }
361
- end
362
- elsif value.respond_to? :to_hash
363
- value.to_hash
364
- else
365
- value
366
- end
367
- end
368
-
369
- end
370
-
371
- end