phrase 2.0.0 → 2.1.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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -3
  3. data/docs/Account.md +3 -1
  4. data/docs/AccountDetails.md +5 -1
  5. data/docs/AccountDetails1.md +3 -1
  6. data/docs/AccountSearchResult.md +29 -0
  7. data/docs/Branch.md +5 -1
  8. data/docs/Comment.md +3 -1
  9. data/docs/JobTemplate.md +29 -0
  10. data/docs/JobTemplateCreateParameters.md +21 -0
  11. data/docs/JobTemplateLocale.md +23 -0
  12. data/docs/JobTemplateLocaleUpdateParameters.md +23 -0
  13. data/docs/JobTemplateLocalesApi.md +347 -0
  14. data/docs/JobTemplateLocalesCreateParameters.md +23 -0
  15. data/docs/JobTemplatePreview.md +19 -0
  16. data/docs/JobTemplateUpdateParameters.md +21 -0
  17. data/docs/JobTemplateUserPreview.md +23 -0
  18. data/docs/JobTemplatesApi.md +337 -0
  19. data/docs/KeysApi.md +132 -4
  20. data/docs/KeysExcludeParameters.md +23 -0
  21. data/docs/KeysIncludeParameters.md +23 -0
  22. data/docs/KeysSearchParameters.md +1 -1
  23. data/docs/KeysTagParameters.md +1 -1
  24. data/docs/KeysUntagParameters.md +1 -1
  25. data/docs/LocalePreview1.md +23 -0
  26. data/docs/LocalesApi.md +68 -2
  27. data/docs/MemberSpaces.md +2 -2
  28. data/docs/MemberUpdateParameters.md +4 -2
  29. data/docs/Notification.md +41 -0
  30. data/docs/NotificationGroup.md +23 -0
  31. data/docs/NotificationGroupDetail.md +27 -0
  32. data/docs/NotificationGroupsApi.md +194 -0
  33. data/docs/NotificationsApi.md +194 -0
  34. data/docs/OrderCreateParameters.md +2 -0
  35. data/docs/Project.md +2 -0
  36. data/docs/ProjectCreateParameters.md +35 -1
  37. data/docs/ProjectDetails.md +2 -0
  38. data/docs/ProjectsApi.md +7 -1
  39. data/docs/SearchApi.md +72 -0
  40. data/docs/SearchInAccountParameters.md +23 -0
  41. data/docs/Space1.md +25 -0
  42. data/docs/Subscription.md +19 -0
  43. data/docs/TranslationOrder.md +2 -0
  44. data/docs/User.md +0 -2
  45. data/lib/phrase.rb +23 -0
  46. data/lib/phrase/api/job_template_locales_api.rb +417 -0
  47. data/lib/phrase/api/job_templates_api.rb +387 -0
  48. data/lib/phrase/api/keys_api.rb +152 -4
  49. data/lib/phrase/api/locales_api.rb +71 -2
  50. data/lib/phrase/api/notification_groups_api.rb +202 -0
  51. data/lib/phrase/api/notifications_api.rb +202 -0
  52. data/lib/phrase/api/projects_api.rb +9 -0
  53. data/lib/phrase/api/search_api.rb +84 -0
  54. data/lib/phrase/models/account.rb +13 -4
  55. data/lib/phrase/models/account_details.rb +22 -4
  56. data/lib/phrase/models/account_details1.rb +10 -1
  57. data/lib/phrase/models/account_search_result.rb +250 -0
  58. data/lib/phrase/models/branch.rb +19 -1
  59. data/lib/phrase/models/comment.rb +15 -4
  60. data/lib/phrase/models/job_template.rb +248 -0
  61. data/lib/phrase/models/job_template_create_parameters.rb +220 -0
  62. data/lib/phrase/models/job_template_locale.rb +223 -0
  63. data/lib/phrase/models/job_template_locale_update_parameters.rb +234 -0
  64. data/lib/phrase/models/job_template_locales_create_parameters.rb +234 -0
  65. data/lib/phrase/models/job_template_preview.rb +203 -0
  66. data/lib/phrase/models/job_template_update_parameters.rb +220 -0
  67. data/lib/phrase/models/job_template_user_preview.rb +221 -0
  68. data/lib/phrase/models/keys_exclude_parameters.rb +225 -0
  69. data/lib/phrase/models/keys_include_parameters.rb +225 -0
  70. data/lib/phrase/models/keys_search_parameters.rb +1 -1
  71. data/lib/phrase/models/keys_tag_parameters.rb +1 -1
  72. data/lib/phrase/models/keys_untag_parameters.rb +1 -1
  73. data/lib/phrase/models/locale_preview1.rb +221 -0
  74. data/lib/phrase/models/member_spaces.rb +2 -2
  75. data/lib/phrase/models/member_update_parameters.rb +12 -2
  76. data/lib/phrase/models/notification.rb +302 -0
  77. data/lib/phrase/models/notification_group.rb +221 -0
  78. data/lib/phrase/models/notification_group_detail.rb +239 -0
  79. data/lib/phrase/models/order_create_parameters.rb +11 -1
  80. data/lib/phrase/models/project.rb +10 -1
  81. data/lib/phrase/models/project_create_parameters.rb +174 -4
  82. data/lib/phrase/models/project_details.rb +10 -1
  83. data/lib/phrase/models/search_in_account_parameters.rb +225 -0
  84. data/lib/phrase/models/space1.rb +230 -0
  85. data/lib/phrase/models/subscription.rb +203 -0
  86. data/lib/phrase/models/translation_order.rb +10 -1
  87. data/lib/phrase/models/user.rb +1 -10
  88. data/lib/phrase/version.rb +1 -1
  89. data/spec/api/job_template_locales_api_spec.rb +103 -0
  90. data/spec/api/job_templates_api_spec.rb +98 -0
  91. data/spec/api/keys_api_spec.rb +30 -2
  92. data/spec/api/locales_api_spec.rb +16 -1
  93. data/spec/api/notification_groups_api_spec.rb +62 -0
  94. data/spec/api/notifications_api_spec.rb +62 -0
  95. data/spec/api/projects_api_spec.rb +3 -0
  96. data/spec/api/search_api_spec.rb +37 -0
  97. data/spec/models/account_details1_spec.rb +6 -0
  98. data/spec/models/account_details_spec.rb +12 -0
  99. data/spec/models/account_search_result_spec.rb +65 -0
  100. data/spec/models/account_spec.rb +6 -0
  101. data/spec/models/branch_spec.rb +12 -0
  102. data/spec/models/comment_spec.rb +6 -0
  103. data/spec/models/job_template_create_parameters_spec.rb +41 -0
  104. data/spec/models/job_template_locale_spec.rb +47 -0
  105. data/spec/models/job_template_locale_update_parameters_spec.rb +47 -0
  106. data/spec/models/job_template_locales_create_parameters_spec.rb +47 -0
  107. data/spec/models/job_template_preview_spec.rb +35 -0
  108. data/spec/models/job_template_spec.rb +65 -0
  109. data/spec/models/job_template_update_parameters_spec.rb +41 -0
  110. data/spec/models/job_template_user_preview_spec.rb +47 -0
  111. data/spec/models/keys_exclude_parameters_spec.rb +47 -0
  112. data/spec/models/keys_include_parameters_spec.rb +47 -0
  113. data/spec/models/locale_preview1_spec.rb +47 -0
  114. data/spec/models/member_update_parameters_spec.rb +6 -0
  115. data/spec/models/notification_group_detail_spec.rb +59 -0
  116. data/spec/models/notification_group_spec.rb +47 -0
  117. data/spec/models/notification_spec.rb +101 -0
  118. data/spec/models/order_create_parameters_spec.rb +6 -0
  119. data/spec/models/project_create_parameters_spec.rb +102 -0
  120. data/spec/models/project_details_spec.rb +6 -0
  121. data/spec/models/project_spec.rb +6 -0
  122. data/spec/models/search_in_account_parameters_spec.rb +47 -0
  123. data/spec/models/space1_spec.rb +53 -0
  124. data/spec/models/subscription_spec.rb +35 -0
  125. data/spec/models/translation_order_spec.rb +6 -0
  126. data/spec/models/user_spec.rb +0 -6
  127. metadata +268 -176
