clever-ruby 1.2.5 → 2.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 (171) hide show
  1. checksums.yaml +4 -4
  2. data/1.8, +0 -0
  3. data/= +0 -0
  4. data/CHANGELOG.md +3 -3
  5. data/Gemfile +0 -1
  6. data/Gemfile.lock +8 -9
  7. data/README.md +89 -70
  8. data/clever-ruby.gemspec +3 -4
  9. data/doc_coverage.txt +2 -0
  10. data/docs/{StudentContact.md → Contact.md} +2 -2
  11. data/docs/{GradeLevelsResponse.md → ContactObject.md} +2 -2
  12. data/docs/{StudentContactObject.md → ContactResponse.md} +2 -2
  13. data/docs/{StudentcontactsCreated.md → ContactsCreated.md} +2 -2
  14. data/docs/{StudentcontactsDeleted.md → ContactsDeleted.md} +2 -2
  15. data/docs/ContactsResponse.md +8 -0
  16. data/docs/{StudentcontactsUpdated.md → ContactsUpdated.md} +2 -2
  17. data/docs/Course.md +10 -0
  18. data/docs/{StudentContactResponse.md → CourseObject.md} +2 -2
  19. data/docs/CourseResponse.md +8 -0
  20. data/docs/CoursesCreated.md +11 -0
  21. data/docs/CoursesDeleted.md +11 -0
  22. data/docs/{StudentContactsForStudentResponse.md → CoursesResponse.md} +2 -2
  23. data/docs/CoursesUpdated.md +11 -0
  24. data/docs/DataApi.md +862 -182
  25. data/docs/District.md +8 -0
  26. data/docs/{DistrictStatusResponse.md → DistrictAdminObject.md} +2 -2
  27. data/docs/DistrictAdminsResponse.md +1 -1
  28. data/docs/DistrictadminsCreated.md +11 -0
  29. data/docs/DistrictadminsDeleted.md +11 -0
  30. data/docs/DistrictadminsUpdated.md +11 -0
  31. data/docs/EventsApi.md +6 -302
  32. data/docs/Section.md +2 -4
  33. data/docs/Term.md +1 -0
  34. data/docs/TermObject.md +8 -0
  35. data/docs/TermResponse.md +8 -0
  36. data/docs/TermsCreated.md +11 -0
  37. data/docs/TermsDeleted.md +11 -0
  38. data/docs/TermsResponse.md +8 -0
  39. data/docs/TermsUpdated.md +11 -0
  40. data/lib/clever-ruby.rb +26 -14
  41. data/lib/clever-ruby/api/data_api.rb +828 -132
  42. data/lib/clever-ruby/api/events_api.rb +8 -312
  43. data/lib/clever-ruby/api_client.rb +40 -27
  44. data/lib/clever-ruby/api_error.rb +2 -2
  45. data/lib/clever-ruby/configuration.rb +3 -3
  46. data/lib/clever-ruby/models/bad_request.rb +2 -2
  47. data/lib/clever-ruby/models/{student_contact.rb → contact.rb} +69 -10
  48. data/lib/clever-ruby/models/{student_contact_object.rb → contact_object.rb} +4 -4
  49. data/lib/clever-ruby/models/{student_contact_response.rb → contact_response.rb} +4 -4
  50. data/lib/clever-ruby/models/contacts_created.rb +221 -0
  51. data/lib/clever-ruby/models/contacts_deleted.rb +221 -0
  52. data/lib/clever-ruby/models/{student_contacts_response.rb → contacts_response.rb} +4 -4
  53. data/lib/clever-ruby/models/contacts_updated.rb +221 -0
  54. data/lib/clever-ruby/models/course.rb +206 -0
  55. data/lib/clever-ruby/models/course_object.rb +188 -0
  56. data/lib/clever-ruby/models/{district_status_response.rb → course_response.rb} +4 -4
  57. data/lib/clever-ruby/models/courses_created.rb +221 -0
  58. data/lib/clever-ruby/models/courses_deleted.rb +221 -0
  59. data/lib/clever-ruby/models/{district_status_responses.rb → courses_response.rb} +4 -4
  60. data/lib/clever-ruby/models/courses_updated.rb +221 -0
  61. data/lib/clever-ruby/models/credentials.rb +2 -2
  62. data/lib/clever-ruby/models/district.rb +111 -6
  63. data/lib/clever-ruby/models/district_admin.rb +2 -2
  64. data/lib/clever-ruby/models/district_admin_object.rb +188 -0
  65. data/lib/clever-ruby/models/district_admin_response.rb +2 -2
  66. data/lib/clever-ruby/models/district_admins_response.rb +3 -3
  67. data/lib/clever-ruby/models/district_object.rb +2 -2
  68. data/lib/clever-ruby/models/district_response.rb +2 -2
  69. data/lib/clever-ruby/models/districtadmins_created.rb +221 -0
  70. data/lib/clever-ruby/models/districtadmins_deleted.rb +221 -0
  71. data/lib/clever-ruby/models/districtadmins_updated.rb +221 -0
  72. data/lib/clever-ruby/models/districts_created.rb +22 -7
  73. data/lib/clever-ruby/models/districts_deleted.rb +22 -8
  74. data/lib/clever-ruby/models/districts_response.rb +2 -2
  75. data/lib/clever-ruby/models/districts_updated.rb +21 -7
  76. data/lib/clever-ruby/models/event.rb +2 -2
  77. data/lib/clever-ruby/models/event_response.rb +2 -2
  78. data/lib/clever-ruby/models/events_response.rb +2 -2
  79. data/lib/clever-ruby/models/internal_error.rb +2 -2
  80. data/lib/clever-ruby/models/location.rb +2 -2
  81. data/lib/clever-ruby/models/name.rb +2 -2
  82. data/lib/clever-ruby/models/not_found.rb +2 -2
  83. data/lib/clever-ruby/models/principal.rb +2 -2
  84. data/lib/clever-ruby/models/school.rb +2 -2
  85. data/lib/clever-ruby/models/school_admin.rb +2 -2
  86. data/lib/clever-ruby/models/school_admin_object.rb +2 -2
  87. data/lib/clever-ruby/models/school_admin_response.rb +2 -2
  88. data/lib/clever-ruby/models/school_admins_response.rb +2 -2
  89. data/lib/clever-ruby/models/school_object.rb +2 -2
  90. data/lib/clever-ruby/models/school_response.rb +2 -2
  91. data/lib/clever-ruby/models/schooladmins_created.rb +21 -7
  92. data/lib/clever-ruby/models/schooladmins_deleted.rb +21 -7
  93. data/lib/clever-ruby/models/schooladmins_updated.rb +21 -7
  94. data/lib/clever-ruby/models/schools_created.rb +21 -7
  95. data/lib/clever-ruby/models/schools_deleted.rb +21 -7
  96. data/lib/clever-ruby/models/schools_response.rb +2 -2
  97. data/lib/clever-ruby/models/schools_updated.rb +21 -7
  98. data/lib/clever-ruby/models/section.rb +15 -33
  99. data/lib/clever-ruby/models/section_object.rb +2 -2
  100. data/lib/clever-ruby/models/section_response.rb +2 -2
  101. data/lib/clever-ruby/models/sections_created.rb +21 -7
  102. data/lib/clever-ruby/models/sections_deleted.rb +21 -7
  103. data/lib/clever-ruby/models/sections_response.rb +2 -2
  104. data/lib/clever-ruby/models/sections_updated.rb +21 -7
  105. data/lib/clever-ruby/models/student.rb +4 -4
  106. data/lib/clever-ruby/models/student_object.rb +2 -2
  107. data/lib/clever-ruby/models/student_response.rb +2 -2
  108. data/lib/clever-ruby/models/students_created.rb +20 -7
  109. data/lib/clever-ruby/models/students_deleted.rb +22 -7
  110. data/lib/clever-ruby/models/students_response.rb +2 -2
  111. data/lib/clever-ruby/models/students_updated.rb +21 -7
  112. data/lib/clever-ruby/models/teacher.rb +2 -2
  113. data/lib/clever-ruby/models/teacher_object.rb +2 -2
  114. data/lib/clever-ruby/models/teacher_response.rb +2 -2
  115. data/lib/clever-ruby/models/teachers_created.rb +21 -7
  116. data/lib/clever-ruby/models/teachers_deleted.rb +21 -7
  117. data/lib/clever-ruby/models/teachers_response.rb +2 -2
  118. data/lib/clever-ruby/models/teachers_updated.rb +21 -7
  119. data/lib/clever-ruby/models/term.rb +12 -3
  120. data/lib/clever-ruby/models/term_object.rb +188 -0
  121. data/lib/clever-ruby/models/term_response.rb +188 -0
  122. data/lib/clever-ruby/models/{studentcontacts_updated.rb → terms_created.rb} +23 -9
  123. data/{override/models/studentcontacts_created.rb → lib/clever-ruby/models/terms_deleted.rb} +23 -9
  124. data/lib/clever-ruby/models/{grade_levels_response.rb → terms_response.rb} +4 -4
  125. data/lib/clever-ruby/models/{studentcontacts_created.rb → terms_updated.rb} +23 -9
  126. data/lib/clever-ruby/version.rb +3 -3
  127. data/override/README-extension.md +5 -5
  128. data/override/api_client.rb +40 -27
  129. data/override/models/contacts_created.rb +221 -0
  130. data/override/models/contacts_deleted.rb +221 -0
  131. data/override/models/contacts_updated.rb +221 -0
  132. data/override/models/courses_created.rb +221 -0
  133. data/override/models/courses_deleted.rb +221 -0
  134. data/override/models/courses_updated.rb +221 -0
  135. data/override/models/districtadmins_created.rb +221 -0
  136. data/override/models/districtadmins_deleted.rb +221 -0
  137. data/override/models/districtadmins_updated.rb +221 -0
  138. data/override/models/districts_created.rb +22 -7
  139. data/override/models/districts_deleted.rb +22 -8
  140. data/override/models/districts_updated.rb +21 -7
  141. data/override/models/schooladmins_created.rb +21 -7
  142. data/override/models/schooladmins_deleted.rb +21 -7
  143. data/override/models/schooladmins_updated.rb +21 -7
  144. data/override/models/schools_created.rb +21 -7
  145. data/override/models/schools_deleted.rb +21 -7
  146. data/override/models/schools_updated.rb +21 -7
  147. data/override/models/sections_created.rb +21 -7
  148. data/override/models/sections_deleted.rb +21 -7
  149. data/override/models/sections_updated.rb +21 -7
  150. data/override/models/students_created.rb +20 -7
  151. data/override/models/students_deleted.rb +22 -7
  152. data/override/models/students_updated.rb +21 -7
  153. data/override/models/teachers_created.rb +21 -7
  154. data/override/models/teachers_deleted.rb +21 -7
  155. data/override/models/teachers_updated.rb +21 -7
  156. data/{lib/clever-ruby/models/studentcontacts_deleted.rb → override/models/terms_created.rb} +23 -9
  157. data/override/models/terms_deleted.rb +221 -0
  158. data/override/models/terms_updated.rb +221 -0
  159. data/sample/sample.rb +2 -2
  160. data/spec/events_api_spec.rb +1 -1
  161. data/test.rb +1 -1
  162. metadata +111 -85
  163. data/clever-ruby-2.0.0.gem +0 -0
  164. data/docs/DistrictStatus.md +0 -15
  165. data/docs/DistrictStatusResponses.md +0 -8
  166. data/docs/StudentContactsResponse.md +0 -8
  167. data/lib/clever-ruby/models/district_status.rb +0 -284
  168. data/lib/clever-ruby/models/student_contacts_for_student_response.rb +0 -190
  169. data/override/models/studentcontacts_deleted.rb +0 -207
  170. data/override/models/studentcontacts_updated.rb +0 -207
  171. data/spec/data_api_spec.rb +0 -32
