From cdc61534a8e8fa96c0a2da5cf75f95521059a9eb Mon Sep 17 00:00:00 2001 From: Jessica Ho Date: Tue, 20 Dec 2022 02:26:59 -0800 Subject: [PATCH] docs: uploads snippets --- CODE_SNIPPETS.md | 203 ++++++++++++++++++++++-- lib/Api/UploadsApi.php | 2 +- test/Integration/UploadsApiSpecTest.php | 4 +- 3 files changed, 189 insertions(+), 20 deletions(-) diff --git a/CODE_SNIPPETS.md b/CODE_SNIPPETS.md index 65cffd5..e363e06 100644 --- a/CODE_SNIPPETS.md +++ b/CODE_SNIPPETS.md @@ -100,7 +100,7 @@ $apiInstance = new OpenAPI\Client\Api\AddressesApi($config, new GuzzleHttp\Clien try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -259,7 +259,7 @@ $apiInstance = new OpenAPI\Client\Api\PostcardsApi($config, new GuzzleHttp\Clien try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -378,7 +378,7 @@ $apiInstance = new OpenAPI\Client\Api\SelfMailersApi($config, new GuzzleHttp\Cli try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -503,7 +503,7 @@ $apiInstance = new OpenAPI\Client\Api\LettersApi($config, new GuzzleHttp\Client( try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -628,7 +628,7 @@ $apiInstance = new OpenAPI\Client\Api\ChecksApi($config, new GuzzleHttp\Client() try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -692,7 +692,7 @@ $apiInstance = new OpenAPI\Client\Api\BankAccountsApi($config, new GuzzleHttp\Cl try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -706,9 +706,9 @@ try { ### Verify ```bash curl https://api.lob.com/v1/bank_accounts/bank_dfceb4a2a05b57e/verify \ - -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ - -d "amounts[]=25" \ - -d "amounts[]=63" \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -d "amounts[]=25" \ + -d "amounts[]=63" \ ``` ```php @@ -821,7 +821,7 @@ $apiInstance = new OpenAPI\Client\Api\TemplatesApi($config, new GuzzleHttp\Clien try { $result = $apiInstance->list( - 2, // limit + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -941,8 +941,8 @@ $apiInstance = new OpenAPI\Client\Api\TemplateVersionsApi($config, new GuzzleHtt try { $result = $apiInstance->list( - tmpl_dadaaf7b76c9f25, // tmplId - 2, // limit + tmpl_dadaaf7b76c9f25, // tmplId + 2, // limit ); print_r($result); } catch (Exception $e) { @@ -1005,6 +1005,177 @@ try { } ``` +## Uploads Api + +### List +```bash +curl -X GET "https://api.lob.com/v1/uploads?limit=2" \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +try { + $result = $apiInstance->list_upload(); + print_r($result); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + + +### Retrieve Export +```bash +curl https://api.lob.com/v1/uploads/upl_71be866e430b11e9/exports/ex_6a94fe68fd151e0f8 \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -d "type=failures" +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +try { + $export = $apiInstance->get_export("upl_71be866e430b11e9", "ex_6a94fe68fd151e0f8"); + print_r($export); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + + +### Upload File + +```bash +curl -X POST https://api.lob.com/v1/uploads/upl_71be866e430b11e9/file \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -F file=@ +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); +$myFile = new \SplFileObject("", "r"); + +try { + $upload = $apiInstance->upload_file("upl_71be866e430b11e9", $myFile); + print_r($upload); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + +### Retrieve +```bash +curl https://api.lob.com/v1/uploads/upl_71be866e430b11e9 \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +try { + $result = $apiInstance->get_upload("upl_71be866e430b11e9"); + print_r($result); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + + + +### Create Export +```bash +curl https://api.lob.com/v1/uploads/upl_71be866e430b11e9/exports \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -d "type=failures" +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +$exportModel = new ExportModel(); +$exportModel->setType("all"); + +try { + $export = $apiInstance->create_export("upl_71be866e430b11e9", $exportModel); + print_r($export); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + + +### Update +```bash +curl -X PATCH https://api.lob.com/v1/upl_71be866e430b11e9 \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -d "state=Ready for Validation" \ +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +$uploadUpdatable = new OpenAPI\Client\Model\UploadUpdatable(); + +$requiredAddressColumnMapping = new OpenAPI\Client\Model\RequiredAddressColumnMapping(); +$requiredAddressColumnMapping->setName("recipient"); +$requiredAddressColumnMapping->setAddressLine1("primary line"); +$requiredAddressColumnMapping->setAddressCity("city"); +$requiredAddressColumnMapping->setAddressState("state"); +$requiredAddressColumnMapping->setAddressZip("zip_code"); + +$uploadUpdatable->setRequiredAddressColumnMapping($requiredAddressColumnMapping); + +try { + $result = $apiInstance->update_upload("upl_71be866e430b11e9", $uploadUpdatable); + print_r($result); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + +### Create +```bash +curl https://api.lob.com/v1/uploads \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \ + -d "campaignId=cmp_e05ee61ff80764b" \ +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); +$upload_writable = new OpenAPI\Client\Model\UploadWritable(); +$upload_writable->setCampaignId("cmp_e05ee61ff80764b"); + +try { + $result = $apiInstance->create_upload($upload_writable); + print_r($result); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` + + +### Delete +```bash +curl -X DELETE "https://api.lob.com/v1/uploads/upl_71be866e430b11e9" \ + -u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: +``` + +```php +$apiInstance = new OpenAPI\Client\Api\UploadsApi($config, new GuzzleHttp\Client()); + +try { + $result = $apiInstance->delete_upload("upl_71be866e430b11e9"); + print_r($result); +} catch (Exception $e) { + echo $e->getMessage(), PHP_EOL; +} +``` ## IntlVerifications Api @@ -1056,14 +1227,14 @@ curl https://api.lob.com/v1/bulk/intl_verifications \ ```php -$verificationData0 = new OpenAPI\Client\Model\MultipleComponentsIntl(array( +$verificationData0 = new OpenAPI\Client\Model\MultipleComponentsIntl(array( 'primary_line' => '35 Tower Hill', 'city' => 'London', 'postal_code' => 'EC3N 4DR', 'country' => 'GB', )); -$verificationData1 = new OpenAPI\Client\Model\MultipleComponentsIntl(array( +$verificationData1 = new OpenAPI\Client\Model\MultipleComponentsIntl(array( 'primary_line' => '370 Water St', 'city' => 'Summerside', 'state' => 'Prince Edward Island', @@ -1105,14 +1276,14 @@ curl https://api.lob.com/v1/bulk/us_verifications \ ```php -$verificationData0 = new OpenAPI\Client\Model\MultipleComponents(array( +$verificationData0 = new OpenAPI\Client\Model\MultipleComponents(array( 'primary_line' => '210 King Street', 'city' => 'San Francisco', 'state' => 'CA', 'zip_code' => '94017', )); -$verificationData1 = new OpenAPI\Client\Model\MultipleComponents(array( +$verificationData1 = new OpenAPI\Client\Model\MultipleComponents(array( 'primary_line' => '185 BERRY ST STE 6600', 'city' => 'SAN FRANCISCO', 'state' => 'CA', diff --git a/lib/Api/UploadsApi.php b/lib/Api/UploadsApi.php index 12de2ae..fe53e1b 100755 --- a/lib/Api/UploadsApi.php +++ b/lib/Api/UploadsApi.php @@ -811,7 +811,7 @@ public function upload_fileWithHttpInfo($upl_id, $file) [ 'multipart' => [[ 'name' => 'file', - 'contents' => Utils::tryFopen('/Users/jessica-ho/Desktop/lob-php/test/assets/lobster-family.csv', 'r') + 'contents' => Utils::tryFopen($file, 'r') ]], 'auth' => $options['auth'] ] diff --git a/test/Integration/UploadsApiSpecTest.php b/test/Integration/UploadsApiSpecTest.php index f017ac2..3140c8e 100644 --- a/test/Integration/UploadsApiSpecTest.php +++ b/test/Integration/UploadsApiSpecTest.php @@ -192,9 +192,7 @@ public function testUploadFile() { try { $createdUpload = self::$uploadApi->create_upload(self::$uploadWritable); - $myFile = new \SplFileObject("test/assets/lobster-family.csv", "r"); - - $upload = self::$uploadApi->upload_file($createdUpload->getId(), $myFile); + $upload = self::$uploadApi->upload_file($createdUpload->getId(), "test/assets/lobster-family.csv"); $this->assertEquals("File uploaded successfully", $upload["message"]); // cleanup