From 049fc48fb4aa73ad935799bc679c6b4761c1d115 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Wed, 14 Feb 2024 04:38:34 -0600 Subject: [PATCH 1/3] feat: integrate JotForm API with SDK Added JotForm API integration in Laravel package. Defined API key configuration in 'config/jotform-sdk.php'. Updated 'JotformSDK' facade return type for clarity. Implemented `api` method in `JotformSDK` to provide access to JotForm API. Refactored 'JotformSDKServiceProvider' to register JotForm API as a singleton. Updated `composer.json` to include necessary packages for the integration. --- composer.json | 8 +++++--- config/jotform-sdk.php | 2 +- src/Facades/JotformSDK.php | 2 +- src/JotformSDK.php | 7 +++++++ src/JotformSDKServiceProvider.php | 18 +++++++++++++----- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index dd9660c..0262082 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,10 @@ ], "require": { "php": "^8.1", - "spatie/laravel-package-tools": "^1.14.0", - "illuminate/contracts": "^10.0" + "chrisreedio/jotform-api-php": "^1.0", + "illuminate/contracts": "^10.0", + "saloonphp/laravel-plugin": "^3.0", + "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { "laravel/pint": "^1.0", @@ -81,4 +83,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/config/jotform-sdk.php b/config/jotform-sdk.php index c0f2e06..3a650d8 100644 --- a/config/jotform-sdk.php +++ b/config/jotform-sdk.php @@ -2,5 +2,5 @@ // config for ChrisReedIO/JotformSDK return [ - + 'api_key' => env('JOTFORM_API_KEY'), ]; diff --git a/src/Facades/JotformSDK.php b/src/Facades/JotformSDK.php index 1a4032b..2a293cd 100644 --- a/src/Facades/JotformSDK.php +++ b/src/Facades/JotformSDK.php @@ -9,7 +9,7 @@ */ class JotformSDK extends Facade { - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return \ChrisReedIO\JotformSDK\JotformSDK::class; } diff --git a/src/JotformSDK.php b/src/JotformSDK.php index 9fb5621..559bec8 100755 --- a/src/JotformSDK.php +++ b/src/JotformSDK.php @@ -2,6 +2,13 @@ namespace ChrisReedIO\JotformSDK; +use Illuminate\Support\Facades\App; +use JotForm; + class JotformSDK { + public static function api(): JotForm + { + return App::make(JotForm::class); + } } diff --git a/src/JotformSDKServiceProvider.php b/src/JotformSDKServiceProvider.php index 4a1d5ad..0f5556c 100644 --- a/src/JotformSDKServiceProvider.php +++ b/src/JotformSDKServiceProvider.php @@ -2,9 +2,10 @@ namespace ChrisReedIO\JotformSDK; +use ChrisReedIO\JotformSDK\Commands\JotformSDKCommand; +use JotForm; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; -use ChrisReedIO\JotformSDK\Commands\JotformSDKCommand; class JotformSDKServiceProvider extends PackageServiceProvider { @@ -17,9 +18,16 @@ public function configurePackage(Package $package): void */ $package ->name('laravel-jotform-sdk') - ->hasConfigFile() - ->hasViews() - ->hasMigration('create_laravel-jotform-sdk_table') - ->hasCommand(JotformSDKCommand::class); + ->hasConfigFile(); + // ->hasViews() + // ->hasMigration('create_laravel-jotform-sdk_table') + // ->hasCommand(JotformSDKCommand::class); + } + + public function packageRegistered(): void + { + $this->app->singleton(JotForm::class , function () { + return new Jotform(config('jotform-sdk.api_key')); + }); } } From a5c811f99ad0350e1e847e8631fa226c91112790 Mon Sep 17 00:00:00 2001 From: chrisreedio Date: Wed, 14 Feb 2024 10:38:58 +0000 Subject: [PATCH 2/3] Fix styling --- src/JotformSDKServiceProvider.php | 8 ++++---- tests/TestCase.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JotformSDKServiceProvider.php b/src/JotformSDKServiceProvider.php index 0f5556c..b83adc3 100644 --- a/src/JotformSDKServiceProvider.php +++ b/src/JotformSDKServiceProvider.php @@ -19,14 +19,14 @@ public function configurePackage(Package $package): void $package ->name('laravel-jotform-sdk') ->hasConfigFile(); - // ->hasViews() - // ->hasMigration('create_laravel-jotform-sdk_table') - // ->hasCommand(JotformSDKCommand::class); + // ->hasViews() + // ->hasMigration('create_laravel-jotform-sdk_table') + // ->hasCommand(JotformSDKCommand::class); } public function packageRegistered(): void { - $this->app->singleton(JotForm::class , function () { + $this->app->singleton(JotForm::class, function () { return new Jotform(config('jotform-sdk.api_key')); }); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 10a4526..462c861 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,9 +2,9 @@ namespace ChrisReedIO\JotformSDK\Tests; +use ChrisReedIO\JotformSDK\JotformSDKServiceProvider; use Illuminate\Database\Eloquent\Factories\Factory; use Orchestra\Testbench\TestCase as Orchestra; -use ChrisReedIO\JotformSDK\JotformSDKServiceProvider; class TestCase extends Orchestra { From 4ff37bdf69854b461ea9b13799eeaed44e9515f2 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Thu, 22 Feb 2024 06:26:07 -0600 Subject: [PATCH 3/3] docs: update README with streamlined config example Removed outdated examples and support us section. Added concise package description and improved installation instructions. Simplified usage example to demonstrate Laravel facade integration. This change enhances readability and provides developers with a quick start guide. --- README.md | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 97f5730..f9e055b 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,9 @@ [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/chrisreedio/laravel-jotform-sdk/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/chrisreedio/laravel-jotform-sdk/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/chrisreedio/laravel-jotform-sdk.svg?style=flat-square)](https://packagist.org/packages/chrisreedio/laravel-jotform-sdk) -This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. +This package provides a Laravel wrapper for the Jotform SDK/API. -## Support us - -[](https://spatie.be/github-ad-click/laravel-jotform-sdk) - -We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). - -We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). +The goal is to streamline the usage in a Laravel application by auto-injecting the API key from the config file. ## Installation @@ -40,20 +34,16 @@ This is the contents of the published config file: ```php return [ + 'api_key' => env('JOTFORM_API_KEY'), ]; ``` -Optionally, you can publish the views using - -```bash -php artisan vendor:publish --tag="laravel-jotform-sdk-views" -``` - ## Usage ```php -$jotformSDK = new ChrisReedIO\JotformSDK(); -echo $jotformSDK->echoPhrase('Hello, ChrisReedIO!'); +use ChrisReedIO\JotformSDK\Facades\JotformSDK; +$folders = JotformSDK::api() + ->getFolders(); ``` ## Testing