@@ -2,6 +2,10 @@ require 'date'
2
2
 
3
3
  module Phrase
4
4
  class Branch
5
+ attr_accessor :base_project_id
6
+
7
+ attr_accessor :branch_project_id
8
+
5
9
  attr_accessor :name
6
10
 
7
11
  attr_accessor :created_at
@@ -19,6 +23,8 @@ module Phrase
19
23
  # Attribute mapping from ruby-style variable name to JSON key.
20
24
  def self.attribute_map
21
25
  {
26
+ :'base_project_id' => :'base_project_id',
27
+ :'branch_project_id' => :'branch_project_id',
22
28
  :'name' => :'name',
23
29
  :'created_at' => :'created_at',
24
30
  :'updated_at' => :'updated_at',
@@ -32,6 +38,8 @@ module Phrase
32
38
  # Attribute type mapping.
33
39
  def self.openapi_types
34
40
  {
41
+ :'base_project_id' => :'String',
42
+ :'branch_project_id' => :'String',
35
43
  :'name' => :'String',
36
44
  :'created_at' => :'DateTime',
37
45
  :'updated_at' => :'DateTime',
@@ -63,6 +71,14 @@ module Phrase
63
71
  h[k.to_sym] = v
64
72
  }
65
73
 
74
+ if attributes.key?(:'base_project_id')
75
+ self.base_project_id = attributes[:'base_project_id']
76
+ end
77
+
78
+ if attributes.key?(:'branch_project_id')
79
+ self.branch_project_id = attributes[:'branch_project_id']
80
+ end
81
+
66
82
  if attributes.key?(:'name')
67
83
  self.name = attributes[:'name']
68
84
  end
@@ -110,6 +126,8 @@ module Phrase
110
126
  def ==(o)
111
127
  return true if self.equal?(o)
112
128
  self.class == o.class &&
129
+ base_project_id == o.base_project_id &&
130
+ branch_project_id == o.branch_project_id &&
113
131
  name == o.name &&
114
132
  created_at == o.created_at &&
115
133
  updated_at == o.updated_at &&
@@ -128,7 +146,7 @@ module Phrase
128
146
  # Calculates hash code according to all attributes.
129
147
  # @return [Integer] Hash code
130
148
  def hash
131
- [name, created_at, updated_at, merged_at, merged_by, created_by, state].hash
149
+ [base_project_id, branch_project_id, name, created_at, updated_at, merged_at, merged_by, created_by, state].hash
132
150
  end
133
151
 
134
152
  # Builds the object from hash
@@ -12,6 +12,8 @@ module Phrase
12
12
 
13
13
  attr_accessor :updated_at
14
14
 
15
+ attr_accessor :mentioned_users
16
+
15
17
  # Attribute mapping from ruby-style variable name to JSON key.
16
18
  def self.attribute_map
17
19
  {
@@ -19,7 +21,8 @@ module Phrase
19
21
  :'message' => :'message',
20
22
  :'user' => :'user',
21
23
  :'created_at' => :'created_at',
22
- :'updated_at' => :'updated_at'
24
+ :'updated_at' => :'updated_at',
25
+ :'mentioned_users' => :'mentioned_users'
23
26
  }
24
27
  end
25
28
 
@@ -30,7 +33,8 @@ module Phrase
30
33
  :'message' => :'String',
31
34
  :'user' => :'UserPreview',
32
35
  :'created_at' => :'DateTime',
33
- :'updated_at' => :'DateTime'
36
+ :'updated_at' => :'DateTime',
37
+ :'mentioned_users' => :'Array<UserPreview>'
34
38
  }
