Skip to content

Commit

Permalink
Merge pull request #14 from MichaelJ2324/2.0
Browse files Browse the repository at this point in the history
2.0.Beta.1
  • Loading branch information
geraldclark committed Jun 6, 2017
2 parents e9fa22b + bfd6337 commit 071461a
Show file tree
Hide file tree
Showing 161 changed files with 3,229 additions and 5,962 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.iml
.idea/
vendor/

composer.lock
coverage/
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
"api"
],
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"michaelj2324/php-rest-client": ">=1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0|~5.0"
},
"autoload": {
"psr-4": {
"SugarAPI\\SDK\\": "src/"
"Sugarcrm\\REST\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"SugarAPI\\SDK\\Tests\\": "tests/"
"Sugarcrm\\REST\\Tests\\": "tests/"
}
}
}
26 changes: 26 additions & 0 deletions examples/AuditLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "Logged In: <pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Audit Log Test");
$Account->save();
echo "<pre>Created Account: {$Account['id']}</pre><br>";
$Account->set('phone_office','555-555-5555');
$Account['name'] = 'Audit Log Test - Updated';
$Account['assigned_user_id'] = 'seed_max_id';
$Account->save();
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre><br>";
$Account->audit();
echo "<pre> Audit Log:".print_r($Account->getResponse()->getBody(),true)."</pre><br>";
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
}
38 changes: 0 additions & 38 deletions examples/BulkAPI.php

This file was deleted.

83 changes: 22 additions & 61 deletions examples/CRUD.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,29 @@
<?php

require_once 'include.php';

require_once __DIR__ . '/../vendor/autoload.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/',array('username' => 'admin','password'=>'asdf'));
$SugarAPI->login();
$EP = $SugarAPI->filterRecords('Accounts');
$response = $EP->execute()->getResponse();
print_r($EP->getRequest());
if ($response->getStatus()=='200'){
$recordList = $response->getBody(false);
$max=count($recordList->records);
echo "found $max records from Filter Records request. <br>";
$number = rand(0,$max);
$randomRecord = $recordList->records[$number];
echo "Choose random record #$number, with ID: ".$randomRecord->id." <br>";

$getRecord = $SugarAPI->getRecord('Accounts',$randomRecord->id)->execute(array(
'fields' => 'name'
));
$response = $getRecord->getResponse();
if ($response->getStatus()=='200'){
echo "Retrieved Record <br>";
$randomRecord = $getRecord->getResponse()->getBody(false);
$randomRecord->name = 'Updated Record Name';
$updateRecord = $SugarAPI->updateRecord('Accounts', $randomRecord->id)->execute($randomRecord);
$response = $updateRecord->getResponse();
if ($response->getStatus()=='200'){
$randomRecord = $updateRecord->getResponse()->getBody(false);
echo "Updated Record <br>";
print_r($randomRecord);

$deleteRecord = $SugarAPI->deleteRecord('Accounts', $randomRecord->id)->execute();
$response = $deleteRecord->getResponse();
if ($response->getStatus()=='200'){
$response = $deleteRecord->getResponse()->getBody();
echo "Deleted Record <br>";
print_r($response);
}else{
echo "Failed to Delete record<br>";
echo "Response: ".$response->getStatus()."<br>";
print_r($response->getBody());
}
}else{
print_r($updateRecord->getRequest());
echo "Failed to Update record<br>";
echo "Response: ".$response->getStatus()."<br>";
print_r($response->getBody());
}
}else{
echo "Failed to retrieve record<br>";
echo "Response: ".$response->getStatus()."<br>";
print_r($response->getBody());
}
}else{
echo "Response: ".$response->getStatus();
print_r($response->getBody());
}
}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){
echo "Credentails:<pre>";
print_r($SugarAPI->getCredentials());
echo "</pre> Error Message: ";
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Test")->set("phone_office","555-555-5555");
echo "<pre> Account:".print_r($Account->asArray(),true)."</pre><br>";
$Account->save();
echo "<pre> Saved Account ID: {$Account['id']}</pre><br>";
$Account->set('employees','100');
$Account['shipping_address_city'] = 'Indianapolis';
$Account->save();
echo "<pre> Account Updated: <br>".print_r($Account->asArray(),true)."</pre>";
$Account2 = $SugarAPI->module('Accounts',$Account['id']);
$Account2->retrieve();
echo "<pre> Account2:".print_r($Account2->asArray(),true)."</pre><br>";
$Account2->delete();
echo "Account Deleted. <br><pre>".print_r($Account2->getResponse(),true)."</pre>";
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
}catch (\SugarAPI\SDK\Exception\SDKException $ex){
echo $ex->__toString();
}
24 changes: 0 additions & 24 deletions examples/CreateRecord.php

This file was deleted.

22 changes: 22 additions & 0 deletions examples/Favorite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);

try{
$SugarAPI->login();
echo "Logged In: <pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Favorite Test");
$Account->save();
echo "<pre> Account Created: {$Account['id']}</pre><br>";
$Account->favorite();
echo "<pre> Account added to Favorites: <br>".print_r($Account,true)."</pre>";
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
}
19 changes: 0 additions & 19 deletions examples/FavoriteRecord.php

This file was deleted.

27 changes: 27 additions & 0 deletions examples/FilterAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->filter()->and()
->or()
->starts('name','s')
->contains('name','test')
->endOr()
->equals('assigned_user_id','seed_max_id')
->endAnd();
echo "<pre> Filter Accounts that are assigned to User Max, and that either start with an S or contain 'test' in the name: ".var_dump($Accounts->filter()->compile())."</pre><br>";
$Accounts->filter()->execute();
echo "<pre> Response:".print_r($Accounts->getResponse()->getBody(),true)."</pre><br>";
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
}
25 changes: 0 additions & 25 deletions examples/GetFile.php

This file was deleted.

27 changes: 0 additions & 27 deletions examples/Login.php

This file was deleted.

26 changes: 26 additions & 0 deletions examples/RelateRecords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once 'include.php';

$SugarAPI = new \Sugarcrm\REST\Client\Sugar7API($server,$credentials);
try{
$SugarAPI->login();
echo "<pre>";
print_r($SugarAPI->getAuth()->getToken()->access_token);
echo "</pre>";
$Account = $SugarAPI->module('Accounts')->set("name","Relate Records Test");
$Account->save();
echo "<pre> Saved Account ID: {$Account['id']}</pre><br>";
$Opportunity = $SugarAPI->module('Opportunities');
$Opportunity['name'] = 'Test Opportunity';
$Opportunity['description'] = 'This opportunity was created via the SugarCRM REST API Client v2 to test creating relationships.';
$Opportunity->save();
echo "<pre> Opportunity Created: <br>".print_r($Opportunity->asArray(),true)."</pre>";
$Account->relate('opportunities',$Opportunity['id']);
echo "<pre> Relationship Created:".print_r($Account->getResponse(),true)."</pre><br>";
}catch (Exception $ex){
echo "<pre>";
//print_r($SugarAPI);
echo "</pre>";
print $ex->getMessage();
}
Loading

0 comments on commit 071461a

Please sign in to comment.