feat(api): add a curl example to the api_token creation
This commit is contained in:
parent
d4322bf947
commit
df031a7563
3 changed files with 50 additions and 1 deletions
22
app/assets/stylesheets/code_example.scss
Normal file
22
app/assets/stylesheets/code_example.scss
Normal file
|
@ -0,0 +1,22 @@
|
|||
@import "constants";
|
||||
@import "colors";
|
||||
|
||||
.code-example {
|
||||
background-color: var(--background-contrast-grey);
|
||||
|
||||
.example-header {
|
||||
display: flex;
|
||||
background-color: var(--background-alt-grey);
|
||||
align-items: center;
|
||||
|
||||
.lang {
|
||||
margin-right: auto;
|
||||
padding: $default-padding;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 0 $default-padding;
|
||||
}
|
||||
}
|
|
@ -30,6 +30,8 @@ module Administrateurs
|
|||
|
||||
@api_token.update!(name:, write_access:,
|
||||
allowed_procedure_ids:, authorized_networks:, expires_at:)
|
||||
|
||||
@curl_command = curl_command(@packed_token, @api_token.procedure_ids.first)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
@ -60,6 +62,16 @@ module Administrateurs
|
|||
|
||||
private
|
||||
|
||||
def curl_command(packed_token, procedure_id)
|
||||
<<~EOF
|
||||
curl \\
|
||||
-H 'Content-Type: application/json' \\
|
||||
-H 'Authorization: Bearer #{packed_token}' \\
|
||||
--data '{ "query": "{ demarche(number: #{procedure_id}) { title } }" }' \\
|
||||
'#{api_v2_graphql_url}'
|
||||
EOF
|
||||
end
|
||||
|
||||
def all_params
|
||||
[:name, :access, :target, :targets, :networkFiltering, :networks, :lifetime, :customLifetime]
|
||||
.index_with { |param| params[param] }
|
||||
|
|
|
@ -14,7 +14,22 @@
|
|||
|
||||
%p{ data: { controller: 'clipboard', clipboard_text_value: @packed_token } }
|
||||
%code= @packed_token
|
||||
%button.fr-btn.fr-btn-primary.fr-btn-small.fr-ml-2w{ data: { action: 'clipboard#copy' }, title: 'Copier dans le presse-papier' } Copier
|
||||
%button.fr-btn.fr-btn-primary.fr-btn-small.fr-ml-2w{ data: { action: 'clipboard#copy', clipboard_target: 'toHide' }, title: 'Copier dans le presse-papier' } Copier
|
||||
%button.fr-btn.fr-btn-primary.fr-btn-small.fr-ml-2w.hidden{ data: { clipboard_target: 'success' } } Copié !
|
||||
|
||||
%p.fr-mt-4w Voici un premier exemple d'utilisation de votre jeton d'API. Il vous permet de récupérer le titre de l'une de vos démarches :
|
||||
|
||||
.code-example{ data: { controller: 'clipboard', clipboard_text_value: @curl_command } }
|
||||
.example-header
|
||||
%span.lang bash
|
||||
%button.fr-btn.fr-btn--icon-left.fr-icon-clipboard-line.fr-btn--sm.fr-btn--tertiary-no-outline{ data: { action: 'clipboard#copy', clipboard_target: 'toHide' }, title: 'Copier dans le presse-papier' } Copier
|
||||
%button.fr-btn.fr-btn--icon-left.fr-icon-checkbox-line.fr-btn--sm.fr-btn--tertiary-no-outline.hidden{ data: { clipboard_target: 'success' } } Copié !
|
||||
%pre
|
||||
%code= @curl_command
|
||||
|
||||
%p.fr-text--sm.fr-text-mention--grey
|
||||
Pour continuer, vous pouvez consulter
|
||||
= link_to("notre documentation sur l'API", API_DOC_URL, **external_link_attributes)
|
||||
|
||||
%p.fr-mt-4w Résumé des informations du jeton :
|
||||
%ul
|
||||
|
|
Loading…
Reference in a new issue