zyphr 0.1.48 → 0.1.49

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.
@@ -0,0 +1,363 @@
1
+ =begin
2
+ #Zyphr API
3
+
4
+ #Zyphr is a multi-channel notification platform that enables developers to send emails, push notifications, SMS, and in-app messages through a unified API. ## Authentication All API requests require authentication using an API key. Include your API key in the `X-API-Key` header: ``` X-API-Key: zy_live_xxxxxxxxxxxx ``` API keys can be created in the Zyphr Dashboard. Use `zy_test_*` keys for testing and `zy_live_*` keys for production. ## Rate Limiting The API implements rate limiting to ensure fair usage. Rate limit information is included in response headers: - `X-RateLimit-Limit`: Maximum requests per window - `X-RateLimit-Remaining`: Remaining requests in current window - `X-RateLimit-Reset`: Unix timestamp when the window resets ## Account Sending Status Every authenticated response carries the account's current sending state so you can surface it in your own tooling without a separate call: - `X-Account-Sending-Status`: `active`, `throttled`, or `frozen` - `X-Account-Sending-Status-Reason`: human-readable reason (present only when the status is `throttled` or `frozen`) This header is informational and non-blocking on non-send endpoints (reads, billing, and deliverability stay available). Send-capable endpoints additionally enforce the state: a frozen account receives `403 account_frozen` and a throttled account receives `429 account_throttled`, both with the reason in the error message. ## Errors All errors follow a consistent format: ```json { \"error\": { \"code\": \"error_code\", \"message\": \"Human readable message\", \"details\": {} }, \"meta\": { \"request_id\": \"req_xxxx\" } } ```
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: support@zyphr.dev
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Zyphr
17
+ class PasswordStrength
18
+ # Whether the password would be accepted by the server's enforcement path. A password that is valid here is accepted by registration.
19
+ attr_accessor :valid
20
+
21
+ # Strength score, 0-100.
22
+ attr_accessor :score
23
+
24
+ # Strength label derived from the score.
25
+ attr_accessor :label
26
+
27
+ # Actionable feedback — policy errors plus strength-improvement suggestions.
28
+ attr_accessor :feedback
29
+
30
+ class EnumAttributeValidator
31
+ attr_reader :datatype
32
+ attr_reader :allowable_values
33
+
34
+ def initialize(datatype, allowable_values)
35
+ @allowable_values = allowable_values.map do |value|
36
+ case datatype.to_s
37
+ when /Integer/i
38
+ value.to_i
39
+ when /Float/i
40
+ value.to_f
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+
47
+ def valid?(value)
48
+ !value || allowable_values.include?(value)
49
+ end
50
+ end
51
+
52
+ # Attribute mapping from ruby-style variable name to JSON key.
53
+ def self.attribute_map
54
+ {
55
+ :'valid' => :'valid',
56
+ :'score' => :'score',
57
+ :'label' => :'label',
58
+ :'feedback' => :'feedback'
59
+ }
60
+ end
61
+
62
+ # Returns attribute mapping this model knows about
63
+ def self.acceptable_attribute_map
64
+ attribute_map
65
+ end
66
+
67
+ # Returns all the JSON keys this model knows about
68
+ def self.acceptable_attributes
69
+ acceptable_attribute_map.values
70
+ end
71
+
72
+ # Attribute type mapping.
73
+ def self.openapi_types
74
+ {
75
+ :'valid' => :'Boolean',
76
+ :'score' => :'Integer',
77
+ :'label' => :'String',
78
+ :'feedback' => :'Array<String>'
79
+ }
80
+ end
81
+
82
+ # List of attributes with nullable: true
83
+ def self.openapi_nullable
84
+ Set.new([
85
+ ])
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ if (!attributes.is_a?(Hash))
92
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::PasswordStrength` initialize method"
93
+ end
94
+
95
+ # check to see if the attribute exists and convert string to symbol for hash key
96
+ acceptable_attribute_map = self.class.acceptable_attribute_map
97
+ attributes = attributes.each_with_object({}) { |(k, v), h|
98
+ if (!acceptable_attribute_map.key?(k.to_sym))
99
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::PasswordStrength`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
100
+ end
101
+ h[k.to_sym] = v
102
+ }
103
+
104
+ if attributes.key?(:'valid')
105
+ self.valid = attributes[:'valid']
106
+ else
107
+ self.valid = nil
108
+ end
109
+
110
+ if attributes.key?(:'score')
111
+ self.score = attributes[:'score']
112
+ else
113
+ self.score = nil
114
+ end
115
+
116
+ if attributes.key?(:'label')
117
+ self.label = attributes[:'label']
118
+ else
119
+ self.label = nil
120
+ end
121
+
122
+ if attributes.key?(:'feedback')
123
+ if (value = attributes[:'feedback']).is_a?(Array)
124
+ self.feedback = value
125
+ end
126
+ else
127
+ self.feedback = nil
128
+ end
129
+ end
130
+
131
+ # Show invalid properties with the reasons. Usually used together with valid?
132
+ # @return Array for valid properties with the reasons
133
+ def list_invalid_properties
134
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
135
+ invalid_properties = Array.new
136
+ if @valid.nil?
137
+ invalid_properties.push('invalid value for "valid", valid cannot be nil.')
138
+ end
139
+
140
+ if @score.nil?
141
+ invalid_properties.push('invalid value for "score", score cannot be nil.')
142
+ end
143
+
144
+ if @score > 100
145
+ invalid_properties.push('invalid value for "score", must be smaller than or equal to 100.')
146
+ end
147
+
148
+ if @score < 0
149
+ invalid_properties.push('invalid value for "score", must be greater than or equal to 0.')
150
+ end
151
+
152
+ if @label.nil?
153
+ invalid_properties.push('invalid value for "label", label cannot be nil.')
154
+ end
155
+
156
+ if @feedback.nil?
157
+ invalid_properties.push('invalid value for "feedback", feedback cannot be nil.')
158
+ end
159
+
160
+ invalid_properties
161
+ end
162
+
163
+ # Check to see if the all the properties in the model are valid
164
+ # @return true if the model is valid
165
+ def valid?
166
+ warn '[DEPRECATED] the `valid?` method is obsolete'
167
+ return false if @valid.nil?
168
+ return false if @score.nil?
169
+ return false if @score > 100
170
+ return false if @score < 0
171
+ return false if @label.nil?
172
+ label_validator = EnumAttributeValidator.new('String', ["weak", "fair", "good", "strong"])
173
+ return false unless label_validator.valid?(@label)
174
+ return false if @feedback.nil?
175
+ true
176
+ end
177
+
178
+ # Custom attribute writer method with validation
179
+ # @param [Object] valid Value to be assigned
180
+ def valid=(valid)
181
+ if valid.nil?
182
+ fail ArgumentError, 'valid cannot be nil'
183
+ end
184
+
185
+ @valid = valid
186
+ end
187
+
188
+ # Custom attribute writer method with validation
189
+ # @param [Object] score Value to be assigned
190
+ def score=(score)
191
+ if score.nil?
192
+ fail ArgumentError, 'score cannot be nil'
193
+ end
194
+
195
+ if score > 100
196
+ fail ArgumentError, 'invalid value for "score", must be smaller than or equal to 100.'
197
+ end
198
+
199
+ if score < 0
200
+ fail ArgumentError, 'invalid value for "score", must be greater than or equal to 0.'
201
+ end
202
+
203
+ @score = score
204
+ end
205
+
206
+ # Custom attribute writer method checking allowed values (enum).
207
+ # @param [Object] label Object to be assigned
208
+ def label=(label)
209
+ validator = EnumAttributeValidator.new('String', ["weak", "fair", "good", "strong"])
210
+ unless validator.valid?(label)
211
+ fail ArgumentError, "invalid value for \"label\", must be one of #{validator.allowable_values}."
212
+ end
213
+ @label = label
214
+ end
215
+
216
+ # Custom attribute writer method with validation
217
+ # @param [Object] feedback Value to be assigned
218
+ def feedback=(feedback)
219
+ if feedback.nil?
220
+ fail ArgumentError, 'feedback cannot be nil'
221
+ end
222
+
223
+ @feedback = feedback
224
+ end
225
+
226
+ # Checks equality by comparing each attribute.
227
+ # @param [Object] Object to be compared
228
+ def ==(o)
229
+ return true if self.equal?(o)
230
+ self.class == o.class &&
231
+ valid == o.valid &&
232
+ score == o.score &&
233
+ label == o.label &&
234
+ feedback == o.feedback
235
+ end
236
+
237
+ # @see the `==` method
238
+ # @param [Object] Object to be compared
239
+ def eql?(o)
240
+ self == o
241
+ end
242
+
243
+ # Calculates hash code according to all attributes.
244
+ # @return [Integer] Hash code
245
+ def hash
246
+ [valid, score, label, feedback].hash
247
+ end
248
+
249
+ # Builds the object from hash
250
+ # @param [Hash] attributes Model attributes in the form of hash
251
+ # @return [Object] Returns the model itself
252
+ def self.build_from_hash(attributes)
253
+ return nil unless attributes.is_a?(Hash)
254
+ attributes = attributes.transform_keys(&:to_sym)
255
+ transformed_hash = {}
256
+ openapi_types.each_pair do |key, type|
257
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
258
+ transformed_hash["#{key}"] = nil
259
+ elsif type =~ /\AArray<(.*)>/i
260
+ # check to ensure the input is an array given that the attribute
261
+ # is documented as an array but the input is not
262
+ if attributes[attribute_map[key]].is_a?(Array)
263
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
264
+ end
265
+ elsif !attributes[attribute_map[key]].nil?
266
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
267
+ end
268
+ end
269
+ new(transformed_hash)
270
+ end
271
+
272
+ # Deserializes the data based on type
273
+ # @param string type Data type
274
+ # @param string value Value to be deserialized
275
+ # @return [Object] Deserialized data
276
+ def self._deserialize(type, value)
277
+ case type.to_sym
278
+ when :Time
279
+ Time.parse(value)
280
+ when :Date
281
+ Date.parse(value)
282
+ when :String
283
+ value.to_s
284
+ when :Integer
285
+ value.to_i
286
+ when :Float
287
+ value.to_f
288
+ when :Boolean
289
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
290
+ true
291
+ else
292
+ false
293
+ end
294
+ when :Object
295
+ # generic object (usually a Hash), return directly
296
+ value
297
+ when /\AArray<(?<inner_type>.+)>\z/
298
+ inner_type = Regexp.last_match[:inner_type]
299
+ value.map { |v| _deserialize(inner_type, v) }
300
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
301
+ k_type = Regexp.last_match[:k_type]
302
+ v_type = Regexp.last_match[:v_type]
303
+ {}.tap do |hash|
304
+ value.each do |k, v|
305
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
306
+ end
307
+ end
308
+ else # model
309
+ # models (e.g. Pet) or oneOf
310
+ klass = Zyphr.const_get(type)
311
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
312
+ end
313
+ end
314
+
315
+ # Returns the string representation of the object
316
+ # @return [String] String presentation of the object
317
+ def to_s
318
+ to_hash.to_s
319
+ end
320
+
321
+ # to_body is an alias to to_hash (backward compatibility)
322
+ # @return [Hash] Returns the object in the form of hash
323
+ def to_body
324
+ to_hash
325
+ end
326
+
327
+ # Returns the object in the form of hash
328
+ # @return [Hash] Returns the object in the form of hash
329
+ def to_hash
330
+ hash = {}
331
+ self.class.attribute_map.each_pair do |attr, param|
332
+ value = self.send(attr)
333
+ if value.nil?
334
+ is_nullable = self.class.openapi_nullable.include?(attr)
335
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
336
+ end
337
+
338
+ hash[param] = _to_hash(value)
339
+ end
340
+ hash
341
+ end
342
+
343
+ # Outputs non-array value in the form of hash
344
+ # For object, use to_hash. Otherwise, just return the value
345
+ # @param [Object] value Any valid value
346
+ # @return [Hash] Returns the value in the form of hash
347
+ def _to_hash(value)
348
+ if value.is_a?(Array)
349
+ value.compact.map { |v| _to_hash(v) }
350
+ elsif value.is_a?(Hash)
351
+ {}.tap do |hash|
352
+ value.each { |k, v| hash[k] = _to_hash(v) }
353
+ end
354
+ elsif value.respond_to? :to_hash
355
+ value.to_hash
356
+ else
357
+ value
358
+ end
359
+ end
360
+
361
+ end
362
+
363
+ end
@@ -14,28 +14,19 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module Zyphr
17
- class PasswordRequirements
18
- attr_accessor :min_length
17
+ # Pre-submit password strength check request. The password is evaluated against the application's policy and never logged or persisted.
18
+ class PasswordStrengthRequest
19
+ # The password to evaluate.
20
+ attr_accessor :password
19
21
 
