metatron_ruby_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +140 -0
  3. data/config.json +13 -0
  4. data/docs/Asset.md +9 -0
  5. data/docs/AssetAttributes.md +8 -0
  6. data/docs/AssetData.md +10 -0
  7. data/docs/AssetMeta.md +8 -0
  8. data/docs/AssetResultSet.md +10 -0
  9. data/docs/AssetResultSetMeta.md +8 -0
  10. data/docs/DefaultApi.md +631 -0
  11. data/docs/Error.md +10 -0
  12. data/docs/Errors.md +8 -0
  13. data/docs/Item.md +9 -0
  14. data/docs/ItemData.md +8 -0
  15. data/docs/ItemResultSet.md +10 -0
  16. data/docs/Links.md +10 -0
  17. data/docs/Manifestation.md +9 -0
  18. data/docs/ManifestationAttributes.md +11 -0
  19. data/docs/ManifestationData.md +11 -0
  20. data/docs/ManifestationRelationships.md +10 -0
  21. data/docs/ManifestationResultSet.md +10 -0
  22. data/docs/Meta.md +10 -0
  23. data/docs/OneToManyRelationship.md +10 -0
  24. data/docs/OneToOneRelationship.md +10 -0
  25. data/docs/Resource.md +10 -0
  26. data/docs/ResourceData.md +11 -0
  27. data/docs/ResourceLink.md +9 -0
  28. data/docs/ResultSetMeta.md +10 -0
  29. data/docs/Work.md +9 -0
  30. data/docs/WorkAttributes.md +8 -0
  31. data/docs/WorkData.md +11 -0
  32. data/docs/WorkRelationships.md +8 -0
  33. data/docs/WorkResultSet.md +11 -0
  34. data/generate.sh +0 -0
  35. data/git_push.sh +52 -0
  36. data/lib/metatron_ruby_client/api/default_api.rb +727 -0
  37. data/lib/metatron_ruby_client/api_client.rb +361 -0
  38. data/lib/metatron_ruby_client/api_error.rb +34 -0
  39. data/lib/metatron_ruby_client/configuration.rb +170 -0
  40. data/lib/metatron_ruby_client/models/asset.rb +195 -0
  41. data/lib/metatron_ruby_client/models/asset_attributes.rb +212 -0
  42. data/lib/metatron_ruby_client/models/asset_data.rb +208 -0
  43. data/lib/metatron_ruby_client/models/asset_meta.rb +198 -0
  44. data/lib/metatron_ruby_client/models/asset_result_set.rb +202 -0
  45. data/lib/metatron_ruby_client/models/asset_result_set_meta.rb +196 -0
  46. data/lib/metatron_ruby_client/models/error.rb +208 -0
  47. data/lib/metatron_ruby_client/models/errors.rb +184 -0
  48. data/lib/metatron_ruby_client/models/item.rb +197 -0
  49. data/lib/metatron_ruby_client/models/item_data.rb +186 -0
  50. data/lib/metatron_ruby_client/models/item_result_set.rb +206 -0
  51. data/lib/metatron_ruby_client/models/links.rb +204 -0
  52. data/lib/metatron_ruby_client/models/manifestation.rb +197 -0
  53. data/lib/metatron_ruby_client/models/manifestation_attributes.rb +209 -0
  54. data/lib/metatron_ruby_client/models/manifestation_data.rb +235 -0
  55. data/lib/metatron_ruby_client/models/manifestation_relationships.rb +200 -0
  56. data/lib/metatron_ruby_client/models/manifestation_result_set.rb +214 -0
  57. data/lib/metatron_ruby_client/models/meta.rb +260 -0
  58. data/lib/metatron_ruby_client/models/one_to_many_relationship.rb +206 -0
  59. data/lib/metatron_ruby_client/models/one_to_one_relationship.rb +204 -0
  60. data/lib/metatron_ruby_client/models/resource.rb +281 -0
  61. data/lib/metatron_ruby_client/models/resource_data.rb +221 -0
  62. data/lib/metatron_ruby_client/models/resource_link.rb +199 -0
  63. data/lib/metatron_ruby_client/models/result_set_meta.rb +203 -0
  64. data/lib/metatron_ruby_client/models/work.rb +197 -0
  65. data/lib/metatron_ruby_client/models/work_attributes.rb +186 -0
  66. data/lib/metatron_ruby_client/models/work_data.rb +235 -0
  67. data/lib/metatron_ruby_client/models/work_relationships.rb +182 -0
  68. data/lib/metatron_ruby_client/models/work_result_set.rb +213 -0
  69. data/lib/metatron_ruby_client/version.rb +13 -0
  70. data/lib/metatron_ruby_client.rb +60 -0
  71. data/metatron_ruby_client.gemspec +31 -0
  72. data/spec/api/default_api_spec.rb +218 -0
  73. data/spec/models/asset_attributes_spec.rb +46 -0
  74. data/spec/models/asset_data_spec.rb +66 -0
  75. data/spec/models/asset_meta_spec.rb +46 -0
  76. data/spec/models/asset_result_set_spec.rb +66 -0
  77. data/spec/models/asset_spec.rb +56 -0
  78. data/spec/models/error_spec.rb +66 -0
  79. data/spec/models/errors_spec.rb +46 -0
  80. data/spec/models/item_data_spec.rb +46 -0
  81. data/spec/models/item_result_set_spec.rb +66 -0
  82. data/spec/models/item_spec.rb +56 -0
  83. data/spec/models/links_spec.rb +66 -0
  84. data/spec/models/manifestation_attributes_spec.rb +76 -0
  85. data/spec/models/manifestation_data_spec.rb +76 -0
  86. data/spec/models/manifestation_relationships_spec.rb +66 -0
  87. data/spec/models/manifestation_result_set_spec.rb +66 -0
  88. data/spec/models/manifestation_spec.rb +56 -0
  89. data/spec/models/meta_spec.rb +66 -0
  90. data/spec/models/one_to_many_relationship_spec.rb +66 -0
  91. data/spec/models/one_to_one_relationship_spec.rb +66 -0
  92. data/spec/models/resource_data_spec.rb +76 -0
  93. data/spec/models/resource_link_spec.rb +56 -0
  94. data/spec/models/resource_spec.rb +66 -0
  95. data/spec/models/result_set_meta_spec.rb +66 -0
  96. data/spec/models/work_attributes_spec.rb +46 -0
  97. data/spec/models/work_data_spec.rb +76 -0
  98. data/spec/models/work_relationships_spec.rb +46 -0
  99. data/spec/models/work_result_set_spec.rb +76 -0
  100. data/spec/models/work_spec.rb +56 -0
  101. data/stub-service/.swagger-codegen-ignore +23 -0
  102. data/stub-service/Gemfile +4 -0
  103. data/stub-service/Gemfile.lock +22 -0
  104. data/stub-service/LICENSE +201 -0
  105. data/stub-service/README.md +29 -0
  106. data/stub-service/api/default_api.rb +370 -0
  107. data/stub-service/config.ru +2 -0
  108. data/stub-service/lib/result_set.rb +37 -0
  109. data/stub-service/lib/swaggering.rb +163 -0
  110. data/stub-service/my_app.rb +13 -0
  111. data/stub-service/responses/works/includes/manifestations.assets.yaml +42 -0
  112. data/stub-service/responses/works/includes/manifestations.yaml +88 -0
  113. data/stub-service/responses/works/result_set.yaml +18 -0
  114. data/stub-service/swagger.yaml +756 -0
  115. data/swagger-codegen-cli.jar +0 -0
  116. metadata +369 -0
