clever-ruby 0.14.0 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -1
- data/Makefile +10 -0
- data/README.md +175 -68
- data/Rakefile +6 -36
- data/circle.yml +1 -1
- data/clever-ruby.gemspec +43 -33
- data/docs/BadRequest.md +8 -0
- data/docs/DataApi.md +2144 -0
- data/docs/District.md +10 -0
- data/docs/DistrictAdmin.md +12 -0
- data/docs/DistrictAdminResponse.md +8 -0
- data/docs/DistrictAdminsResponse.md +8 -0
- data/docs/DistrictObject.md +8 -0
- data/docs/DistrictResponse.md +8 -0
- data/docs/DistrictStatus.md +15 -0
- data/docs/DistrictStatusResponse.md +8 -0
- data/docs/DistrictsCreated.md +10 -0
- data/docs/DistrictsDeleted.md +10 -0
- data/docs/DistrictsResponse.md +8 -0
- data/docs/DistrictsUpdated.md +10 -0
- data/docs/Event.md +9 -0
- data/docs/EventResponse.md +8 -0
- data/docs/EventsApi.md +424 -0
- data/docs/EventsResponse.md +8 -0
- data/docs/GradeLevelsResponse.md +8 -0
- data/docs/InternalError.md +8 -0
- data/docs/Location.md +13 -0
- data/docs/Name.md +10 -0
- data/docs/NotFound.md +8 -0
- data/docs/Principal.md +9 -0
- data/docs/School.md +22 -0
- data/docs/SchoolAdmin.md +14 -0
- data/docs/SchoolAdminObject.md +8 -0
- data/docs/SchoolAdminResponse.md +8 -0
- data/docs/SchoolAdminsResponse.md +8 -0
- data/docs/SchoolObject.md +8 -0
- data/docs/SchoolResponse.md +8 -0
- data/docs/SchooladminsCreated.md +10 -0
- data/docs/SchooladminsDeleted.md +10 -0
- data/docs/SchooladminsUpdated.md +10 -0
- data/docs/SchoolsCreated.md +10 -0
- data/docs/SchoolsDeleted.md +10 -0
- data/docs/SchoolsResponse.md +8 -0
- data/docs/SchoolsUpdated.md +10 -0
- data/docs/Section.md +25 -0
- data/docs/SectionObject.md +8 -0
- data/docs/SectionResponse.md +8 -0
- data/docs/SectionsCreated.md +10 -0
- data/docs/SectionsDeleted.md +10 -0
- data/docs/SectionsResponse.md +8 -0
- data/docs/SectionsUpdated.md +10 -0
- data/docs/Student.md +27 -0
- data/docs/StudentContact.md +16 -0
- data/docs/StudentContactObject.md +8 -0
- data/docs/StudentContactResponse.md +8 -0
- data/docs/StudentContactsResponse.md +8 -0
- data/docs/StudentObject.md +8 -0
- data/docs/StudentResponse.md +8 -0
- data/docs/StudentcontactsCreated.md +10 -0
- data/docs/StudentcontactsDeleted.md +10 -0
- data/docs/StudentcontactsUpdated.md +10 -0
- data/docs/StudentsCreated.md +10 -0
- data/docs/StudentsDeleted.md +10 -0
- data/docs/StudentsResponse.md +8 -0
- data/docs/StudentsUpdated.md +10 -0
- data/docs/Teacher.md +19 -0
- data/docs/TeacherObject.md +8 -0
- data/docs/TeacherResponse.md +8 -0
- data/docs/TeachersCreated.md +10 -0
- data/docs/TeachersDeleted.md +10 -0
- data/docs/TeachersResponse.md +8 -0
- data/docs/TeachersUpdated.md +10 -0
- data/docs/Term.md +10 -0
- data/git_push.sh +55 -0
- data/instructions.md +12 -0
- data/lib/clever-ruby.rb +89 -318
- data/lib/clever-ruby/api/data_api.rb +2090 -0
- data/lib/clever-ruby/api/events_api.rb +429 -0
- data/lib/clever-ruby/api_client.rb +401 -0
- data/lib/clever-ruby/api_error.rb +37 -0
- data/lib/clever-ruby/configuration.rb +187 -25
- data/lib/clever-ruby/models/bad_request.rb +187 -0
- data/lib/clever-ruby/models/district.rb +205 -0
- data/lib/clever-ruby/models/district_admin.rb +223 -0
- data/lib/clever-ruby/models/district_admin_response.rb +187 -0
- data/lib/clever-ruby/models/district_admins_response.rb +189 -0
- data/lib/clever-ruby/models/district_object.rb +187 -0
- data/lib/clever-ruby/models/district_response.rb +187 -0
- data/lib/clever-ruby/models/district_status.rb +250 -0
- data/lib/clever-ruby/models/district_status_response.rb +187 -0
- data/lib/clever-ruby/models/districts_created.rb +206 -0
- data/lib/clever-ruby/models/districts_deleted.rb +207 -0
- data/lib/clever-ruby/models/districts_response.rb +189 -0
- data/lib/clever-ruby/models/districts_updated.rb +207 -0
- data/lib/clever-ruby/models/event.rb +201 -0
- data/lib/clever-ruby/models/event_response.rb +187 -0
- data/lib/clever-ruby/models/events_response.rb +189 -0
- data/lib/clever-ruby/models/grade_levels_response.rb +189 -0
- data/lib/clever-ruby/models/internal_error.rb +187 -0
- data/lib/clever-ruby/models/location.rb +232 -0
- data/lib/clever-ruby/models/name.rb +205 -0
- data/lib/clever-ruby/models/not_found.rb +187 -0
- data/lib/clever-ruby/models/principal.rb +196 -0
- data/lib/clever-ruby/models/school.rb +313 -0
- data/lib/clever-ruby/models/school_admin.rb +243 -0
- data/lib/clever-ruby/models/school_admin_object.rb +187 -0
- data/lib/clever-ruby/models/school_admin_response.rb +187 -0
- data/lib/clever-ruby/models/school_admins_response.rb +189 -0
- data/lib/clever-ruby/models/school_object.rb +187 -0
- data/lib/clever-ruby/models/school_response.rb +187 -0
- data/lib/clever-ruby/models/schooladmins_created.rb +207 -0
- data/lib/clever-ruby/models/schooladmins_deleted.rb +207 -0
- data/lib/clever-ruby/models/schooladmins_updated.rb +207 -0
- data/lib/clever-ruby/models/schools_created.rb +207 -0
- data/lib/clever-ruby/models/schools_deleted.rb +207 -0
- data/lib/clever-ruby/models/schools_response.rb +189 -0
- data/lib/clever-ruby/models/schools_updated.rb +207 -0
- data/lib/clever-ruby/models/section.rb +344 -0
- data/lib/clever-ruby/models/section_object.rb +187 -0
- data/lib/clever-ruby/models/section_response.rb +187 -0
- data/lib/clever-ruby/models/sections_created.rb +207 -0
- data/lib/clever-ruby/models/sections_deleted.rb +207 -0
- data/lib/clever-ruby/models/sections_response.rb +189 -0
- data/lib/clever-ruby/models/sections_updated.rb +207 -0
- data/lib/clever-ruby/models/student.rb +360 -0
- data/lib/clever-ruby/models/student_contact.rb +259 -0
- data/lib/clever-ruby/models/student_contact_object.rb +187 -0
- data/lib/clever-ruby/models/student_contact_response.rb +187 -0
- data/lib/clever-ruby/models/student_contacts_response.rb +189 -0
- data/lib/clever-ruby/models/student_object.rb +187 -0
- data/lib/clever-ruby/models/student_response.rb +187 -0
- data/lib/clever-ruby/models/studentcontacts_created.rb +207 -0
- data/lib/clever-ruby/models/studentcontacts_deleted.rb +207 -0
- data/lib/clever-ruby/models/studentcontacts_updated.rb +207 -0
- data/lib/clever-ruby/models/students_created.rb +196 -0
- data/lib/clever-ruby/models/students_deleted.rb +206 -0
- data/lib/clever-ruby/models/students_response.rb +189 -0
- data/lib/clever-ruby/models/students_updated.rb +207 -0
- data/lib/clever-ruby/models/teacher.rb +288 -0
- data/lib/clever-ruby/models/teacher_object.rb +187 -0
- data/lib/clever-ruby/models/teacher_response.rb +187 -0
- data/lib/clever-ruby/models/teachers_created.rb +207 -0
- data/lib/clever-ruby/models/teachers_deleted.rb +207 -0
- data/lib/clever-ruby/models/teachers_response.rb +189 -0
- data/lib/clever-ruby/models/teachers_updated.rb +207 -0
- data/lib/clever-ruby/models/term.rb +205 -0
- data/lib/clever-ruby/version.rb +12 -4
- data/override/api_client.rb +401 -0
- data/override/config.json +5 -0
- data/override/models/districts_created.rb +206 -0
- data/override/models/districts_deleted.rb +207 -0
- data/override/models/districts_updated.rb +207 -0
- data/override/models/schooladmins_created.rb +207 -0
- data/override/models/schooladmins_deleted.rb +207 -0
- data/override/models/schooladmins_updated.rb +207 -0
- data/override/models/schools_created.rb +207 -0
- data/override/models/schools_deleted.rb +207 -0
- data/override/models/schools_updated.rb +207 -0
- data/override/models/sections_created.rb +207 -0
- data/override/models/sections_deleted.rb +207 -0
- data/override/models/sections_updated.rb +207 -0
- data/override/models/studentcontacts_created.rb +207 -0
- data/override/models/studentcontacts_deleted.rb +207 -0
- data/override/models/studentcontacts_updated.rb +207 -0
- data/override/models/students_created.rb +196 -0
- data/override/models/students_deleted.rb +206 -0
- data/override/models/students_updated.rb +207 -0
- data/override/models/teachers_created.rb +207 -0
- data/override/models/teachers_deleted.rb +207 -0
- data/override/models/teachers_updated.rb +207 -0
- data/override/override.sh +9 -0
- data/sample/sample.rb +16 -0
- metadata +252 -293
- data/.document +0 -5
- data/.gitignore +0 -22
- data/.rubocop.yml +0 -4
- data/.yardopts +0 -2
- data/LICENSE.txt +0 -20
- data/lib/clever-ruby/api_operations/list.rb +0 -130
- data/lib/clever-ruby/api_operations/nested_list.rb +0 -95
- data/lib/clever-ruby/api_operations/page.rb +0 -71
- data/lib/clever-ruby/api_operations/pagelist.rb +0 -43
- data/lib/clever-ruby/api_operations/results_list.rb +0 -31
- data/lib/clever-ruby/api_resource.rb +0 -174
- data/lib/clever-ruby/clever_object.rb +0 -246
- data/lib/clever-ruby/district.rb +0 -75
- data/lib/clever-ruby/district_admin.rb +0 -45
- data/lib/clever-ruby/errors/api_connection_error.rb +0 -5
- data/lib/clever-ruby/errors/api_error.rb +0 -5
- data/lib/clever-ruby/errors/authentication_error.rb +0 -5
- data/lib/clever-ruby/errors/clever_error.rb +0 -52
- data/lib/clever-ruby/errors/invalid_request_error.rb +0 -17
- data/lib/clever-ruby/event.rb +0 -61
- data/lib/clever-ruby/json.rb +0 -34
- data/lib/clever-ruby/nested_resource.rb +0 -41
- data/lib/clever-ruby/school.rb +0 -17
- data/lib/clever-ruby/school_admin.rb +0 -19
- data/lib/clever-ruby/section.rb +0 -17
- data/lib/clever-ruby/student.rb +0 -30
- data/lib/clever-ruby/teacher.rb +0 -17
- data/lib/clever-ruby/util.rb +0 -108
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_district_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_event_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_school_admin_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_school_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_section_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_student_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/counts_teacher_properly.yml +0 -52
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_district.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_district_admin.yml +0 -90
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_event.yml +0 -124
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_school.yml +0 -113
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_school_admin.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_section.yml +0 -368
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_student.yml +0 -176
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_a_single_teacher.yml +0 -191
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_districts_by_page.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_districts_with_multiple_ids.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_events_by_page.yml +0 -122
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_events_with_multiple_ids.yml +0 -131
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_school_admins_by_page.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_school_admins_with_multiple_ids.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_schools_by_page.yml +0 -110
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_schools_with_multiple_ids.yml +0 -116
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_sections_by_page.yml +0 -1168
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_sections_with_multiple_ids.yml +0 -163
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_students_by_page.yml +0 -1207
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_students_with_multiple_ids.yml +0 -127
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_teachers_by_page.yml +0 -190
- data/test/data/vcr_cassettes/Clever_APIOperations_List/finds_teachers_with_multiple_ids.yml +0 -131
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_district.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_event.yml +0 -122
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_school.yml +0 -110
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_school_admin.yml +0 -101
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_section.yml +0 -1168
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_student.yml +0 -1207
- data/test/data/vcr_cassettes/Clever_APIOperations_List/retrieves_all_teacher.yml +0 -190
- data/test/data/vcr_cassettes/Clever_District/pages_methods/pages_a_district_s_events.yml +0 -526
- data/test/data/vcr_cassettes/Clever_District/pages_methods/pages_a_district_s_schools.yml +0 -240
- data/test/data/vcr_cassettes/Clever_District/pages_methods/pages_a_district_s_sections.yml +0 -3674
- data/test/data/vcr_cassettes/Clever_District/pages_methods/pages_a_district_s_students.yml +0 -2387
- data/test/data/vcr_cassettes/Clever_District/pages_methods/pages_a_district_s_teachers.yml +0 -717
- data/test/data/vcr_cassettes/Clever_District_without_global_token/pages_methods/pages_a_district_s_events.yml +0 -152
- data/test/data/vcr_cassettes/Clever_District_without_global_token/pages_methods/pages_a_district_s_schools.yml +0 -211
- data/test/data/vcr_cassettes/Clever_District_without_global_token/pages_methods/pages_a_district_s_sections.yml +0 -3649
- data/test/data/vcr_cassettes/Clever_District_without_global_token/pages_methods/pages_a_district_s_students.yml +0 -2362
- data/test/data/vcr_cassettes/Clever_District_without_global_token/pages_methods/pages_a_district_s_teachers.yml +0 -688
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_events.yml +0 -89
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_school_admins.yml +0 -101
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_schools.yml +0 -164
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_sections.yml +0 -1168
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_students.yml +0 -1207
- data/test/data/vcr_cassettes/Clever_District_without_global_token/retrieves_a_district_s_teachers.yml +0 -324
- data/test/data/vcr_cassettes/Clever_NestedResource/must_include_auth_token_in_linked_resources.yml +0 -197
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_district_s_events.yml +0 -237
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_district_s_schools.yml +0 -217
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_district_s_sections.yml +0 -2333
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_district_s_students.yml +0 -2411
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_district_s_teachers.yml +0 -377
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_admin_s_schools.yml +0 -205
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_s_district.yml +0 -162
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_s_events.yml +0 -215
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_s_sections.yml +0 -1153
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_s_students.yml +0 -1081
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_school_s_teachers.yml +0 -283
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_section_s_district.yml +0 -417
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_section_s_events.yml +0 -470
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_section_s_school.yml +0 -420
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_section_s_students.yml +0 -482
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_section_s_teacher.yml +0 -418
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_student_s_district.yml +0 -226
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_student_s_events.yml +0 -279
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_student_s_school.yml +0 -229
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_student_s_sections.yml +0 -301
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_student_s_teachers.yml +0 -277
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_teacher_s_district.yml +0 -240
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_teacher_s_events.yml +0 -293
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_teacher_s_school.yml +0 -243
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_teacher_s_sections.yml +0 -321
- data/test/data/vcr_cassettes/Clever_NestedResource/retrieves_a_teacher_s_students.yml +0 -323
- data/test/data/vcr_cassettes/Error_handling/raises_an_InvalidRequestError_when_given_a_bad_created_since.yml +0 -151
- data/test/data/vcr_cassettes/Optional_attributes/has_the_expected_value_for_an_optional_attribute_that_is_present.yml +0 -55
- data/test/data/vcr_cassettes/last_method/page/has_working_first_and_last_methods.yml +0 -800
- data/test/integration/api_operations/list_test.rb +0 -117
- data/test/integration/district_test.rb +0 -53
- data/test/integration/district_with_non_global_token_test.rb +0 -88
- data/test/integration/error_handling_test.rb +0 -17
- data/test/integration/last_test.rb +0 -56
- data/test/integration/nested_resource_test.rb +0 -31
- data/test/test_helper.rb +0 -18
- data/test/unit/api_resource_test.rb +0 -48
- data/test/unit/clever_test.rb +0 -65
- data/test/unit/configuration_test.rb +0 -37
- data/test/unit/event_test.rb +0 -57
- data/test/unit/optional_attributes_test.rb +0 -27
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#Clever API
|
|
3
|
+
|
|
4
|
+
#The Clever API
|
|
5
|
+
|
|
6
|
+
OpenAPI spec version: 1.2.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
9
|
+
|
|
10
|
+
=end
|
|
11
|
+
|
|
12
|
+
require 'date'
|
|
13
|
+
|
|
14
|
+
module Clever
|
|
15
|
+
|
|
16
|
+
class Term
|
|
17
|
+
attr_accessor :name
|
|
18
|
+
|
|
19
|
+
attr_accessor :start_date
|
|
20
|
+
|
|
21
|
+
attr_accessor :end_date
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
25
|
+
def self.attribute_map
|
|
26
|
+
{
|
|
27
|
+
:'name' => :'name',
|
|
28
|
+
:'start_date' => :'start_date',
|
|
29
|
+
:'end_date' => :'end_date'
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Attribute type mapping.
|
|
34
|
+
def self.swagger_types
|
|
35
|
+
{
|
|
36
|
+
:'name' => :'String',
|
|
37
|
+
:'start_date' => :'String',
|
|
38
|
+
:'end_date' => :'String'
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Initializes the object
|
|
43
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
44
|
+
def initialize(attributes = {})
|
|
45
|
+
return unless attributes.is_a?(Hash)
|
|
46
|
+
|
|
47
|
+
# convert string to symbol for hash key
|
|
48
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
|
49
|
+
|
|
50
|
+
if attributes.has_key?(:'name')
|
|
51
|
+
self.name = attributes[:'name']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if attributes.has_key?(:'start_date')
|
|
55
|
+
self.start_date = attributes[:'start_date']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if attributes.has_key?(:'end_date')
|
|
59
|
+
self.end_date = attributes[:'end_date']
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
65
|
+
# @return Array for valid properies with the reasons
|
|
66
|
+
def list_invalid_properties
|
|
67
|
+
invalid_properties = Array.new
|
|
68
|
+
return invalid_properties
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Check to see if the all the properties in the model are valid
|
|
72
|
+
# @return true if the model is valid
|
|
73
|
+
def valid?
|
|
74
|
+
return true
|
|
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
|
+
name == o.name &&
|
|
83
|
+
start_date == o.start_date &&
|
|
84
|
+
end_date == o.end_date
|
|
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
|
+
[name, start_date, end_date].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 =~ /\AArray<(.*)>/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 =~ /\A(true|t|yes|y|1)\z/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 = Clever.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
|
+
|
|
205
|
+
end
|
data/lib/clever-ruby/version.rb
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
=begin
|
|
2
|
+
#Clever API
|
|
3
|
+
|
|
4
|
+
#The Clever API
|
|
5
|
+
|
|
6
|
+
OpenAPI spec version: 1.2.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
9
|
+
|
|
10
|
+
=end
|
|
11
|
+
|
|
2
12
|
module Clever
|
|
3
|
-
|
|
4
|
-
# http://semver.org/
|
|
5
|
-
VERSION = '0.14.0'
|
|
13
|
+
VERSION = "1.0.0"
|
|
6
14
|
end
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#Clever API
|
|
3
|
+
|
|
4
|
+
#The Clever API
|
|
5
|
+
|
|
6
|
+
OpenAPI spec version: 1.2.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
9
|
+
|
|
10
|
+
=end
|
|
11
|
+
|
|
12
|
+
require 'date'
|
|
13
|
+
require 'json'
|
|
14
|
+
require 'logger'
|
|
15
|
+
require 'tempfile'
|
|
16
|
+
require 'typhoeus'
|
|
17
|
+
require 'uri'
|
|
18
|
+
|
|
19
|
+
module Clever
|
|
20
|
+
class ApiClient
|
|
21
|
+
# The Configuration object holding settings to be used in the API client.
|
|
22
|
+
attr_accessor :config
|
|
23
|
+
|
|
24
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
|
25
|
+
#
|
|
26
|
+
# @return [Hash]
|
|
27
|
+
attr_accessor :default_headers
|
|
28
|
+
|
|
29
|
+
# Initializes the ApiClient
|
|
30
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
|
31
|
+
def initialize(config = Configuration.default)
|
|
32
|
+
@config = config
|
|
33
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
|
34
|
+
@default_headers = {
|
|
35
|
+
'Content-Type' => "application/json",
|
|
36
|
+
'User-Agent' => @user_agent
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.default
|
|
41
|
+
@@default ||= ApiClient.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Call an API with given options.
|
|
45
|
+
#
|
|
46
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
|
47
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
|
48
|
+
def call_api(http_method, path, opts = {})
|
|
49
|
+
request = build_request(http_method, path, opts)
|
|
50
|
+
response = request.run
|
|
51
|
+
|
|
52
|
+
if @config.debugging
|
|
53
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
unless response.success?
|
|
57
|
+
if response.timed_out?
|
|
58
|
+
fail ApiError.new('Connection timed out')
|
|
59
|
+
elsif response.code == 0
|
|
60
|
+
# Errors from libcurl will be made visible here
|
|
61
|
+
fail ApiError.new(:code => 0,
|
|
62
|
+
:message => response.return_message)
|
|
63
|
+
else
|
|
64
|
+
fail ApiError.new(:code => response.code,
|
|
65
|
+
:response_headers => response.headers,
|
|
66
|
+
:response_body => response.body),
|
|
67
|
+
response.status_message
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if opts[:return_type]
|
|
72
|
+
data = deserialize(response, opts[:return_type])
|
|
73
|
+
else
|
|
74
|
+
data = nil
|
|
75
|
+
end
|
|
76
|
+
return data, response.code, response.headers
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Builds the HTTP request
|
|
80
|
+
#
|
|
81
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
|
82
|
+
# @param [String] path URL path (e.g. /account/new)
|
|
83
|
+
# @option opts [Hash] :header_params Header parameters
|
|
84
|
+
# @option opts [Hash] :query_params Query parameters
|
|
85
|
+
# @option opts [Hash] :form_params Query parameters
|
|
86
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
|
87
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
|
88
|
+
def build_request(http_method, path, opts = {})
|
|
89
|
+
url = build_request_url(path)
|
|
90
|
+
http_method = http_method.to_sym.downcase
|
|
91
|
+
|
|
92
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
|
93
|
+
query_params = opts[:query_params] || {}
|
|
94
|
+
form_params = opts[:form_params] || {}
|
|
95
|
+
|
|
96
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
|
97
|
+
|
|
98
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
|
99
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
|
100
|
+
|
|
101
|
+
req_opts = {
|
|
102
|
+
:method => http_method,
|
|
103
|
+
:headers => header_params,
|
|
104
|
+
:params => query_params,
|
|
105
|
+
:params_encoding => @config.params_encoding,
|
|
106
|
+
:timeout => @config.timeout,
|
|
107
|
+
:ssl_verifypeer => @config.verify_ssl,
|
|
108
|
+
:ssl_verifyhost => _verify_ssl_host,
|
|
109
|
+
:sslcert => @config.cert_file,
|
|
110
|
+
:sslkey => @config.key_file,
|
|
111
|
+
:verbose => @config.debugging
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# set custom cert, if provided
|
|
115
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
|
116
|
+
|
|
117
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
|
118
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
|
119
|
+
req_opts.update :body => req_body
|
|
120
|
+
if @config.debugging
|
|
121
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
Typhoeus::Request.new(url, req_opts)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Check if the given MIME is a JSON MIME.
|
|
129
|
+
# JSON MIME examples:
|
|
130
|
+
# application/json
|
|
131
|
+
# application/json; charset=UTF8
|
|
132
|
+
# APPLICATION/JSON
|
|
133
|
+
# */*
|
|
134
|
+
# @param [String] mime MIME
|
|
135
|
+
# @return [Boolean] True if the MIME is application/json
|
|
136
|
+
def json_mime?(mime)
|
|
137
|
+
(mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Deserialize the response to the given return type.
|
|
141
|
+
#
|
|
142
|
+
# @param [Response] response HTTP response
|
|
143
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
|
144
|
+
def deserialize(response, return_type)
|
|
145
|
+
body = response.body
|
|
146
|
+
return nil if body.nil? || body.empty?
|
|
147
|
+
|
|
148
|
+
# return response body directly for String return type
|
|
149
|
+
return body if return_type == 'String'
|
|
150
|
+
|
|
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
|
+
# ensuring a default content type
|
|
155
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
|
156
|
+
|
|
157
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
|
158
|
+
|
|
159
|
+
begin
|
|
160
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
|
161
|
+
rescue JSON::ParserError => e
|
|
162
|
+
if %w(String Date DateTime).include?(return_type)
|
|
163
|
+
data = body
|
|
164
|
+
else
|
|
165
|
+
raise e
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
convert_to_type data, return_type
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Convert data to the given return type.
|
|
173
|
+
# @param [Object] data Data to be converted
|
|
174
|
+
# @param [String] return_type Return type
|
|
175
|
+
# @return [Mixed] Data in a particular type
|
|
176
|
+
def convert_to_type(data, return_type)
|
|
177
|
+
return nil if data.nil?
|
|
178
|
+
case return_type
|
|
179
|
+
when 'String'
|
|
180
|
+
data.to_s
|
|
181
|
+
when 'Integer'
|
|
182
|
+
data.to_i
|
|
183
|
+
when 'Float'
|
|
184
|
+
data.to_f
|
|
185
|
+
when 'BOOLEAN'
|
|
186
|
+
data == true
|
|
187
|
+
when 'DateTime'
|
|
188
|
+
# parse date time (expecting ISO 8601 format)
|
|
189
|
+
DateTime.parse data
|
|
190
|
+
when 'Date'
|
|
191
|
+
# parse date time (expecting ISO 8601 format)
|
|
192
|
+
Date.parse data
|
|
193
|
+
when 'Object'
|
|
194
|
+
# generic object (usually a Hash), return directly
|
|
195
|
+
data
|
|
196
|
+
when /\AArray<(.+)>\z/
|
|
197
|
+
# e.g. Array<Pet>
|
|
198
|
+
sub_type = $1
|
|
199
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
|
200
|
+
when /\AHash\<String, (.+)\>\z/
|
|
201
|
+
# e.g. Hash<String, Integer>
|
|
202
|
+
sub_type = $1
|
|
203
|
+
{}.tap do |hash|
|
|
204
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
|
205
|
+
end
|
|
206
|
+
when 'EventsResponse'
|
|
207
|
+
Clever.const_get(return_type).new.tap do |model|
|
|
208
|
+
resp = model.build_from_hash data
|
|
209
|
+
resps = []
|
|
210
|
+
data[:data].each do |eventResponse|
|
|
211
|
+
singleResp = parse_event_response(eventResponse[:data])
|
|
212
|
+
resps.push(singleResp)
|
|
213
|
+
end
|
|
214
|
+
resp.data = resps
|
|
215
|
+
return resp
|
|
216
|
+
end
|
|
217
|
+
when 'EventResponse'
|
|
218
|
+
parse_event_response data[:data]
|
|
219
|
+
else
|
|
220
|
+
# models, e.g. Pet
|
|
221
|
+
Clever.const_get(return_type).new.tap do |model|
|
|
222
|
+
model.build_from_hash data
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def parse_event_response(data)
|
|
228
|
+
classObj = data[:type].split(".").collect(&:capitalize).join
|
|
229
|
+
Clever.const_get(classObj).new.tap do |model|
|
|
230
|
+
parsed = model.build_from_hash data
|
|
231
|
+
Clever.const_get("EventsResponse").new.tap do |model|
|
|
232
|
+
resp = model.build_from_hash data
|
|
233
|
+
resp.data = parsed
|
|
234
|
+
return resp
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
|
240
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
|
241
|
+
#
|
|
242
|
+
# @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
|
+
|
|
254
|
+
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
|
|
259
|
+
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
|
+
end
|
|
266
|
+
|
|
267
|
+
# Sanitize filename by removing path.
|
|
268
|
+
# e.g. ../../sun.gif becomes sun.gif
|
|
269
|
+
#
|
|
270
|
+
# @param [String] filename the filename to be sanitized
|
|
271
|
+
# @return [String] the sanitized filename
|
|
272
|
+
def sanitize_filename(filename)
|
|
273
|
+
filename.gsub(/.*[\/\\]/, '')
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def build_request_url(path)
|
|
277
|
+
# Add leading and trailing slashes to path
|
|
278
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
|
279
|
+
URI.encode(@config.base_url + path)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# Builds the HTTP request body
|
|
283
|
+
#
|
|
284
|
+
# @param [Hash] header_params Header parameters
|
|
285
|
+
# @param [Hash] form_params Query parameters
|
|
286
|
+
# @param [Object] body HTTP body (JSON/XML)
|
|
287
|
+
# @return [String] HTTP body data in the form of string
|
|
288
|
+
def build_request_body(header_params, form_params, body)
|
|
289
|
+
# http form
|
|
290
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
|
291
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
|
292
|
+
data = {}
|
|
293
|
+
form_params.each do |key, value|
|
|
294
|
+
case value
|
|
295
|
+
when File, Array, nil
|
|
296
|
+
# let typhoeus handle File, Array and nil parameters
|
|
297
|
+
data[key] = value
|
|
298
|
+
else
|
|
299
|
+
data[key] = value.to_s
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
elsif body
|
|
303
|
+
data = body.is_a?(String) ? body : body.to_json
|
|
304
|
+
else
|
|
305
|
+
data = nil
|
|
306
|
+
end
|
|
307
|
+
data
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# Update hearder and query params based on authentication settings.
|
|
311
|
+
#
|
|
312
|
+
# @param [Hash] header_params Header parameters
|
|
313
|
+
# @param [Hash] query_params Query parameters
|
|
314
|
+
# @param [String] auth_names Authentication scheme name
|
|
315
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
|
316
|
+
Array(auth_names).each do |auth_name|
|
|
317
|
+
auth_setting = @config.auth_settings[auth_name]
|
|
318
|
+
next unless auth_setting
|
|
319
|
+
case auth_setting[:in]
|
|
320
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
|
321
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
|
322
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Sets user agent in HTTP header
|
|
328
|
+
#
|
|
329
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
|
330
|
+
def user_agent=(user_agent)
|
|
331
|
+
@user_agent = user_agent
|
|
332
|
+
@default_headers['User-Agent'] = @user_agent
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Return Accept header based on an array of accepts provided.
|
|
336
|
+
# @param [Array] accepts array for Accept
|
|
337
|
+
# @return [String] the Accept header (e.g. application/json)
|
|
338
|
+
def select_header_accept(accepts)
|
|
339
|
+
return nil if accepts.nil? || accepts.empty?
|
|
340
|
+
# use JSON when present, otherwise use all of the provided
|
|
341
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
|
342
|
+
return json_accept || accepts.join(',')
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Return Content-Type header based on an array of content types provided.
|
|
346
|
+
# @param [Array] content_types array for Content-Type
|
|
347
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
|
348
|
+
def select_header_content_type(content_types)
|
|
349
|
+
# use application/json by default
|
|
350
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
|
351
|
+
# use JSON when present, otherwise use the first one
|
|
352
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
|
353
|
+
return json_content_type || content_types.first
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
|
357
|
+
# @param [Object] model object to be converted into JSON string
|
|
358
|
+
# @return [String] JSON string representation of the object
|
|
359
|
+
def object_to_http_body(model)
|
|
360
|
+
return model if model.nil? || model.is_a?(String)
|
|
361
|
+
local_body = nil
|
|
362
|
+
if model.is_a?(Array)
|
|
363
|
+
local_body = model.map{|m| object_to_hash(m) }
|
|
364
|
+
else
|
|
365
|
+
local_body = object_to_hash(model)
|
|
366
|
+
end
|
|
367
|
+
local_body.to_json
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
# Convert object(non-array) to hash.
|
|
371
|
+
# @param [Object] obj object to be converted into JSON string
|
|
372
|
+
# @return [String] JSON string representation of the object
|
|
373
|
+
def object_to_hash(obj)
|
|
374
|
+
if obj.respond_to?(:to_hash)
|
|
375
|
+
obj.to_hash
|
|
376
|
+
else
|
|
377
|
+
obj
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# Build parameter value according to the given collection format.
|
|
382
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
|
383
|
+
def build_collection_param(param, collection_format)
|
|
384
|
+
case collection_format
|
|
385
|
+
when :csv
|
|
386
|
+
param.join(',')
|
|
387
|
+
when :ssv
|
|
388
|
+
param.join(' ')
|
|
389
|
+
when :tsv
|
|
390
|
+
param.join("\t")
|
|
391
|
+
when :pipes
|
|
392
|
+
param.join('|')
|
|
393
|
+
when :multi
|
|
394
|
+
# return the array directly as typhoeus will handle it as expected
|
|
395
|
+
param
|
|
396
|
+
else
|
|
397
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
end
|