Skip to content

Commit

Permalink
Fix fields request and Facades
Browse files Browse the repository at this point in the history
  • Loading branch information
mchev committed Feb 6, 2023
1 parent 266a053 commit 31afce8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `laravel-odk` will be documented in this file

## 1.3.0 - 2023-02-06

- BREAKING CHANGE : `$odk->projects($projectId)->forms($xmlFormId)->fields()` is replaced by `$odk->projects($projectId)->forms($xmlFormId)->fields()->get()`
- Laravel 10 Support
- OdkCentral Facade

## 1.2.3 - 2021-08-27

- Let a version be empty on publish
Expand Down
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,35 @@ namespace App\Http\Controllers;

use Mchev\LaravelOdk\OdkCentral;

class SomeController extends Controller
class SomeController
{
public function testOdk()
{
$odk = new OdkCentral;

$project = $odk->projects(1)->get();
dd($project);
}
}
```

$form = $odk->projects(1)->forms('basic')->get();
Usage with Facade :

```php
namespace App\Http\Controllers;

dd($project, $form);
use Mchev\LaravelOdk\Facades\OdkCentral;

class SomeController
{
public function returnFormFields($projectId, $xmlFormId)
{
$fields = OdkCentral::projects($projectId)->forms($xmlFormId)->fields()->get();
dd($fields);
}
}
```


### [Users](https://odkcentral.docs.apiary.io/#reference/accounts-and-users/users)

```php
Expand Down Expand Up @@ -214,18 +227,16 @@ $form = $odk->projects($projectId)->forms()->create($request->file('your_input_f
// Getting form details
$form = $odk->projects($projectId)->forms($xmlFormId)->get();

// Getting form fields
$form = $odk->projects($projectId)->forms($xmlFormId)->fields();
// Getting form schema fields
$form = $odk->projects($projectId)->forms($xmlFormId)->fields()->get();
// You may optionally add the 'true' parameter to the fields() method to sanitize the field names and paths to match the way they will be outputted for OData

// Listing form attachments
$form = $odk->projects($projectId)->forms($xmlFormId)->attachments()->get();

// Downloading a form attachment
return $odk->projects($projectId)->forms($xmlFormId)->downloadAttachment($filename);

// Getting form shema fields
$form = $odk->projects($projectId)->forms($xmlFormId)->fields()->get();

// Modifying a form
$form = $odk->projects($projectId)->forms($xmlFormId)->update([
'state' => 'open'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"Mchev\\LaravelOdk\\Providers\\OdkCentralServiceProvider"
],
"aliases": {
"OdkCentral": "Mchev\\LaravelOdk\\Facades\\OdkCentralFacade"
"OdkCentral": "Mchev\\LaravelOdk\\Facades\\OdkCentral"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
|
*/

'api_url' => env('ODK_API_URL', 'https://private-anon-f36a3f79fb-odkcentral.apiary-mock.com/v1'),
'api_url' => env('ODK_API_URL', 'https://private-anon-7f664ec078-odkcentral.apiary-mock.com/v1/'),

/*
|--------------------------------------------------------------------------
Expand All @@ -25,6 +25,6 @@

'user_email' => env('ODK_USER_EMAIL', '[email protected]'),

'user_password' => env('ODK_USER_PASSWORD', 'my.super.secure.password'),
'user_password' => env('ODK_USER_PASSWORD', 'my.password'),

];
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Mchev\LaravelOdk\Facades;

use Illuminate\Support\Facades\Facade;
use Mchev\LaravelOdk\OdkCentral;

class OdkCentralFacade extends Facade
class OdkCentral extends Facade
{
/**
* Get the registered name of the component.
Expand All @@ -14,6 +13,6 @@ class OdkCentralFacade extends Facade
*/
protected static function getFacadeAccessor()
{
return new OdkCentral;
return 'odkcentral';
}
}
2 changes: 1 addition & 1 deletion src/OdkCentral.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function fields($odata = false)
{
$this->endpoint .= '/fields?odata='.$odata;

return $this->get();
return $this;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/OdkCentralAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function generateAccessToken()
'password' => $this->password,
]);

$response->throw();

$body = $response->body();
$token = $response->json()['token'];

Expand Down
32 changes: 6 additions & 26 deletions src/Providers/OdkCentralServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mchev\LaravelOdk\Providers;

use Illuminate\Support\ServiceProvider;
use Mchev\LaravelOdk\OdkCentral;

class OdkCentralServiceProvider extends ServiceProvider
{
Expand All @@ -11,36 +12,10 @@ class OdkCentralServiceProvider extends ServiceProvider
*/
public function boot()
{
/*
* Optional methods to load your package assets
*/
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-odk');
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-odk');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('odkcentral.php'),
], 'config');

// Publishing the views.
/*$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/laravel-odk'),
], 'views');*/

// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/laravel-odk'),
], 'assets');*/

// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-odk'),
], 'lang');*/

// Registering package commands.
// $this->commands([]);
}
}

Expand All @@ -51,5 +26,10 @@ public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'odkcentral');

$this->app->bind('odkcentral', function($app) {
return new OdkCentral();
});

}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getPackageProviders($app): array
protected function getPackageAliases($app): array
{
return [
'OdkCentral' => 'Mchev\LaravelOdk\Facades\OdkCentralFacade',
'OdkCentral' => 'Mchev\LaravelOdk\Facades\OdkCentral',
];
}
}

0 comments on commit 31afce8

Please sign in to comment.