Skip to content

Commit

Permalink
- Changed the default response decoding to output an array instead of…
Browse files Browse the repository at this point in the history
… an object.

- Replace old long array(...) syntax with newer [...] short syntax.
- Completed the home page with links to all available examples.
  • Loading branch information
macrini committed Oct 22, 2020
1 parent 7061d86 commit b2f2767
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 84 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.rulers": [80],
"cSpell.words": [
"Proximify",
"Uniweb"
Expand Down
2 changes: 1 addition & 1 deletion queries/example1/markup_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function makeTableItem($picture, $name, $title, $interests, $description)

// Note that title and interests are LOVs so their values are arrays with an ID
// ad the first element, and a display string as the second element. Additional
// elements corresponds extra info, sich as the parent theme of teh interest, etc
// elements corresponds to extra info such as the parent theme of the interest, etc
$title = $title[1];

for ($i = 0; $i < $numInterests; $i++) {
Expand Down
4 changes: 2 additions & 2 deletions queries/example12.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
$mimeType = 'image/' . pathinfo($imagePath, PATHINFO_EXTENSION);
$fileName = 'profilePicture'; // A unique name for the file (with no periods in it)

$resources = array('profile/picture' => array('attachment' => $fileName));
$resources = ['profile/picture' => ['attachment' => $fileName]];

$request = array('id' => $id, 'resources' => $resources);
$request = ['id' => $id, 'resources' => $resources];

$client->addFileAttachment($request, $fileName, $imagePath, $mimeType);

Expand Down
20 changes: 10 additions & 10 deletions queries/example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@

$currentInterests = [];

foreach ($result->{'profile/research_interests'} as $item) {
$currentInterests[] = $item->interest;
foreach ($result['profile/research_interests'] as $item) {
$currentInterests[] = $item['interest'];
}

$interest1 = 'Artificial Intelligence';
$interest2 = array('Expert Systems', 'Artificial Intelligence');
$interest2 = ['Expert Systems', 'Artificial Intelligence'];

// Use the client API helper function below to see if the user already have
// the interests that we want to add
Expand All @@ -52,9 +52,9 @@
}

// Get the value options for field 'interest' in section 'research_interests']
$resources = array('profile/research_interests/_fields_/interest');
$resources = ['profile/research_interests/_fields_/interest'];
$options = $client->getOptions($resources);
$options = $options->{'profile/research_interests'}->interest;
$options = $options['profile/research_interests']['interest'] ?? [];


// Use the client API helper function below to find the ID of the interests that we
Expand All @@ -77,12 +77,12 @@
exit;
}

$resources = array('profile/research_interests' => array(
array('interest' => $interestId1),
array('interest' => $interestId2)
));
$resources = ['profile/research_interests' => [
['interest' => $interestId1],
['interest' => $interestId2]
]];

$params = array('resources' => $resources, 'id' => $id);
$params = ['resources' => $resources, 'id' => $id];
$response = $client->add($params);

if ($response) {
Expand Down
6 changes: 3 additions & 3 deletions queries/example3.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
$client = new UniwebClient(UniwebClient::loadCredentials());

// Request the information about a section, its field names and the type of each field.
$resources = array('cv/contributions/presentations');
$resources = ['cv/contributions/presentations'];
$response = $client->getInfo($resources);
$client->printResponse($response, 'Section info');

// Request the information for some specific fields in the section.
$resources = array('cv/contributions/presentations/_fields_/main_audience/invited');
$resources = ['cv/contributions/presentations/_fields_/main_audience/invited'];
$response = $client->getInfo($resources);
$client->printResponse($response, 'Fields info');

// Request the valid options for some LOV fields.
$resources = array('cv/contributions/presentations/_fields_/main_audience/invited');
$resources = ['cv/contributions/presentations/_fields_/main_audience/invited'];
$response = $client->getOptions($resources);
$client->printResponse($response, 'Fields options');
36 changes: 18 additions & 18 deletions queries/example4.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
$sectionName = 'cv/contributions/presentations';
$subsectionName = $sectionName . '/funding_sources';

$resources = array($sectionName);
$params = array('id' => $id, 'resources' => $resources);
$resources = [$sectionName];
$params = ['id' => $id, 'resources' => $resources];
$response = $client->clear($params);

if (!$response) {
Expand All @@ -49,41 +49,41 @@
// Get the options for all fields in the section and subsection to which we will add
// new items

$resources = array($sectionName, $subsectionName);
$resources = [$sectionName, $subsectionName];
$response = $client->getOptions($resources);
var_dump($response);

$organizations = $response->{$subsectionName}->funding_organization;
$organizations = $response[$subsectionName]['funding_organization'] ?? [];
$org1 = 'Natural Sciences and Engineering Research Council of Canada (NSERC)';
$orgId1 = $client->findFieldOptionId($organizations, $org1);

// SUBITEM: Create one subitem to add to the funding sources of the main item.
$fundingItem1 = array(
$fundingItem1 = [
'funding_organization' => $orgId1,
'funding_reference_number' => 1
);
];

// MAIN ITEMS: Defined items to insert
$sectionItem1 = array(
$sectionItem1 = [
'presentation_title' => 'TED Talk',
'description_contribution_value' => array(
'description_contribution_value' => [
'english' => 'Hi there',
'french' => 'Alo'
),
'funding_sources' => array(
],
'funding_sources' => [
$fundingItem1
)
);
]
];

$sectionItem2 = array(
$sectionItem2 = [
'presentation_title' => 'UN Talk',
'description_contribution_value' => array(
'description_contribution_value' => [
'english' => 'There is only this English value'
)
);
]
];

$resources = array($sectionName => array($sectionItem1, $sectionItem2));
$params = array('resources' => $resources, 'id' => $id);
$resources = [$sectionName => [$sectionItem1, $sectionItem2]];
$params = ['resources' => $resources, 'id' => $id];
$response = $client->add($params); // add items

if ($response) {
Expand Down
12 changes: 9 additions & 3 deletions queries/example5.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* 1. Query member data with the filter "loginName".
* 2. Iterate over the interests. Each interest is an array with ID, name the the
* research there, name of the parent of the research them, name of the grand parent of
* the research theme, and so on. Here I'm just using the base name of the interest.
*/

require_once __DIR__ . '/../src/UniwebClient.php';

use Proximify\Uniweb\API\UniwebClient;
Expand All @@ -15,7 +22,6 @@
// The read() function has a second parameter. If true, the response is an array instead
// of an object.
$response = $client->read($params, true);
$client->printResponse($response, 'Response is an array when read($params, true)');

if (!$response) {
throw new Exception('Count not find the member');
Expand All @@ -27,7 +33,7 @@
$memberData = $response[$memberId];

// Show the data
$client->printResponse($response, 'Member data obtained by using a filter');
$client->printResponse($response, 'Member data obtained by using a filter (loginName)');

$info = $memberData['profile/membership_information'];
$interests = $memberData['profile/research_interests'];
Expand All @@ -39,7 +45,7 @@
// research there, name of the parent of the research them, name of the grand parent of
// the research theme, and so on. Here I'm just using the base name of the interest.

$researchInterestsList = array();
$researchInterestsList = [];

foreach ($interests as $tuple) {
$researchInterestsList[] = $tuple['interest'][1];
Expand Down
16 changes: 9 additions & 7 deletions queries/example6.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

/**
* 1. Query by ID (single result instead of array).
* 2. Iterate over the interests.
*/

require_once __DIR__ . '/../src/UniwebClient.php';

use Proximify\Uniweb\API\UniwebClient;
Expand All @@ -9,14 +14,11 @@
// When selecting one member, you can use the property 'id' instead of a filter. In that
// case, the response won't be an array of members but just the member that you need
$id = '[email protected]';
$resources = array('profile/membership_information', 'profile/research_interests');
$params = array('id' => $id, 'resources' => $resources);
$resources = ['profile/membership_information', 'profile/research_interests'];
$params = ['id' => $id, 'resources' => $resources];

// Retrieve the data from the server
// For Bruno: I added a second parameter so that the response is an array instead of an
// object. I find that easier to deal with.

$response = $client->read($params, true);
$response = $client->read($params);

if (!$response) {
throw new Exception('Count not find the member');
Expand All @@ -36,7 +38,7 @@
// research there, name of the parent of the research them, name of the grand parent of
// the research theme, and so on. Here I'm just using the base name of the interest.

$researchInterestsList = array();
$researchInterestsList = [];

foreach ($interests as $tuple) {
$researchInterestsList[] = $tuple['interest'][1];
Expand Down
19 changes: 10 additions & 9 deletions queries/example7.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* Edit some of the information on the membership section.
* It is important to notice that if there is already an item with data in the
* section, then only the field values that we send will modify existing values.
* In other words, if, for example, we don't send a middle name, and the user
* had set a middle name, then the existing middle name will be unchanged.
*/
require_once __DIR__ . '/../src/UniwebClient.php';

use Proximify\Uniweb\API\UniwebClient;
Expand All @@ -9,21 +16,15 @@
// Set the login name of the user whose profile we want to write to.
$id = '[email protected]';

// We are editing some of the information on the membership section. It is important to
// notice that if there is already an item with data in the section, then only the field
// values that we send will modify existing values. In other words, if, for example,
// we don't send a middle name, and the user had set a middle name, then the existing
// middle name will be unchanged.

$resources = array('profile/membership_information' => [
$resources = ['profile/membership_information' => [
"first_name" => "Juan",
"last_name" => "Pedro",
"account_type" => 1,
"position_title" => 1,
"email" => "dmac"
]);
]];

$params = array('id' => $id, 'resources' => $resources);
$params = ['id' => $id, 'resources' => $resources];
$response = $client->edit($params);

if ($response) {
Expand Down
14 changes: 7 additions & 7 deletions queries/example8.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
$client = new UniwebClient(UniwebClient::loadCredentials());

$id = '[email protected]';
$resources = array('cv/user_profile');
$readParams = array('id' => $id, 'resources' => $resources);
$resources = ['cv/user_profile'];
$readParams = ['id' => $id, 'resources' => $resources];

$response = $client->read($readParams);
$client->printResponse($response, 'User profile in CV before "edit"');

$currentInterests = array();
$currentInterests = [];

// Create a bilingual string
$bilingualStr = array(
$bilingualStr = [
'english' => 'Artificial intelligence',
'french' => 'Intelligence artificielle'
);
];

$resources = array('cv/user_profile' => array('research_interests' => $bilingualStr));
$editParams = array('id' => $id, 'resources' => $resources);
$resources = ['cv/user_profile' => ['research_interests' => $bilingualStr]];
$editParams = ['id' => $id, 'resources' => $resources];
$response = $client->edit($editParams);

if ($response) {
Expand Down
Loading

0 comments on commit b2f2767

Please sign in to comment.