phrase 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -3
  3. data/docs/Account.md +2 -0
  4. data/docs/AccountDetails.md +3 -3
  5. data/docs/AccountsApi.md +2 -2
  6. data/docs/AuthorizationsApi.md +2 -2
  7. data/docs/BlacklistedKeysApi.md +4 -2
  8. data/docs/BranchesApi.md +2 -2
  9. data/docs/CommentsApi.md +2 -2
  10. data/docs/DistributionsApi.md +2 -2
  11. data/docs/Document.md +23 -0
  12. data/docs/DocumentsApi.md +137 -0
  13. data/docs/GitHubSyncApi.md +130 -0
  14. data/docs/GitLabSyncApi.md +2 -2
  15. data/docs/GithubSyncExportParameters.md +17 -0
  16. data/docs/GithubSyncImportParameters.md +17 -0
  17. data/docs/GlossariesApi.md +2 -2
  18. data/docs/GlossaryTermsApi.md +2 -2
  19. data/docs/InlineResponse422.md +19 -0
  20. data/docs/InlineResponse422Errors.md +21 -0
  21. data/docs/InvitationsApi.md +2 -2
  22. data/docs/JobLocalesApi.md +2 -2
  23. data/docs/JobsApi.md +2 -2
  24. data/docs/KeysApi.md +4 -4
  25. data/docs/LocalesApi.md +2 -2
  26. data/docs/MembersApi.md +2 -2
  27. data/docs/OrdersApi.md +2 -2
  28. data/docs/Project.md +2 -0
  29. data/docs/ProjectDetails.md +2 -2
  30. data/docs/ProjectsApi.md +2 -2
  31. data/docs/ReleasesApi.md +2 -2
  32. data/docs/ScreenshotMarkersApi.md +2 -2
  33. data/docs/ScreenshotsApi.md +2 -2
  34. data/docs/SpacesApi.md +4 -4
  35. data/docs/StyleGuidesApi.md +2 -2
  36. data/docs/TagsApi.md +2 -2
  37. data/docs/TeamsApi.md +2 -2
  38. data/docs/TranslationsApi.md +8 -8
  39. data/docs/UploadsApi.md +2 -2
  40. data/docs/VersionsHistoryApi.md +2 -2
  41. data/docs/WebhooksApi.md +2 -2
  42. data/lib/phrase.rb +7 -0
  43. data/lib/phrase/api/accounts_api.rb +2 -2
  44. data/lib/phrase/api/authorizations_api.rb +2 -2
  45. data/lib/phrase/api/blacklisted_keys_api.rb +5 -2
  46. data/lib/phrase/api/branches_api.rb +2 -2
  47. data/lib/phrase/api/comments_api.rb +2 -2
  48. data/lib/phrase/api/distributions_api.rb +2 -2
  49. data/lib/phrase/api/documents_api.rb +152 -0
  50. data/lib/phrase/api/git_hub_sync_api.rb +146 -0
  51. data/lib/phrase/api/git_lab_sync_api.rb +2 -2
  52. data/lib/phrase/api/glossaries_api.rb +2 -2
  53. data/lib/phrase/api/glossary_terms_api.rb +2 -2
  54. data/lib/phrase/api/invitations_api.rb +2 -2
  55. data/lib/phrase/api/job_locales_api.rb +2 -2
  56. data/lib/phrase/api/jobs_api.rb +2 -2
  57. data/lib/phrase/api/keys_api.rb +4 -4
  58. data/lib/phrase/api/locales_api.rb +2 -2
  59. data/lib/phrase/api/members_api.rb +2 -2
  60. data/lib/phrase/api/orders_api.rb +2 -2
  61. data/lib/phrase/api/projects_api.rb +2 -2
  62. data/lib/phrase/api/releases_api.rb +2 -2
  63. data/lib/phrase/api/screenshot_markers_api.rb +2 -2
  64. data/lib/phrase/api/screenshots_api.rb +2 -2
  65. data/lib/phrase/api/spaces_api.rb +4 -4
  66. data/lib/phrase/api/style_guides_api.rb +2 -2
  67. data/lib/phrase/api/tags_api.rb +2 -2
  68. data/lib/phrase/api/teams_api.rb +2 -2
  69. data/lib/phrase/api/translations_api.rb +8 -8
  70. data/lib/phrase/api/uploads_api.rb +2 -2
  71. data/lib/phrase/api/versions_history_api.rb +2 -2
  72. data/lib/phrase/api/webhooks_api.rb +2 -2
  73. data/lib/phrase/models/account.rb +10 -1
  74. data/lib/phrase/models/account_details.rb +13 -13
  75. data/lib/phrase/models/document.rb +221 -0
  76. data/lib/phrase/models/github_sync_export_parameters.rb +195 -0
  77. data/lib/phrase/models/github_sync_import_parameters.rb +195 -0
  78. data/lib/phrase/models/inline_response422.rb +205 -0
  79. data/lib/phrase/models/inline_response422_errors.rb +212 -0
  80. data/lib/phrase/models/project.rb +10 -1
  81. data/lib/phrase/models/project_details.rb +10 -10
  82. data/lib/phrase/version.rb +1 -1
  83. data/spec/api/accounts_api_spec.rb +1 -1
  84. data/spec/api/authorizations_api_spec.rb +1 -1
  85. data/spec/api/blacklisted_keys_api_spec.rb +2 -1
  86. data/spec/api/branches_api_spec.rb +1 -1
  87. data/spec/api/comments_api_spec.rb +1 -1
  88. data/spec/api/distributions_api_spec.rb +1 -1
  89. data/spec/api/documents_api_spec.rb +52 -0
  90. data/spec/api/git_hub_sync_api_spec.rb +49 -0
  91. data/spec/api/git_lab_sync_api_spec.rb +1 -1
  92. data/spec/api/glossaries_api_spec.rb +1 -1
  93. data/spec/api/glossary_terms_api_spec.rb +1 -1
  94. data/spec/api/invitations_api_spec.rb +1 -1
  95. data/spec/api/job_locales_api_spec.rb +1 -1
  96. data/spec/api/jobs_api_spec.rb +1 -1
  97. data/spec/api/keys_api_spec.rb +2 -2
  98. data/spec/api/locales_api_spec.rb +1 -1
  99. data/spec/api/members_api_spec.rb +1 -1
  100. data/spec/api/orders_api_spec.rb +1 -1
  101. data/spec/api/projects_api_spec.rb +1 -1
  102. data/spec/api/releases_api_spec.rb +1 -1
  103. data/spec/api/screenshot_markers_api_spec.rb +1 -1
  104. data/spec/api/screenshots_api_spec.rb +1 -1
  105. data/spec/api/spaces_api_spec.rb +2 -2
  106. data/spec/api/style_guides_api_spec.rb +1 -1
  107. data/spec/api/tags_api_spec.rb +1 -1
  108. data/spec/api/teams_api_spec.rb +1 -1
  109. data/spec/api/translations_api_spec.rb +4 -4
  110. data/spec/api/uploads_api_spec.rb +1 -1
  111. data/spec/api/versions_history_api_spec.rb +1 -1
  112. data/spec/api/webhooks_api_spec.rb +1 -1
  113. data/spec/models/account_details_spec.rb +4 -4
  114. data/spec/models/account_spec.rb +6 -0
  115. data/spec/models/document_spec.rb +47 -0
  116. data/spec/models/github_sync_export_parameters_spec.rb +29 -0
  117. data/spec/models/github_sync_import_parameters_spec.rb +29 -0
  118. data/spec/models/inline_response422_errors_spec.rb +41 -0
  119. data/spec/models/inline_response422_spec.rb +35 -0
  120. data/spec/models/project_details_spec.rb +6 -6
  121. data/spec/models/project_spec.rb +6 -0
  122. metadata +181 -153