@@ -3,13 +3,13 @@
3
3
 
4
4
  #The Clever API
5
5
 
6
- OpenAPI spec version: 1.2.0
6
+ OpenAPI spec version: 2.0.0
7
7
 
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.2.3
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
10
 
11
11
  =end
12
12
 
13
13
  module Clever
14
- VERSION = "1.2.5"
14
+ VERSION = "2.0.0"
15
15
  end
@@ -1,9 +1,9 @@
1
1
  ## Previous Versions
2
2
 
3
- The current client support v1.2 of the API. For v1.1 please use:
3
+ The current client support v2.0 of the API. For v1.2 please use:
4
4
 
5
- https://rubygems.org/gems/clever-ruby/versions/0.14.0
6
- https://github.com/Clever/clever-ruby/tree/0.14
5
+ - https://rubygems.org/gems/clever-ruby/versions/1.2.4
6
+ - https://github.com/Clever/clever-ruby/tree/v1.2.4
7
7
 
8
8
 
9
9
  ## Updating the Library
@@ -14,7 +14,7 @@ https://github.com/Clever/clever-ruby/tree/0.14
14
14
 
15
15
  3. Run this command in the swagger-codegen repo
16
16
  ```
17
- java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i $PATH_TO_SWAGGER_API_REPO/v1.2-client.yml -l ruby -o $PATH_TO_THIS_REPO --additional-properties gemVersion=$VERSION
17
+ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i $PATH_TO_SWAGGER_API_REPO/v2.0-client.yml -l ruby -o $PATH_TO_THIS_REPO --additional-properties gemVersion=$VERSION
18
18
  ```