20
- attr_accessor :max_length
21
-
22
- attr_accessor :require_uppercase
23
-
24
- attr_accessor :require_lowercase
25
-
26
- attr_accessor :require_numbers
27
-
28
- attr_accessor :require_special
22
+ # Optional. When provided, the password is checked for similarity to the email's local-part; a match is flagged and marks the password invalid.
23
+ attr_accessor :email
29
24
 
30
25
  # Attribute mapping from ruby-style variable name to JSON key.
31
26
  def self.attribute_map
32
27
  {
33
- :'min_length' => :'min_length',
34
- :'max_length' => :'max_length',
35
- :'require_uppercase' => :'require_uppercase',
36
- :'require_lowercase' => :'require_lowercase',
37
- :'require_numbers' => :'require_numbers',
38
- :'require_special' => :'require_special'
28
+ :'password' => :'password',
29
+ :'email' => :'email'
39
30
  }
40
31
  end
41
32
 
@@ -52,12 +43,8 @@ module Zyphr
52
43
  # Attribute type mapping.
53
44
  def self.openapi_types
54
45
  {
55
- :'min_length' => :'Integer',
56
- :'max_length' => :'Integer',
57
- :'require_uppercase' => :'Boolean',
58
- :'require_lowercase' => :'Boolean',
59
- :'require_numbers' => :'Boolean',
60
- :'require_special' => :'Boolean'
46
+ :'password' => :'String',
47
+ :'email' => :'String'
61
48
  }
