moderation_api 1.2.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ignore +2 -0
- data/CHANGELOG.md +28 -0
- data/README.md +200 -62
- data/SECURITY.md +27 -0
- data/lib/moderation_api/client.rb +98 -0
- data/lib/moderation_api/errors.rb +228 -0
- data/lib/moderation_api/file_part.rb +58 -0
- data/lib/moderation_api/internal/transport/base_client.rb +577 -0
- data/lib/moderation_api/internal/transport/pooled_net_requester.rb +208 -0
- data/lib/moderation_api/internal/type/array_of.rb +168 -0
- data/lib/moderation_api/internal/type/base_model.rb +534 -0
- data/lib/moderation_api/internal/type/base_page.rb +55 -0
- data/lib/moderation_api/internal/type/boolean.rb +77 -0
- data/lib/moderation_api/internal/type/converter.rb +327 -0
- data/lib/moderation_api/internal/type/enum.rb +131 -0
- data/lib/moderation_api/internal/type/file_input.rb +111 -0
- data/lib/moderation_api/internal/type/hash_of.rb +188 -0
- data/lib/moderation_api/internal/type/request_parameters.rb +42 -0
- data/lib/moderation_api/internal/type/union.rb +243 -0
- data/lib/moderation_api/internal/type/unknown.rb +81 -0
- data/lib/moderation_api/internal/util.rb +915 -0
- data/lib/moderation_api/internal.rb +20 -0
- data/lib/moderation_api/models/account_list_params.rb +14 -0
- data/lib/moderation_api/models/account_list_response.rb +68 -0
- data/lib/moderation_api/models/action_create_params.rb +217 -0
- data/lib/moderation_api/models/action_create_response.rb +188 -0
- data/lib/moderation_api/models/action_delete_params.rb +14 -0
- data/lib/moderation_api/models/action_delete_response.rb +25 -0
- data/lib/moderation_api/models/action_list_params.rb +20 -0
- data/lib/moderation_api/models/action_list_response.rb +247 -0
- data/lib/moderation_api/models/action_retrieve_params.rb +14 -0
- data/lib/moderation_api/models/action_retrieve_response.rb +244 -0
- data/lib/moderation_api/models/action_update_params.rb +217 -0
- data/lib/moderation_api/models/action_update_response.rb +188 -0
- data/lib/moderation_api/models/actions/execute_execute_by_id_params.rb +48 -0
- data/lib/moderation_api/models/actions/execute_execute_by_id_response.rb +35 -0
- data/lib/moderation_api/models/actions/execute_execute_params.rb +64 -0
- data/lib/moderation_api/models/actions/execute_execute_response.rb +21 -0
- data/lib/moderation_api/models/auth_create_params.rb +14 -0
- data/lib/moderation_api/models/auth_create_response.rb +33 -0
- data/lib/moderation_api/models/auth_retrieve_params.rb +14 -0
- data/lib/moderation_api/models/auth_retrieve_response.rb +25 -0
- data/lib/moderation_api/models/author_create_params.rb +127 -0
- data/lib/moderation_api/models/author_create_response.rb +272 -0
- data/lib/moderation_api/models/author_delete_params.rb +14 -0
- data/lib/moderation_api/models/author_delete_response.rb +16 -0
- data/lib/moderation_api/models/author_list_params.rb +93 -0
- data/lib/moderation_api/models/author_list_response.rb +326 -0
- data/lib/moderation_api/models/author_retrieve_params.rb +14 -0
- data/lib/moderation_api/models/author_retrieve_response.rb +274 -0
- data/lib/moderation_api/models/author_update_params.rb +119 -0
- data/lib/moderation_api/models/author_update_response.rb +272 -0
- data/lib/moderation_api/models/content_submit_params.rb +871 -0
- data/lib/moderation_api/models/content_submit_response.rb +742 -0
- data/lib/moderation_api/models/queue/item_list_params.rb +118 -0
- data/lib/moderation_api/models/queue/item_list_response.rb +235 -0
- data/lib/moderation_api/models/queue/item_resolve_params.rb +32 -0
- data/lib/moderation_api/models/queue/item_resolve_response.rb +34 -0
- data/lib/moderation_api/models/queue/item_unresolve_params.rb +32 -0
- data/lib/moderation_api/models/queue/item_unresolve_response.rb +34 -0
- data/lib/moderation_api/models/queue_get_stats_params.rb +22 -0
- data/lib/moderation_api/models/queue_get_stats_response.rb +251 -0
- data/lib/moderation_api/models/queue_retrieve_params.rb +14 -0
- data/lib/moderation_api/models/queue_retrieve_response.rb +190 -0
- data/lib/moderation_api/models/wordlist/word_add_params.rb +24 -0
- data/lib/moderation_api/models/wordlist/word_add_response.rb +35 -0
- data/lib/moderation_api/models/wordlist/word_remove_params.rb +24 -0
- data/lib/moderation_api/models/wordlist/word_remove_response.rb +35 -0
- data/lib/moderation_api/models/wordlist_get_embedding_status_params.rb +14 -0
- data/lib/moderation_api/models/wordlist_get_embedding_status_response.rb +35 -0
- data/lib/moderation_api/models/wordlist_list_params.rb +14 -0
- data/lib/moderation_api/models/wordlist_list_response.rb +52 -0
- data/lib/moderation_api/models/wordlist_retrieve_params.rb +14 -0
- data/lib/moderation_api/models/wordlist_retrieve_response.rb +65 -0
- data/lib/moderation_api/models/wordlist_update_params.rb +58 -0
- data/lib/moderation_api/models/wordlist_update_response.rb +65 -0
- data/lib/moderation_api/models.rb +90 -0
- data/lib/moderation_api/request_options.rb +78 -0
- data/lib/moderation_api/resources/account.rb +32 -0
- data/lib/moderation_api/resources/actions/execute.rb +80 -0
- data/lib/moderation_api/resources/actions.rb +175 -0
- data/lib/moderation_api/resources/auth.rb +50 -0
- data/lib/moderation_api/resources/authors.rb +179 -0
- data/lib/moderation_api/resources/content.rb +53 -0
- data/lib/moderation_api/resources/queue/items.rb +131 -0
- data/lib/moderation_api/resources/queue.rb +63 -0
- data/lib/moderation_api/resources/wordlist/words.rb +64 -0
- data/lib/moderation_api/resources/wordlist.rb +111 -0
- data/lib/moderation_api/version.rb +3 -13
- data/lib/moderation_api.rb +115 -89
- data/manifest.yaml +17 -0
- data/rbi/moderation_api/client.rbi +67 -0
- data/rbi/moderation_api/errors.rbi +205 -0
- data/rbi/moderation_api/file_part.rbi +37 -0
- data/rbi/moderation_api/internal/transport/base_client.rbi +305 -0
- data/rbi/moderation_api/internal/transport/pooled_net_requester.rbi +84 -0
- data/rbi/moderation_api/internal/type/array_of.rbi +104 -0
- data/rbi/moderation_api/internal/type/base_model.rbi +314 -0
- data/rbi/moderation_api/internal/type/base_page.rbi +43 -0
- data/rbi/moderation_api/internal/type/boolean.rbi +58 -0
- data/rbi/moderation_api/internal/type/converter.rbi +225 -0
- data/rbi/moderation_api/internal/type/enum.rbi +82 -0
- data/rbi/moderation_api/internal/type/file_input.rbi +59 -0
- data/rbi/moderation_api/internal/type/hash_of.rbi +104 -0
- data/rbi/moderation_api/internal/type/request_parameters.rbi +31 -0
- data/rbi/moderation_api/internal/type/union.rbi +128 -0
- data/rbi/moderation_api/internal/type/unknown.rbi +58 -0
- data/rbi/moderation_api/internal/util.rbi +487 -0
- data/rbi/moderation_api/internal.rbi +18 -0
- data/rbi/moderation_api/models/account_list_params.rbi +32 -0
- data/rbi/moderation_api/models/account_list_response.rbi +115 -0
- data/rbi/moderation_api/models/action_create_params.rbi +433 -0
- data/rbi/moderation_api/models/action_create_response.rbi +354 -0
- data/rbi/moderation_api/models/action_delete_params.rbi +32 -0
- data/rbi/moderation_api/models/action_delete_response.rbi +36 -0
- data/rbi/moderation_api/models/action_list_params.rbi +41 -0
- data/rbi/moderation_api/models/action_list_response.rbi +450 -0
- data/rbi/moderation_api/models/action_retrieve_params.rbi +32 -0
- data/rbi/moderation_api/models/action_retrieve_response.rbi +442 -0
- data/rbi/moderation_api/models/action_update_params.rbi +436 -0
- data/rbi/moderation_api/models/action_update_response.rbi +354 -0
- data/rbi/moderation_api/models/actions/execute_execute_by_id_params.rbi +84 -0
- data/rbi/moderation_api/models/actions/execute_execute_by_id_response.rbi +54 -0
- data/rbi/moderation_api/models/actions/execute_execute_params.rbi +103 -0
- data/rbi/moderation_api/models/actions/execute_execute_response.rbi +33 -0
- data/rbi/moderation_api/models/auth_create_params.rbi +32 -0
- data/rbi/moderation_api/models/auth_create_response.rbi +48 -0
- data/rbi/moderation_api/models/auth_retrieve_params.rbi +32 -0
- data/rbi/moderation_api/models/auth_retrieve_response.rbi +36 -0
- data/rbi/moderation_api/models/author_create_params.rbi +184 -0
- data/rbi/moderation_api/models/author_create_response.rbi +467 -0
- data/rbi/moderation_api/models/author_delete_params.rbi +32 -0
- data/rbi/moderation_api/models/author_delete_response.rbi +26 -0
- data/rbi/moderation_api/models/author_list_params.rbi +213 -0
- data/rbi/moderation_api/models/author_list_response.rbi +593 -0
- data/rbi/moderation_api/models/author_retrieve_params.rbi +32 -0
- data/rbi/moderation_api/models/author_retrieve_response.rbi +472 -0
- data/rbi/moderation_api/models/author_update_params.rbi +176 -0
- data/rbi/moderation_api/models/author_update_response.rbi +467 -0
- data/rbi/moderation_api/models/content_submit_params.rbi +1641 -0
- data/rbi/moderation_api/models/content_submit_response.rbi +1456 -0
- data/rbi/moderation_api/models/queue/item_list_params.rbi +237 -0
- data/rbi/moderation_api/models/queue/item_list_response.rbi +440 -0
- data/rbi/moderation_api/models/queue/item_resolve_params.rbi +59 -0
- data/rbi/moderation_api/models/queue/item_resolve_response.rbi +55 -0
- data/rbi/moderation_api/models/queue/item_unresolve_params.rbi +59 -0
- data/rbi/moderation_api/models/queue/item_unresolve_response.rbi +52 -0
- data/rbi/moderation_api/models/queue_get_stats_params.rbi +49 -0
- data/rbi/moderation_api/models/queue_get_stats_response.rbi +466 -0
- data/rbi/moderation_api/models/queue_retrieve_params.rbi +32 -0
- data/rbi/moderation_api/models/queue_retrieve_response.rbi +411 -0
- data/rbi/moderation_api/models/wordlist/word_add_params.rbi +48 -0
- data/rbi/moderation_api/models/wordlist/word_add_response.rbi +58 -0
- data/rbi/moderation_api/models/wordlist/word_remove_params.rbi +48 -0
- data/rbi/moderation_api/models/wordlist/word_remove_response.rbi +58 -0
- data/rbi/moderation_api/models/wordlist_get_embedding_status_params.rbi +32 -0
- data/rbi/moderation_api/models/wordlist_get_embedding_status_response.rbi +53 -0
- data/rbi/moderation_api/models/wordlist_list_params.rbi +32 -0
- data/rbi/moderation_api/models/wordlist_list_response.rbi +80 -0
- data/rbi/moderation_api/models/wordlist_retrieve_params.rbi +32 -0
- data/rbi/moderation_api/models/wordlist_retrieve_response.rbi +88 -0
- data/rbi/moderation_api/models/wordlist_update_params.rbi +95 -0
- data/rbi/moderation_api/models/wordlist_update_response.rbi +88 -0
- data/rbi/moderation_api/models.rbi +50 -0
- data/rbi/moderation_api/request_options.rbi +59 -0
- data/rbi/moderation_api/resources/account.rbi +21 -0
- data/rbi/moderation_api/resources/actions/execute.rbi +69 -0
- data/rbi/moderation_api/resources/actions.rbi +164 -0
- data/rbi/moderation_api/resources/auth.rbi +28 -0
- data/rbi/moderation_api/resources/authors.rbi +143 -0
- data/rbi/moderation_api/resources/content.rbi +84 -0
- data/rbi/moderation_api/resources/queue/items.rbi +95 -0
- data/rbi/moderation_api/resources/queue.rbi +47 -0
- data/rbi/moderation_api/resources/wordlist/words.rbi +48 -0
- data/rbi/moderation_api/resources/wordlist.rbi +82 -0
- data/rbi/moderation_api/version.rbi +5 -0
- data/sig/moderation_api/client.rbs +38 -0
- data/sig/moderation_api/errors.rbs +117 -0
- data/sig/moderation_api/file_part.rbs +21 -0
- data/sig/moderation_api/internal/transport/base_client.rbs +133 -0
- data/sig/moderation_api/internal/transport/pooled_net_requester.rbs +48 -0
- data/sig/moderation_api/internal/type/array_of.rbs +48 -0
- data/sig/moderation_api/internal/type/base_model.rbs +104 -0
- data/sig/moderation_api/internal/type/base_page.rbs +24 -0
- data/sig/moderation_api/internal/type/boolean.rbs +26 -0
- data/sig/moderation_api/internal/type/converter.rbs +79 -0
- data/sig/moderation_api/internal/type/enum.rbs +32 -0
- data/sig/moderation_api/internal/type/file_input.rbs +25 -0
- data/sig/moderation_api/internal/type/hash_of.rbs +48 -0
- data/sig/moderation_api/internal/type/request_parameters.rbs +19 -0
- data/sig/moderation_api/internal/type/union.rbs +52 -0
- data/sig/moderation_api/internal/type/unknown.rbs +26 -0
- data/sig/moderation_api/internal/util.rbs +185 -0
- data/sig/moderation_api/internal.rbs +10 -0
- data/sig/moderation_api/models/account_list_params.rbs +15 -0
- data/sig/moderation_api/models/account_list_response.rbs +56 -0
- data/sig/moderation_api/models/action_create_params.rbs +195 -0
- data/sig/moderation_api/models/action_create_response.rbs +143 -0
- data/sig/moderation_api/models/action_delete_params.rbs +15 -0
- data/sig/moderation_api/models/action_delete_response.rbs +15 -0
- data/sig/moderation_api/models/action_list_params.rbs +25 -0
- data/sig/moderation_api/models/action_list_response.rbs +190 -0
- data/sig/moderation_api/models/action_retrieve_params.rbs +15 -0
- data/sig/moderation_api/models/action_retrieve_response.rbs +185 -0
- data/sig/moderation_api/models/action_update_params.rbs +197 -0
- data/sig/moderation_api/models/action_update_response.rbs +143 -0
- data/sig/moderation_api/models/actions/execute_execute_by_id_params.rbs +51 -0
- data/sig/moderation_api/models/actions/execute_execute_by_id_response.rbs +28 -0
- data/sig/moderation_api/models/actions/execute_execute_params.rbs +63 -0
- data/sig/moderation_api/models/actions/execute_execute_response.rbs +15 -0
- data/sig/moderation_api/models/auth_create_params.rbs +15 -0
- data/sig/moderation_api/models/auth_create_response.rbs +18 -0
- data/sig/moderation_api/models/auth_retrieve_params.rbs +15 -0
- data/sig/moderation_api/models/auth_retrieve_response.rbs +15 -0
- data/sig/moderation_api/models/author_create_params.rbs +106 -0
- data/sig/moderation_api/models/author_create_response.rbs +195 -0
- data/sig/moderation_api/models/author_delete_params.rbs +15 -0
- data/sig/moderation_api/models/author_delete_response.rbs +13 -0
- data/sig/moderation_api/models/author_list_params.rbs +110 -0
- data/sig/moderation_api/models/author_list_response.rbs +254 -0
- data/sig/moderation_api/models/author_retrieve_params.rbs +15 -0
- data/sig/moderation_api/models/author_retrieve_response.rbs +195 -0
- data/sig/moderation_api/models/author_update_params.rbs +101 -0
- data/sig/moderation_api/models/author_update_response.rbs +195 -0
- data/sig/moderation_api/models/content_submit_params.rbs +733 -0
- data/sig/moderation_api/models/content_submit_response.rbs +599 -0
- data/sig/moderation_api/models/queue/item_list_params.rbs +127 -0
- data/sig/moderation_api/models/queue/item_list_response.rbs +209 -0
- data/sig/moderation_api/models/queue/item_resolve_params.rbs +32 -0
- data/sig/moderation_api/models/queue/item_resolve_response.rbs +26 -0
- data/sig/moderation_api/models/queue/item_unresolve_params.rbs +32 -0
- data/sig/moderation_api/models/queue/item_unresolve_response.rbs +24 -0
- data/sig/moderation_api/models/queue_get_stats_params.rbs +26 -0
- data/sig/moderation_api/models/queue_get_stats_response.rbs +207 -0
- data/sig/moderation_api/models/queue_retrieve_params.rbs +15 -0
- data/sig/moderation_api/models/queue_retrieve_response.rbs +207 -0
- data/sig/moderation_api/models/wordlist/word_add_params.rbs +26 -0
- data/sig/moderation_api/models/wordlist/word_add_response.rbs +28 -0
- data/sig/moderation_api/models/wordlist/word_remove_params.rbs +26 -0
- data/sig/moderation_api/models/wordlist/word_remove_response.rbs +32 -0
- data/sig/moderation_api/models/wordlist_get_embedding_status_params.rbs +15 -0
- data/sig/moderation_api/models/wordlist_get_embedding_status_response.rbs +26 -0
- data/sig/moderation_api/models/wordlist_list_params.rbs +15 -0
- data/sig/moderation_api/models/wordlist_list_response.rbs +45 -0
- data/sig/moderation_api/models/wordlist_retrieve_params.rbs +15 -0
- data/sig/moderation_api/models/wordlist_retrieve_response.rbs +50 -0
- data/sig/moderation_api/models/wordlist_update_params.rbs +56 -0
- data/sig/moderation_api/models/wordlist_update_response.rbs +50 -0
- data/sig/moderation_api/models.rbs +47 -0
- data/sig/moderation_api/request_options.rbs +36 -0
- data/sig/moderation_api/resources/account.rbs +11 -0
- data/sig/moderation_api/resources/actions/execute.rbs +28 -0
- data/sig/moderation_api/resources/actions.rbs +57 -0
- data/sig/moderation_api/resources/auth.rbs +15 -0
- data/sig/moderation_api/resources/authors.rbs +54 -0
- data/sig/moderation_api/resources/content.rbs +20 -0
- data/sig/moderation_api/resources/queue/items.rbs +39 -0
- data/sig/moderation_api/resources/queue.rbs +20 -0
- data/sig/moderation_api/resources/wordlist/words.rbs +21 -0
- data/sig/moderation_api/resources/wordlist.rbs +33 -0
- data/sig/moderation_api/version.rbs +3 -0
- metadata +277 -302
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -87
- data/Rakefile +0 -10
- data/docs/AccountApi.md +0 -74
- data/docs/AccountGet200Response.md +0 -26
- data/docs/AccountGet200ResponseCurrentProject.md +0 -20
- data/docs/ActionsCreateRequest.md +0 -36
- data/docs/ActionsCreateRequestWebhooksInner.md +0 -24
- data/docs/ActionsDelete200Response.md +0 -20
- data/docs/ActionsExecute200Response.md +0 -22
- data/docs/ActionsExecuteDeprecatedRequest.md +0 -22
- data/docs/ActionsExecuteRequest.md +0 -24
- data/docs/ActionsGet200Response.md +0 -40
- data/docs/ActionsGet200ResponseWebhooksInner.md +0 -26
- data/docs/ActionsList200ResponseInner.md +0 -38
- data/docs/ActionsList200ResponseInnerPossibleValuesInner.md +0 -18
- data/docs/ActionsList400Response.md +0 -22
- data/docs/ActionsList400ResponseIssuesInner.md +0 -18
- data/docs/ActionsUpdateRequest.md +0 -36
- data/docs/ModerateApi.md +0 -357
- data/docs/ModerationAudioRequest.md +0 -28
- data/docs/ModerationImage200Response.md +0 -28
- data/docs/ModerationImage200ResponseLabelsInner.md +0 -20
- data/docs/ModerationImageRequest.md +0 -28
- data/docs/ModerationObject200Response.md +0 -36
- data/docs/ModerationObject200ResponseAllOfEntitiesInner.md +0 -22
- data/docs/ModerationObject200ResponseAllOfFieldsInner.md +0 -22
- data/docs/ModerationObject200ResponseAllOfLabelsInner.md +0 -22
- data/docs/ModerationObjectRequest.md +0 -28
- data/docs/ModerationObjectRequestValue.md +0 -20
- data/docs/ModerationObjectRequestValueDataValue.md +0 -22
- data/docs/ModerationText200Response.md +0 -64
- data/docs/ModerationText200ResponseAllOfAddress.md +0 -28
- data/docs/ModerationText200ResponseAllOfEmail.md +0 -28
- data/docs/ModerationText200ResponseAllOfName.md +0 -28
- data/docs/ModerationText200ResponseAllOfNsfw.md +0 -26
- data/docs/ModerationText200ResponseAllOfNsfwLabelScores.md +0 -22
- data/docs/ModerationText200ResponseAllOfPhone.md +0 -28
- data/docs/ModerationText200ResponseAllOfProfanity.md +0 -28
- data/docs/ModerationText200ResponseAllOfPropriety.md +0 -26
- data/docs/ModerationText200ResponseAllOfProprietyLabelScores.md +0 -22
- data/docs/ModerationText200ResponseAllOfQuality.md +0 -26
- data/docs/ModerationText200ResponseAllOfQualityLabelScores.md +0 -24
- data/docs/ModerationText200ResponseAllOfRequest.md +0 -20
- data/docs/ModerationText200ResponseAllOfSensitive.md +0 -28
- data/docs/ModerationText200ResponseAllOfSentiment.md +0 -26
- data/docs/ModerationText200ResponseAllOfSentimentLabelScores.md +0 -22
- data/docs/ModerationText200ResponseAllOfToxicity.md +0 -26
- data/docs/ModerationText200ResponseAllOfToxicityLabelScores.md +0 -30
- data/docs/ModerationText200ResponseAllOfUrl.md +0 -28
- data/docs/ModerationText200ResponseAllOfUsername.md +0 -28
- data/docs/ModerationText200ResponseAllOfWordlist.md +0 -28
- data/docs/ModerationText200ResponseAllOfWordlistsInner.md +0 -36
- data/docs/ModerationTextRequest.md +0 -28
- data/docs/ModerationVideo200Response.md +0 -24
- data/docs/ModerationVideoRequest.md +0 -28
- data/docs/QueueActionsApi.md +0 -503
- data/git_push.sh +0 -57
- data/lib/moderation_api/api/account_api.rb +0 -79
- data/lib/moderation_api/api/moderate_api.rb +0 -362
- data/lib/moderation_api/api/queue_actions_api.rb +0 -492
- data/lib/moderation_api/api_client.rb +0 -437
- data/lib/moderation_api/api_error.rb +0 -58
- data/lib/moderation_api/configuration.rb +0 -392
- data/lib/moderation_api/models/account_get200_response.rb +0 -278
- data/lib/moderation_api/models/account_get200_response_current_project.rb +0 -237
- data/lib/moderation_api/models/actions_create_request.rb +0 -374
- data/lib/moderation_api/models/actions_create_request_webhooks_inner.rb +0 -260
- data/lib/moderation_api/models/actions_delete200_response.rb +0 -239
- data/lib/moderation_api/models/actions_execute200_response.rb +0 -258
- data/lib/moderation_api/models/actions_execute_deprecated_request.rb +0 -244
- data/lib/moderation_api/models/actions_execute_request.rb +0 -261
- data/lib/moderation_api/models/actions_get200_response.rb +0 -408
- data/lib/moderation_api/models/actions_get200_response_webhooks_inner.rb +0 -278
- data/lib/moderation_api/models/actions_list200_response_inner.rb +0 -396
- data/lib/moderation_api/models/actions_list200_response_inner_possible_values_inner.rb +0 -222
- data/lib/moderation_api/models/actions_list400_response.rb +0 -248
- data/lib/moderation_api/models/actions_list400_response_issues_inner.rb +0 -221
- data/lib/moderation_api/models/actions_update_request.rb +0 -367
- data/lib/moderation_api/models/moderation_audio_request.rb +0 -302
- data/lib/moderation_api/models/moderation_image200_response.rb +0 -296
- data/lib/moderation_api/models/moderation_image200_response_labels_inner.rb +0 -301
- data/lib/moderation_api/models/moderation_image_request.rb +0 -302
- data/lib/moderation_api/models/moderation_object200_response.rb +0 -368
- data/lib/moderation_api/models/moderation_object200_response_all_of_entities_inner.rb +0 -251
- data/lib/moderation_api/models/moderation_object200_response_all_of_fields_inner.rb +0 -258
- data/lib/moderation_api/models/moderation_object200_response_all_of_labels_inner.rb +0 -284
- data/lib/moderation_api/models/moderation_object_request.rb +0 -301
- data/lib/moderation_api/models/moderation_object_request_value.rb +0 -275
- data/lib/moderation_api/models/moderation_object_request_value_data_value.rb +0 -285
- data/lib/moderation_api/models/moderation_text200_response.rb +0 -488
- data/lib/moderation_api/models/moderation_text200_response_all_of_address.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_email.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_name.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_nsfw.rb +0 -255
- data/lib/moderation_api/models/moderation_text200_response_all_of_nsfw_label_scores.rb +0 -235
- data/lib/moderation_api/models/moderation_text200_response_all_of_phone.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_profanity.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_propriety.rb +0 -255
- data/lib/moderation_api/models/moderation_text200_response_all_of_propriety_label_scores.rb +0 -235
- data/lib/moderation_api/models/moderation_text200_response_all_of_quality.rb +0 -255
- data/lib/moderation_api/models/moderation_text200_response_all_of_quality_label_scores.rb +0 -245
- data/lib/moderation_api/models/moderation_text200_response_all_of_request.rb +0 -240
- data/lib/moderation_api/models/moderation_text200_response_all_of_sensitive.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_sentiment.rb +0 -255
- data/lib/moderation_api/models/moderation_text200_response_all_of_sentiment_label_scores.rb +0 -235
- data/lib/moderation_api/models/moderation_text200_response_all_of_toxicity.rb +0 -262
- data/lib/moderation_api/models/moderation_text200_response_all_of_toxicity_label_scores.rb +0 -275
- data/lib/moderation_api/models/moderation_text200_response_all_of_url.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_username.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_wordlist.rb +0 -303
- data/lib/moderation_api/models/moderation_text200_response_all_of_wordlists_inner.rb +0 -377
- data/lib/moderation_api/models/moderation_text_request.rb +0 -330
- data/lib/moderation_api/models/moderation_video200_response.rb +0 -265
- data/lib/moderation_api/models/moderation_video_request.rb +0 -302
- data/lib/moderation_api/webhook.rb +0 -41
- data/moderation_api-1.2.0.gem +0 -0
- data/moderation_api-1.2.1.gem +0 -0
- data/moderation_api.gemspec +0 -45
- data/ruby_config.yaml +0 -30
- data/spec/api/account_api_spec.rb +0 -46
- data/spec/api/moderate_api_spec.rb +0 -95
- data/spec/api/queue_actions_api_spec.rb +0 -121
- data/spec/models/account_get200_response_current_project_spec.rb +0 -42
- data/spec/models/account_get200_response_spec.rb +0 -60
- data/spec/models/actions_create_request_spec.rb +0 -98
- data/spec/models/actions_create_request_webhooks_inner_spec.rb +0 -54
- data/spec/models/actions_delete200_response_spec.rb +0 -42
- data/spec/models/actions_execute200_response_spec.rb +0 -48
- data/spec/models/actions_execute_deprecated_request_spec.rb +0 -48
- data/spec/models/actions_execute_request_spec.rb +0 -54
- data/spec/models/actions_get200_response_spec.rb +0 -110
- data/spec/models/actions_get200_response_webhooks_inner_spec.rb +0 -60
- data/spec/models/actions_list200_response_inner_possible_values_inner_spec.rb +0 -36
- data/spec/models/actions_list200_response_inner_spec.rb +0 -104
- data/spec/models/actions_list400_response_issues_inner_spec.rb +0 -36
- data/spec/models/actions_list400_response_spec.rb +0 -48
- data/spec/models/actions_update_request_spec.rb +0 -98
- data/spec/models/moderation_audio_request_spec.rb +0 -66
- data/spec/models/moderation_image200_response_labels_inner_spec.rb +0 -46
- data/spec/models/moderation_image200_response_spec.rb +0 -66
- data/spec/models/moderation_image_request_spec.rb +0 -66
- data/spec/models/moderation_object200_response_all_of_entities_inner_spec.rb +0 -48
- data/spec/models/moderation_object200_response_all_of_fields_inner_spec.rb +0 -48
- data/spec/models/moderation_object200_response_all_of_labels_inner_spec.rb +0 -48
- data/spec/models/moderation_object200_response_spec.rb +0 -90
- data/spec/models/moderation_object_request_spec.rb +0 -66
- data/spec/models/moderation_object_request_value_data_value_spec.rb +0 -52
- data/spec/models/moderation_object_request_value_spec.rb +0 -46
- data/spec/models/moderation_text200_response_all_of_address_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_email_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_name_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_nsfw_label_scores_spec.rb +0 -48
- data/spec/models/moderation_text200_response_all_of_nsfw_spec.rb +0 -60
- data/spec/models/moderation_text200_response_all_of_phone_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_profanity_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_propriety_label_scores_spec.rb +0 -48
- data/spec/models/moderation_text200_response_all_of_propriety_spec.rb +0 -60
- data/spec/models/moderation_text200_response_all_of_quality_label_scores_spec.rb +0 -54
- data/spec/models/moderation_text200_response_all_of_quality_spec.rb +0 -60
- data/spec/models/moderation_text200_response_all_of_request_spec.rb +0 -42
- data/spec/models/moderation_text200_response_all_of_sensitive_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_sentiment_label_scores_spec.rb +0 -48
- data/spec/models/moderation_text200_response_all_of_sentiment_spec.rb +0 -60
- data/spec/models/moderation_text200_response_all_of_toxicity_label_scores_spec.rb +0 -72
- data/spec/models/moderation_text200_response_all_of_toxicity_spec.rb +0 -60
- data/spec/models/moderation_text200_response_all_of_url_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_username_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_wordlist_spec.rb +0 -70
- data/spec/models/moderation_text200_response_all_of_wordlists_inner_spec.rb +0 -94
- data/spec/models/moderation_text200_response_spec.rb +0 -174
- data/spec/models/moderation_text_request_spec.rb +0 -66
- data/spec/models/moderation_video200_response_spec.rb +0 -54
- data/spec/models/moderation_video_request_spec.rb +0 -66
- data/spec/spec_helper.rb +0 -111
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ModerationAPI
|
|
4
|
+
module Internal
|
|
5
|
+
module Transport
|
|
6
|
+
# @api private
|
|
7
|
+
#
|
|
8
|
+
# @abstract
|
|
9
|
+
class BaseClient
|
|
10
|
+
extend ModerationAPI::Internal::Util::SorbetRuntimeSupport
|
|
11
|
+
|
|
12
|
+
# from whatwg fetch spec
|
|
13
|
+
MAX_REDIRECTS = 20
|
|
14
|
+
|
|
15
|
+
# rubocop:disable Style/MutableConstant
|
|
16
|
+
PLATFORM_HEADERS =
|
|
17
|
+
{
|
|
18
|
+
"x-stainless-arch" => ModerationAPI::Internal::Util.arch,
|
|
19
|
+
"x-stainless-lang" => "ruby",
|
|
20
|
+
"x-stainless-os" => ModerationAPI::Internal::Util.os,
|
|
21
|
+
"x-stainless-package-version" => ModerationAPI::VERSION,
|
|
22
|
+
"x-stainless-runtime" => ::RUBY_ENGINE,
|
|
23
|
+
"x-stainless-runtime-version" => ::RUBY_ENGINE_VERSION
|
|
24
|
+
}
|
|
25
|
+
# rubocop:enable Style/MutableConstant
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
# @api private
|
|
29
|
+
#
|
|
30
|
+
# @param req [Hash{Symbol=>Object}]
|
|
31
|
+
#
|
|
32
|
+
# @raise [ArgumentError]
|
|
33
|
+
def validate!(req)
|
|
34
|
+
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
|
|
35
|
+
case req
|
|
36
|
+
in Hash
|
|
37
|
+
req.each_key do |k|
|
|
38
|
+
unless keys.include?(k)
|
|
39
|
+
raise ArgumentError.new("Request `req` keys must be one of #{keys}, got #{k.inspect}")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
raise ArgumentError.new("Request `req` must be a Hash or RequestOptions, got #{req.inspect}")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @api private
|
|
48
|
+
#
|
|
49
|
+
# @param status [Integer]
|
|
50
|
+
# @param headers [Hash{String=>String}]
|
|
51
|
+
#
|
|
52
|
+
# @return [Boolean]
|
|
53
|
+
def should_retry?(status, headers:)
|
|
54
|
+
coerced = ModerationAPI::Internal::Util.coerce_boolean(headers["x-should-retry"])
|
|
55
|
+
case [coerced, status]
|
|
56
|
+
in [true | false, _]
|
|
57
|
+
coerced
|
|
58
|
+
in [_, 408 | 409 | 429 | (500..)]
|
|
59
|
+
# retry on:
|
|
60
|
+
# 408: timeouts
|
|
61
|
+
# 409: locks
|
|
62
|
+
# 429: rate limits
|
|
63
|
+
# 500+: unknown errors
|
|
64
|
+
true
|
|
65
|
+
else
|
|
66
|
+
false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @api private
|
|
71
|
+
#
|
|
72
|
+
# @param request [Hash{Symbol=>Object}] .
|
|
73
|
+
#
|
|
74
|
+
# @option request [Symbol] :method
|
|
75
|
+
#
|
|
76
|
+
# @option request [URI::Generic] :url
|
|
77
|
+
#
|
|
78
|
+
# @option request [Hash{String=>String}] :headers
|
|
79
|
+
#
|
|
80
|
+
# @option request [Object] :body
|
|
81
|
+
#
|
|
82
|
+
# @option request [Integer] :max_retries
|
|
83
|
+
#
|
|
84
|
+
# @option request [Float] :timeout
|
|
85
|
+
#
|
|
86
|
+
# @param status [Integer]
|
|
87
|
+
#
|
|
88
|
+
# @param response_headers [Hash{String=>String}]
|
|
89
|
+
#
|
|
90
|
+
# @return [Hash{Symbol=>Object}]
|
|
91
|
+
def follow_redirect(request, status:, response_headers:)
|
|
92
|
+
method, url, headers = request.fetch_values(:method, :url, :headers)
|
|
93
|
+
location =
|
|
94
|
+
Kernel.then do
|
|
95
|
+
URI.join(url, response_headers["location"])
|
|
96
|
+
rescue ArgumentError
|
|
97
|
+
message = "Server responded with status #{status} but no valid location header."
|
|
98
|
+
raise ModerationAPI::Errors::APIConnectionError.new(
|
|
99
|
+
url: url,
|
|
100
|
+
response: response_headers,
|
|
101
|
+
message: message
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
request = {**request, url: location}
|
|
106
|
+
|
|
107
|
+
case [url.scheme, location.scheme]
|
|
108
|
+
in ["https", "http"]
|
|
109
|
+
message = "Tried to redirect to a insecure URL"
|
|
110
|
+
raise ModerationAPI::Errors::APIConnectionError.new(
|
|
111
|
+
url: url,
|
|
112
|
+
response: response_headers,
|
|
113
|
+
message: message
|
|
114
|
+
)
|
|
115
|
+
else
|
|
116
|
+
nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# from whatwg fetch spec
|
|
120
|
+
case [status, method]
|
|
121
|
+
in [301 | 302, :post] | [303, _]
|
|
122
|
+
drop = %w[content-encoding content-language content-length content-location content-type]
|
|
123
|
+
request = {
|
|
124
|
+
**request,
|
|
125
|
+
method: method == :head ? :head : :get,
|
|
126
|
+
headers: headers.except(*drop),
|
|
127
|
+
body: nil
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# from undici
|
|
133
|
+
if ModerationAPI::Internal::Util.uri_origin(url) != ModerationAPI::Internal::Util.uri_origin(location)
|
|
134
|
+
drop = %w[authorization cookie host proxy-authorization]
|
|
135
|
+
request = {**request, headers: request.fetch(:headers).except(*drop)}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
request
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# @api private
|
|
142
|
+
#
|
|
143
|
+
# @param status [Integer, ModerationAPI::Errors::APIConnectionError]
|
|
144
|
+
# @param stream [Enumerable<String>, nil]
|
|
145
|
+
def reap_connection!(status, stream:)
|
|
146
|
+
case status
|
|
147
|
+
in (..199) | (300..499)
|
|
148
|
+
stream&.each { next }
|
|
149
|
+
in ModerationAPI::Errors::APIConnectionError | (500..)
|
|
150
|
+
ModerationAPI::Internal::Util.close_fused!(stream)
|
|
151
|
+
else
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# @return [URI::Generic]
|
|
157
|
+
attr_reader :base_url
|
|
158
|
+
|
|
159
|
+
# @return [Float]
|
|
160
|
+
attr_reader :timeout
|
|
161
|
+
|
|
162
|
+
# @return [Integer]
|
|
163
|
+
attr_reader :max_retries
|
|
164
|
+
|
|
165
|
+
# @return [Float]
|
|
166
|
+
attr_reader :initial_retry_delay
|
|
167
|
+
|
|
168
|
+
# @return [Float]
|
|
169
|
+
attr_reader :max_retry_delay
|
|
170
|
+
|
|
171
|
+
# @return [Hash{String=>String}]
|
|
172
|
+
attr_reader :headers
|
|
173
|
+
|
|
174
|
+
# @return [String, nil]
|
|
175
|
+
attr_reader :idempotency_header
|
|
176
|
+
|
|
177
|
+
# @api private
|
|
178
|
+
# @return [ModerationAPI::Internal::Transport::PooledNetRequester]
|
|
179
|
+
attr_reader :requester
|
|
180
|
+
|
|
181
|
+
# @api private
|
|
182
|
+
#
|
|
183
|
+
# @param base_url [String]
|
|
184
|
+
# @param timeout [Float]
|
|
185
|
+
# @param max_retries [Integer]
|
|
186
|
+
# @param initial_retry_delay [Float]
|
|
187
|
+
# @param max_retry_delay [Float]
|
|
188
|
+
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
|
|
189
|
+
# @param idempotency_header [String, nil]
|
|
190
|
+
def initialize(
|
|
191
|
+
base_url:,
|
|
192
|
+
timeout: 0.0,
|
|
193
|
+
max_retries: 0,
|
|
194
|
+
initial_retry_delay: 0.0,
|
|
195
|
+
max_retry_delay: 0.0,
|
|
196
|
+
headers: {},
|
|
197
|
+
idempotency_header: nil
|
|
198
|
+
)
|
|
199
|
+
@requester = ModerationAPI::Internal::Transport::PooledNetRequester.new
|
|
200
|
+
@headers = ModerationAPI::Internal::Util.normalized_headers(
|
|
201
|
+
self.class::PLATFORM_HEADERS,
|
|
202
|
+
{
|
|
203
|
+
"accept" => "application/json",
|
|
204
|
+
"content-type" => "application/json",
|
|
205
|
+
"user-agent" => user_agent
|
|
206
|
+
},
|
|
207
|
+
headers
|
|
208
|
+
)
|
|
209
|
+
@base_url_components = ModerationAPI::Internal::Util.parse_uri(base_url)
|
|
210
|
+
@base_url = ModerationAPI::Internal::Util.unparse_uri(@base_url_components)
|
|
211
|
+
@idempotency_header = idempotency_header&.to_s&.downcase
|
|
212
|
+
@timeout = timeout
|
|
213
|
+
@max_retries = max_retries
|
|
214
|
+
@initial_retry_delay = initial_retry_delay
|
|
215
|
+
@max_retry_delay = max_retry_delay
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# @api private
|
|
219
|
+
#
|
|
220
|
+
# @return [Hash{String=>String}]
|
|
221
|
+
private def auth_headers = {}
|
|
222
|
+
|
|
223
|
+
# @api private
|
|
224
|
+
#
|
|
225
|
+
# @return [String]
|
|
226
|
+
private def user_agent = "#{self.class.name}/Ruby #{ModerationAPI::VERSION}"
|
|
227
|
+
|
|
228
|
+
# @api private
|
|
229
|
+
#
|
|
230
|
+
# @return [String]
|
|
231
|
+
private def generate_idempotency_key = "stainless-ruby-retry-#{SecureRandom.uuid}"
|
|
232
|
+
|
|
233
|
+
# @api private
|
|
234
|
+
#
|
|
235
|
+
# @param req [Hash{Symbol=>Object}] .
|
|
236
|
+
#
|
|
237
|
+
# @option req [Symbol] :method
|
|
238
|
+
#
|
|
239
|
+
# @option req [String, Array<String>] :path
|
|
240
|
+
#
|
|
241
|
+
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
|
|
242
|
+
#
|
|
243
|
+
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
|
|
244
|
+
#
|
|
245
|
+
# @option req [Object, nil] :body
|
|
246
|
+
#
|
|
247
|
+
# @option req [Symbol, Integer, Array<Symbol, Integer>, Proc, nil] :unwrap
|
|
248
|
+
#
|
|
249
|
+
# @option req [Class<ModerationAPI::Internal::Type::BasePage>, nil] :page
|
|
250
|
+
#
|
|
251
|
+
# @option req [Class<ModerationAPI::Internal::Type::BaseStream>, nil] :stream
|
|
252
|
+
#
|
|
253
|
+
# @option req [ModerationAPI::Internal::Type::Converter, Class, nil] :model
|
|
254
|
+
#
|
|
255
|
+
# @param opts [Hash{Symbol=>Object}] .
|
|
256
|
+
#
|
|
257
|
+
# @option opts [String, nil] :idempotency_key
|
|
258
|
+
#
|
|
259
|
+
# @option opts [Hash{String=>Array<String>, String, nil}, nil] :extra_query
|
|
260
|
+
#
|
|
261
|
+
# @option opts [Hash{String=>String, nil}, nil] :extra_headers
|
|
262
|
+
#
|
|
263
|
+
# @option opts [Object, nil] :extra_body
|
|
264
|
+
#
|
|
265
|
+
# @option opts [Integer, nil] :max_retries
|
|
266
|
+
#
|
|
267
|
+
# @option opts [Float, nil] :timeout
|
|
268
|
+
#
|
|
269
|
+
# @return [Hash{Symbol=>Object}]
|
|
270
|
+
private def build_request(req, opts)
|
|
271
|
+
method, uninterpolated_path = req.fetch_values(:method, :path)
|
|
272
|
+
|
|
273
|
+
path = ModerationAPI::Internal::Util.interpolate_path(uninterpolated_path)
|
|
274
|
+
|
|
275
|
+
query = ModerationAPI::Internal::Util.deep_merge(req[:query].to_h, opts[:extra_query].to_h)
|
|
276
|
+
|
|
277
|
+
headers = ModerationAPI::Internal::Util.normalized_headers(
|
|
278
|
+
@headers,
|
|
279
|
+
auth_headers,
|
|
280
|
+
req[:headers].to_h,
|
|
281
|
+
opts[:extra_headers].to_h
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
if @idempotency_header &&
|
|
285
|
+
!headers.key?(@idempotency_header) &&
|
|
286
|
+
(!Net::HTTP::IDEMPOTENT_METHODS_.include?(method.to_s.upcase) || opts.key?(:idempotency_key))
|
|
287
|
+
headers[@idempotency_header] = opts.fetch(:idempotency_key) { generate_idempotency_key }
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
unless headers.key?("x-stainless-retry-count")
|
|
291
|
+
headers["x-stainless-retry-count"] = "0"
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
timeout = opts.fetch(:timeout, @timeout).to_f.clamp(0..)
|
|
295
|
+
unless headers.key?("x-stainless-timeout") || timeout.zero?
|
|
296
|
+
headers["x-stainless-timeout"] = timeout.to_s
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
headers.reject! { |_, v| v.to_s.empty? }
|
|
300
|
+
|
|
301
|
+
body =
|
|
302
|
+
case method
|
|
303
|
+
in :get | :head | :options | :trace
|
|
304
|
+
nil
|
|
305
|
+
else
|
|
306
|
+
ModerationAPI::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
url = ModerationAPI::Internal::Util.join_parsed_uri(
|
|
310
|
+
@base_url_components,
|
|
311
|
+
{**req, path: path, query: query}
|
|
312
|
+
)
|
|
313
|
+
headers, encoded = ModerationAPI::Internal::Util.encode_content(headers, body)
|
|
314
|
+
{
|
|
315
|
+
method: method,
|
|
316
|
+
url: url,
|
|
317
|
+
headers: headers,
|
|
318
|
+
body: encoded,
|
|
319
|
+
max_retries: opts.fetch(:max_retries, @max_retries),
|
|
320
|
+
timeout: timeout
|
|
321
|
+
}
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# @api private
|
|
325
|
+
#
|
|
326
|
+
# @param headers [Hash{String=>String}]
|
|
327
|
+
# @param retry_count [Integer]
|
|
328
|
+
#
|
|
329
|
+
# @return [Float]
|
|
330
|
+
private def retry_delay(headers, retry_count:)
|
|
331
|
+
# Non-standard extension
|
|
332
|
+
span = Float(headers["retry-after-ms"], exception: false)&.then { _1 / 1000 }
|
|
333
|
+
return span if span
|
|
334
|
+
|
|
335
|
+
retry_header = headers["retry-after"]
|
|
336
|
+
return span if (span = Float(retry_header, exception: false))
|
|
337
|
+
|
|
338
|
+
span = retry_header&.then do
|
|
339
|
+
Time.httpdate(_1) - Time.now
|
|
340
|
+
rescue ArgumentError
|
|
341
|
+
nil
|
|
342
|
+
end
|
|
343
|
+
return span if span
|
|
344
|
+
|
|
345
|
+
scale = retry_count**2
|
|
346
|
+
jitter = 1 - (0.25 * rand)
|
|
347
|
+
(@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# @api private
|
|
351
|
+
#
|
|
352
|
+
# @param request [Hash{Symbol=>Object}] .
|
|
353
|
+
#
|
|
354
|
+
# @option request [Symbol] :method
|
|
355
|
+
#
|
|
356
|
+
# @option request [URI::Generic] :url
|
|
357
|
+
#
|
|
358
|
+
# @option request [Hash{String=>String}] :headers
|
|
359
|
+
#
|
|
360
|
+
# @option request [Object] :body
|
|
361
|
+
#
|
|
362
|
+
# @option request [Integer] :max_retries
|
|
363
|
+
#
|
|
364
|
+
# @option request [Float] :timeout
|
|
365
|
+
#
|
|
366
|
+
# @param redirect_count [Integer]
|
|
367
|
+
#
|
|
368
|
+
# @param retry_count [Integer]
|
|
369
|
+
#
|
|
370
|
+
# @param send_retry_header [Boolean]
|
|
371
|
+
#
|
|
372
|
+
# @raise [ModerationAPI::Errors::APIError]
|
|
373
|
+
# @return [Array(Integer, Net::HTTPResponse, Enumerable<String>)]
|
|
374
|
+
def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
|
375
|
+
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
|
376
|
+
input = {**request.except(:timeout), deadline: ModerationAPI::Internal::Util.monotonic_secs + timeout}
|
|
377
|
+
|
|
378
|
+
if send_retry_header
|
|
379
|
+
headers["x-stainless-retry-count"] = retry_count.to_s
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
begin
|
|
383
|
+
status, response, stream = @requester.execute(input)
|
|
384
|
+
rescue ModerationAPI::Errors::APIConnectionError => e
|
|
385
|
+
status = e
|
|
386
|
+
end
|
|
387
|
+
headers = ModerationAPI::Internal::Util.normalized_headers(response&.each_header&.to_h)
|
|
388
|
+
|
|
389
|
+
case status
|
|
390
|
+
in ..299
|
|
391
|
+
[status, response, stream]
|
|
392
|
+
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
|
393
|
+
self.class.reap_connection!(status, stream: stream)
|
|
394
|
+
|
|
395
|
+
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
|
396
|
+
raise ModerationAPI::Errors::APIConnectionError.new(
|
|
397
|
+
url: url,
|
|
398
|
+
response: response,
|
|
399
|
+
message: message
|
|
400
|
+
)
|
|
401
|
+
in 300..399
|
|
402
|
+
self.class.reap_connection!(status, stream: stream)
|
|
403
|
+
|
|
404
|
+
request = self.class.follow_redirect(request, status: status, response_headers: headers)
|
|
405
|
+
send_request(
|
|
406
|
+
request,
|
|
407
|
+
redirect_count: redirect_count + 1,
|
|
408
|
+
retry_count: retry_count,
|
|
409
|
+
send_retry_header: send_retry_header
|
|
410
|
+
)
|
|
411
|
+
in ModerationAPI::Errors::APIConnectionError if retry_count >= max_retries
|
|
412
|
+
raise status
|
|
413
|
+
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: headers)
|
|
414
|
+
decoded = Kernel.then do
|
|
415
|
+
ModerationAPI::Internal::Util.decode_content(headers, stream: stream, suppress_error: true)
|
|
416
|
+
ensure
|
|
417
|
+
self.class.reap_connection!(status, stream: stream)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
raise ModerationAPI::Errors::APIStatusError.for(
|
|
421
|
+
url: url,
|
|
422
|
+
status: status,
|
|
423
|
+
headers: headers,
|
|
424
|
+
body: decoded,
|
|
425
|
+
request: nil,
|
|
426
|
+
response: response
|
|
427
|
+
)
|
|
428
|
+
in (400..) | ModerationAPI::Errors::APIConnectionError
|
|
429
|
+
self.class.reap_connection!(status, stream: stream)
|
|
430
|
+
|
|
431
|
+
delay = retry_delay(response || {}, retry_count: retry_count)
|
|
432
|
+
sleep(delay)
|
|
433
|
+
|
|
434
|
+
send_request(
|
|
435
|
+
request,
|
|
436
|
+
redirect_count: redirect_count,
|
|
437
|
+
retry_count: retry_count + 1,
|
|
438
|
+
send_retry_header: send_retry_header
|
|
439
|
+
)
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
# Execute the request specified by `req`. This is the method that all resource
|
|
444
|
+
# methods call into.
|
|
445
|
+
#
|
|
446
|
+
# @overload request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: ModerationAPI::Internal::Type::Unknown, options: {})
|
|
447
|
+
#
|
|
448
|
+
# @param method [Symbol]
|
|
449
|
+
#
|
|
450
|
+
# @param path [String, Array<String>]
|
|
451
|
+
#
|
|
452
|
+
# @param query [Hash{String=>Array<String>, String, nil}, nil]
|
|
453
|
+
#
|
|
454
|
+
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil]
|
|
455
|
+
#
|
|
456
|
+
# @param body [Object, nil]
|
|
457
|
+
#
|
|
458
|
+
# @param unwrap [Symbol, Integer, Array<Symbol, Integer>, Proc, nil]
|
|
459
|
+
#
|
|
460
|
+
# @param page [Class<ModerationAPI::Internal::Type::BasePage>, nil]
|
|
461
|
+
#
|
|
462
|
+
# @param stream [Class<ModerationAPI::Internal::Type::BaseStream>, nil]
|
|
463
|
+
#
|
|
464
|
+
# @param model [ModerationAPI::Internal::Type::Converter, Class, nil]
|
|
465
|
+
#
|
|
466
|
+
# @param options [ModerationAPI::RequestOptions, Hash{Symbol=>Object}, nil] .
|
|
467
|
+
#
|
|
468
|
+
# @option options [String, nil] :idempotency_key
|
|
469
|
+
#
|
|
470
|
+
# @option options [Hash{String=>Array<String>, String, nil}, nil] :extra_query
|
|
471
|
+
#
|
|
472
|
+
# @option options [Hash{String=>String, nil}, nil] :extra_headers
|
|
473
|
+
#
|
|
474
|
+
# @option options [Object, nil] :extra_body
|
|
475
|
+
#
|
|
476
|
+
# @option options [Integer, nil] :max_retries
|
|
477
|
+
#
|
|
478
|
+
# @option options [Float, nil] :timeout
|
|
479
|
+
#
|
|
480
|
+
# @raise [ModerationAPI::Errors::APIError]
|
|
481
|
+
# @return [Object]
|
|
482
|
+
def request(req)
|
|
483
|
+
self.class.validate!(req)
|
|
484
|
+
model = req.fetch(:model) { ModerationAPI::Internal::Type::Unknown }
|
|
485
|
+
opts = req[:options].to_h
|
|
486
|
+
unwrap = req[:unwrap]
|
|
487
|
+
ModerationAPI::RequestOptions.validate!(opts)
|
|
488
|
+
request = build_request(req.except(:options), opts)
|
|
489
|
+
url = request.fetch(:url)
|
|
490
|
+
|
|
491
|
+
# Don't send the current retry count in the headers if the caller modified the header defaults.
|
|
492
|
+
send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
|
|
493
|
+
status, response, stream = send_request(
|
|
494
|
+
request,
|
|
495
|
+
redirect_count: 0,
|
|
496
|
+
retry_count: 0,
|
|
497
|
+
send_retry_header: send_retry_header
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
headers = ModerationAPI::Internal::Util.normalized_headers(response.each_header.to_h)
|
|
501
|
+
decoded = ModerationAPI::Internal::Util.decode_content(headers, stream: stream)
|
|
502
|
+
case req
|
|
503
|
+
in {stream: Class => st}
|
|
504
|
+
st.new(
|
|
505
|
+
model: model,
|
|
506
|
+
url: url,
|
|
507
|
+
status: status,
|
|
508
|
+
headers: headers,
|
|
509
|
+
response: response,
|
|
510
|
+
unwrap: unwrap,
|
|
511
|
+
stream: decoded
|
|
512
|
+
)
|
|
513
|
+
in {page: Class => page}
|
|
514
|
+
page.new(client: self, req: req, headers: headers, page_data: decoded)
|
|
515
|
+
else
|
|
516
|
+
unwrapped = ModerationAPI::Internal::Util.dig(decoded, unwrap)
|
|
517
|
+
ModerationAPI::Internal::Type::Converter.coerce(model, unwrapped)
|
|
518
|
+
end
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# @api private
|
|
522
|
+
#
|
|
523
|
+
# @return [String]
|
|
524
|
+
def inspect
|
|
525
|
+
# rubocop:disable Layout/LineLength
|
|
526
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{@base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
|
|
527
|
+
# rubocop:enable Layout/LineLength
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
define_sorbet_constant!(:RequestComponents) do
|
|
531
|
+
T.type_alias do
|
|
532
|
+
{
|
|
533
|
+
method: Symbol,
|
|
534
|
+
path: T.any(String, T::Array[String]),
|
|
535
|
+
query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
|
|
536
|
+
headers: T.nilable(
|
|
537
|
+
T::Hash[String,
|
|
538
|
+
T.nilable(
|
|
539
|
+
T.any(
|
|
540
|
+
String,
|
|
541
|
+
Integer,
|
|
542
|
+
T::Array[T.nilable(T.any(String, Integer))]
|
|
543
|
+
)
|
|
544
|
+
)]
|
|
545
|
+
),
|
|
546
|
+
body: T.nilable(T.anything),
|
|
547
|
+
unwrap: T.nilable(
|
|
548
|
+
T.any(
|
|
549
|
+
Symbol,
|
|
550
|
+
Integer,
|
|
551
|
+
T::Array[T.any(Symbol, Integer)],
|
|
552
|
+
T.proc.params(arg0: T.anything).returns(T.anything)
|
|
553
|
+
)
|
|
554
|
+
),
|
|
555
|
+
page: T.nilable(T::Class[ModerationAPI::Internal::Type::BasePage[ModerationAPI::Internal::Type::BaseModel]]),
|
|
556
|
+
stream: T.nilable(T::Class[T.anything]),
|
|
557
|
+
model: T.nilable(ModerationAPI::Internal::Type::Converter::Input),
|
|
558
|
+
options: T.nilable(ModerationAPI::RequestOptions::OrHash)
|
|
559
|
+
}
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
define_sorbet_constant!(:RequestInput) do
|
|
563
|
+
T.type_alias do
|
|
564
|
+
{
|
|
565
|
+
method: Symbol,
|
|
566
|
+
url: URI::Generic,
|
|
567
|
+
headers: T::Hash[String, String],
|
|
568
|
+
body: T.anything,
|
|
569
|
+
max_retries: Integer,
|
|
570
|
+
timeout: Float
|
|
571
|
+
}
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
end
|
|
576
|
+
end
|
|
577
|
+
end
|