Skip to content

Fix namespace issue and add limit argument to read() #10

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

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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "magnussolution/magnusbilling-api",
"name": "imskm/magnusbilling-api-php",
"description": "PHP wrapper for the MagnusBilling API.",
"type": "library",
"license": "MIT",
Expand All @@ -17,4 +17,4 @@
"magnusbilling\\api\\": "src/"
}
}
}
}
42 changes: 37 additions & 5 deletions src/magnusBilling.php → src/MagnusBilling.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ private function query(array $req = array())
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (isset($req['write_cb'])) {
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $req['write_cb']);
} else {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; MagnusBilling PHP bot; ' . php_uname('a') . '; PHP/' . phpversion() . ')'
);
} else {
if (isset($req['write_cb'])) {
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $req['write_cb']);
} else {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
}
curl_setopt($ch, CURLOPT_URL, $trading_url . '/index.php/' . $module . '/' . $action);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
Expand All @@ -76,7 +86,11 @@ private function query(array $req = array())
$res = curl_exec($ch);

if ($res === false) {
throw new Exception('Curl error: ' . curl_error($ch));
throw new \Exception('Curl error: ' . curl_error($ch));
}

if (isset($req['write_cb'])) {
return $res;
}

$dec = json_decode($res, true);
Expand Down Expand Up @@ -116,16 +130,16 @@ public function destroy($module, $id)
)
);
}
public function read($module, $page = 1, $action = 'read')
public function read($module, $page = 1, $action = 'read', $limit = 25)
{

return $this->query(
array(
'module' => $module,
'action' => $action,
'page' => $page,
'start' => $page == 1 ? 0 : ($page - 1) * 25,
'limit' => 25,
'start' => $page == 1 ? 0 : ($page - 1) * $limit,
'limit' => $limit,
'filter' => json_encode($this->filter),
)
);
Expand Down Expand Up @@ -179,6 +193,24 @@ public function releaseDID($did)
);
}

public function getCallAudioRecording($call_id, $stream_cb)
{
$this->clearFilter();
$this->setFilter('id', $call_id, 'eq', 'numeric');

return $this->query(
array(
'module' => "call",
'action' => "downloadRecordTwo",
'page' => $page = 1,
'start' => $page == 1 ? 0 : ($page - 1) * $limit,
'limit' => $limit = 25,
'filter' => json_encode($this->filter),
'write_cb' => $stream_cb,
)
);
}

public function getFields($module)
{
return $this->query(
Expand Down