62
49
  end
63
50
 
@@ -71,40 +58,26 @@ module Zyphr
71
58
  # @param [Hash] attributes Model attributes in the form of hash
72
59
  def initialize(attributes = {})
73
60
  if (!attributes.is_a?(Hash))
74
- fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::PasswordRequirements` initialize method"
61
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::PasswordStrengthRequest` initialize method"
75
62
  end
76
63
 
77
64
  # check to see if the attribute exists and convert string to symbol for hash key
78
65
  acceptable_attribute_map = self.class.acceptable_attribute_map
79
66
  attributes = attributes.each_with_object({}) { |(k, v), h|
80
67
  if (!acceptable_attribute_map.key?(k.to_sym))
81
- fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::PasswordRequirements`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
68
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::PasswordStrengthRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
82
69
  end
83
70
  h[k.to_sym] = v
84
71
  }
85
72
 
86
- if attributes.key?(:'min_length')
87
- self.min_length = attributes[:'min_length']
88
- end
89
-
90
- if attributes.key?(:'max_length')
91
- self.max_length = attributes[:'max_length']
92
- end
93
-
94
- if attributes.key?(:'require_uppercase')
95
- self.require_uppercase = attributes[:'require_uppercase']
96
- end
97
-
98
- if attributes.key?(:'require_lowercase')
99
- self.require_lowercase = attributes[:'require_lowercase']
100
- end
101
-
102
- if attributes.key?(:'require_numbers')
103
- self.require_numbers = attributes[:'require_numbers']
73
+ if attributes.key?(:'password')
74
+ self.password = attributes[:'password']
75
+ else
76
+ self.password = nil
104
77
  end
105
78
 
106
- if attributes.key?(:'require_special')
107
- self.require_special = attributes[:'require_special']
79
+ if attributes.key?(:'email')
80
+ self.email = attributes[:'email']
108
81
  end
109
82
  end
110
83
 
@@ -113,6 +86,10 @@ module Zyphr
113
86
  def list_invalid_properties
114
87
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
115
88
  invalid_properties = Array.new
89
+ if @password.nil?
90
+ invalid_properties.push('invalid value for "password", password cannot be nil.')
91
+ end
92
+
116
93
  invalid_properties
117
94
  end
118
95
 
@@ -120,20 +97,27 @@ module Zyphr
120
97
  # @return true if the model is valid
121
98
  def valid?
122
99
  warn '[DEPRECATED] the `valid?` method is obsolete'
100
+ return false if @password.nil?
123
101
  true
124
102
  end
125
103
 
104
+ # Custom attribute writer method with validation
105
+ # @param [Object] password Value to be assigned
106
+ def password=(password)
107
+ if password.nil?
108
+ fail ArgumentError, 'password cannot be nil'
109
+ end
110
+
111
+ @password = password
112
+ end
113
+
126
114
  # Checks equality by comparing each attribute.
127
115
  # @param [Object] Object to be compared
128
116
  def ==(o)
129
117
  return true if self.equal?(o)
130
118
  self.class == o.class &&
131
- min_length == o.min_length &&
132
- max_length == o.max_length &&
133
- require_uppercase == o.require_uppercase &&
134
- require_lowercase == o.require_lowercase &&
135
- require_numbers == o.require_numbers &&
136
- require_special == o.require_special
119
+ password == o.password &&
120
+ email == o.email
137
121
  end
138
122
 
139
123
  # @see the `==` method
@@ -145,7 +129,7 @@ module Zyphr
145
129
  # Calculates hash code according to all attributes.
146
130
  # @return [Integer] Hash code
147
131
  def hash
148
- [min_length, max_length, require_uppercase, require_lowercase, require_numbers, require_special].hash
132
+ [password, email].hash
149
133
  end
150
134
 
151
135
  # Builds the object from hash