Skip to content

Commit

Permalink
Merge pull request #32 from Oneflow/development
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
joseandrespg authored Jan 31, 2019
2 parents 87d9e1d + 0540e8a commit 29acfb5
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 27 deletions.
18 changes: 18 additions & 0 deletions samples/ship-shipment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
date_default_timezone_set('Europe/London');
error_reporting(E_ALL);
require_once '../src/ProductionSDK.php';

$productionClient = new ProductionSDK(
'https://ONEFLOW-URL-HERE/api',
'ONEFLOW-ACCOUNT-TOKEN-HERE',
'ONEFLOW-ACCOUNT-SECRET-HERE'
);

$shipmentId = "SHIPMENT_ID_HERE";

$response = $productionClient->setShipmentAsShipped($shipmentId);

if (!empty($response)) {
echo $response;
}
29 changes: 11 additions & 18 deletions src/OneflowSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,17 @@ public function ordersUpdateById($id, $orderData){
else return false;
}

/////////////////////////////////////////////////////////////////

/**
* request function.
* Performs an HTTP request to the OneFlow API
*
* @access private
* @param mixed $method
* @param mixed $path
* @param mixed $jsonData (default: null)
* @param mixed $optional_headers (default: null)
* @throws Exception
* @return mixed
*/
protected function request($method, $path, $jsonData=null, $optional_headers = null) {
public function request($method, $path, $jsonData=null, $optional_headers = null) {
ini_set("track_errors","on");

$timestamp = time();
Expand Down Expand Up @@ -283,14 +280,13 @@ protected function request($method, $path, $jsonData=null, $optional_headers = n
}

/**
* get function.
* Performs a GET HTTP request
*
* @access private
* @param mixed $path
* @param string $format (default: 'application/json')
* @return mixed
*/
protected function get($path, $format = 'application/json'){
public function get($path, $format = 'application/json'){
try {
$response = $this->request("GET", $path, "", array(
'Accept' => $format,
Expand All @@ -305,15 +301,14 @@ protected function get($path, $format = 'application/json'){
}

/**
* post function.
* Performs a POST HTTP request
*
* @access private
* @param mixed $path
* @param mixed $jsonData
* @param string $format (default: 'application/json')
* @return mixed
*/
protected function post($path, $jsonData, $format = 'application/json') {
public function post($path, $jsonData, $format = 'application/json') {
try {
$response = $this->request("POST", $path, $jsonData, array(
'Content-Type' => $format,
Expand All @@ -328,15 +323,14 @@ protected function post($path, $jsonData, $format = 'application/json') {
}

/**
* put function.
* Performs a PUT HTTP request
*
* @access private
* @param mixed $path
* @param mixed $jsonData
* @param string $format (default: 'application/json')
* @return mixed
*/
protected function put($path, $jsonData = null, $format = 'application/json'){
public function put($path, $jsonData = null, $format = 'application/json'){
try {
$response = $this->request("PUT", $path, $jsonData, array(
'Content-Type' => $format,
Expand All @@ -351,14 +345,13 @@ protected function put($path, $jsonData = null, $format = 'application/json'){
}

/**
* del function.
* Performs a DELETE HTTP request
*
* @access private
* @param mixed $path
* @param string $format (default: 'application/json')
* @return mixed
*/
protected function del($path, $format = 'application/json'){
public function del($path, $format = 'application/json'){
try {
$response = $this->request("DELETE", $path, "", array(
'Accept' => $format,
Expand Down Expand Up @@ -427,4 +420,4 @@ private function token($method, $path, $timestamp){
$stringToSign = strtoupper($method) . ' ' . $path . ' ' . $timestamp;
return $this->key . ':' . hash_hmac('sha1', $stringToSign, $this->secret);
}
}
}
166 changes: 157 additions & 9 deletions src/ProductionSDK.php
Original file line number Diff line number Diff line change
@@ -1,117 +1,265 @@
<?php

if (!class_exists('OneflowSDK')) {
require_once 'OneFlowSDK.php';
require_once __DIR__ . '/OneflowSDK.php';
}

class ProductionSDK extends OneflowSDK {

/**
* Returns a list of stations
* @return mixed
*/
public function getStations(){
return $this->get("/station");
}

/**
* Creates a station
* @param $jsonData
* @return mixed
*/
public function addStation($jsonData){
return $this->post("/station", $jsonData);
}

/**
* Returns a list of SKUs
* @return mixed
*/
public function getSKUs(){
return $this->get("/sku");
}

/**
* Creates a SKU
* @param $jsonData
* @return mixed
*/
public function addSKU($jsonData){
return $this->post("/sku", $jsonData);
}

/**
* Returns a list of clients
* @return mixed
*/
public function getClients(){
return $this->get("/client");
}

/**
* Creates a client
* @param $jsonData
* @return mixed
*/
public function addClient($jsonData){
return $this->post("/client", $jsonData);
}

/**
* Returns a list of batches
* @return mixed
*/
public function getBatches(){
return $this->get("/batch");
}

/**
* Returns a list of walls
* @return mixed
*/
public function getWalls(){
return $this->get("/wall");
}

/**
* Creates a wall
* @param $jsonData
* @return mixed
*/
public function addWall($jsonData){
return $this->post("/wall", $jsonData);
}

/**
* Returns a list of stocks
* @return mixed
*/
public function getStock(){
return $this->get("/stock");
}

/**
* Creates a stock
* @param $jsonData
* @return mixed
*/
public function addStock($jsonData){
return $this->post("/stock", $jsonData);
}

/**
* Returns a list of couriers
* @return mixed
*/
public function getCouriers(){
return $this->get("/courier");
}

/**
* Creates a courier
* @param $jsonData
* @return mixed
*/
public function addCourier($jsonData){
return $this->post("/courier", $jsonData);
}

public function getPresses(){
return $this->get("/press");
}
public function addPress($jsonData){
return $this->post("/press", $jsonData);
}

/**
* Returns a list of accounts
* @return mixed
*/
public function getAccounts(){
return $this->get("/account");
}

/**
* Return a list of accounts
* @return mixed
*/
public function getAccount(){
return $this->get("/account");
}

/**
* Returns the current account settings
* @return mixed
*/
public function getAccountSettings(){
return $this->get("/accountSettings");
}

/**
* Returns the sub-batches for a given station
* @param $id
* @return mixed
*/
public function getStationWorkList($id){
return $this->get("/worklist/id/$id");
}

/**
* Returns a list of products
* @return mixed
*/
public function getProducts(){
return $this->get("/product");
}

/**
* Creates a product
* @param $jsonData
* @return mixed
*/
public function addProduct($jsonData){
return $this->post("/product", $jsonData);
}

/**
* Deletes a product
* @param $id
* @return mixed
*/
public function removeProduct($id){
return $this->del("/product/$id");
}

/**
* Creates a event type
* @param $jsonData
* @return mixed
*/
public function addEventType($jsonData){
return $this->post("/event-type", $jsonData);
}

/**
* Returns a list of event types
* @return mixed
*/
public function getEventTypes(){
return $this->get("/event-type");
}

/**
* Returns a list of papers
* @return mixed
*/
public function getPaper(){
return $this->get("/paper");
}

/**
* Creates a paper
* @param $jsonData
* @return mixed
*/
public function addPaper($jsonData){
return $this->post("/paper", $jsonData);
}

/**
* Returns a list of printers
* @return mixed
*/
public function getPrinters(){
return $this->get("/printer");
}

/**
* Creates a printer
* @param $jsonData
* @return mixed
*/
public function addPrinter($jsonData){
return $this->post("/printer", $jsonData);
}

/**
* Returns a list of users
* @return mixed
*/
public function getUsers(){
return $this->get("/user");
}

/**
* Creates a user
* @param $jsonData
* @return mixed
*/
public function addUser($jsonData){
return $this->post("/register", $jsonData);
}

/**
* Returns a list of files for a given order
* @param $orderId
* @return mixed
*/
public function getOrderFiles($orderId){
return $this->get("/files/order/$orderId");
}

}
/**
* Sets a shipment as shipped
* @param $orderId
* @param $jsonData
* @return mixed
*/
public function setShipmentAsShipped($shipmentId, $jsonData = null){
return $this->put("/shipment/shipped/$shipmentId", $jsonData);
}

}

0 comments on commit 29acfb5

Please sign in to comment.