Skip to content

Commit e15478f

Browse files
committed
feat: move code samples to spec
1 parent dc1d50c commit e15478f

File tree

6 files changed

+86
-91
lines changed

6 files changed

+86
-91
lines changed

spec/code_samples/PHP/me/get.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

spec/code_samples/PHP/scores/post.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

spec/code_samples/PHP/users@{user}@scores/get.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

spec/code_samples/Python/me/get.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

spec/code_samples/Python/scores/post.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

spec/openapi.yaml

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,38 @@ paths:
123123
- OAuth2:
124124
- account.public_profile
125125
- account.education_profile
126+
x-codeSamples:
127+
- lang: 'Python'
128+
source: |
129+
from pprint import pprint
130+
import os
131+
132+
import flat_api
133+
from flat_api.rest import ApiException
134+
135+
configuration = flat_api.Configuration()
136+
configuration.access_token = os.environ['FLAT_ACCESS_TOKEN']
137+
flat_api_client = flat_api.ApiClient(configuration)
138+
try:
139+
pprint(flat_api.AccountApi(flat_api_client).get_authenticated_user())
140+
except ApiException as e:
141+
print(e)
142+
- lang: 'PHP'
143+
source: |
144+
<?php
145+
require_once(__DIR__ . '/vendor/autoload.php');
146+
147+
// Configure OAuth2 access token
148+
Flat\APIClient\Configuration::getDefaultConfiguration()->setAccessToken($_ENV['FLAT_ACCESS_TOKEN']);
149+
150+
$api = new Flat\APIClient\Api\AccountApi();
151+
152+
try {
153+
$result = $api->getAuthenticatedUser();
154+
print_r($result);
155+
} catch (Exception $e) {
156+
echo 'Exception when calling AccountApi->getAuthenticatedUser: ', $e->getMessage(), PHP_EOL;
157+
}
126158
/scores:
127159
post:
128160
tags:
@@ -185,7 +217,7 @@ paths:
185217
source: |
186218
require 'flat_api'
187219
FlatApi.configure do |config|
188-
config.access_token = ''
220+
config.access_token = 'your_access_token'
189221
end
190222
begin
191223
score_data = File.open("my-score.musicxml", "r:UTF-8") { |f| f.read }
@@ -197,6 +229,59 @@ paths:
197229
rescue FlatApi::ApiError => e
198230
puts "Error when calling ScoreApi->create_score: #{e}"
199231
end
232+
- lang: 'Python'
233+
source: |
234+
from pprint import pprint
235+
import os
236+
from urllib.request import urlopen
237+
from urllib.error import HTTPError
238+
239+
import flat_api
240+
from flat_api.rest import ApiException
241+
242+
SCORE_TO_IMPORT='https://gist.githubusercontent.com/gierschv/938479bec2bbe8c39eebbc9e19d027a0/raw/2caa4fa312184412d0d544feb361f918869ceaa5/hello-world.xml'
243+
244+
configuration = flat_api.Configuration()
245+
configuration.access_token = os.environ['FLAT_ACCESS_TOKEN']
246+
flat_api_client = flat_api.ApiClient(configuration)
247+
248+
try:
249+
# Download a MusicXML "Hello World"
250+
hello_world = urlopen(SCORE_TO_IMPORT).read().decode('utf-8')
251+
252+
# The new score meta, including the MusicXML file as `data`
253+
new_score = flat_api.ScoreCreation(
254+
title='Hello World',
255+
privacy='private',
256+
data=hello_world
257+
)
258+
259+
# Create the document and print the meta returned by the API
260+
pprint(flat_api.ScoreApi(flat_api_client).create_score(new_score))
261+
except (ApiException, HTTPError) as e:
262+
print(e)
263+
- lang: 'PHP'
264+
source: |
265+
<?php
266+
require_once(__DIR__ . '/vendor/autoload.php');
267+
268+
// Configure OAuth2 access token
269+
Flat\APIClient\Configuration::getDefaultConfiguration()->setAccessToken($_ENV['FLAT_ACCESS_TOKEN']);
270+
271+
$musicXml = file_get_contents('https://gist.githubusercontent.com/gierschv/938479bec2bbe8c39eebbc9e19d027a0/raw/2caa4fa312184412d0d544feb361f918869ceaa5/hello-world.xml');
272+
273+
try {
274+
$body = new \Flat\APIClient\Model\ScoreCreation();
275+
$body->setTitle('Hello world');
276+
$body->setPrivacy('private');
277+
$body->setData($musicXml);
278+
279+
$scoreApi = new Flat\APIClient\Api\ScoreApi();
280+
$result = $scoreApi->createScore($body);
281+
print_r($result);
282+
} catch (Exception $e) {
283+
echo 'Exception when calling ScoreApi->createScore: ', $e->getMessage(), PHP_EOL;
284+
}
200285
/scores/{score}:
201286
parameters:
202287
- name: score

0 commit comments

Comments
 (0)