35
39
  end
36
40
 
@@ -74,6 +78,12 @@ module Phrase
74
78
  if attributes.key?(:'updated_at')
75
79
  self.updated_at = attributes[:'updated_at']
76
80
  end
81
+
82
+ if attributes.key?(:'mentioned_users')
83
+ if (value = attributes[:'mentioned_users']).is_a?(Array)
84
+ self.mentioned_users = value
85
+ end
86
+ end
77
87
  end
78
88
 
79
89
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -98,7 +108,8 @@ module Phrase
98
108
  message == o.message &&
99
109
  user == o.user &&
100
110
  created_at == o.created_at &&
101
- updated_at == o.updated_at
111
+ updated_at == o.updated_at &&
112
+ mentioned_users == o.mentioned_users
102
113
  end
103
114
 
104
115
  # @see the `==` method
@@ -110,7 +121,7 @@ module Phrase
110
121
  # Calculates hash code according to all attributes.
111
122
  # @return [Integer] Hash code
112
123
  def hash
113
- [id, message, user, created_at, updated_at].hash
124
+ [id, message, user, created_at, updated_at, mentioned_users].hash
114
125
  end
115
126
 
116
127
  # Builds the object from hash
@@ -0,0 +1,248 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class JobTemplate
5
+ attr_accessor :id
6
+
7
+ attr_accessor :name
8
+
9
+ attr_accessor :briefing
10
+
11
+ attr_accessor :project
12
+
13
+ attr_accessor :branch
14
+
15
+ attr_accessor :created_at
16
+
17
+ attr_accessor :updated_at
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ :'id' => :'id',
23
+ :'name' => :'name',
24
+ :'briefing' => :'briefing',
25
+ :'project' => :'project',
26
+ :'branch' => :'branch',
27
+ :'created_at' => :'created_at',
28
+ :'updated_at' => :'updated_at'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'id' => :'String',
36
+ :'name' => :'String',
37
+ :'briefing' => :'String',
38
+ :'project' => :'ProjectShort',
39
+ :'branch' => :'Branch',
40
+ :'created_at' => :'DateTime',
41
+ :'updated_at' => :'DateTime'
42
+ }
43
+ end
44
+
45
+ # List of attributes with nullable: true
46
+ def self.openapi_nullable
47
+ Set.new([
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::JobTemplate` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::JobTemplate`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'id')
67
+ self.id = attributes[:'id']
68
+ end
69
+
70
+ if attributes.key?(:'name')
71
+ self.name = attributes[:'name']
72
+ end
73
+
74
+ if attributes.key?(:'briefing')
75
+ self.briefing = attributes[:'briefing']
76
+ end
77
+
78
+ if attributes.key?(:'project')
79
+ self.project = attributes[:'project']
80
+ end
81
+
82
+ if attributes.key?(:'branch')
83
+ self.branch = attributes[:'branch']
84
+ end
85
+
86
+ if attributes.key?(:'created_at')
87
+ self.created_at = attributes[:'created_at']
88
+ end
89
+
90
+ if attributes.key?(:'updated_at')
91
+ self.updated_at = attributes[:'updated_at']
92
+ end
93
+ end
94
+
95
+ # Show invalid properties with the reasons. Usually used together with valid?
96
+ # @return Array for valid properties with the reasons
97
+ def list_invalid_properties
98
+ invalid_properties = Array.new
99
+ invalid_properties
100
+ end
101
+
102
+ # Check to see if the all the properties in the model are valid
103
+ # @return true if the model is valid
104
+ def valid?
105
+ true
106
+ end
107
+
108
+ # Checks equality by comparing each attribute.
109
+ # @param [Object] Object to be compared
110
+ def ==(o)
111
+ return true if self.equal?(o)
112
+ self.class == o.class &&
113
+ id == o.id &&
114
+ name == o.name &&
115
+ briefing == o.briefing &&
116
+ project == o.project &&
117
+ branch == o.branch &&
118
+ created_at == o.created_at &&
119
+ updated_at == o.updated_at
120
+ end
121
+
122
+ # @see the `==` method
123
+ # @param [Object] Object to be compared
124
+ def eql?(o)
125
+ self == o
126
+ end
127
+
128
+ # Calculates hash code according to all attributes.
129
+ # @return [Integer] Hash code
130
+ def hash
131
+ [id, name, briefing, project, branch, created_at, updated_at].hash
132
+ end
133
+
134
+ # Builds the object from hash
135
+ # @param [Hash] attributes Model attributes in the form of hash
136
+ # @return [Object] Returns the model itself
137
+ def self.build_from_hash(attributes)
138
+ new.build_from_hash(attributes)
139
+ end
140
+
141
+ # Builds the object from hash
142
+ # @param [Hash] attributes Model attributes in the form of hash
143
+ # @return [Object] Returns the model itself
144
+ def build_from_hash(attributes)
145
+ return nil unless attributes.is_a?(Hash)
146
+ self.class.openapi_types.each_pair do |key, type|
147
+ if type =~ /\AArray<(.*)>/i
148
+ # check to ensure the input is an array given that the attribute
149
+ # is documented as an array but the input is not
150
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
151
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
152
+ end
153
+ elsif !attributes[self.class.attribute_map[key]].nil?
154
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
155
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
156
+ end
157
+
158
+ self
159
+ end
160
+
161
+ # Deserializes the data based on type
162
+ # @param string type Data type
163
+ # @param string value Value to be deserialized
164
+ # @return [Object] Deserialized data
165
+ def _deserialize(type, value)
166
+ case type.to_sym
167
+ when :DateTime
168
+ DateTime.parse(value)
169
+ when :Date
170
+ Date.parse(value)
171
+ when :String
172
+ value.to_s
173
+ when :Integer
174
+ value.to_i
175
+ when :Float
176
+ value.to_f
177
+ when :Boolean
178
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
179
+ true
180
+ else
181
+ false
182
+ end
183
+ when :Object
184
+ # generic object (usually a Hash), return directly
185
+ value
186
+ when /\AArray<(?<inner_type>.+)>\z/
187
+ inner_type = Regexp.last_match[:inner_type]
188
+ value.map { |v| _deserialize(inner_type, v) }
189
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
190
+ k_type = Regexp.last_match[:k_type]
191
+ v_type = Regexp.last_match[:v_type]
192
+ {}.tap do |hash|
193
+ value.each do |k, v|
194
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
195
+ end
196
+ end
197
+ else # model
198
+ Phrase.const_get(type).build_from_hash(value)
199
+ end
200
+ end
201
+
202
+ # Returns the string representation of the object
203
+ # @return [String] String presentation of the object
204
+ def to_s
205
+ to_hash.to_s
206
+ end
207
+
208
+ # to_body is an alias to to_hash (backward compatibility)
209
+ # @return [Hash] Returns the object in the form of hash
210
+ def to_body
211
+ to_hash
212
+ end
213
+
214
+ # Returns the object in the form of hash
215
+ # @return [Hash] Returns the object in the form of hash
216
+ def to_hash
217
+ hash = {}
218
+ self.class.attribute_map.each_pair do |attr, param|
219
+ value = self.send(attr)
220
+ if value.nil?
221
+ is_nullable = self.class.openapi_nullable.include?(attr)
222
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
223
+ end
224
+
225
+ hash[param] = _to_hash(value)
226
+ end
227
+ hash
228
+ end
229
+
230
+ # Outputs non-array value in the form of hash
231
+ # For object, use to_hash. Otherwise, just return the value
232
+ # @param [Object] value Any valid value
233
+ # @return [Hash] Returns the value in the form of hash
234
+ def _to_hash(value)
235
+ if value.is_a?(Array)
236
+ value.compact.map { |v| _to_hash(v) }
237
+ elsif value.is_a?(Hash)
238
+ {}.tap do |hash|
239
+ value.each { |k, v| hash[k] = _to_hash(v) }
240
+ end
241
+ elsif value.respond_to? :to_hash
242
+ value.to_hash
243
+ else
244
+ value
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,220 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class JobTemplateCreateParameters
5
+ # specify the branch to use
6
+ attr_accessor :branch
7
+
8
+ # Job template name
9
+ attr_accessor :name
10
+
11
+ # Briefing for the translators
12
+ attr_accessor :briefing
13
+
14
+ # Attribute mapping from ruby-style variable name to JSON key.
15
+ def self.attribute_map
16
+ {
17
+ :'branch' => :'branch',
18
+ :'name' => :'name',
19
+ :'briefing' => :'briefing'
20
+ }
21
+ end
22
+
23
+ # Attribute type mapping.
24
+ def self.openapi_types
25
+ {
26
+ :'branch' => :'String',
27
+ :'name' => :'String',
28
+ :'briefing' => :'String'
29
+ }
30
+ end
31
+
32
+ # List of attributes with nullable: true
33
+ def self.openapi_nullable
34
+ Set.new([
35
+ ])
36
+ end
37
+
38
+ # Initializes the object
39
+ # @param [Hash] attributes Model attributes in the form of hash
40
+ def initialize(attributes = {})
41
+ if (!attributes.is_a?(Hash))
42
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::JobTemplateCreateParameters` initialize method"
43
+ end
44
+
45
+ # check to see if the attribute exists and convert string to symbol for hash key
46
+ attributes = attributes.each_with_object({}) { |(k, v), h|
47
+ if (!self.class.attribute_map.key?(k.to_sym))
48
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::JobTemplateCreateParameters`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
49
+ end
50
+ h[k.to_sym] = v
51
+ }
52
+
53
+ if attributes.key?(:'branch')
54
+ self.branch = attributes[:'branch']
55
+ end
56
+
57
+ if attributes.key?(:'name')
58
+ self.name = attributes[:'name']
59
+ end
60
+
61
+ if attributes.key?(:'briefing')
62
+ self.briefing = attributes[:'briefing']
63
+ end
64
+ end
65
+
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ invalid_properties = Array.new
70
+ if @name.nil?
71
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
72
+ end
73
+
74
+ invalid_properties
75
+ end
76
+
77
+ # Check to see if the all the properties in the model are valid
78
+ # @return true if the model is valid
79
+ def valid?
80
+ return false if @name.nil?
81
+ true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(o)
87
+ return true if self.equal?(o)
88
+ self.class == o.class &&
89
+ branch == o.branch &&
90
+ name == o.name &&
91
+ briefing == o.briefing
92
+ end
93
+
94
+ # @see the `==` method
95
+ # @param [Object] Object to be compared
96
+ def eql?(o)
97
+ self == o
98
+ end
99
+
100
+ # Calculates hash code according to all attributes.
101
+ # @return [Integer] Hash code
102
+ def hash
103
+ [branch, name, briefing].hash
104
+ end
105
+
106
+ # Builds the object from hash
107
+ # @param [Hash] attributes Model attributes in the form of hash
108
+ # @return [Object] Returns the model itself
109
+ def self.build_from_hash(attributes)
110
+ new.build_from_hash(attributes)
111
+ end
112
+
113
+ # Builds the object from hash
114
+ # @param [Hash] attributes Model attributes in the form of hash
115
+ # @return [Object] Returns the model itself
116
+ def build_from_hash(attributes)
117
+ return nil unless attributes.is_a?(Hash)
118
+ self.class.openapi_types.each_pair do |key, type|
119
+ if type =~ /\AArray<(.*)>/i
120
+ # check to ensure the input is an array given that the attribute
121
+ # is documented as an array but the input is not
122
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
123
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
124
+ end
125
+ elsif !attributes[self.class.attribute_map[key]].nil?
126
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
127
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
128
+ end
129
+
130
+ self
131
+ end
132
+
133
+ # Deserializes the data based on type
134
+ # @param string type Data type
135
+ # @param string value Value to be deserialized
136
+ # @return [Object] Deserialized data
137
+ def _deserialize(type, value)
138
+ case type.to_sym
139
+ when :DateTime
140
+ DateTime.parse(value)
141
+ when :Date
142
+ Date.parse(value)
143
+ when :String
144
+ value.to_s
145
+ when :Integer
146
+ value.to_i
147
+ when :Float
148
+ value.to_f
149
+ when :Boolean
150
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
151
+ true
152
+ else
153
+ false
154
+ end
155
+ when :Object
156
+ # generic object (usually a Hash), return directly
157
+ value
158
+ when /\AArray<(?<inner_type>.+)>\z/
159
+ inner_type = Regexp.last_match[:inner_type]
160
+ value.map { |v| _deserialize(inner_type, v) }
161
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
162
+ k_type = Regexp.last_match[:k_type]
163
+ v_type = Regexp.last_match[:v_type]
164
+ {}.tap do |hash|
165
+ value.each do |k, v|
166
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
167
+ end
168
+ end
169
+ else # model
170
+ Phrase.const_get(type).build_from_hash(value)
171
+ end
172
+ end
173
+
174
+ # Returns the string representation of the object
175
+ # @return [String] String presentation of the object
176
+ def to_s
177
+ to_hash.to_s
178
+ end
179
+
180
+ # to_body is an alias to to_hash (backward compatibility)
181
+ # @return [Hash] Returns the object in the form of hash
182
+ def to_body
183
+ to_hash
184
+ end
185
+
186
+ # Returns the object in the form of hash
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_hash
189
+ hash = {}
190
+ self.class.attribute_map.each_pair do |attr, param|
191
+ value = self.send(attr)
192
+ if value.nil?
193
+ is_nullable = self.class.openapi_nullable.include?(attr)
194
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
195
+ end
196
+
197
+ hash[param] = _to_hash(value)
198
+ end
199
+ hash
200
+ end
201
+
202
+ # Outputs non-array value in the form of hash
203
+ # For object, use to_hash. Otherwise, just return the value
204
+ # @param [Object] value Any valid value
205
+ # @return [Hash] Returns the value in the form of hash
206
+ def _to_hash(value)
207
+ if value.is_a?(Array)
208
+ value.compact.map { |v| _to_hash(v) }
209
+ elsif value.is_a?(Hash)
210
+ {}.tap do |hash|
211
+ value.each { |k, v| hash[k] = _to_hash(v) }
212
+ end
213
+ elsif value.respond_to? :to_hash
214
+ value.to_hash
215
+ else
216
+ value
217
+ end
218
+ end
219
+ end
220
+ end