finch-api 0.1.0.pre.alpha.1 → 0.1.0.pre.alpha.2
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/README.md +63 -20
- data/lib/finch-api/base_client.rb +52 -59
- data/lib/finch-api/base_model.rb +453 -415
- data/lib/finch-api/base_page.rb +34 -15
- data/lib/finch-api/client.rb +3 -7
- data/lib/finch-api/errors.rb +12 -17
- data/lib/finch-api/extern.rb +1 -4
- data/lib/finch-api/individuals_page.rb +28 -34
- data/lib/finch-api/models/account_update_event.rb +6 -31
- data/lib/finch-api/models/company_event.rb +3 -11
- data/lib/finch-api/models/connect/session_new_params.rb +9 -52
- data/lib/finch-api/models/connect/session_reauthenticate_params.rb +3 -22
- data/lib/finch-api/models/connection_status_type.rb +3 -21
- data/lib/finch-api/models/create_access_token_response.rb +6 -30
- data/lib/finch-api/models/directory_event.rb +3 -15
- data/lib/finch-api/models/employment_event.rb +3 -15
- data/lib/finch-api/models/hris/benefit_contribution.rb +3 -14
- data/lib/finch-api/models/hris/benefit_features_and_operations.rb +9 -39
- data/lib/finch-api/models/hris/benefit_frequency.rb +3 -15
- data/lib/finch-api/models/hris/benefit_type.rb +3 -22
- data/lib/finch-api/models/hris/benefits/enrolled_individual.rb +3 -18
- data/lib/finch-api/models/hris/benefits/individual_benefit.rb +3 -14
- data/lib/finch-api/models/hris/benefits/individual_enroll_many_params.rb +9 -40
- data/lib/finch-api/models/hris/company.rb +9 -52
- data/lib/finch-api/models/hris/document_list_params.rb +3 -13
- data/lib/finch-api/models/hris/document_response.rb +3 -14
- data/lib/finch-api/models/hris/document_retreive_response.rb +7 -23
- data/lib/finch-api/models/hris/employment_data.rb +9 -58
- data/lib/finch-api/models/hris/individual.rb +12 -66
- data/lib/finch-api/models/hris/pay_statement.rb +12 -70
- data/lib/finch-api/models/hris/payment.rb +3 -21
- data/lib/finch-api/models/hris/supported_benefit.rb +9 -39
- data/lib/finch-api/models/hris/w42005.rb +12 -49
- data/lib/finch-api/models/hris/w42020.rb +8 -29
- data/lib/finch-api/models/income.rb +3 -22
- data/lib/finch-api/models/individual_event.rb +3 -15
- data/lib/finch-api/models/introspection.rb +9 -50
- data/lib/finch-api/models/job_completion_event.rb +3 -21
- data/lib/finch-api/models/jobs/automated_async_job.rb +6 -35
- data/lib/finch-api/models/jobs/automated_create_params.rb +3 -12
- data/lib/finch-api/models/jobs/automated_list_response.rb +100 -0
- data/lib/finch-api/models/jobs/manual_async_job.rb +3 -17
- data/lib/finch-api/models/operation_support.rb +3 -18
- data/lib/finch-api/models/pay_statement_event.rb +3 -15
- data/lib/finch-api/models/payment_event.rb +3 -15
- data/lib/finch-api/models/payroll/pay_group_list_response.rb +3 -21
- data/lib/finch-api/models/payroll/pay_group_retrieve_response.rb +3 -21
- data/lib/finch-api/models/provider.rb +3 -20
- data/lib/finch-api/models/sandbox/company_update_params.rb +9 -52
- data/lib/finch-api/models/sandbox/company_update_response.rb +9 -52
- data/lib/finch-api/models/sandbox/connection_create_params.rb +3 -17
- data/lib/finch-api/models/sandbox/connection_create_response.rb +3 -17
- data/lib/finch-api/models/sandbox/connections/account_create_params.rb +3 -17
- data/lib/finch-api/models/sandbox/connections/account_create_response.rb +3 -17
- data/lib/finch-api/models/sandbox/connections/account_update_response.rb +3 -17
- data/lib/finch-api/models/sandbox/directory_create_params.rb +21 -124
- data/lib/finch-api/models/sandbox/employment_update_params.rb +9 -58
- data/lib/finch-api/models/sandbox/employment_update_response.rb +9 -58
- data/lib/finch-api/models/sandbox/individual_update_params.rb +12 -66
- data/lib/finch-api/models/sandbox/individual_update_response.rb +12 -66
- data/lib/finch-api/models/sandbox/job_create_params.rb +3 -12
- data/lib/finch-api/models/sandbox/jobs/configuration_retrieve_response.rb +2 -1
- data/lib/finch-api/models/sandbox/jobs/sandbox_job_configuration.rb +6 -28
- data/lib/finch-api/models/sandbox/payment_create_params.rb +12 -70
- data/lib/finch-api/models/webhook_event.rb +10 -27
- data/lib/finch-api/page.rb +28 -34
- data/lib/finch-api/pooled_net_requester.rb +51 -46
- data/lib/finch-api/request_options.rb +5 -12
- data/lib/finch-api/resources/access_tokens.rb +0 -2
- data/lib/finch-api/resources/account.rb +0 -3
- data/lib/finch-api/resources/connect/sessions.rb +0 -3
- data/lib/finch-api/resources/connect.rb +0 -1
- data/lib/finch-api/resources/hris/benefits/individuals.rb +2 -6
- data/lib/finch-api/resources/hris/benefits.rb +0 -6
- data/lib/finch-api/resources/hris/company.rb +0 -2
- data/lib/finch-api/resources/hris/directory.rb +1 -24
- data/lib/finch-api/resources/hris/documents.rb +4 -7
- data/lib/finch-api/resources/hris/employments.rb +0 -2
- data/lib/finch-api/resources/hris/individuals.rb +0 -2
- data/lib/finch-api/resources/hris/pay_statements.rb +0 -2
- data/lib/finch-api/resources/hris/payments.rb +0 -2
- data/lib/finch-api/resources/hris.rb +0 -1
- data/lib/finch-api/resources/jobs/automated.rb +2 -7
- data/lib/finch-api/resources/jobs/manual.rb +0 -2
- data/lib/finch-api/resources/jobs.rb +0 -1
- data/lib/finch-api/resources/payroll/pay_groups.rb +0 -3
- data/lib/finch-api/resources/payroll.rb +0 -1
- data/lib/finch-api/resources/providers.rb +0 -2
- data/lib/finch-api/resources/request_forwarding.rb +0 -2
- data/lib/finch-api/resources/sandbox/company.rb +0 -2
- data/lib/finch-api/resources/sandbox/connections/accounts.rb +0 -3
- data/lib/finch-api/resources/sandbox/connections.rb +0 -2
- data/lib/finch-api/resources/sandbox/directory.rb +0 -2
- data/lib/finch-api/resources/sandbox/employment.rb +0 -2
- data/lib/finch-api/resources/sandbox/individual.rb +0 -2
- data/lib/finch-api/resources/sandbox/jobs/configuration.rb +0 -3
- data/lib/finch-api/resources/sandbox/jobs.rb +0 -2
- data/lib/finch-api/resources/sandbox/payment.rb +0 -2
- data/lib/finch-api/resources/sandbox.rb +0 -1
- data/lib/finch-api/resources/webhooks.rb +0 -1
- data/lib/finch-api/responses_page.rb +24 -31
- data/lib/finch-api/single_page.rb +23 -31
- data/lib/finch-api/util.rb +216 -124
- data/lib/finch-api/version.rb +1 -1
- data/lib/finch-api.rb +17 -0
- data/manifest.yaml +1 -0
- data/rbi/lib/finch-api/base_client.rbi +89 -66
- data/rbi/lib/finch-api/base_model.rbi +403 -236
- data/rbi/lib/finch-api/base_page.rbi +3 -6
- data/rbi/lib/finch-api/client.rbi +23 -28
- data/rbi/lib/finch-api/errors.rbi +20 -22
- data/rbi/lib/finch-api/extern.rbi +1 -1
- data/rbi/lib/finch-api/individuals_page.rbi +5 -23
- data/rbi/lib/finch-api/models/access_token_create_params.rbi +13 -24
- data/rbi/lib/finch-api/models/account_disconnect_params.rbi +9 -2
- data/rbi/lib/finch-api/models/account_introspect_params.rbi +9 -2
- data/rbi/lib/finch-api/models/account_update_event.rbi +871 -983
- data/rbi/lib/finch-api/models/base_webhook_event.rbi +13 -19
- data/rbi/lib/finch-api/models/company_event.rbi +28 -20
- data/rbi/lib/finch-api/models/connect/session_new_params.rbi +90 -104
- data/rbi/lib/finch-api/models/connect/session_new_response.rbi +6 -14
- data/rbi/lib/finch-api/models/connect/session_reauthenticate_params.rbi +37 -47
- data/rbi/lib/finch-api/models/connect/session_reauthenticate_response.rbi +6 -14
- data/rbi/lib/finch-api/models/connection_status_type.rbi +13 -9
- data/rbi/lib/finch-api/models/create_access_token_response.rbi +61 -78
- data/rbi/lib/finch-api/models/directory_event.rbi +42 -27
- data/rbi/lib/finch-api/models/disconnect_response.rbi +4 -8
- data/rbi/lib/finch-api/models/employment_event.rbi +42 -27
- data/rbi/lib/finch-api/models/hris/benefit_contribution.rbi +29 -21
- data/rbi/lib/finch-api/models/hris/benefit_create_params.rbi +18 -26
- data/rbi/lib/finch-api/models/hris/benefit_features_and_operations.rbi +199 -86
- data/rbi/lib/finch-api/models/hris/benefit_frequency.rbi +9 -6
- data/rbi/lib/finch-api/models/hris/benefit_list_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/benefit_list_supported_benefits_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/benefit_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/benefit_type.rbi +26 -22
- data/rbi/lib/finch-api/models/hris/benefit_update_params.rbi +7 -11
- data/rbi/lib/finch-api/models/hris/benefits/enrolled_individual.rbi +43 -49
- data/rbi/lib/finch-api/models/hris/benefits/individual_benefit.rbi +74 -63
- data/rbi/lib/finch-api/models/hris/benefits/individual_enroll_many_params.rbi +249 -104
- data/rbi/lib/finch-api/models/hris/benefits/individual_enrolled_ids_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/benefits/individual_enrolled_ids_response.rbi +4 -14
- data/rbi/lib/finch-api/models/hris/benefits/individual_retrieve_many_benefits_params.rbi +11 -8
- data/rbi/lib/finch-api/models/hris/benefits/individual_unenroll_many_params.rbi +7 -8
- data/rbi/lib/finch-api/models/hris/benefits/unenrolled_individual.rbi +23 -39
- data/rbi/lib/finch-api/models/hris/benefits_support.rbi +88 -86
- data/rbi/lib/finch-api/models/hris/benfit_contribution.rbi +1 -1
- data/rbi/lib/finch-api/models/hris/company.rbi +119 -171
- data/rbi/lib/finch-api/models/hris/company_benefit.rbi +13 -32
- data/rbi/lib/finch-api/models/hris/company_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/create_company_benefits_response.rbi +3 -8
- data/rbi/lib/finch-api/models/hris/directory_list_individuals_params.rbi +11 -13
- data/rbi/lib/finch-api/models/hris/directory_list_params.rbi +11 -13
- data/rbi/lib/finch-api/models/hris/document_list_params.rbi +32 -31
- data/rbi/lib/finch-api/models/hris/document_list_response.rbi +10 -17
- data/rbi/lib/finch-api/models/hris/document_response.rbi +40 -43
- data/rbi/lib/finch-api/models/hris/document_retreive_params.rbi +9 -2
- data/rbi/lib/finch-api/models/hris/document_retreive_response.rbi +6 -4
- data/rbi/lib/finch-api/models/hris/employment_data.rbi +163 -205
- data/rbi/lib/finch-api/models/hris/employment_data_response.rbi +18 -17
- data/rbi/lib/finch-api/models/hris/employment_retrieve_many_params.rbi +12 -21
- data/rbi/lib/finch-api/models/hris/individual.rbi +126 -151
- data/rbi/lib/finch-api/models/hris/individual_in_directory.rbi +42 -68
- data/rbi/lib/finch-api/models/hris/individual_response.rbi +18 -17
- data/rbi/lib/finch-api/models/hris/individual_retrieve_many_params.rbi +27 -31
- data/rbi/lib/finch-api/models/hris/pay_statement.rbi +290 -341
- data/rbi/lib/finch-api/models/hris/pay_statement_response.rbi +18 -20
- data/rbi/lib/finch-api/models/hris/pay_statement_response_body.rbi +13 -16
- data/rbi/lib/finch-api/models/hris/pay_statement_retrieve_many_params.rbi +18 -31
- data/rbi/lib/finch-api/models/hris/payment.rbi +63 -103
- data/rbi/lib/finch-api/models/hris/payment_list_params.rbi +9 -15
- data/rbi/lib/finch-api/models/hris/support_per_benefit_type.rbi +10 -14
- data/rbi/lib/finch-api/models/hris/supported_benefit.rbi +83 -79
- data/rbi/lib/finch-api/models/hris/update_company_benefit_response.rbi +3 -8
- data/rbi/lib/finch-api/models/hris/w42005.rbi +86 -70
- data/rbi/lib/finch-api/models/hris/w42020.rbi +84 -86
- data/rbi/lib/finch-api/models/income.rbi +34 -41
- data/rbi/lib/finch-api/models/individual_event.rbi +42 -27
- data/rbi/lib/finch-api/models/introspection.rbi +138 -178
- data/rbi/lib/finch-api/models/job_completion_event.rbi +48 -37
- data/rbi/lib/finch-api/models/jobs/automated_async_job.rbi +66 -94
- data/rbi/lib/finch-api/models/jobs/automated_create_params.rbi +26 -33
- data/rbi/lib/finch-api/models/jobs/automated_create_response.rbi +11 -31
- data/rbi/lib/finch-api/models/jobs/automated_list_params.rbi +11 -13
- data/rbi/lib/finch-api/models/jobs/automated_list_response.rbi +126 -0
- data/rbi/lib/finch-api/models/jobs/automated_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/jobs/manual_async_job.rbi +32 -27
- data/rbi/lib/finch-api/models/jobs/manual_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/location.rbi +16 -59
- data/rbi/lib/finch-api/models/money.rbi +7 -13
- data/rbi/lib/finch-api/models/operation_support.rbi +18 -7
- data/rbi/lib/finch-api/models/operation_support_matrix.rbi +65 -27
- data/rbi/lib/finch-api/models/paging.rbi +10 -12
- data/rbi/lib/finch-api/models/pay_statement_event.rbi +46 -32
- data/rbi/lib/finch-api/models/payment_event.rbi +39 -34
- data/rbi/lib/finch-api/models/payroll/pay_group_list_params.rbi +9 -13
- data/rbi/lib/finch-api/models/payroll/pay_group_list_response.rbi +55 -30
- data/rbi/lib/finch-api/models/payroll/pay_group_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/payroll/pay_group_retrieve_response.rbi +45 -46
- data/rbi/lib/finch-api/models/provider.rbi +873 -964
- data/rbi/lib/finch-api/models/provider_list_params.rbi +9 -2
- data/rbi/lib/finch-api/models/request_forwarding_forward_params.rbi +20 -33
- data/rbi/lib/finch-api/models/request_forwarding_forward_response.rbi +40 -59
- data/rbi/lib/finch-api/models/sandbox/company_update_params.rbi +144 -166
- data/rbi/lib/finch-api/models/sandbox/company_update_response.rbi +145 -174
- data/rbi/lib/finch-api/models/sandbox/connection_create_params.rbi +43 -39
- data/rbi/lib/finch-api/models/sandbox/connection_create_response.rbi +38 -59
- data/rbi/lib/finch-api/models/sandbox/connections/account_create_params.rbi +62 -39
- data/rbi/lib/finch-api/models/sandbox/connections/account_create_response.rbi +54 -62
- data/rbi/lib/finch-api/models/sandbox/connections/account_update_params.rbi +17 -11
- data/rbi/lib/finch-api/models/sandbox/connections/account_update_response.rbi +55 -54
- data/rbi/lib/finch-api/models/sandbox/directory_create_params.rbi +380 -332
- data/rbi/lib/finch-api/models/sandbox/directory_create_response.rbi +1 -1
- data/rbi/lib/finch-api/models/sandbox/employment_update_params.rbi +190 -194
- data/rbi/lib/finch-api/models/sandbox/employment_update_response.rbi +195 -198
- data/rbi/lib/finch-api/models/sandbox/individual_update_params.rbi +151 -145
- data/rbi/lib/finch-api/models/sandbox/individual_update_response.rbi +163 -151
- data/rbi/lib/finch-api/models/sandbox/job_create_params.rbi +22 -19
- data/rbi/lib/finch-api/models/sandbox/job_create_response.rbi +11 -31
- data/rbi/lib/finch-api/models/sandbox/jobs/configuration_retrieve_params.rbi +9 -2
- data/rbi/lib/finch-api/models/sandbox/jobs/configuration_retrieve_response.rbi +2 -1
- data/rbi/lib/finch-api/models/sandbox/jobs/configuration_update_params.rbi +9 -2
- data/rbi/lib/finch-api/models/sandbox/jobs/sandbox_job_configuration.rbi +56 -26
- data/rbi/lib/finch-api/models/sandbox/payment_create_params.rbi +409 -393
- data/rbi/lib/finch-api/models/sandbox/payment_create_response.rbi +6 -14
- data/rbi/lib/finch-api/models/webhook_event.rbi +4 -4
- data/rbi/lib/finch-api/page.rbi +5 -23
- data/rbi/lib/finch-api/pooled_net_requester.rbi +39 -16
- data/rbi/lib/finch-api/request_options.rbi +33 -54
- data/rbi/lib/finch-api/resources/access_tokens.rbi +4 -3
- data/rbi/lib/finch-api/resources/account.rbi +6 -4
- data/rbi/lib/finch-api/resources/connect/sessions.rbi +17 -8
- data/rbi/lib/finch-api/resources/connect.rbi +3 -4
- data/rbi/lib/finch-api/resources/hris/benefits/individuals.rbi +33 -10
- data/rbi/lib/finch-api/resources/hris/benefits.rbi +32 -13
- data/rbi/lib/finch-api/resources/hris/company.rbi +4 -3
- data/rbi/lib/finch-api/resources/hris/directory.rbi +11 -15
- data/rbi/lib/finch-api/resources/hris/documents.rbi +27 -7
- data/rbi/lib/finch-api/resources/hris/employments.rbi +10 -5
- data/rbi/lib/finch-api/resources/hris/individuals.rbi +6 -5
- data/rbi/lib/finch-api/resources/hris/pay_statements.rbi +13 -5
- data/rbi/lib/finch-api/resources/hris/payments.rbi +13 -4
- data/rbi/lib/finch-api/resources/hris.rbi +10 -18
- data/rbi/lib/finch-api/resources/jobs/automated.rbi +39 -10
- data/rbi/lib/finch-api/resources/jobs/manual.rbi +5 -3
- data/rbi/lib/finch-api/resources/jobs.rbi +4 -6
- data/rbi/lib/finch-api/resources/payroll/pay_groups.rbi +6 -4
- data/rbi/lib/finch-api/resources/payroll.rbi +3 -4
- data/rbi/lib/finch-api/resources/providers.rbi +4 -3
- data/rbi/lib/finch-api/resources/request_forwarding.rbi +27 -4
- data/rbi/lib/finch-api/resources/sandbox/company.rbi +19 -7
- data/rbi/lib/finch-api/resources/sandbox/connections/accounts.rbi +19 -7
- data/rbi/lib/finch-api/resources/sandbox/connections.rbi +10 -6
- data/rbi/lib/finch-api/resources/sandbox/directory.rbi +12 -6
- data/rbi/lib/finch-api/resources/sandbox/employment.rbi +30 -11
- data/rbi/lib/finch-api/resources/sandbox/individual.rbi +26 -8
- data/rbi/lib/finch-api/resources/sandbox/jobs/configuration.rbi +9 -7
- data/rbi/lib/finch-api/resources/sandbox/jobs.rbi +11 -7
- data/rbi/lib/finch-api/resources/sandbox/payment.rbi +5 -4
- data/rbi/lib/finch-api/resources/sandbox.rbi +9 -16
- data/rbi/lib/finch-api/resources/webhooks.rbi +2 -2
- data/rbi/lib/finch-api/responses_page.rbi +4 -17
- data/rbi/lib/finch-api/single_page.rbi +4 -12
- data/rbi/lib/finch-api/util.rbi +228 -115
- data/rbi/lib/finch-api/version.rbi +1 -1
- data/sig/finch-api/base_client.rbs +20 -15
- data/sig/finch-api/base_model.rbs +36 -18
- data/sig/finch-api/base_page.rbs +1 -1
- data/sig/finch-api/client.rbs +8 -8
- data/sig/finch-api/errors.rbs +21 -21
- data/sig/finch-api/individuals_page.rbs +2 -7
- data/sig/finch-api/models/access_token_create_params.rbs +7 -12
- data/sig/finch-api/models/account_disconnect_params.rbs +1 -6
- data/sig/finch-api/models/account_introspect_params.rbs +1 -6
- data/sig/finch-api/models/account_update_event.rbs +204 -361
- data/sig/finch-api/models/base_webhook_event.rbs +5 -5
- data/sig/finch-api/models/company_event.rbs +13 -11
- data/sig/finch-api/models/connect/session_new_params.rbs +28 -32
- data/sig/finch-api/models/connect/session_new_response.rbs +1 -6
- data/sig/finch-api/models/connect/session_reauthenticate_params.rbs +11 -14
- data/sig/finch-api/models/connect/session_reauthenticate_response.rbs +1 -6
- data/sig/finch-api/models/connection_status_type.rbs +4 -2
- data/sig/finch-api/models/create_access_token_response.rbs +20 -21
- data/sig/finch-api/models/directory_event.rbs +13 -19
- data/sig/finch-api/models/disconnect_response.rbs +1 -5
- data/sig/finch-api/models/employment_event.rbs +13 -19
- data/sig/finch-api/models/hris/benefit_contribution.rbs +8 -11
- data/sig/finch-api/models/hris/benefit_create_params.rbs +6 -11
- data/sig/finch-api/models/hris/benefit_features_and_operations.rbs +25 -29
- data/sig/finch-api/models/hris/benefit_frequency.rbs +4 -2
- data/sig/finch-api/models/hris/benefit_list_params.rbs +1 -6
- data/sig/finch-api/models/hris/benefit_list_supported_benefits_params.rbs +1 -6
- data/sig/finch-api/models/hris/benefit_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/hris/benefit_type.rbs +4 -2
- data/sig/finch-api/models/hris/benefit_update_params.rbs +4 -6
- data/sig/finch-api/models/hris/benefits/enrolled_individual.rbs +14 -18
- data/sig/finch-api/models/hris/benefits/individual_benefit.rbs +16 -25
- data/sig/finch-api/models/hris/benefits/individual_enroll_many_params.rbs +35 -54
- data/sig/finch-api/models/hris/benefits/individual_enrolled_ids_params.rbs +1 -6
- data/sig/finch-api/models/hris/benefits/individual_enrolled_ids_response.rbs +4 -6
- data/sig/finch-api/models/hris/benefits/individual_retrieve_many_benefits_params.rbs +4 -9
- data/sig/finch-api/models/hris/benefits/individual_unenroll_many_params.rbs +4 -9
- data/sig/finch-api/models/hris/benefits/unenrolled_individual.rbs +10 -16
- data/sig/finch-api/models/hris/benefits_support.rbs +14 -18
- data/sig/finch-api/models/hris/benfit_contribution.rbs +0 -1
- data/sig/finch-api/models/hris/company.rbs +39 -57
- data/sig/finch-api/models/hris/company_benefit.rbs +6 -10
- data/sig/finch-api/models/hris/company_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/hris/create_company_benefits_response.rbs +1 -6
- data/sig/finch-api/models/hris/directory_list_individuals_params.rbs +5 -10
- data/sig/finch-api/models/hris/directory_list_params.rbs +5 -10
- data/sig/finch-api/models/hris/document_list_params.rbs +11 -14
- data/sig/finch-api/models/hris/document_list_response.rbs +4 -9
- data/sig/finch-api/models/hris/document_response.rbs +11 -14
- data/sig/finch-api/models/hris/document_retreive_params.rbs +1 -6
- data/sig/finch-api/models/hris/document_retreive_response.rbs +4 -2
- data/sig/finch-api/models/hris/employment_data.rbs +41 -59
- data/sig/finch-api/models/hris/employment_data_response.rbs +5 -10
- data/sig/finch-api/models/hris/employment_retrieve_many_params.rbs +5 -15
- data/sig/finch-api/models/hris/individual.rbs +39 -45
- data/sig/finch-api/models/hris/individual_in_directory.rbs +11 -26
- data/sig/finch-api/models/hris/individual_response.rbs +5 -10
- data/sig/finch-api/models/hris/individual_retrieve_many_params.rbs +7 -22
- data/sig/finch-api/models/hris/pay_statement.rbs +75 -131
- data/sig/finch-api/models/hris/pay_statement_response.rbs +5 -10
- data/sig/finch-api/models/hris/pay_statement_response_body.rbs +4 -9
- data/sig/finch-api/models/hris/pay_statement_retrieve_many_params.rbs +9 -15
- data/sig/finch-api/models/hris/payment.rbs +19 -26
- data/sig/finch-api/models/hris/payment_list_params.rbs +5 -10
- data/sig/finch-api/models/hris/support_per_benefit_type.rbs +4 -9
- data/sig/finch-api/models/hris/supported_benefit.rbs +22 -21
- data/sig/finch-api/models/hris/update_company_benefit_response.rbs +1 -6
- data/sig/finch-api/models/hris/w42005.rbs +26 -30
- data/sig/finch-api/models/hris/w42020.rbs +23 -25
- data/sig/finch-api/models/income.rbs +10 -10
- data/sig/finch-api/models/individual_event.rbs +13 -19
- data/sig/finch-api/models/introspection.rbs +43 -54
- data/sig/finch-api/models/job_completion_event.rbs +13 -20
- data/sig/finch-api/models/jobs/automated_async_job.rbs +20 -26
- data/sig/finch-api/models/jobs/automated_create_params.rbs +10 -18
- data/sig/finch-api/models/jobs/automated_create_response.rbs +6 -11
- data/sig/finch-api/models/jobs/automated_list_params.rbs +5 -10
- data/sig/finch-api/models/jobs/automated_list_response.rbs +82 -0
- data/sig/finch-api/models/jobs/automated_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/jobs/manual_async_job.rbs +9 -11
- data/sig/finch-api/models/jobs/manual_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/location.rbs +10 -12
- data/sig/finch-api/models/money.rbs +1 -3
- data/sig/finch-api/models/operation_support.rbs +4 -2
- data/sig/finch-api/models/operation_support_matrix.rbs +6 -10
- data/sig/finch-api/models/paging.rbs +1 -3
- data/sig/finch-api/models/pay_statement_event.rbs +13 -20
- data/sig/finch-api/models/payment_event.rbs +13 -17
- data/sig/finch-api/models/payroll/pay_group_list_params.rbs +5 -10
- data/sig/finch-api/models/payroll/pay_group_list_response.rbs +9 -12
- data/sig/finch-api/models/payroll/pay_group_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/payroll/pay_group_retrieve_response.rbs +10 -13
- data/sig/finch-api/models/provider.rbs +200 -347
- data/sig/finch-api/models/provider_list_params.rbs +1 -5
- data/sig/finch-api/models/request_forwarding_forward_params.rbs +8 -13
- data/sig/finch-api/models/request_forwarding_forward_response.rbs +13 -23
- data/sig/finch-api/models/sandbox/company_update_params.rbs +39 -58
- data/sig/finch-api/models/sandbox/company_update_response.rbs +38 -57
- data/sig/finch-api/models/sandbox/connection_create_params.rbs +11 -14
- data/sig/finch-api/models/sandbox/connection_create_response.rbs +14 -17
- data/sig/finch-api/models/sandbox/connections/account_create_params.rbs +11 -14
- data/sig/finch-api/models/sandbox/connections/account_create_response.rbs +13 -16
- data/sig/finch-api/models/sandbox/connections/account_update_params.rbs +4 -9
- data/sig/finch-api/models/sandbox/connections/account_update_response.rbs +12 -15
- data/sig/finch-api/models/sandbox/directory_create_params.rbs +76 -102
- data/sig/finch-api/models/sandbox/employment_update_params.rbs +40 -59
- data/sig/finch-api/models/sandbox/employment_update_response.rbs +40 -59
- data/sig/finch-api/models/sandbox/individual_update_params.rbs +39 -46
- data/sig/finch-api/models/sandbox/individual_update_response.rbs +39 -46
- data/sig/finch-api/models/sandbox/job_create_params.rbs +8 -11
- data/sig/finch-api/models/sandbox/job_create_response.rbs +6 -11
- data/sig/finch-api/models/sandbox/jobs/configuration_retrieve_params.rbs +1 -6
- data/sig/finch-api/models/sandbox/jobs/configuration_update_params.rbs +1 -6
- data/sig/finch-api/models/sandbox/jobs/sandbox_job_configuration.rbs +12 -13
- data/sig/finch-api/models/sandbox/payment_create_params.rbs +81 -143
- data/sig/finch-api/models/sandbox/payment_create_response.rbs +1 -6
- data/sig/finch-api/models/webhook_event.rbs +5 -3
- data/sig/finch-api/page.rbs +2 -7
- data/sig/finch-api/pooled_net_requester.rbs +13 -4
- data/sig/finch-api/request_options.rbs +6 -2
- data/sig/finch-api/resources/access_tokens.rbs +7 -11
- data/sig/finch-api/resources/account.rbs +6 -16
- data/sig/finch-api/resources/connect/sessions.rbs +19 -29
- data/sig/finch-api/resources/hris/benefits/individuals.rbs +19 -43
- data/sig/finch-api/resources/hris/benefits.rbs +21 -48
- data/sig/finch-api/resources/hris/company.rbs +3 -8
- data/sig/finch-api/resources/hris/directory.rbs +6 -20
- data/sig/finch-api/resources/hris/documents.rbs +11 -22
- data/sig/finch-api/resources/hris/employments.rbs +4 -9
- data/sig/finch-api/resources/hris/individuals.rbs +5 -10
- data/sig/finch-api/resources/hris/pay_statements.rbs +4 -9
- data/sig/finch-api/resources/hris/payments.rbs +5 -10
- data/sig/finch-api/resources/jobs/automated.rbs +14 -30
- data/sig/finch-api/resources/jobs/manual.rbs +4 -10
- data/sig/finch-api/resources/payroll/pay_groups.rbs +9 -20
- data/sig/finch-api/resources/providers.rbs +3 -7
- data/sig/finch-api/resources/request_forwarding.rbs +8 -13
- data/sig/finch-api/resources/sandbox/company.rbs +11 -16
- data/sig/finch-api/resources/sandbox/connections/accounts.rbs +11 -21
- data/sig/finch-api/resources/sandbox/connections.rbs +7 -12
- data/sig/finch-api/resources/sandbox/directory.rbs +4 -9
- data/sig/finch-api/resources/sandbox/employment.rbs +22 -28
- data/sig/finch-api/resources/sandbox/individual.rbs +16 -22
- data/sig/finch-api/resources/sandbox/jobs/configuration.rbs +8 -18
- data/sig/finch-api/resources/sandbox/jobs.rbs +4 -9
- data/sig/finch-api/resources/sandbox/payment.rbs +6 -11
- data/sig/finch-api/responses_page.rbs +2 -7
- data/sig/finch-api/single_page.rbs +2 -7
- data/sig/finch-api/util.rbs +37 -12
- data/sig/finch-api/version.rbs +1 -1
- metadata +7 -4
data/lib/finch-api/base_model.rb
CHANGED
@@ -1,41 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module FinchAPI
|
4
|
-
# @private
|
5
|
-
#
|
6
|
-
# @abstract
|
7
|
-
#
|
4
|
+
# @api private
|
8
5
|
module Converter
|
9
6
|
# rubocop:disable Lint/UnusedMethodArgument
|
10
7
|
|
11
|
-
# @private
|
8
|
+
# @api private
|
12
9
|
#
|
13
10
|
# @param value [Object]
|
14
11
|
#
|
15
12
|
# @return [Object]
|
16
|
-
#
|
17
13
|
def coerce(value) = value
|
18
14
|
|
19
|
-
# @private
|
15
|
+
# @api private
|
20
16
|
#
|
21
17
|
# @param value [Object]
|
22
18
|
#
|
23
19
|
# @return [Object]
|
24
|
-
#
|
25
20
|
def dump(value) = value
|
26
21
|
|
27
|
-
# @private
|
22
|
+
# @api private
|
28
23
|
#
|
29
24
|
# @param value [Object]
|
30
25
|
#
|
31
26
|
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
32
|
-
#
|
33
27
|
def try_strict_coerce(value) = (raise NotImplementedError)
|
34
28
|
|
35
29
|
# rubocop:enable Lint/UnusedMethodArgument
|
36
30
|
|
37
31
|
class << self
|
38
|
-
# @private
|
32
|
+
# @api private
|
39
33
|
#
|
40
34
|
# @param spec [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class] .
|
41
35
|
#
|
@@ -48,23 +42,22 @@ module FinchAPI
|
|
48
42
|
# @option spec [Boolean] :"nil?"
|
49
43
|
#
|
50
44
|
# @return [Proc]
|
51
|
-
#
|
52
45
|
def type_info(spec)
|
53
46
|
case spec
|
54
47
|
in Hash
|
55
48
|
type_info(spec.slice(:const, :enum, :union).first&.last)
|
56
49
|
in Proc
|
57
50
|
spec
|
58
|
-
in FinchAPI::Converter |
|
51
|
+
in FinchAPI::Converter | Module | Symbol
|
59
52
|
-> { spec }
|
60
53
|
in true | false
|
61
54
|
-> { FinchAPI::BooleanModel }
|
62
|
-
in NilClass |
|
55
|
+
in NilClass | Integer | Float
|
63
56
|
-> { spec.class }
|
64
57
|
end
|
65
58
|
end
|
66
59
|
|
67
|
-
# @private
|
60
|
+
# @api private
|
68
61
|
#
|
69
62
|
# Based on `target`, transform `value` into `target`, to the extent possible:
|
70
63
|
#
|
@@ -77,12 +70,18 @@ module FinchAPI
|
|
77
70
|
# @param value [Object]
|
78
71
|
#
|
79
72
|
# @return [Object]
|
80
|
-
#
|
81
73
|
def coerce(target, value)
|
82
74
|
case target
|
83
75
|
in FinchAPI::Converter
|
84
76
|
target.coerce(value)
|
85
|
-
in
|
77
|
+
in Symbol
|
78
|
+
case value
|
79
|
+
in Symbol | String if (val = value.to_sym) == target
|
80
|
+
val
|
81
|
+
else
|
82
|
+
value
|
83
|
+
end
|
84
|
+
in Module
|
86
85
|
case target
|
87
86
|
in -> { _1 <= NilClass }
|
88
87
|
nil
|
@@ -104,13 +103,12 @@ module FinchAPI
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
# @private
|
106
|
+
# @api private
|
108
107
|
#
|
109
108
|
# @param target [FinchAPI::Converter, Class]
|
110
109
|
# @param value [Object]
|
111
110
|
#
|
112
111
|
# @return [Object]
|
113
|
-
#
|
114
112
|
def dump(target, value)
|
115
113
|
case target
|
116
114
|
in FinchAPI::Converter
|
@@ -120,7 +118,7 @@ module FinchAPI
|
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
|
-
# @private
|
121
|
+
# @api private
|
124
122
|
#
|
125
123
|
# The underlying algorithm for computing maximal compatibility is subject to
|
126
124
|
# future improvements.
|
@@ -135,12 +133,18 @@ module FinchAPI
|
|
135
133
|
# @param value [Object]
|
136
134
|
#
|
137
135
|
# @return [Object]
|
138
|
-
#
|
139
136
|
def try_strict_coerce(target, value)
|
140
137
|
case target
|
141
138
|
in FinchAPI::Converter
|
142
139
|
target.try_strict_coerce(value)
|
143
|
-
in
|
140
|
+
in Symbol
|
141
|
+
case value
|
142
|
+
in Symbol | String if (val = value.to_sym) == target
|
143
|
+
[true, val, 1]
|
144
|
+
else
|
145
|
+
[false, false, 0]
|
146
|
+
end
|
147
|
+
in Module
|
144
148
|
case [target, value]
|
145
149
|
in [-> { _1 <= NilClass }, _]
|
146
150
|
[true, nil, value.nil? ? 1 : 0]
|
@@ -155,7 +159,7 @@ module FinchAPI
|
|
155
159
|
in [-> { _1 <= Date || _1 <= Time }, String]
|
156
160
|
Kernel.then do
|
157
161
|
[true, target.parse(value), 1]
|
158
|
-
rescue ArgumentError
|
162
|
+
rescue ArgumentError
|
159
163
|
[false, false, 0]
|
160
164
|
end
|
161
165
|
in [_, ^target]
|
@@ -168,7 +172,7 @@ module FinchAPI
|
|
168
172
|
end
|
169
173
|
end
|
170
174
|
|
171
|
-
# @private
|
175
|
+
# @api private
|
172
176
|
#
|
173
177
|
# @abstract
|
174
178
|
#
|
@@ -178,53 +182,48 @@ module FinchAPI
|
|
178
182
|
|
179
183
|
# rubocop:disable Lint/UnusedMethodArgument
|
180
184
|
|
181
|
-
private_class_method :new
|
182
|
-
|
183
185
|
# @param other [Object]
|
184
186
|
#
|
185
187
|
# @return [Boolean]
|
186
|
-
#
|
187
188
|
def self.===(other) = true
|
188
189
|
|
189
190
|
# @param other [Object]
|
190
191
|
#
|
191
192
|
# @return [Boolean]
|
192
|
-
#
|
193
193
|
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::Unknown
|
194
194
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
[false, true, 0]
|
195
|
+
class << self
|
196
|
+
# @!parse
|
197
|
+
# # @api private
|
198
|
+
# #
|
199
|
+
# # @param value [Object]
|
200
|
+
# #
|
201
|
+
# # @return [Object]
|
202
|
+
# def coerce(value) = super
|
203
|
+
|
204
|
+
# @!parse
|
205
|
+
# # @api private
|
206
|
+
# #
|
207
|
+
# # @param value [Object]
|
208
|
+
# #
|
209
|
+
# # @return [Object]
|
210
|
+
# def dump(value) = super
|
211
|
+
|
212
|
+
# @api private
|
213
|
+
#
|
214
|
+
# @param value [Object]
|
215
|
+
#
|
216
|
+
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
217
|
+
def try_strict_coerce(value)
|
218
|
+
# prevent unknown variant from being chosen during the first coercion pass
|
219
|
+
[false, true, 0]
|
220
|
+
end
|
222
221
|
end
|
223
222
|
|
224
223
|
# rubocop:enable Lint/UnusedMethodArgument
|
225
224
|
end
|
226
225
|
|
227
|
-
# @private
|
226
|
+
# @api private
|
228
227
|
#
|
229
228
|
# @abstract
|
230
229
|
#
|
@@ -232,57 +231,50 @@ module FinchAPI
|
|
232
231
|
class BooleanModel
|
233
232
|
extend FinchAPI::Converter
|
234
233
|
|
235
|
-
private_class_method :new
|
236
|
-
|
237
234
|
# @param other [Object]
|
238
235
|
#
|
239
236
|
# @return [Boolean]
|
240
|
-
#
|
241
237
|
def self.===(other) = other == true || other == false
|
242
238
|
|
243
239
|
# @param other [Object]
|
244
240
|
#
|
245
241
|
# @return [Boolean]
|
246
|
-
#
|
247
242
|
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::BooleanModel
|
248
243
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
[false, false, 0]
|
244
|
+
class << self
|
245
|
+
# @!parse
|
246
|
+
# # @api private
|
247
|
+
# #
|
248
|
+
# # @param value [Boolean, Object]
|
249
|
+
# #
|
250
|
+
# # @return [Boolean, Object]
|
251
|
+
# def coerce(value) = super
|
252
|
+
|
253
|
+
# @!parse
|
254
|
+
# # @api private
|
255
|
+
# #
|
256
|
+
# # @param value [Boolean, Object]
|
257
|
+
# #
|
258
|
+
# # @return [Boolean, Object]
|
259
|
+
# def dump(value) = super
|
260
|
+
|
261
|
+
# @api private
|
262
|
+
#
|
263
|
+
# @param value [Object]
|
264
|
+
#
|
265
|
+
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
266
|
+
def try_strict_coerce(value)
|
267
|
+
case value
|
268
|
+
in true | false
|
269
|
+
[true, value, 1]
|
270
|
+
else
|
271
|
+
[false, false, 0]
|
272
|
+
end
|
279
273
|
end
|
280
274
|
end
|
281
275
|
end
|
282
276
|
|
283
|
-
# @private
|
284
|
-
#
|
285
|
-
# @abstract
|
277
|
+
# @api private
|
286
278
|
#
|
287
279
|
# A value from among a specified list of options. OpenAPI enum values map to Ruby
|
288
280
|
# values in the SDK as follows:
|
@@ -294,65 +286,88 @@ module FinchAPI
|
|
294
286
|
#
|
295
287
|
# We can therefore convert string values to Symbols, but can't convert other
|
296
288
|
# values safely.
|
297
|
-
|
298
|
-
|
289
|
+
#
|
290
|
+
# @example
|
291
|
+
# # `connection_status_type` is a `FinchAPI::Models::ConnectionStatusType`
|
292
|
+
# case connection_status_type
|
293
|
+
# when FinchAPI::Models::ConnectionStatusType::PENDING
|
294
|
+
# # ...
|
295
|
+
# when FinchAPI::Models::ConnectionStatusType::PROCESSING
|
296
|
+
# # ...
|
297
|
+
# when FinchAPI::Models::ConnectionStatusType::CONNECTED
|
298
|
+
# # ...
|
299
|
+
# else
|
300
|
+
# puts(connection_status_type)
|
301
|
+
# end
|
302
|
+
#
|
303
|
+
# @example
|
304
|
+
# case connection_status_type
|
305
|
+
# in :pending
|
306
|
+
# # ...
|
307
|
+
# in :processing
|
308
|
+
# # ...
|
309
|
+
# in :connected
|
310
|
+
# # ...
|
311
|
+
# else
|
312
|
+
# puts(connection_status_type)
|
313
|
+
# end
|
314
|
+
module Enum
|
315
|
+
include FinchAPI::Converter
|
299
316
|
|
300
317
|
# All of the valid Symbol values for this enum.
|
301
318
|
#
|
302
319
|
# @return [Array<NilClass, Boolean, Integer, Float, Symbol>]
|
303
|
-
|
304
|
-
def self.values = (@values ||= constants.map { const_get(_1) })
|
320
|
+
def values = (@values ||= constants.map { const_get(_1) })
|
305
321
|
|
306
|
-
# @private
|
322
|
+
# @api private
|
307
323
|
#
|
308
324
|
# Guard against thread safety issues by instantiating `@values`.
|
309
|
-
|
310
|
-
private_class_method def self.finalize! = values
|
311
|
-
|
312
|
-
private_class_method :new
|
325
|
+
private def finalize! = values
|
313
326
|
|
314
327
|
# @param other [Object]
|
315
328
|
#
|
316
329
|
# @return [Boolean]
|
317
|
-
|
318
|
-
def self.===(other) = values.include?(other)
|
330
|
+
def ===(other) = values.include?(other)
|
319
331
|
|
320
332
|
# @param other [Object]
|
321
333
|
#
|
322
334
|
# @return [Boolean]
|
323
|
-
|
324
|
-
|
325
|
-
other.is_a?(Class) && other <= FinchAPI::Enum && other.values.to_set == values.to_set
|
335
|
+
def ==(other)
|
336
|
+
other.is_a?(Module) && other.singleton_class.ancestors.include?(FinchAPI::Enum) && other.values.to_set == values.to_set
|
326
337
|
end
|
327
338
|
|
328
|
-
# @private
|
339
|
+
# @api private
|
329
340
|
#
|
330
341
|
# @param value [String, Symbol, Object]
|
331
342
|
#
|
332
343
|
# @return [Symbol, Object]
|
333
|
-
|
334
|
-
|
344
|
+
def coerce(value)
|
345
|
+
case value
|
346
|
+
in Symbol | String if values.include?(val = value.to_sym)
|
347
|
+
val
|
348
|
+
else
|
349
|
+
value
|
350
|
+
end
|
351
|
+
end
|
335
352
|
|
336
353
|
# @!parse
|
337
|
-
# # @private
|
354
|
+
# # @api private
|
338
355
|
# #
|
339
356
|
# # @param value [Symbol, Object]
|
340
357
|
# #
|
341
358
|
# # @return [Symbol, Object]
|
342
|
-
#
|
343
|
-
# def self.dump(value) = super
|
359
|
+
# def dump(value) = super
|
344
360
|
|
345
|
-
# @private
|
361
|
+
# @api private
|
346
362
|
#
|
347
363
|
# @param value [Object]
|
348
364
|
#
|
349
365
|
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
350
|
-
|
351
|
-
def self.try_strict_coerce(value)
|
366
|
+
def try_strict_coerce(value)
|
352
367
|
return [true, value, 1] if values.include?(value)
|
353
368
|
|
354
369
|
case value
|
355
|
-
in String if values.include?(val = value.to_sym)
|
370
|
+
in Symbol | String if values.include?(val = value.to_sym)
|
356
371
|
[true, val, 1]
|
357
372
|
else
|
358
373
|
case [value, values.first]
|
@@ -365,45 +380,63 @@ module FinchAPI
|
|
365
380
|
end
|
366
381
|
end
|
367
382
|
|
368
|
-
# @private
|
383
|
+
# @api private
|
369
384
|
#
|
370
|
-
# @
|
385
|
+
# @example
|
386
|
+
# # `document_retreive_response` is a `FinchAPI::Models::HRIS::DocumentRetreiveResponse`
|
387
|
+
# case document_retreive_response
|
388
|
+
# when FinchAPI::Models::HRIS::W42020
|
389
|
+
# puts(document_retreive_response.data)
|
390
|
+
# when FinchAPI::Models::HRIS::W42005
|
391
|
+
# puts(document_retreive_response.type)
|
392
|
+
# else
|
393
|
+
# puts(document_retreive_response)
|
394
|
+
# end
|
371
395
|
#
|
372
|
-
|
373
|
-
|
396
|
+
# @example
|
397
|
+
# case document_retreive_response
|
398
|
+
# in {type: :w4_2020, data: data, year: year}
|
399
|
+
# puts(data)
|
400
|
+
# in {type: :w4_2005, data: data, year: year}
|
401
|
+
# puts(year)
|
402
|
+
# else
|
403
|
+
# puts(document_retreive_response)
|
404
|
+
# end
|
405
|
+
module Union
|
406
|
+
include FinchAPI::Converter
|
374
407
|
|
375
|
-
# @private
|
408
|
+
# @api private
|
376
409
|
#
|
377
410
|
# All of the specified variant info for this union.
|
378
411
|
#
|
379
412
|
# @return [Array<Array(Symbol, Proc)>]
|
413
|
+
private def known_variants = (@known_variants ||= [])
|
414
|
+
|
415
|
+
# @api private
|
380
416
|
#
|
381
|
-
|
417
|
+
# @return [Array<Array(Symbol, Object)>]
|
418
|
+
protected def derefed_variants
|
419
|
+
@known_variants.map { |key, variant_fn| [key, variant_fn.call] }
|
420
|
+
end
|
382
421
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
# @return [Array<Array(Symbol, Object)>]
|
389
|
-
#
|
390
|
-
protected def variants
|
391
|
-
@known_variants.map { |key, variant_fn| [key, variant_fn.call] }
|
392
|
-
end
|
422
|
+
# All of the specified variants for this union.
|
423
|
+
#
|
424
|
+
# @return [Array<Object>]
|
425
|
+
def variants
|
426
|
+
derefed_variants.map(&:last)
|
393
427
|
end
|
394
428
|
|
395
|
-
# @private
|
429
|
+
# @api private
|
396
430
|
#
|
397
431
|
# @param property [Symbol]
|
398
|
-
|
399
|
-
private_class_method def self.discriminator(property)
|
432
|
+
private def discriminator(property)
|
400
433
|
case property
|
401
434
|
in Symbol
|
402
435
|
@discriminator = property
|
403
436
|
end
|
404
437
|
end
|
405
438
|
|
406
|
-
# @private
|
439
|
+
# @api private
|
407
440
|
#
|
408
441
|
# @param key [Symbol, Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
409
442
|
#
|
@@ -416,26 +449,24 @@ module FinchAPI
|
|
416
449
|
# @option spec [Proc] :union
|
417
450
|
#
|
418
451
|
# @option spec [Boolean] :"nil?"
|
419
|
-
|
420
|
-
private_class_method def self.variant(key, spec = nil)
|
452
|
+
private def variant(key, spec = nil)
|
421
453
|
variant_info =
|
422
454
|
case key
|
423
455
|
in Symbol
|
424
456
|
[key, FinchAPI::Converter.type_info(spec)]
|
425
|
-
in Proc | FinchAPI::Converter |
|
457
|
+
in Proc | FinchAPI::Converter | Module | Hash
|
426
458
|
[nil, FinchAPI::Converter.type_info(key)]
|
427
459
|
end
|
428
460
|
|
429
461
|
known_variants << variant_info
|
430
462
|
end
|
431
463
|
|
432
|
-
# @private
|
464
|
+
# @api private
|
433
465
|
#
|
434
466
|
# @param value [Object]
|
435
467
|
#
|
436
468
|
# @return [FinchAPI::Converter, Class, nil]
|
437
|
-
|
438
|
-
private_class_method def self.resolve_variant(value)
|
469
|
+
private def resolve_variant(value)
|
439
470
|
case [@discriminator, value]
|
440
471
|
in [_, FinchAPI::BaseModel]
|
441
472
|
value.class
|
@@ -458,13 +489,10 @@ module FinchAPI
|
|
458
489
|
# rubocop:disable Style/HashEachMethods
|
459
490
|
# rubocop:disable Style/CaseEquality
|
460
491
|
|
461
|
-
private_class_method :new
|
462
|
-
|
463
492
|
# @param other [Object]
|
464
493
|
#
|
465
494
|
# @return [Boolean]
|
466
|
-
|
467
|
-
def self.===(other)
|
495
|
+
def ===(other)
|
468
496
|
known_variants.any? do |_, variant_fn|
|
469
497
|
variant_fn.call === other
|
470
498
|
end
|
@@ -473,18 +501,16 @@ module FinchAPI
|
|
473
501
|
# @param other [Object]
|
474
502
|
#
|
475
503
|
# @return [Boolean]
|
476
|
-
|
477
|
-
|
478
|
-
other.is_a?(Class) && other <= FinchAPI::Union && other.variants == variants
|
504
|
+
def ==(other)
|
505
|
+
other.is_a?(Module) && other.singleton_class.ancestors.include?(FinchAPI::Union) && other.derefed_variants == derefed_variants
|
479
506
|
end
|
480
507
|
|
481
|
-
# @private
|
508
|
+
# @api private
|
482
509
|
#
|
483
510
|
# @param value [Object]
|
484
511
|
#
|
485
512
|
# @return [Object]
|
486
|
-
|
487
|
-
def self.coerce(value)
|
513
|
+
def coerce(value)
|
488
514
|
if (variant = resolve_variant(value))
|
489
515
|
return FinchAPI::Converter.coerce(variant, value)
|
490
516
|
end
|
@@ -508,13 +534,12 @@ module FinchAPI
|
|
508
534
|
variant.nil? ? value : FinchAPI::Converter.coerce(variant, value)
|
509
535
|
end
|
510
536
|
|
511
|
-
# @private
|
537
|
+
# @api private
|
512
538
|
#
|
513
539
|
# @param value [Object]
|
514
540
|
#
|
515
541
|
# @return [Object]
|
516
|
-
|
517
|
-
def self.dump(value)
|
542
|
+
def dump(value)
|
518
543
|
if (variant = resolve_variant(value))
|
519
544
|
return FinchAPI::Converter.dump(variant, value)
|
520
545
|
end
|
@@ -528,13 +553,12 @@ module FinchAPI
|
|
528
553
|
value
|
529
554
|
end
|
530
555
|
|
531
|
-
# @private
|
556
|
+
# @api private
|
532
557
|
#
|
533
558
|
# @param value [Object]
|
534
559
|
#
|
535
560
|
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
536
|
-
|
537
|
-
def self.try_strict_coerce(value)
|
561
|
+
def try_strict_coerce(value)
|
538
562
|
# TODO(ruby) this will result in super linear decoding behaviour for nested unions
|
539
563
|
# follow up with a decoding context that captures current strictness levels
|
540
564
|
if (variant = resolve_variant(value))
|
@@ -565,7 +589,7 @@ module FinchAPI
|
|
565
589
|
# rubocop:enable Style/HashEachMethods
|
566
590
|
end
|
567
591
|
|
568
|
-
# @private
|
592
|
+
# @api private
|
569
593
|
#
|
570
594
|
# @abstract
|
571
595
|
#
|
@@ -573,14 +597,22 @@ module FinchAPI
|
|
573
597
|
class ArrayOf
|
574
598
|
include FinchAPI::Converter
|
575
599
|
|
576
|
-
|
577
|
-
|
578
|
-
|
600
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
601
|
+
#
|
602
|
+
# @param spec [Hash{Symbol=>Object}] .
|
603
|
+
#
|
604
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
605
|
+
#
|
606
|
+
# @option spec [Proc] :enum
|
607
|
+
#
|
608
|
+
# @option spec [Proc] :union
|
609
|
+
#
|
610
|
+
# @option spec [Boolean] :"nil?"
|
611
|
+
def self.[](type_info, spec = {}) = new(type_info, spec)
|
579
612
|
|
580
613
|
# @param other [Object]
|
581
614
|
#
|
582
615
|
# @return [Boolean]
|
583
|
-
#
|
584
616
|
def ===(other)
|
585
617
|
type = item_type
|
586
618
|
case other
|
@@ -596,15 +628,13 @@ module FinchAPI
|
|
596
628
|
# @param other [Object]
|
597
629
|
#
|
598
630
|
# @return [Boolean]
|
599
|
-
#
|
600
631
|
def ==(other) = other.is_a?(FinchAPI::ArrayOf) && other.item_type == item_type
|
601
632
|
|
602
|
-
# @private
|
633
|
+
# @api private
|
603
634
|
#
|
604
635
|
# @param value [Enumerable, Object]
|
605
636
|
#
|
606
637
|
# @return [Array<Object>, Object]
|
607
|
-
#
|
608
638
|
def coerce(value)
|
609
639
|
type = item_type
|
610
640
|
case value
|
@@ -615,12 +645,11 @@ module FinchAPI
|
|
615
645
|
end
|
616
646
|
end
|
617
647
|
|
618
|
-
# @private
|
648
|
+
# @api private
|
619
649
|
#
|
620
650
|
# @param value [Enumerable, Object]
|
621
651
|
#
|
622
652
|
# @return [Array<Object>, Object]
|
623
|
-
#
|
624
653
|
def dump(value)
|
625
654
|
type = item_type
|
626
655
|
case value
|
@@ -631,12 +660,11 @@ module FinchAPI
|
|
631
660
|
end
|
632
661
|
end
|
633
662
|
|
634
|
-
# @private
|
663
|
+
# @api private
|
635
664
|
#
|
636
665
|
# @param value [Object]
|
637
666
|
#
|
638
667
|
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
639
|
-
#
|
640
668
|
def try_strict_coerce(value)
|
641
669
|
case value
|
642
670
|
in Array
|
@@ -670,13 +698,12 @@ module FinchAPI
|
|
670
698
|
end
|
671
699
|
end
|
672
700
|
|
673
|
-
# @private
|
701
|
+
# @api private
|
674
702
|
#
|
675
703
|
# @return [FinchAPI::Converter, Class]
|
676
|
-
#
|
677
704
|
protected def item_type = @item_type_fn.call
|
678
705
|
|
679
|
-
# @private
|
706
|
+
# @api private
|
680
707
|
#
|
681
708
|
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
682
709
|
#
|
@@ -689,13 +716,12 @@ module FinchAPI
|
|
689
716
|
# @option spec [Proc] :union
|
690
717
|
#
|
691
718
|
# @option spec [Boolean] :"nil?"
|
692
|
-
#
|
693
719
|
def initialize(type_info, spec = {})
|
694
720
|
@item_type_fn = FinchAPI::Converter.type_info(type_info || spec)
|
695
721
|
end
|
696
722
|
end
|
697
723
|
|
698
|
-
# @private
|
724
|
+
# @api private
|
699
725
|
#
|
700
726
|
# @abstract
|
701
727
|
#
|
@@ -703,14 +729,22 @@ module FinchAPI
|
|
703
729
|
class HashOf
|
704
730
|
include FinchAPI::Converter
|
705
731
|
|
706
|
-
|
707
|
-
|
708
|
-
|
732
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
733
|
+
#
|
734
|
+
# @param spec [Hash{Symbol=>Object}] .
|
735
|
+
#
|
736
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
737
|
+
#
|
738
|
+
# @option spec [Proc] :enum
|
739
|
+
#
|
740
|
+
# @option spec [Proc] :union
|
741
|
+
#
|
742
|
+
# @option spec [Boolean] :"nil?"
|
743
|
+
def self.[](type_info, spec = {}) = new(type_info, spec)
|
709
744
|
|
710
745
|
# @param other [Object]
|
711
746
|
#
|
712
747
|
# @return [Boolean]
|
713
|
-
#
|
714
748
|
def ===(other)
|
715
749
|
type = item_type
|
716
750
|
case other
|
@@ -731,15 +765,13 @@ module FinchAPI
|
|
731
765
|
# @param other [Object]
|
732
766
|
#
|
733
767
|
# @return [Boolean]
|
734
|
-
#
|
735
768
|
def ==(other) = other.is_a?(FinchAPI::HashOf) && other.item_type == item_type
|
736
769
|
|
737
|
-
# @private
|
770
|
+
# @api private
|
738
771
|
#
|
739
772
|
# @param value [Hash{Object=>Object}, Object]
|
740
773
|
#
|
741
774
|
# @return [Hash{Symbol=>Object}, Object]
|
742
|
-
#
|
743
775
|
def coerce(value)
|
744
776
|
type = item_type
|
745
777
|
case value
|
@@ -753,12 +785,11 @@ module FinchAPI
|
|
753
785
|
end
|
754
786
|
end
|
755
787
|
|
756
|
-
# @private
|
788
|
+
# @api private
|
757
789
|
#
|
758
790
|
# @param value [Hash{Object=>Object}, Object]
|
759
791
|
#
|
760
792
|
# @return [Hash{Symbol=>Object}, Object]
|
761
|
-
#
|
762
793
|
def dump(value)
|
763
794
|
type = item_type
|
764
795
|
case value
|
@@ -771,12 +802,11 @@ module FinchAPI
|
|
771
802
|
end
|
772
803
|
end
|
773
804
|
|
774
|
-
# @private
|
805
|
+
# @api private
|
775
806
|
#
|
776
807
|
# @param value [Object]
|
777
808
|
#
|
778
809
|
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
779
|
-
#
|
780
810
|
def try_strict_coerce(value)
|
781
811
|
case value
|
782
812
|
in Hash
|
@@ -810,13 +840,12 @@ module FinchAPI
|
|
810
840
|
end
|
811
841
|
end
|
812
842
|
|
813
|
-
# @private
|
843
|
+
# @api private
|
814
844
|
#
|
815
845
|
# @return [FinchAPI::Converter, Class]
|
816
|
-
#
|
817
846
|
protected def item_type = @item_type_fn.call
|
818
847
|
|
819
|
-
# @private
|
848
|
+
# @api private
|
820
849
|
#
|
821
850
|
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
822
851
|
#
|
@@ -829,175 +858,177 @@ module FinchAPI
|
|
829
858
|
# @option spec [Proc] :union
|
830
859
|
#
|
831
860
|
# @option spec [Boolean] :"nil?"
|
832
|
-
#
|
833
861
|
def initialize(type_info, spec = {})
|
834
862
|
@item_type_fn = FinchAPI::Converter.type_info(type_info || spec)
|
835
863
|
end
|
836
864
|
end
|
837
865
|
|
838
|
-
# @private
|
839
|
-
#
|
840
866
|
# @abstract
|
841
867
|
#
|
868
|
+
# @example
|
869
|
+
# # `operation_support_matrix` is a `FinchAPI::Models::OperationSupportMatrix`
|
870
|
+
# operation_support_matrix => {
|
871
|
+
# create: create,
|
872
|
+
# delete: delete,
|
873
|
+
# read: read
|
874
|
+
# }
|
842
875
|
class BaseModel
|
843
876
|
extend FinchAPI::Converter
|
844
877
|
|
845
|
-
# @private
|
846
|
-
#
|
847
|
-
# Assumes superclass fields are totally defined before fields are accessed /
|
848
|
-
# defined on subclasses.
|
849
|
-
#
|
850
|
-
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
851
|
-
#
|
852
|
-
def self.known_fields
|
853
|
-
@known_fields ||= (self < FinchAPI::BaseModel ? superclass.known_fields.dup : {})
|
854
|
-
end
|
855
|
-
|
856
878
|
class << self
|
857
|
-
# @private
|
879
|
+
# @api private
|
880
|
+
#
|
881
|
+
# Assumes superclass fields are totally defined before fields are accessed /
|
882
|
+
# defined on subclasses.
|
858
883
|
#
|
859
884
|
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
885
|
+
def known_fields
|
886
|
+
@known_fields ||= (self < FinchAPI::BaseModel ? superclass.known_fields.dup : {})
|
887
|
+
end
|
888
|
+
|
889
|
+
# @api private
|
890
|
+
#
|
891
|
+
# @return [Hash{Symbol=>Symbol}]
|
892
|
+
def reverse_map
|
893
|
+
@reverse_map ||= (self < FinchAPI::BaseModel ? superclass.reverse_map.dup : {})
|
894
|
+
end
|
895
|
+
|
896
|
+
# @api private
|
860
897
|
#
|
898
|
+
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
|
861
899
|
def fields
|
862
900
|
known_fields.transform_values do |field|
|
863
901
|
{**field.except(:type_fn), type: field.fetch(:type_fn).call}
|
864
902
|
end
|
865
903
|
end
|
866
|
-
end
|
867
904
|
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
def self.defaults = (@defaults ||= {})
|
905
|
+
# @api private
|
906
|
+
#
|
907
|
+
# @return [Hash{Symbol=>Proc}]
|
908
|
+
def defaults = (@defaults ||= {})
|
873
909
|
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
end
|
910
|
+
# @api private
|
911
|
+
#
|
912
|
+
# @param name_sym [Symbol]
|
913
|
+
#
|
914
|
+
# @param required [Boolean]
|
915
|
+
#
|
916
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
917
|
+
#
|
918
|
+
# @param spec [Hash{Symbol=>Object}] .
|
919
|
+
#
|
920
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
921
|
+
#
|
922
|
+
# @option spec [Proc] :enum
|
923
|
+
#
|
924
|
+
# @option spec [Proc] :union
|
925
|
+
#
|
926
|
+
# @option spec [Boolean] :"nil?"
|
927
|
+
private def add_field(name_sym, required:, type_info:, spec:)
|
928
|
+
type_fn, info =
|
929
|
+
case type_info
|
930
|
+
in Proc | Module | FinchAPI::Converter
|
931
|
+
[FinchAPI::Converter.type_info({**spec, union: type_info}), spec]
|
932
|
+
in Hash
|
933
|
+
[FinchAPI::Converter.type_info(type_info), type_info]
|
934
|
+
end
|
900
935
|
|
901
|
-
|
902
|
-
|
936
|
+
fallback = info[:const]
|
937
|
+
defaults[name_sym] = fallback if required && !info[:nil?] && info.key?(:const)
|
903
938
|
|
904
|
-
|
905
|
-
|
939
|
+
key = info[:api_name]&.tap { reverse_map[_1] = name_sym } || name_sym
|
940
|
+
setter = "#{name_sym}="
|
906
941
|
|
907
|
-
|
908
|
-
|
909
|
-
|
942
|
+
if known_fields.key?(name_sym)
|
943
|
+
[name_sym, setter].each { undef_method(_1) }
|
944
|
+
end
|
910
945
|
|
911
|
-
|
946
|
+
known_fields[name_sym] = {mode: @mode, key: key, required: required, type_fn: type_fn}
|
912
947
|
|
913
|
-
|
914
|
-
|
915
|
-
|
948
|
+
define_method(setter) do |val|
|
949
|
+
@data[key] = val
|
950
|
+
end
|
916
951
|
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
952
|
+
define_method(name_sym) do
|
953
|
+
field_type = type_fn.call
|
954
|
+
value = @data.fetch(key) { self.class.defaults[key] }
|
955
|
+
FinchAPI::Converter.coerce(field_type, value)
|
956
|
+
rescue StandardError
|
957
|
+
name = self.class.name.split("::").last
|
958
|
+
raise FinchAPI::ConversionError.new(
|
959
|
+
"Failed to parse #{name}.#{name_sym} as #{field_type.inspect}. " \
|
960
|
+
"To get the unparsed API response, use #{name}[:#{key}]."
|
961
|
+
)
|
962
|
+
end
|
927
963
|
end
|
928
|
-
end
|
929
964
|
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
end
|
965
|
+
# @api private
|
966
|
+
#
|
967
|
+
# @param name_sym [Symbol]
|
968
|
+
#
|
969
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
970
|
+
#
|
971
|
+
# @param spec [Hash{Symbol=>Object}] .
|
972
|
+
#
|
973
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
974
|
+
#
|
975
|
+
# @option spec [Proc] :enum
|
976
|
+
#
|
977
|
+
# @option spec [Proc] :union
|
978
|
+
#
|
979
|
+
# @option spec [Boolean] :"nil?"
|
980
|
+
def required(name_sym, type_info, spec = {})
|
981
|
+
add_field(name_sym, required: true, type_info: type_info, spec: spec)
|
982
|
+
end
|
949
983
|
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
end
|
984
|
+
# @api private
|
985
|
+
#
|
986
|
+
# @param name_sym [Symbol]
|
987
|
+
#
|
988
|
+
# @param type_info [Hash{Symbol=>Object}, Proc, FinchAPI::Converter, Class]
|
989
|
+
#
|
990
|
+
# @param spec [Hash{Symbol=>Object}] .
|
991
|
+
#
|
992
|
+
# @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
|
993
|
+
#
|
994
|
+
# @option spec [Proc] :enum
|
995
|
+
#
|
996
|
+
# @option spec [Proc] :union
|
997
|
+
#
|
998
|
+
# @option spec [Boolean] :"nil?"
|
999
|
+
def optional(name_sym, type_info, spec = {})
|
1000
|
+
add_field(name_sym, required: false, type_info: type_info, spec: spec)
|
1001
|
+
end
|
969
1002
|
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
end
|
1003
|
+
# @api private
|
1004
|
+
#
|
1005
|
+
# `request_only` attributes not excluded from `.#coerce` when receiving responses
|
1006
|
+
# even if well behaved servers should not send them
|
1007
|
+
#
|
1008
|
+
# @param blk [Proc]
|
1009
|
+
private def request_only(&blk)
|
1010
|
+
@mode = :dump
|
1011
|
+
blk.call
|
1012
|
+
ensure
|
1013
|
+
@mode = nil
|
1014
|
+
end
|
983
1015
|
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
1016
|
+
# @api private
|
1017
|
+
#
|
1018
|
+
# `response_only` attributes are omitted from `.#dump` when making requests
|
1019
|
+
#
|
1020
|
+
# @param blk [Proc]
|
1021
|
+
private def response_only(&blk)
|
1022
|
+
@mode = :coerce
|
1023
|
+
blk.call
|
1024
|
+
ensure
|
1025
|
+
@mode = nil
|
1026
|
+
end
|
995
1027
|
end
|
996
1028
|
|
997
1029
|
# @param other [Object]
|
998
1030
|
#
|
999
1031
|
# @return [Boolean]
|
1000
|
-
#
|
1001
1032
|
def ==(other)
|
1002
1033
|
case other
|
1003
1034
|
in FinchAPI::BaseModel
|
@@ -1007,108 +1038,107 @@ module FinchAPI
|
|
1007
1038
|
end
|
1008
1039
|
end
|
1009
1040
|
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1041
|
+
class << self
|
1042
|
+
# @api private
|
1043
|
+
#
|
1044
|
+
# @param value [FinchAPI::BaseModel, Hash{Object=>Object}, Object]
|
1045
|
+
#
|
1046
|
+
# @return [FinchAPI::BaseModel, Object]
|
1047
|
+
def coerce(value)
|
1048
|
+
case FinchAPI::Util.coerce_hash(value)
|
1049
|
+
in Hash => coerced
|
1050
|
+
new(coerced)
|
1051
|
+
else
|
1052
|
+
value
|
1053
|
+
end
|
1022
1054
|
end
|
1023
|
-
end
|
1024
1055
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
end
|
1056
|
+
# @api private
|
1057
|
+
#
|
1058
|
+
# @param value [FinchAPI::BaseModel, Object]
|
1059
|
+
#
|
1060
|
+
# @return [Hash{Object=>Object}, Object]
|
1061
|
+
def dump(value)
|
1062
|
+
unless (coerced = FinchAPI::Util.coerce_hash(value)).is_a?(Hash)
|
1063
|
+
return value
|
1064
|
+
end
|
1035
1065
|
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
else
|
1042
|
-
mode, type_fn, api_name = field.fetch_values(:mode, :type_fn, :key)
|
1043
|
-
case mode
|
1044
|
-
in :coerce
|
1045
|
-
next
|
1066
|
+
values = coerced.filter_map do |key, val|
|
1067
|
+
name = key.to_sym
|
1068
|
+
case (field = known_fields[name])
|
1069
|
+
in nil
|
1070
|
+
[name, val]
|
1046
1071
|
else
|
1047
|
-
|
1048
|
-
|
1072
|
+
mode, type_fn, api_name = field.fetch_values(:mode, :type_fn, :key)
|
1073
|
+
case mode
|
1074
|
+
in :coerce
|
1075
|
+
next
|
1076
|
+
else
|
1077
|
+
target = type_fn.call
|
1078
|
+
[api_name, FinchAPI::Converter.dump(target, val)]
|
1079
|
+
end
|
1049
1080
|
end
|
1050
|
-
end
|
1051
|
-
end.to_h
|
1081
|
+
end.to_h
|
1052
1082
|
|
1053
|
-
|
1054
|
-
|
1083
|
+
defaults.each do |key, val|
|
1084
|
+
next if values.key?(key)
|
1055
1085
|
|
1056
|
-
|
1086
|
+
values[key] = val
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
values
|
1057
1090
|
end
|
1058
1091
|
|
1059
|
-
|
1060
|
-
|
1092
|
+
# @api private
|
1093
|
+
#
|
1094
|
+
# @param value [Object]
|
1095
|
+
#
|
1096
|
+
# @return [Array(true, Object, nil), Array(false, Boolean, Integer)]
|
1097
|
+
def try_strict_coerce(value)
|
1098
|
+
case value
|
1099
|
+
in Hash | FinchAPI::BaseModel
|
1100
|
+
value = value.to_h
|
1101
|
+
else
|
1102
|
+
return [false, false, 0]
|
1103
|
+
end
|
1061
1104
|
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
in Hash | FinchAPI::BaseModel
|
1071
|
-
value = value.to_h
|
1072
|
-
else
|
1073
|
-
return [false, false, 0]
|
1074
|
-
end
|
1105
|
+
keys = value.keys.to_set
|
1106
|
+
great_success = true
|
1107
|
+
tally = 0
|
1108
|
+
acc = {}
|
1109
|
+
|
1110
|
+
known_fields.each_value do |field|
|
1111
|
+
mode, required, type_fn, api_name = field.fetch_values(:mode, :required, :type_fn, :key)
|
1112
|
+
keys.delete(api_name)
|
1075
1113
|
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
acc[api_name] = coerced
|
1093
|
-
in [false, true, score]
|
1114
|
+
case [required && mode != :dump, value.key?(api_name)]
|
1115
|
+
in [_, true]
|
1116
|
+
target = type_fn.call
|
1117
|
+
item = value.fetch(api_name)
|
1118
|
+
case FinchAPI::Converter.try_strict_coerce(target, item)
|
1119
|
+
in [true, coerced, score]
|
1120
|
+
tally += score
|
1121
|
+
acc[api_name] = coerced
|
1122
|
+
in [false, true, score]
|
1123
|
+
great_success = false
|
1124
|
+
tally += score
|
1125
|
+
acc[api_name] = item
|
1126
|
+
in [false, false, _]
|
1127
|
+
great_success &&= item.nil?
|
1128
|
+
end
|
1129
|
+
in [true, false]
|
1094
1130
|
great_success = false
|
1095
|
-
|
1096
|
-
|
1097
|
-
in [false, false, _]
|
1098
|
-
great_success &&= item.nil?
|
1131
|
+
in [false, false]
|
1132
|
+
nil
|
1099
1133
|
end
|
1100
|
-
in [true, false]
|
1101
|
-
great_success = false
|
1102
|
-
in [false, false]
|
1103
|
-
nil
|
1104
1134
|
end
|
1105
|
-
end
|
1106
1135
|
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1136
|
+
keys.each do |key|
|
1137
|
+
acc[key] = value.fetch(key)
|
1138
|
+
end
|
1110
1139
|
|
1111
|
-
|
1140
|
+
great_success ? [true, new(acc), tally] : [false, true, tally]
|
1141
|
+
end
|
1112
1142
|
end
|
1113
1143
|
|
1114
1144
|
# Returns the raw value associated with the given key, if found. Otherwise, nil is
|
@@ -1121,7 +1151,6 @@ module FinchAPI
|
|
1121
1151
|
# @param key [Symbol]
|
1122
1152
|
#
|
1123
1153
|
# @return [Object, nil]
|
1124
|
-
#
|
1125
1154
|
def [](key)
|
1126
1155
|
unless key.instance_of?(Symbol)
|
1127
1156
|
raise ArgumentError.new("Expected symbol key for lookup, got #{key.inspect}")
|
@@ -1140,7 +1169,6 @@ module FinchAPI
|
|
1140
1169
|
# should not be mutated.
|
1141
1170
|
#
|
1142
1171
|
# @return [Hash{Symbol=>Object}]
|
1143
|
-
#
|
1144
1172
|
def to_h = @data
|
1145
1173
|
|
1146
1174
|
alias_method :to_hash, :to_h
|
@@ -1148,7 +1176,6 @@ module FinchAPI
|
|
1148
1176
|
# @param keys [Array<Symbol>, nil]
|
1149
1177
|
#
|
1150
1178
|
# @return [Hash{Symbol=>Object}]
|
1151
|
-
#
|
1152
1179
|
def deconstruct_keys(keys)
|
1153
1180
|
(keys || self.class.known_fields.keys).filter_map do |k|
|
1154
1181
|
unless self.class.known_fields.key?(k)
|
@@ -1163,22 +1190,33 @@ module FinchAPI
|
|
1163
1190
|
# Create a new instance of a model.
|
1164
1191
|
#
|
1165
1192
|
# @param data [Hash{Symbol=>Object}, FinchAPI::BaseModel]
|
1166
|
-
#
|
1167
1193
|
def initialize(data = {})
|
1168
1194
|
case FinchAPI::Util.coerce_hash(data)
|
1169
1195
|
in Hash => coerced
|
1170
|
-
@data = coerced.
|
1196
|
+
@data = coerced.to_h do |key, value|
|
1197
|
+
name = key.to_sym
|
1198
|
+
mapped = self.class.reverse_map.fetch(name, name)
|
1199
|
+
type = self.class.fields[mapped]&.fetch(:type)
|
1200
|
+
stored =
|
1201
|
+
case [type, value]
|
1202
|
+
in [Module, Hash] if type <= FinchAPI::BaseModel
|
1203
|
+
type.new(value)
|
1204
|
+
in [FinchAPI::ArrayOf, Array] | [FinchAPI::HashOf, Hash]
|
1205
|
+
type.coerce(value)
|
1206
|
+
else
|
1207
|
+
value
|
1208
|
+
end
|
1209
|
+
[name, stored]
|
1210
|
+
end
|
1171
1211
|
else
|
1172
1212
|
raise ArgumentError.new("Expected a #{Hash} or #{FinchAPI::BaseModel}, got #{data.inspect}")
|
1173
1213
|
end
|
1174
1214
|
end
|
1175
1215
|
|
1176
1216
|
# @return [String]
|
1177
|
-
#
|
1178
1217
|
def to_s = @data.to_s
|
1179
1218
|
|
1180
1219
|
# @return [String]
|
1181
|
-
#
|
1182
1220
|
def inspect
|
1183
1221
|
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{deconstruct_keys(nil).map do |k, v|
|
1184
1222
|
"#{k}=#{v.inspect}"
|