File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ /** Get or create a new application */
2+ public function getOrCreate(
3+ ApplicationIn $applicationIn,
4+ ?ApplicationCreateOptions $options = null,
5+ ): ApplicationOut {
6+ $request = $this->client->newReq('POST', '/api/v1/app');
7+ if (null !== $options) {
8+ $request->setHeaderParam('idempotency-key', $options->idempotencyKey);
9+ }
10+ $request->setQueryParam("get_if_exists", "true");
11+ $request->setBody(json_encode($applicationIn));
12+ $res = $this->client->send($request);
13+
14+ return ApplicationOut::fromJson($res);
15+ }
Original file line number Diff line number Diff line change @@ -75,5 +75,8 @@ class {{ resource_type_name }}
7575 {% endif -%}
7676 }
7777
78+ {% set api_operation_extra -%} api_extra/{{ resource.name | to_snake_case }}_{{ op.name | to_snake_case }}.php{% endset %}
79+ {% include api_operation_extra ignore missing %}
80+
7881 {% endfor -%}
7982}
Original file line number Diff line number Diff line change @@ -48,6 +48,22 @@ public function create(
4848 return ApplicationOut::fromJson ($ res );
4949 }
5050
51+ /** Get or create a new application */
52+ public function getOrCreate (
53+ ApplicationIn $ applicationIn ,
54+ ?ApplicationCreateOptions $ options = null ,
55+ ): ApplicationOut {
56+ $ request = $ this ->client ->newReq ('POST ' , '/api/v1/app ' );
57+ if (null !== $ options ) {
58+ $ request ->setHeaderParam ('idempotency-key ' , $ options ->idempotencyKey );
59+ }
60+ $ request ->setQueryParam ('get_if_exists ' , 'true ' );
61+ $ request ->setBody (json_encode ($ applicationIn ));
62+ $ res = $ this ->client ->send ($ request );
63+
64+ return ApplicationOut::fromJson ($ res );
65+ }
66+
5167 /** Get an application. */
5268 public function get (
5369 string $ appId ,
Original file line number Diff line number Diff line change @@ -455,4 +455,18 @@ public function testEmptyAppPortalAccessInBody(): void
455455
456456 $ this ->assertEquals ('{} ' , $ rawBody );
457457 }
458+
459+ public function testGetOrCreate (): void
460+ {
461+ $ this ->mockHandler ->append (new Response (200 , [], AppOut));
462+
463+ $ svx = new \Svix \Svix ("super_secret " , httpClient: $ this ->httpClient );
464+
465+ $ svx ->application ->getOrCreate (ApplicationIn::create ("asd " ));
466+
467+ $ req = $ this ->requestHistory [0 ]['request ' ];
468+
469+ $ this ->assertEquals ('get_if_exists=true ' , $ req ->getUri ()->getQuery ());
470+ }
471+
458472}
You can’t perform that action at this time.
0 commit comments