@@ -0,0 +1,195 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class GithubSyncExportParameters
5
+ # Project ID to specify the actual project the GitHub export should be triggered in.
6
+ attr_accessor :project_id
7
+
8
+ # Attribute mapping from ruby-style variable name to JSON key.
9
+ def self.attribute_map
10
+ {
11
+ :'project_id' => :'project_id'
12
+ }
13
+ end
14
+
15
+ # Attribute type mapping.
16
+ def self.openapi_types
17
+ {
18
+ :'project_id' => :'String'
19
+ }
20
+ end
21
+
22
+ # List of attributes with nullable: true
23
+ def self.openapi_nullable
24
+ Set.new([
25
+ ])
26
+ end
27
+
28
+ # Initializes the object
29
+ # @param [Hash] attributes Model attributes in the form of hash
30
+ def initialize(attributes = {})
31
+ if (!attributes.is_a?(Hash))
32
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::GithubSyncExportParameters` initialize method"
33
+ end
34
+
35
+ # check to see if the attribute exists and convert string to symbol for hash key
36
+ attributes = attributes.each_with_object({}) { |(k, v), h|
37
+ if (!self.class.attribute_map.key?(k.to_sym))
38
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::GithubSyncExportParameters`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
39
+ end
40
+ h[k.to_sym] = v
41
+ }
42
+
43
+ if attributes.key?(:'project_id')
44
+ self.project_id = attributes[:'project_id']
45
+ end
46
+ end
47
+
48
+ # Show invalid properties with the reasons. Usually used together with valid?
49
+ # @return Array for valid properties with the reasons
50
+ def list_invalid_properties
51
+ invalid_properties = Array.new
52
+ invalid_properties
53
+ end
54
+
55
+ # Check to see if the all the properties in the model are valid
56
+ # @return true if the model is valid
57
+ def valid?
58
+ true
59
+ end
60
+
61
+ # Checks equality by comparing each attribute.
62
+ # @param [Object] Object to be compared
63
+ def ==(o)
64
+ return true if self.equal?(o)
65
+ self.class == o.class &&
66
+ project_id == o.project_id
67
+ end
68
+
69
+ # @see the `==` method
70
+ # @param [Object] Object to be compared
71
+ def eql?(o)
72
+ self == o
73
+ end
74
+
75
+ # Calculates hash code according to all attributes.
76
+ # @return [Integer] Hash code
77
+ def hash
78
+ [project_id].hash
79
+ end
80
+
81
+ # Builds the object from hash
82
+ # @param [Hash] attributes Model attributes in the form of hash
83
+ # @return [Object] Returns the model itself
84
+ def self.build_from_hash(attributes)
85
+ new.build_from_hash(attributes)
86
+ end
87
+
88
+ # Builds the object from hash
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ # @return [Object] Returns the model itself
91
+ def build_from_hash(attributes)
92
+ return nil unless attributes.is_a?(Hash)
93
+ self.class.openapi_types.each_pair do |key, type|
94
+ if type =~ /\AArray<(.*)>/i
95
+ # check to ensure the input is an array given that the attribute
96
+ # is documented as an array but the input is not
97
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
98
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
99
+ end
100
+ elsif !attributes[self.class.attribute_map[key]].nil?
101
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
102
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
103
+ end
104
+
105
+ self
106
+ end
107
+
108
+ # Deserializes the data based on type
109
+ # @param string type Data type
110
+ # @param string value Value to be deserialized
111
+ # @return [Object] Deserialized data
112
+ def _deserialize(type, value)
113
+ case type.to_sym
114
+ when :DateTime
115
+ DateTime.parse(value)
116
+ when :Date
117
+ Date.parse(value)
118
+ when :String
119
+ value.to_s
120
+ when :Integer
121
+ value.to_i
122
+ when :Float
123
+ value.to_f
124
+ when :Boolean
125
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
126
+ true
127
+ else
128
+ false
129
+ end
130
+ when :Object
131
+ # generic object (usually a Hash), return directly
132
+ value
133
+ when /\AArray<(?<inner_type>.+)>\z/
134
+ inner_type = Regexp.last_match[:inner_type]
135
+ value.map { |v| _deserialize(inner_type, v) }
136
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
137
+ k_type = Regexp.last_match[:k_type]
138
+ v_type = Regexp.last_match[:v_type]
139
+ {}.tap do |hash|
140
+ value.each do |k, v|
141
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
142
+ end
143
+ end
144
+ else # model
145
+ Phrase.const_get(type).build_from_hash(value)
146
+ end
147
+ end
148
+
149
+ # Returns the string representation of the object
150
+ # @return [String] String presentation of the object
151
+ def to_s
152
+ to_hash.to_s
153
+ end
154
+
155
+ # to_body is an alias to to_hash (backward compatibility)
156
+ # @return [Hash] Returns the object in the form of hash
157
+ def to_body
158
+ to_hash
159
+ end
160
+
161
+ # Returns the object in the form of hash
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_hash
164
+ hash = {}
165
+ self.class.attribute_map.each_pair do |attr, param|
166
+ value = self.send(attr)
167
+ if value.nil?
168
+ is_nullable = self.class.openapi_nullable.include?(attr)
169
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
170
+ end
171
+
172
+ hash[param] = _to_hash(value)
173
+ end
174
+ hash
175
+ end
176
+
177
+ # Outputs non-array value in the form of hash
178
+ # For object, use to_hash. Otherwise, just return the value
179
+ # @param [Object] value Any valid value
180
+ # @return [Hash] Returns the value in the form of hash
181
+ def _to_hash(value)
182
+ if value.is_a?(Array)
183
+ value.compact.map { |v| _to_hash(v) }
184
+ elsif value.is_a?(Hash)
185
+ {}.tap do |hash|
186
+ value.each { |k, v| hash[k] = _to_hash(v) }
187
+ end
188
+ elsif value.respond_to? :to_hash
189
+ value.to_hash
190
+ else
191
+ value
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,195 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class GithubSyncImportParameters
5
+ # Project ID to specify the actual project the GitHub import should be triggered in.
6
+ attr_accessor :project_id
7
+
8
+ # Attribute mapping from ruby-style variable name to JSON key.
9
+ def self.attribute_map
10
+ {
11
+ :'project_id' => :'project_id'
12
+ }
13
+ end
14
+
15
+ # Attribute type mapping.
16
+ def self.openapi_types
17
+ {
18
+ :'project_id' => :'String'
19
+ }
20
+ end
21
+
22
+ # List of attributes with nullable: true
23
+ def self.openapi_nullable
24
+ Set.new([
25
+ ])
26
+ end
27
+
28
+ # Initializes the object
29
+ # @param [Hash] attributes Model attributes in the form of hash
30
+ def initialize(attributes = {})
31
+ if (!attributes.is_a?(Hash))
32
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::GithubSyncImportParameters` initialize method"
33
+ end
34
+
35
+ # check to see if the attribute exists and convert string to symbol for hash key
36
+ attributes = attributes.each_with_object({}) { |(k, v), h|
37
+ if (!self.class.attribute_map.key?(k.to_sym))
38
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::GithubSyncImportParameters`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
39
+ end
40
+ h[k.to_sym] = v
41
+ }
42
+
43
+ if attributes.key?(:'project_id')
44
+ self.project_id = attributes[:'project_id']
45
+ end
46
+ end
47
+
48
+ # Show invalid properties with the reasons. Usually used together with valid?
49
+ # @return Array for valid properties with the reasons
50
+ def list_invalid_properties
51
+ invalid_properties = Array.new
52
+ invalid_properties
53
+ end
54
+
55
+ # Check to see if the all the properties in the model are valid
56
+ # @return true if the model is valid
57
+ def valid?
58
+ true
59
+ end
60
+
61
+ # Checks equality by comparing each attribute.
62
+ # @param [Object] Object to be compared
63
+ def ==(o)
64
+ return true if self.equal?(o)
65
+ self.class == o.class &&
66
+ project_id == o.project_id
67
+ end
68
+
69
+ # @see the `==` method
70
+ # @param [Object] Object to be compared
71
+ def eql?(o)
72
+ self == o
73
+ end
74
+
75
+ # Calculates hash code according to all attributes.
76
+ # @return [Integer] Hash code
77
+ def hash
78
+ [project_id].hash
79
+ end
80
+
81
+ # Builds the object from hash
82
+ # @param [Hash] attributes Model attributes in the form of hash
83
+ # @return [Object] Returns the model itself
84
+ def self.build_from_hash(attributes)
85
+ new.build_from_hash(attributes)
86
+ end
87
+
88
+ # Builds the object from hash
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ # @return [Object] Returns the model itself
91
+ def build_from_hash(attributes)
92
+ return nil unless attributes.is_a?(Hash)
93
+ self.class.openapi_types.each_pair do |key, type|
94
+ if type =~ /\AArray<(.*)>/i
95
+ # check to ensure the input is an array given that the attribute
96
+ # is documented as an array but the input is not
97
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
98
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
99
+ end
100
+ elsif !attributes[self.class.attribute_map[key]].nil?
101
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
102
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
103
+ end
104
+
105
+ self
106
+ end
107
+
108
+ # Deserializes the data based on type
109
+ # @param string type Data type
110
+ # @param string value Value to be deserialized
111
+ # @return [Object] Deserialized data
112
+ def _deserialize(type, value)
113
+ case type.to_sym
114
+ when :DateTime
115
+ DateTime.parse(value)
116
+ when :Date
117
+ Date.parse(value)
118
+ when :String
119
+ value.to_s
120
+ when :Integer
121
+ value.to_i
122
+ when :Float
123
+ value.to_f
124
+ when :Boolean
125
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
126
+ true
127
+ else
128
+ false
129
+ end
130
+ when :Object
131
+ # generic object (usually a Hash), return directly
132
+ value
133
+ when /\AArray<(?<inner_type>.+)>\z/
134
+ inner_type = Regexp.last_match[:inner_type]
135
+ value.map { |v| _deserialize(inner_type, v) }
136
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
137
+ k_type = Regexp.last_match[:k_type]
138
+ v_type = Regexp.last_match[:v_type]
139
+ {}.tap do |hash|
140
+ value.each do |k, v|
141
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
142
+ end
143
+ end
144
+ else # model
145
+ Phrase.const_get(type).build_from_hash(value)
146
+ end
147
+ end
148
+
149
+ # Returns the string representation of the object
150
+ # @return [String] String presentation of the object
151
+ def to_s
152
+ to_hash.to_s
153
+ end
154
+
155
+ # to_body is an alias to to_hash (backward compatibility)
156
+ # @return [Hash] Returns the object in the form of hash
157
+ def to_body
158
+ to_hash
159
+ end
160
+
161
+ # Returns the object in the form of hash
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_hash
164
+ hash = {}
165
+ self.class.attribute_map.each_pair do |attr, param|
166
+ value = self.send(attr)
167
+ if value.nil?
168
+ is_nullable = self.class.openapi_nullable.include?(attr)
169
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
170
+ end
171
+
172
+ hash[param] = _to_hash(value)
173
+ end
174
+ hash
175
+ end
176
+
177
+ # Outputs non-array value in the form of hash
178
+ # For object, use to_hash. Otherwise, just return the value
179
+ # @param [Object] value Any valid value
180
+ # @return [Hash] Returns the value in the form of hash
181
+ def _to_hash(value)
182
+ if value.is_a?(Array)
183
+ value.compact.map { |v| _to_hash(v) }
184
+ elsif value.is_a?(Hash)
185
+ {}.tap do |hash|
186
+ value.each { |k, v| hash[k] = _to_hash(v) }
187
+ end
188
+ elsif value.respond_to? :to_hash
189
+ value.to_hash
190
+ else
191
+ value
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,205 @@
1
+ require 'date'
2
+
3
+ module Phrase
4
+ class InlineResponse422
5
+ attr_accessor :message
6
+
7
+ attr_accessor :errors
8
+
9
+ # Attribute mapping from ruby-style variable name to JSON key.
10
+ def self.attribute_map
11
+ {
12
+ :'message' => :'message',
13
+ :'errors' => :'errors'
14
+ }
15
+ end
16
+
17
+ # Attribute type mapping.
18
+ def self.openapi_types
19
+ {
20
+ :'message' => :'String',
21
+ :'errors' => :'Array<InlineResponse422Errors>'
22
+ }
23
+ end
24
+
25
+ # List of attributes with nullable: true
26
+ def self.openapi_nullable
27
+ Set.new([
28
+ ])
29
+ end
30
+
31
+ # Initializes the object
32
+ # @param [Hash] attributes Model attributes in the form of hash
33
+ def initialize(attributes = {})
34
+ if (!attributes.is_a?(Hash))
35
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Phrase::InlineResponse422` initialize method"
36
+ end
37
+
38
+ # check to see if the attribute exists and convert string to symbol for hash key
39
+ attributes = attributes.each_with_object({}) { |(k, v), h|
40
+ if (!self.class.attribute_map.key?(k.to_sym))
41
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Phrase::InlineResponse422`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
42
+ end
43
+ h[k.to_sym] = v
44
+ }
45
+
46
+ if attributes.key?(:'message')
47
+ self.message = attributes[:'message']
48
+ end
49
+
50
+ if attributes.key?(:'errors')
51
+ if (value = attributes[:'errors']).is_a?(Array)
52
+ self.errors = value
53
+ end
54
+ end
55
+ end
56
+
57
+ # Show invalid properties with the reasons. Usually used together with valid?
58
+ # @return Array for valid properties with the reasons
59
+ def list_invalid_properties
60
+ invalid_properties = Array.new
61
+ invalid_properties
62
+ end
63
+
64
+ # Check to see if the all the properties in the model are valid
65
+ # @return true if the model is valid
66
+ def valid?
67
+ true
68
+ end
69
+
70
+ # Checks equality by comparing each attribute.
71
+ # @param [Object] Object to be compared
72
+ def ==(o)
73
+ return true if self.equal?(o)
74
+ self.class == o.class &&
75
+ message == o.message &&
76
+ errors == o.errors
77
+ end
78
+
79
+ # @see the `==` method
80
+ # @param [Object] Object to be compared
81
+ def eql?(o)
82
+ self == o
83
+ end
84
+
85
+ # Calculates hash code according to all attributes.
86
+ # @return [Integer] Hash code
87
+ def hash
88
+ [message, errors].hash
89
+ end
90
+
91
+ # Builds the object from hash
92
+ # @param [Hash] attributes Model attributes in the form of hash
93
+ # @return [Object] Returns the model itself
94
+ def self.build_from_hash(attributes)
95
+ new.build_from_hash(attributes)
96
+ end
97
+
98
+ # Builds the object from hash
99
+ # @param [Hash] attributes Model attributes in the form of hash
100
+ # @return [Object] Returns the model itself
101
+ def build_from_hash(attributes)
102
+ return nil unless attributes.is_a?(Hash)
103
+ self.class.openapi_types.each_pair do |key, type|
104
+ if type =~ /\AArray<(.*)>/i
105
+ # check to ensure the input is an array given that the attribute
106
+ # is documented as an array but the input is not
107
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
108
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
109
+ end
110
+ elsif !attributes[self.class.attribute_map[key]].nil?
111
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
112
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
113
+ end
114
+
115
+ self
116
+ end
117
+
118
+ # Deserializes the data based on type
119
+ # @param string type Data type
120
+ # @param string value Value to be deserialized
121
+ # @return [Object] Deserialized data
122
+ def _deserialize(type, value)
123
+ case type.to_sym
124
+ when :DateTime
125
+ DateTime.parse(value)
126
+ when :Date
127
+ Date.parse(value)
128
+ when :String
129
+ value.to_s
130
+ when :Integer
131
+ value.to_i
132
+ when :Float
133
+ value.to_f
134
+ when :Boolean
135
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
136
+ true
137
+ else
138
+ false
139
+ end
140
+ when :Object
141
+ # generic object (usually a Hash), return directly
142
+ value
143
+ when /\AArray<(?<inner_type>.+)>\z/
144
+ inner_type = Regexp.last_match[:inner_type]
145
+ value.map { |v| _deserialize(inner_type, v) }
146
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
147
+ k_type = Regexp.last_match[:k_type]
148
+ v_type = Regexp.last_match[:v_type]
149
+ {}.tap do |hash|
150
+ value.each do |k, v|
151
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
152
+ end
153
+ end
154
+ else # model
155
+ Phrase.const_get(type).build_from_hash(value)
156
+ end
157
+ end
158
+
159
+ # Returns the string representation of the object
160
+ # @return [String] String presentation of the object
161
+ def to_s
162
+ to_hash.to_s
163
+ end
164
+
165
+ # to_body is an alias to to_hash (backward compatibility)
166
+ # @return [Hash] Returns the object in the form of hash
167
+ def to_body
168
+ to_hash
169
+ end
170
+
171
+ # Returns the object in the form of hash
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_hash
174
+ hash = {}
175
+ self.class.attribute_map.each_pair do |attr, param|
176
+ value = self.send(attr)
177
+ if value.nil?
178
+ is_nullable = self.class.openapi_nullable.include?(attr)
179
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
180
+ end
181
+
182
+ hash[param] = _to_hash(value)
183
+ end
184
+ hash
185
+ end
186
+
187
+ # Outputs non-array value in the form of hash
188
+ # For object, use to_hash. Otherwise, just return the value
189
+ # @param [Object] value Any valid value
190
+ # @return [Hash] Returns the value in the form of hash
191
+ def _to_hash(value)
192
+ if value.is_a?(Array)
193
+ value.compact.map { |v| _to_hash(v) }
194
+ elsif value.is_a?(Hash)
195
+ {}.tap do |hash|
196
+ value.each { |k, v| hash[k] = _to_hash(v) }
197
+ end
198
+ elsif value.respond_to? :to_hash
199
+ value.to_hash
200
+ else
201
+ value
202
+ end
203
+ end
204
+ end
205
+ end