@@ -0,0 +1,206 @@
1
+ =begin
2
+ production-metatron-api
3
+
4
+ OpenAPI spec version: 2016-07-15T09:42:29Z
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module MetatronClient
14
+ class OneToManyRelationship
15
+ attr_accessor :meta
16
+
17
+ attr_accessor :links
18
+
19
+ attr_accessor :data
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'meta' => :'meta',
25
+ :'links' => :'links',
26
+ :'data' => :'data'
27
+ }
28
+ end
29
+
30
+ # Attribute type mapping.
31
+ def self.swagger_types
32
+ {
33
+ :'meta' => :'Object',
34
+ :'links' => :'Links',
35
+ :'data' => :'Array<ResourceLink>'
36
+ }
37
+ end
38
+
39
+ # Initializes the object
40
+ # @param [Hash] attributes Model attributes in the form of hash
41
+ def initialize(attributes = {})
42
+ return unless attributes.is_a?(Hash)
43
+
44
+ # convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
46
+
47
+ if attributes.has_key?(:'meta')
48
+ self.meta = attributes[:'meta']
49
+ end
50
+
51
+ if attributes.has_key?(:'links')
52
+ self.links = attributes[:'links']
53
+ end
54
+
55
+ if attributes.has_key?(:'data')
56
+ if (value = attributes[:'data']).is_a?(Array)
57
+ self.data = value
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ # Show invalid properties with the reasons. Usually used together with valid?
64
+ # @return Array for valid properies with the reasons
65
+ def list_invalid_properties
66
+ invalid_properties = Array.new
67
+ return invalid_properties
68
+ end
69
+
70
+ # Check to see if the all the properties in the model are valid
71
+ # @return true if the model is valid
72
+ def valid?
73
+ if @data.nil?
74
+ return false
75
+ end
76
+
77
+ end
78
+
79
+ # Checks equality by comparing each attribute.
80
+ # @param [Object] Object to be compared
81
+ def ==(o)
82
+ return true if self.equal?(o)
83
+ self.class == o.class &&
84
+ meta == o.meta &&
85
+ links == o.links &&
86
+ data == o.data
87
+ end
88
+
89
+ # @see the `==` method
90
+ # @param [Object] Object to be compared
91
+ def eql?(o)
92
+ self == o
93
+ end
94
+
95
+ # Calculates hash code according to all attributes.
96
+ # @return [Fixnum] Hash code
97
+ def hash
98
+ [meta, links, data].hash
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+ self.class.swagger_types.each_pair do |key, type|
107
+ if type =~ /^Array<(.*)>/i
108
+ # check to ensure the input is an array given that the the attribute
109
+ # is documented as an array but the input is not
110
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
111
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
112
+ end
113
+ elsif !attributes[self.class.attribute_map[key]].nil?
114
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
115
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
116
+ end
117
+
118
+ self
119
+ end
120
+
121
+ # Deserializes the data based on type
122
+ # @param string type Data type
123
+ # @param string value Value to be deserialized
124
+ # @return [Object] Deserialized data
125
+ def _deserialize(type, value)
126
+ case type.to_sym
127
+ when :DateTime
128
+ DateTime.parse(value)
129
+ when :Date
130
+ Date.parse(value)
131
+ when :String
132
+ value.to_s
133
+ when :Integer
134
+ value.to_i
135
+ when :Float
136
+ value.to_f
137
+ when :BOOLEAN
138
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
139
+ true
140
+ else
141
+ false
142
+ end
143
+ when :Object
144
+ # generic object (usually a Hash), return directly
145
+ value
146
+ when /\AArray<(?<inner_type>.+)>\z/
147
+ inner_type = Regexp.last_match[:inner_type]
148
+ value.map { |v| _deserialize(inner_type, v) }
149
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
150
+ k_type = Regexp.last_match[:k_type]
151
+ v_type = Regexp.last_match[:v_type]
152
+ {}.tap do |hash|
153
+ value.each do |k, v|
154
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
155
+ end
156
+ end
157
+ else # model
158
+ temp_model = MetatronClient.const_get(type).new
159
+ temp_model.build_from_hash(value)
160
+ end
161
+ end
162
+
163
+ # Returns the string representation of the object
164
+ # @return [String] String presentation of the object
165
+ def to_s
166
+ to_hash.to_s
167
+ end
168
+
169
+ # to_body is an alias to to_hash (backward compatibility)
170
+ # @return [Hash] Returns the object in the form of hash
171
+ def to_body
172
+ to_hash
173
+ end
174
+
175
+ # Returns the object in the form of hash
176
+ # @return [Hash] Returns the object in the form of hash
177
+ def to_hash
178
+ hash = {}
179
+ self.class.attribute_map.each_pair do |attr, param|
180
+ value = self.send(attr)
181
+ next if value.nil?
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
+
205
+ end
206
+ end
@@ -0,0 +1,204 @@
1
+ =begin
2
+ production-metatron-api
3
+
4
+ OpenAPI spec version: 2016-07-15T09:42:29Z
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+
13
+ module MetatronClient
14
+ class OneToOneRelationship
15
+ attr_accessor :meta
16
+
17
+ attr_accessor :links
18
+
19
+ attr_accessor :data
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'meta' => :'meta',
25
+ :'links' => :'links',
26
+ :'data' => :'data'
27
+ }
28
+ end
29
+
30
+ # Attribute type mapping.
31
+ def self.swagger_types
32
+ {
33
+ :'meta' => :'Object',
34
+ :'links' => :'Links',
35
+ :'data' => :'ResourceLink'
36
+ }
37
+ end
38
+
39
+ # Initializes the object
40
+ # @param [Hash] attributes Model attributes in the form of hash
41
+ def initialize(attributes = {})
42
+ return unless attributes.is_a?(Hash)
43
+
44
+ # convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
46
+
47
+ if attributes.has_key?(:'meta')
48
+ self.meta = attributes[:'meta']
49
+ end
50
+
51
+ if attributes.has_key?(:'links')
52
+ self.links = attributes[:'links']
53
+ end
54
+
55
+ if attributes.has_key?(:'data')
56
+ self.data = attributes[:'data']
57
+ end
58
+
59
+ end
60
+
61
+ # Show invalid properties with the reasons. Usually used together with valid?
62
+ # @return Array for valid properies with the reasons
63
+ def list_invalid_properties
64
+ invalid_properties = Array.new
65
+ return invalid_properties
66
+ end
67
+
68
+ # Check to see if the all the properties in the model are valid
69
+ # @return true if the model is valid
70
+ def valid?
71
+ if @data.nil?
72
+ return false
73
+ end
74
+
75
+ end
76
+
77
+ # Checks equality by comparing each attribute.
78
+ # @param [Object] Object to be compared
79
+ def ==(o)
80
+ return true if self.equal?(o)
81
+ self.class == o.class &&
82
+ meta == o.meta &&
83
+ links == o.links &&
84
+ data == o.data
85
+ end
86
+
87
+ # @see the `==` method
88
+ # @param [Object] Object to be compared
89
+ def eql?(o)
90
+ self == o
91
+ end
92
+
93
+ # Calculates hash code according to all attributes.
94
+ # @return [Fixnum] Hash code
95
+ def hash
96
+ [meta, links, data].hash
97
+ end
98
+
99
+ # Builds the object from hash
100
+ # @param [Hash] attributes Model attributes in the form of hash
101
+ # @return [Object] Returns the model itself
102
+ def build_from_hash(attributes)
103
+ return nil unless attributes.is_a?(Hash)
104
+ self.class.swagger_types.each_pair do |key, type|
105
+ if type =~ /^Array<(.*)>/i
106
+ # check to ensure the input is an array given that the the attribute
107
+ # is documented as an array but the input is not
108
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
109
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
110
+ end
111
+ elsif !attributes[self.class.attribute_map[key]].nil?
112
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
113
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
114
+ end
115
+
116
+ self
117
+ end
118
+
119
+ # Deserializes the data based on type
120
+ # @param string type Data type
121
+ # @param string value Value to be deserialized
122
+ # @return [Object] Deserialized data
123
+ def _deserialize(type, value)
124
+ case type.to_sym
125
+ when :DateTime
126
+ DateTime.parse(value)
127
+ when :Date
128
+ Date.parse(value)
129
+ when :String
130
+ value.to_s
131
+ when :Integer
132
+ value.to_i
133
+ when :Float
134
+ value.to_f
135
+ when :BOOLEAN
136
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
137
+ true
138
+ else
139
+ false
140
+ end
141
+ when :Object
142
+ # generic object (usually a Hash), return directly
143
+ value
144
+ when /\AArray<(?<inner_type>.+)>\z/
145
+ inner_type = Regexp.last_match[:inner_type]
146
+ value.map { |v| _deserialize(inner_type, v) }
147
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
148
+ k_type = Regexp.last_match[:k_type]
149
+ v_type = Regexp.last_match[:v_type]
150
+ {}.tap do |hash|
151
+ value.each do |k, v|
152
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
153
+ end
154
+ end
155
+ else # model
156
+ temp_model = MetatronClient.const_get(type).new
157
+ temp_model.build_from_hash(value)
158
+ end
159
+ end
160
+
161
+ # Returns the string representation of the object
162
+ # @return [String] String presentation of the object
163
+ def to_s
164
+ to_hash.to_s
165
+ end
166
+
167
+ # to_body is an alias to to_hash (backward compatibility)
168
+ # @return [Hash] Returns the object in the form of hash
169
+ def to_body
170
+ to_hash
171
+ end
172
+
173
+ # Returns the object in the form of hash
174
+ # @return [Hash] Returns the object in the form of hash
175
+ def to_hash
176
+ hash = {}
177
+ self.class.attribute_map.each_pair do |attr, param|
178
+ value = self.send(attr)
179
+ next if value.nil?
180
+ hash[param] = _to_hash(value)
181
+ end
182
+ hash
183
+ end
184
+
185
+ # Outputs non-array value in the form of hash
186
+ # For object, use to_hash. Otherwise, just return the value
187
+ # @param [Object] value Any valid value
188
+ # @return [Hash] Returns the value in the form of hash
189
+ def _to_hash(value)
190
+ if value.is_a?(Array)
191
+ value.compact.map{ |v| _to_hash(v) }
192
+ elsif value.is_a?(Hash)
193
+ {}.tap do |hash|
194
+ value.each { |k, v| hash[k] = _to_hash(v) }
195
+ end
196
+ elsif value.respond_to? :to_hash
197
+ value.to_hash
198
+ else
199
+ value
200
+ end
201
+ end
202
+
203
+ end
204
+ end
@@ -0,0 +1,281 @@
1
+ =begin
2
+ Metatron Server
3
+
4
+ A primitive modelling bibliographic metadata
5
+
6
+ OpenAPI spec version: 2.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module MetatronClient
16
+ class Resource
17
+ attr_accessor :id
18
+
19
+ attr_accessor :type
20
+
21
+ attr_accessor :attributes
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+
27
+ :'id' => :'id',
28
+
29
+ :'type' => :'type',
30
+
31
+ :'attributes' => :'attributes'
32
+
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.swagger_types
38
+ {
39
+
40
+ :'id' => :'String',
41
+
42
+ :'type' => :'String',
43
+
44
+ :'attributes' => :'Object'
45
+
46
+ }
47
+ end
48
+
49
+ # Initializes the object
50
+ # @param [Hash] attributes Model attributes in the form of hash
51
+ def initialize(attributes = {})
52
+ return unless attributes.is_a?(Hash)
53
+
54
+ # convert string to symbol for hash key
55
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
56
+
57
+
58
+ if attributes.has_key?(:'id')
59
+
60
+
61
+ self.id = attributes[:'id']
62
+
63
+
64
+ end
65
+
66
+
67
+ if attributes.has_key?(:'type')
68
+
69
+
70
+ self.type = attributes[:'type']
71
+
72
+
73
+ end
74
+
75
+
76
+ if attributes.has_key?(:'attributes')
77
+
78
+
79
+ self.attributes = attributes[:'attributes']
80
+
81
+
82
+ end
83
+
84
+
85
+ end
86
+
87
+ # Show invalid properties with the reasons. Usually used together with valid?
88
+ # @return Array for valid properies with the reasons
89
+ def list_invalid_properties
90
+ invalid_properties = Array.new
91
+
92
+
93
+ return invalid_properties
94
+ end
95
+
96
+ # Check to see if the all the properties in the model are valid
97
+ # @return true if the model is valid
98
+ def valid?
99
+
100
+
101
+ if @id.nil?
102
+ return false
103
+ end
104
+
105
+
106
+
107
+
108
+
109
+
110
+ if @type.nil?
111
+ return false
112
+ end
113
+
114
+
115
+
116
+ allowed_values = ["agents", "assets", "works", "manifestations"]
117
+ if @type && !allowed_values.include?(@type)
118
+ return false
119
+ end
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ end
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+ # Custom attribute writer method checking allowed values (enum).
137
+ # @param [Object] type Object to be assigned
138
+ def type=(type)
139
+ allowed_values = ["agents", "assets", "works", "manifestations"]
140
+ if type && !allowed_values.include?(type)
141
+ fail ArgumentError, "invalid value for 'type', must be one of #{allowed_values}."
142
+ end
143
+ @type = type
144
+ end
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+ # Checks equality by comparing each attribute.
155
+ # @param [Object] Object to be compared
156
+ def ==(o)
157
+ return true if self.equal?(o)
158
+ self.class == o.class &&
159
+ id == o.id &&
160
+ type == o.type &&
161
+ attributes == o.attributes
162
+ end
163
+
164
+ # @see the `==` method
165
+ # @param [Object] Object to be compared
166
+ def eql?(o)
167
+ self == o
168
+ end
169
+
170
+ # Calculates hash code according to all attributes.
171
+ # @return [Fixnum] Hash code
172
+ def hash
173
+ [id, type, attributes].hash
174
+ end
175
+
176
+ # Builds the object from hash
177
+ # @param [Hash] attributes Model attributes in the form of hash
178
+ # @return [Object] Returns the model itself
179
+ def build_from_hash(attributes)
180
+ return nil unless attributes.is_a?(Hash)
181
+ self.class.swagger_types.each_pair do |key, type|
182
+ if type =~ /^Array<(.*)>/i
183
+ # check to ensure the input is an array given that the the attribute
184
+ # is documented as an array but the input is not
185
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
186
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
187
+ end
188
+ elsif !attributes[self.class.attribute_map[key]].nil?
189
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
190
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
191
+ end
192
+
193
+ self
194
+ end
195
+
196
+ # Deserializes the data based on type
197
+ # @param string type Data type
198
+ # @param string value Value to be deserialized
199
+ # @return [Object] Deserialized data
200
+ def _deserialize(type, value)
201
+ case type.to_sym
202
+ when :DateTime
203
+ DateTime.parse(value)
204
+ when :Date
205
+ Date.parse(value)
206
+ when :String
207
+ value.to_s
208
+ when :Integer
209
+ value.to_i
210
+ when :Float
211
+ value.to_f
212
+ when :BOOLEAN
213
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
214
+ true
215
+ else
216
+ false
217
+ end
218
+ when :Object
219
+ # generic object (usually a Hash), return directly
220
+ value
221
+ when /\AArray<(?<inner_type>.+)>\z/
222
+ inner_type = Regexp.last_match[:inner_type]
223
+ value.map { |v| _deserialize(inner_type, v) }
224
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
225
+ k_type = Regexp.last_match[:k_type]
226
+ v_type = Regexp.last_match[:v_type]
227
+ {}.tap do |hash|
228
+ value.each do |k, v|
229
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
230
+ end
231
+ end
232
+ else # model
233
+ temp_model = MetatronClient.const_get(type).new
234
+ temp_model.build_from_hash(value)
235
+ end
236
+ end
237
+
238
+ # Returns the string representation of the object
239
+ # @return [String] String presentation of the object
240
+ def to_s
241
+ to_hash.to_s
242
+ end
243
+
244
+ # to_body is an alias to to_hash (backward compatibility)
245
+ # @return [Hash] Returns the object in the form of hash
246
+ def to_body
247
+ to_hash
248
+ end
249
+
250
+ # Returns the object in the form of hash
251
+ # @return [Hash] Returns the object in the form of hash
252
+ def to_hash
253
+ hash = {}
254
+ self.class.attribute_map.each_pair do |attr, param|
255
+ value = self.send(attr)
256
+ next if value.nil?
257
+ hash[param] = _to_hash(value)
258
+ end
259
+ hash
260
+ end
261
+
262
+ # Outputs non-array value in the form of hash
263
+ # For object, use to_hash. Otherwise, just return the value
264
+ # @param [Object] value Any valid value
265
+ # @return [Hash] Returns the value in the form of hash
266
+ def _to_hash(value)
267
+ if value.is_a?(Array)
268
+ value.compact.map{ |v| _to_hash(v) }
269
+ elsif value.is_a?(Hash)
270
+ {}.tap do |hash|
271
+ value.each { |k, v| hash[k] = _to_hash(v) }
272
+ end
273
+ elsif value.respond_to? :to_hash
274
+ value.to_hash
275
+ else
276
+ value
277
+ end
278
+ end
279
+
280
+ end
281
+ end