Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few major updates to the library #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library allows you to interact with your Sirportly data using PHP.
## Setting up a Sirportly Client

```php
$sirportly = new Sirportly('the-token','the-secret');
$sirportly = new \Sirportly\Sirportly('the-token','the-secret');
```

## Creating a ticket
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
],
"minimum-stability": "stable",
"autoload": {
"classmap": ["class.php"]
"psr-4": {
"Sirportly\\": "src"
}
},
"require": {

Expand Down
10 changes: 10 additions & 0 deletions src/Exceptions/SirportlyDefaultException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Sirportly\Exceptions;

use Exception;

class SirportlyDefaultException extends Exception
{

}
63 changes: 43 additions & 20 deletions class.php → src/Sirportly.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

namespace Sirportly;

use Sirportly\Exceptions\SirportlyDefaultException;

/**
* Sirportly PHP API Library
* @see https://github.com/sirportly/php-library
Expand All @@ -16,98 +21,116 @@ public function __construct($token,$secret,$url='https://api.sirportly.com') {
$this->url = $url;
}

/**
* @param $action
* @param array $postdata
* @return mixed
* @throws SirportlyDefaultException
*/
private function query($action,$postdata=array()) {
$curl = curl_init();
$query_string = "";
$url = $this->url . $action;
foreach ($postdata AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$header = array('X-Auth-Token: '.$this->token, 'X-Auth-Secret: '.$this->secret);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $this->url.$action);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POST, 1);

$result = curl_exec($curl);
$info = curl_getinfo($curl);

if ($result === false || !in_array($info['http_code'], [200, 201])) {
$error = "No cURL data returned for $url [http error: ". $info['http_code']. "]";
if (curl_error($curl)) {
$error .= "\n" . curl_error($curl);
}
throw new SirportlyDefaultException($error);
}

curl_close($curl);
$decode = json_decode($result,true);
return $decode;
}

public function ticket($ticket_reference) {
return $this->query('/api/v1/tickets/ticket',array('reference' => $ticket_reference));
return $this->query('/api/v2/tickets/ticket', array('ticket' => $ticket_reference));
}

public function create_ticket($params = array()) {
return $this->query('/api/v1/tickets/submit',$params);
return $this->query('/api/v2/tickets/submit',$params);
}

public function post_update($params = array()) {
return $this->query('/api/v1/tickets/post_update',$params);
return $this->query('/api/v2/tickets/post_update',$params);
}

public function tickets($page = '1') {
return $this->query('/api/v1/tickets/all',array('page' => $page));
return $this->query('/api/v2/tickets/all',array('page' => $page));
}

public function update_ticket($params = array()) {
return $this->query('/api/v1/tickets/update',$params);
return $this->query('/api/v2/tickets/update',$params);
}

public function run_macro($params = array()) {
return $this->query('/api/v1/tickets/macro',$params);
return $this->query('/api/v2/tickets/macro',$params);
}

public function add_follow_up($params = array()) {
return $this->query('/api/v1/tickets/followup',$params);
return $this->query('/api/v2/tickets/add_followup',$params);
}

public function create_user($params = array()) {
return $this->query('/api/v1/users/create',$params);
return $this->query('/api/v2/users/create',$params);
}

public function statuses() {
return $this->query('/api/v1/objects/statuses');
return $this->query('/api/v2/objects/statuses');
}

public function priorities() {
return $this->query('/api/v1/objects/priorities');
return $this->query('/api/v2/objects/priorities');
}

public function teams() {
return $this->query('/api/v1/objects/teams');
return $this->query('/api/v2/objects/teams');
}

public function brands() {
return $this->query('/api/v1/objects/brands');
return $this->query('/api/v2/objects/brands');
}

public function departments() {
return $this->query('/api/v1/objects/departments');
return $this->query('/api/v2/objects/departments');
}

public function escalation_paths() {
return $this->query('/api/v1/objects/escalation_paths');
return $this->query('/api/v2/objects/escalation_paths');
}

public function slas() {
return $this->query('/api/v1/objects/slas');
return $this->query('/api/v2/objects/slas');
}

public function filters() {
return $this->query('/api/v1/objects/filters');
return $this->query('/api/v2/objects/filters');
}

public function spql($params = array()) {
return $this->query('/api/v1/tickets/spql',$params);
return $this->query('/api/v2/tickets/spql',$params);
}

/**
* Fetch a list of knowledgebases from your account
* @return array list of knowledgebases in an array format.
*/
public function kb_list() {
return $this->query('/api/v1/knowledge/list');
return $this->query('/api/v2/knowledge/list');
}

/**
Expand All @@ -116,7 +139,7 @@ public function kb_list() {
* @return array The knowledgebase as an array.
*/
public function kb($kb_id) {
return $this->query('/api/v1/knowledge/tree', array('kb' => $kb_id));
return $this->query('/api/v2/knowledge/tree', array('kb' => $kb_id));
}

/**
Expand Down