19
19
 
20
20
  4. Run `make build` to copy over the override files
@@ -28,4 +28,4 @@ To add a new owner, you need to be an owner, then run this command: `gem owner c
28
28
 
29
29
  1. Update `CHANGELOG.md`
30
30
  1. `gem build clever-ruby.gemspec`
31
- 1. `gem push clever-ruby-X.Y.Z.gem`
31
+ 1. `gem push clever-ruby-X.Y.Z.gem`
@@ -3,9 +3,10 @@
3
3
 
4
4
  #The Clever API
5
5
 
6
- OpenAPI spec version: 1.2.0
6
+ OpenAPI spec version: 2.0.0
7
7
 
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
9
10
 
10
11
  =end
11
12
 
@@ -122,7 +123,9 @@ module Clever
122
123
  end
123
124
  end
124
125
 
125
- Typhoeus::Request.new(url, req_opts)
126
+ request = Typhoeus::Request.new(url, req_opts)
127
+ download_file(request) if opts[:return_type] == 'File'
128
+ request
126
129
  end
127
130
 
128
131
  # Check if the given MIME is a JSON MIME.
@@ -143,14 +146,16 @@ module Clever
143
146
  # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
144
147
  def deserialize(response, return_type)
145
148
  body = response.body
149
+
150
+ # handle file downloading - return the File instance processed in request callbacks
151
+ # note that response body is empty when the file is written in chunks in request on_body callback
152
+ return @tempfile if return_type == 'File'
153
+
146
154
  return nil if body.nil? || body.empty?
147
155
 
148
156
  # return response body directly for String return type
149
157
  return body if return_type == 'String'
150
158
 
151
- # handle file downloading - save response body into a tmp file and return the File instance
152
- return download_file(response) if return_type == 'File'
153
-
154
159
  # ensuring a default content type
155
160
  content_type = response.headers['Content-Type'] || 'application/json'
156
161
 
@@ -207,7 +212,7 @@ module Clever
207
212
  Clever.const_get(return_type).new.tap do |model|
208
213
  resp = model.build_from_hash data
209
214
  resps = []
210
- data[:data].each do |eventResponse|
215
+ data[:data].each do |eventResponse|
211
216
  singleResp = parse_event_response(eventResponse[:data])
212
217
  resps.push(singleResp)
213
218
  end
@@ -238,30 +243,38 @@ module Clever
238
243
 
239
244
  # Save response body into a file in (the defined) temporary folder, using the filename
240
245
  # from the "Content-Disposition" header if provided, otherwise a random filename.
246
+ # The response body is written to the file in chunks in order to handle files which
247
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
248
+ # process can use.
241
249
  #
242
250
  # @see Configuration#temp_folder_path
243
- # @return [Tempfile] the file downloaded
244
- def download_file(response)
245
- content_disposition = response.headers['Content-Disposition']
246
- if content_disposition and content_disposition =~ /filename=/i
247
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
248
- prefix = sanitize_filename(filename)
249
- else
250
- prefix = 'download-'
251
- end
252
- prefix = prefix + '-' unless prefix.end_with?('-')
253
-
251
+ def download_file(request)
254
252
  tempfile = nil
255
- encoding = response.body.encoding
256
- Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
257
- file.write(response.body)
258
- tempfile = file
253
+ encoding = nil
254
+ request.on_headers do |response|
255
+ content_disposition = response.headers['Content-Disposition']
256
+ if content_disposition and content_disposition =~ /filename=/i
257
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
258
+ prefix = sanitize_filename(filename)
259
+ else
260
+ prefix = 'download-'
261
+ end
262
+ prefix = prefix + '-' unless prefix.end_with?('-')
263
+ encoding = response.body.encoding
264
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
265
+ @tempfile = tempfile
266
+ end
267
+ request.on_body do |chunk|
268
+ chunk.force_encoding(encoding)
269
+ tempfile.write(chunk)
270
+ end
271
+ request.on_complete do |response|
272
+ tempfile.close
273
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
274
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
275
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
276
+ "explicitly with `tempfile.delete`"
259
277
  end
260
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
261
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
262
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
263
- "explicitly with `tempfile.delete`"
264
- tempfile
265
278
  end
266
279
 
267
280
  # Sanitize filename by removing path.
@@ -292,7 +305,7 @@ module Clever
292
305
  data = {}
293
306
  form_params.each do |key, value|
294
307
  case value
295
- when File, Array, nil
308
+ when ::File, ::Array, nil
296
309
  # let typhoeus handle File, Array and nil parameters
297
310
  data[key] = value
298
311
  else
@@ -0,0 +1,221 @@
1
+ =begin
2
+ #Clever API
3
+
4
+ #The Clever API
5
+
6
+ OpenAPI spec version: 2.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require File.expand_path('../event.rb', __FILE__)
15
+
16
+ module Clever
17
+
18
+ class ContactsCreated < Event
19
+ attr_accessor :created
20
+
21
+ attr_accessor :id
22
+
23
+ attr_accessor :type
24
+
25
+ attr_accessor :data
26
+
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'created' => :'created',
32
+ :'id' => :'id',
33
+ :'type' => :'type',
34
+ :'data' => :'data'
35
+ }
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.swagger_types
40
+ {
41
+ :'created' => :'String',
42
+ :'id' => :'String',
43
+ :'type' => :'String',
44
+ :'data' => :'ContactObject'
45
+ }
46
+ end
47
+
48
+ # Initializes the object
49
+ # @param [Hash] attributes Model attributes in the form of hash
50
+ def initialize(attributes = {})
51
+ return unless attributes.is_a?(Hash)
52
+
53
+ # convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
55
+
56
+ if attributes.has_key?(:'created')
57
+ self.created = attributes[:'created']
58
+ end
59
+
60
+ if attributes.has_key?(:'id')
61
+ self.id = attributes[:'id']
62
+ end
63
+
64
+ if attributes.has_key?(:'type')
65
+ self.type = attributes[:'type']
66
+ end
67
+
68
+ if attributes.has_key?(:'data')
69
+ self.data = attributes[:'data']
70
+ end
71
+
72
+ end
73
+
74
+ # Show invalid properties with the reasons. Usually used together with valid?
75
+ # @return Array for valid properies with the reasons
76
+ def list_invalid_properties
77
+ invalid_properties = Array.new
78
+ if @type.nil?
79
+ invalid_properties.push("invalid value for 'type', type cannot be nil.")
80
+ end
81
+
82
+ return invalid_properties
83
+ end
84
+
85
+ # Check to see if the all the properties in the model are valid
86
+ # @return true if the model is valid
87
+ def valid?
88
+ return false if @type.nil?
89
+ return true
90
+ end
91
+
92
+ # Checks equality by comparing each attribute.
93
+ # @param [Object] Object to be compared
94
+ def ==(o)
95
+ return true if self.equal?(o)
96
+ self.class == o.class &&
97
+ created == o.created &&
98
+ id == o.id &&
99
+ type == o.type &&
100
+ data == o.data
101
+ end
102
+
103
+ # @see the `==` method
104
+ # @param [Object] Object to be compared
105
+ def eql?(o)
106
+ self == o
107
+ end
108
+
109
+ # Calculates hash code according to all attributes.
110
+ # @return [Fixnum] Hash code
111
+ def hash
112
+ [created, id, type, data].hash
113
+ end
114
+
115
+ # Builds the object from hash
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ # @return [Object] Returns the model itself
118
+ def build_from_hash(attributes)
119
+ return nil unless attributes.is_a?(Hash)
120
+ self.class.swagger_types.each_pair do |key, type|
121
+ if type =~ /\AArray<(.*)>/i
122
+ # check to ensure the input is an array given that the the attribute
123
+ # is documented as an array but the input is not
124
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
125
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
126
+ end
127
+ elsif !attributes[self.class.attribute_map[key]].nil?
128
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
129
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
130
+ end
131
+
132
+ self
133
+ end
134
+
135
+ # Deserializes the data based on type
136
+ # @param string type Data type
137
+ # @param string value Value to be deserialized
138
+ # @return [Object] Deserialized data
139
+ def _deserialize(type, value)
140
+ case type.to_sym
141
+ when :DateTime
142
+ DateTime.parse(value)
143
+ when :Date
144
+ Date.parse(value)
145
+ when :String
146
+ value.to_s
147
+ when :Integer
148
+ value.to_i
149
+ when :Float
150
+ value.to_f
151
+ when :BOOLEAN
152
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
153
+ true
154
+ else
155
+ false
156
+ end
157
+ when :Object
158
+ # generic object (usually a Hash), return directly
159
+ value
160
+ when /\AArray<(?<inner_type>.+)>\z/
161
+ inner_type = Regexp.last_match[:inner_type]
162
+ value.map { |v| _deserialize(inner_type, v) }
163
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
164
+ k_type = Regexp.last_match[:k_type]
165
+ v_type = Regexp.last_match[:v_type]
166
+ {}.tap do |hash|
167
+ value.each do |k, v|
168
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
169
+ end
170
+ end
171
+ else # model
172
+ temp_model = Clever.const_get(type).new
173
+ temp_model.build_from_hash(value)
174
+ end
175
+ end
176
+
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ next if value.nil?
196
+ hash[param] = _to_hash(value)
197
+ end
198
+ hash
199
+ end
200
+
201
+ # Outputs non-array value in the form of hash
202
+ # For object, use to_hash. Otherwise, just return the value
203
+ # @param [Object] value Any valid value
204
+ # @return [Hash] Returns the value in the form of hash
205
+ def _to_hash(value)
206
+ if value.is_a?(Array)
207
+ value.compact.map{ |v| _to_hash(v) }
208
+ elsif value.is_a?(Hash)
209
+ {}.tap do |hash|
210
+ value.each { |k, v| hash[k] = _to_hash(v) }
211
+ end
212
+ elsif value.respond_to? :to_hash
213
+ value.to_hash
214
+ else
215
+ value
216
+ end
217
+ end
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,221 @@
1
+ =begin
2
+ #Clever API
3
+
4
+ #The Clever API
5
+
6
+ OpenAPI spec version: 2.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require File.expand_path('../event.rb', __FILE__)
15
+
16
+ module Clever
17
+
18
+ class ContactsDeleted < Event
19
+ attr_accessor :created
20
+
21
+ attr_accessor :id
22
+
23
+ attr_accessor :type
24
+
25
+ attr_accessor :data
26
+
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'created' => :'created',
32
+ :'id' => :'id',
33
+ :'type' => :'type',
34
+ :'data' => :'data'
35
+ }
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.swagger_types
40
+ {
41
+ :'created' => :'String',
42
+ :'id' => :'String',
43
+ :'type' => :'String',
44
+ :'data' => :'ContactObject'
45
+ }
46
+ end
47
+
48
+ # Initializes the object
49
+ # @param [Hash] attributes Model attributes in the form of hash
50
+ def initialize(attributes = {})
51
+ return unless attributes.is_a?(Hash)
52
+
53
+ # convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
55
+
56
+ if attributes.has_key?(:'created')
57
+ self.created = attributes[:'created']
58
+ end
59
+
60
+ if attributes.has_key?(:'id')
61
+ self.id = attributes[:'id']
62
+ end
63
+
64
+ if attributes.has_key?(:'type')
65
+ self.type = attributes[:'type']
66
+ end
67
+
68
+ if attributes.has_key?(:'data')
69
+ self.data = attributes[:'data']
70
+ end
71
+
72
+ end
73
+
74
+ # Show invalid properties with the reasons. Usually used together with valid?
75
+ # @return Array for valid properies with the reasons
76
+ def list_invalid_properties
77
+ invalid_properties = Array.new
78
+ if @type.nil?
79
+ invalid_properties.push("invalid value for 'type', type cannot be nil.")
80
+ end
81
+
82
+ return invalid_properties
83
+ end
84
+
85
+ # Check to see if the all the properties in the model are valid
86
+ # @return true if the model is valid
87
+ def valid?
88
+ return false if @type.nil?
89
+ return true
90
+ end
91
+
92
+ # Checks equality by comparing each attribute.
93
+ # @param [Object] Object to be compared
94
+ def ==(o)
95
+ return true if self.equal?(o)
96
+ self.class == o.class &&
97
+ created == o.created &&
98
+ id == o.id &&
99
+ type == o.type &&
100
+ data == o.data
101
+ end
102
+
103
+ # @see the `==` method
104
+ # @param [Object] Object to be compared
105
+ def eql?(o)
106
+ self == o
107
+ end
108
+
109
+ # Calculates hash code according to all attributes.
110
+ # @return [Fixnum] Hash code
111
+ def hash
112
+ [created, id, type, data].hash
113
+ end
114
+
115
+ # Builds the object from hash
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ # @return [Object] Returns the model itself
118
+ def build_from_hash(attributes)
119
+ return nil unless attributes.is_a?(Hash)
120
+ self.class.swagger_types.each_pair do |key, type|
121
+ if type =~ /\AArray<(.*)>/i
122
+ # check to ensure the input is an array given that the the attribute
123
+ # is documented as an array but the input is not
124
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
125
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
126
+ end
127
+ elsif !attributes[self.class.attribute_map[key]].nil?
128
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
129
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
130
+ end
131
+
132
+ self
133
+ end
134
+
135
+ # Deserializes the data based on type
136
+ # @param string type Data type
137
+ # @param string value Value to be deserialized
138
+ # @return [Object] Deserialized data
139
+ def _deserialize(type, value)
140
+ case type.to_sym
141
+ when :DateTime
142
+ DateTime.parse(value)
143
+ when :Date
144
+ Date.parse(value)
145
+ when :String
146
+ value.to_s
147
+ when :Integer
148
+ value.to_i
149
+ when :Float
150
+ value.to_f
151
+ when :BOOLEAN
152
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
153
+ true
154
+ else
155
+ false
156
+ end
157
+ when :Object
158
+ # generic object (usually a Hash), return directly
159
+ value
160
+ when /\AArray<(?<inner_type>.+)>\z/
161
+ inner_type = Regexp.last_match[:inner_type]
162
+ value.map { |v| _deserialize(inner_type, v) }
163
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
164
+ k_type = Regexp.last_match[:k_type]
165
+ v_type = Regexp.last_match[:v_type]
166
+ {}.tap do |hash|
167
+ value.each do |k, v|
168
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
169
+ end
170
+ end
171
+ else # model
172
+ temp_model = Clever.const_get(type).new
173
+ temp_model.build_from_hash(value)
174
+ end
175
+ end
176
+
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ next if value.nil?
196
+ hash[param] = _to_hash(value)
197
+ end
198
+ hash
199
+ end
200
+
201
+ # Outputs non-array value in the form of hash
202
+ # For object, use to_hash. Otherwise, just return the value
203
+ # @param [Object] value Any valid value
204
+ # @return [Hash] Returns the value in the form of hash
205
+ def _to_hash(value)
206
+ if value.is_a?(Array)
207
+ value.compact.map{ |v| _to_hash(v) }
208
+ elsif value.is_a?(Hash)
209
+ {}.tap do |hash|
210
+ value.each { |k, v| hash[k] = _to_hash(v) }
211
+ end
212
+ elsif value.respond_to? :to_hash
213
+ value.to_hash
214
+ else
215
+ value
216
+ end
217
+ end
218
+
219
+ end
220
+
221
+ end