Skip to content

Commit

Permalink
patchwork
Browse files Browse the repository at this point in the history
non-name-spaced days are certainly gone soon.
  • Loading branch information
ktomk committed May 10, 2021
1 parent f435f90 commit 8f5b904
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions SeaTableAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SeaTableAPI
public $seatable_code; # curl response code from SeaTable server
public $seatable_status; # SeaTable response message
private $handle; # Current curl object
private $http_options = []; # Current curl options
private $http_options = []; # Current curl options
private $response_object; # Curl response
public $response_object_to_array = false; # Convert response to array instead of object - default false
public $response_info; # Curl info
Expand All @@ -56,20 +56,17 @@ class SeaTableAPI
'520' => 'OPERATION_FAILED',
];


/*
* Instanciate SeaTable class
*
* @param string $url
* @param string $user
* @param string $password
* @param int $port
* @throws Exception
*
*/
/**
* Instantiate SeaTable class
*
* @param string $url
* @param string $user
* @param string $password
* @param int $port
* @throws Exception
*/
public function __construct($option = [])
{

/*
* Input validation
*/
Expand Down Expand Up @@ -216,7 +213,6 @@ public function get($url, $http_options = [], $api_token = "")
return $this->decode($this->response_object);
}


/*
* Perform a POST call to the server
*
Expand All @@ -241,13 +237,6 @@ public function post($url, $form_fields = [], $http_options = [])
$http_options[CURLOPT_POST] = true;
$http_options[CURLOPT_POSTFIELDS] = $form_fields;

/*
if(array_key_exists("import", $fields)){
$cfile = new CURLFile(realpath($fields['import']));
$http_options[CURLOPT_POSTFIELDS] = array('dtable' => $cfile);
}
*/

$this->handle = curl_init($url);

if (! curl_setopt_array($this->handle, $http_options)) {
Expand All @@ -261,7 +250,6 @@ public function post($url, $form_fields = [], $http_options = [])
return $this->decode($this->response_object);
}


/*
* Perform a PUT call to the server
*
Expand Down Expand Up @@ -293,7 +281,6 @@ public function put($url, $data = '', $http_options = [])
return $this->decode($this->response_object);
}


/*
* Perform a DELETE call to server
*
Expand Down Expand Up @@ -323,7 +310,6 @@ public function delete($url, $http_options = [])
return $this->decode($this->response_object);
}


/*
* (all) Ping SeaTable server
*
Expand All @@ -335,18 +321,18 @@ public function ping()
return $this->get($request);
}


/*
* Return debugged data
*/
/**
* Output debug data
*
* @deprecated since 0.0.4
*/
public function debug($data)
{
echo "<pre>";
print_r($data);
echo "</pre>";
}


/*
* (all) Return SeaTable account information
*
Expand All @@ -358,7 +344,6 @@ public function checkAccountInfo()
return $this->get($request);
}


/*
* (admin only) Return all users on the SeaTable Server
* https://docs.seatable.io/published/seatable-api/dtable-web-v2.1-admin/users.md
Expand Down Expand Up @@ -447,7 +432,6 @@ public function deleteUser($email)
return $this->delete($request, $d);
}


/*
* List all workspaces
* @return array
Expand Down Expand Up @@ -481,8 +465,7 @@ public function copyDTableExternalLink($link, $dst_workspace_id)
return $this->post($request, $f);
}


// get getDtableToken
// SeaTable: get getDtableToken (via dtable API-Token)
public function getDtableToken($input)
{
if (array_key_exists("api_token", $input)) {
Expand Down Expand Up @@ -549,7 +532,6 @@ public function listDailyActiveUsers($date = '2020-08-12+00:00:00', $per_page =
return $this->get($request);
}


// Organisations (admin only)
// https://docs.seatable.io/published/seatable-api/dtable-web-v2.1-admin/organizations.md

Expand Down Expand Up @@ -623,4 +605,31 @@ public function listOrgBases($org_id, $per_page = 25, $page = 1)
$request = $this->seatable_url.'/api/v2.1/admin/organizations/'. $org_id .'/dtables/?per_page='. $per_page .'&page='. $page;
return $this->get($request);
}

public function addASystemNotificationToAUser($msg, $username)
{
$request = $this->seatable_url.'/api/v2.1/admin/sys-user-notifications/';
$body = [
'msg' => $msg,
'username' => $username,
];
return $this->post($request, $body);
}

public function listAllSystemNotifications($per_page = 25, $page = 1)
{
$request = $this->seatable_url.'/api/v2.1/admin/sys-user-notifications/?per_page='. $per_page .'&page='. $page;
return $this->get($request);
}

// SeaTable: Import dtable (only for own account)
public function importDTable($workspace_id, $dtable_file)
{
$request = $this->seatable_url.'/api/v2.1/workspace/'. $workspace_id .'/import-dtable/';

$cfile = new CURLFile(realpath($dtable_file));
$form_fields = ['dtable' => $cfile];

return $this->post($request, $form_fields);
}
}

0 comments on commit 8f5b904

Please sign in to comment.