@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | if (empty($this->parameters['pageSize'])) |
33 | 33 | $this->parameters['pageSize'] = $pagesize; |
34 | 34 | |
35 | - $this->celcatWebAPI->log()->info('Getting '. (new \ReflectionClass($this))->getShortName());// . (empty($this->parameters) ?: ' with ' . implode(',', $this->parameters))); |
|
35 | + $this->celcatWebAPI->log()->info('Getting '.(new \ReflectionClass($this))->getShortName()); // . (empty($this->parameters) ?: ' with ' . implode(',', $this->parameters))); |
|
36 | 36 | return $this->celcatWebAPI->get((empty($this->name) ? (new \ReflectionClass($this))->getShortName() : $this->name), $this->parameters); |
37 | 37 | } |
38 | 38 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | |
50 | 50 | $results = $this->get(); |
51 | 51 | |
52 | - if($this->hasPagination($results)){ |
|
53 | - for($page = 1; $page < $results['pagination']['TotalPages']; $page++){ |
|
52 | + if ($this->hasPagination($results)) { |
|
53 | + for ($page = 1; $page < $results['pagination']['TotalPages']; $page++) { |
|
54 | 54 | $this->parameters['page'] = $page; |
55 | 55 | $pageResults = $this->get(); |
56 | 56 |
@@ -29,8 +29,9 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function get($pagesize = 50) |
31 | 31 | { |
32 | - if (empty($this->parameters['pageSize'])) |
|
33 | - $this->parameters['pageSize'] = $pagesize; |
|
32 | + if (empty($this->parameters['pageSize'])) { |
|
33 | + $this->parameters['pageSize'] = $pagesize; |
|
34 | + } |
|
34 | 35 | |
35 | 36 | $this->celcatWebAPI->log()->info('Getting '. (new \ReflectionClass($this))->getShortName());// . (empty($this->parameters) ?: ' with ' . implode(',', $this->parameters))); |
36 | 37 | return $this->celcatWebAPI->get((empty($this->name) ? (new \ReflectionClass($this))->getShortName() : $this->name), $this->parameters); |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | */ |
45 | 46 | public function getAll($pagesize = 1000) |
46 | 47 | { |
47 | - if (empty($this->parameters['pageSize'])) |
|
48 | - $this->parameters['pageSize'] = $pagesize; |
|
48 | + if (empty($this->parameters['pageSize'])) { |
|
49 | + $this->parameters['pageSize'] = $pagesize; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | $results = $this->get(); |
51 | 53 |
@@ -68,24 +68,24 @@ discard block |
||
68 | 68 | */ |
69 | 69 | private function query($name, $requestMethod = 'GET', $parameters = []) |
70 | 70 | { |
71 | - $this->log()->info("Starting to perform query - resource: {$name} method: {$requestMethod}". (empty($parameters ?: " parameters: ". implode($parameters)))); |
|
71 | + $this->log()->info("Starting to perform query - resource: {$name} method: {$requestMethod}".(empty($parameters ?: " parameters: ".implode($parameters)))); |
|
72 | 72 | $client = new Client(); |
73 | 73 | if ($this->config['PROXY']) { |
74 | 74 | $client = new Client(['proxy' => $this->config['PROXY']]); |
75 | - if(!empty($this->config['PROXY']['no'])) { |
|
76 | - putenv('no_proxy='. implode(' ,', $this->config['PROXY']['no'])); |
|
75 | + if (!empty($this->config['PROXY']['no'])) { |
|
76 | + putenv('no_proxy='.implode(' ,', $this->config['PROXY']['no'])); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | $options = $this->buildRequest($requestMethod)->options($parameters); |
81 | 81 | $url = $this->buildRequest()->URL($name); |
82 | 82 | |
83 | - try{ |
|
83 | + try { |
|
84 | 84 | $request = $client->request($requestMethod, $url, $options); |
85 | 85 | $header = $request->getHeaders(); |
86 | - if($request->getStatusCode() >= 200 and $request->getStatusCode() <= 299) { |
|
86 | + if ($request->getStatusCode() >= 200 and $request->getStatusCode() <= 299) { |
|
87 | 87 | |
88 | - $this->log()->info('Received ' . $request->getStatusCode()); |
|
88 | + $this->log()->info('Received '.$request->getStatusCode()); |
|
89 | 89 | |
90 | 90 | // Build object to return |
91 | 91 | // Include pagination details |
@@ -101,24 +101,24 @@ discard block |
||
101 | 101 | return $result; |
102 | 102 | } else { |
103 | 103 | // TODO - Error Handling |
104 | - $this->log()->error('An error occurred, received a '. $request->getStatusCode()); |
|
104 | + $this->log()->error('An error occurred, received a '.$request->getStatusCode()); |
|
105 | 105 | $this->log()->transferLogs(); |
106 | - $this->throwRunTimeException('An error occurred, received a '. $request->getStatusCode()); |
|
106 | + $this->throwRunTimeException('An error occurred, received a '.$request->getStatusCode()); |
|
107 | 107 | } |
108 | 108 | } |
109 | - catch (\Exception $exception){ |
|
110 | - if($exception instanceof ClientException){ |
|
111 | - if($exception->getCode() == 404) { |
|
112 | - $this->log()->info('Received '. $exception->getCode()); |
|
109 | + catch (\Exception $exception) { |
|
110 | + if ($exception instanceof ClientException) { |
|
111 | + if ($exception->getCode() == 404) { |
|
112 | + $this->log()->info('Received '.$exception->getCode()); |
|
113 | 113 | $result['error']['code'] = 404; |
114 | 114 | $result['error']['message'] = "No Results Found"; |
115 | 115 | return $result; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | // TODO - Error Handling |
119 | - $this->log()->error('An error occurred, received a '. $exception->getCode() . ' '. $exception->getMessage()); |
|
119 | + $this->log()->error('An error occurred, received a '.$exception->getCode().' '.$exception->getMessage()); |
|
120 | 120 | $this->log()->transferLogs(); |
121 | - $this->throwRunTimeException('An error occurred, received a '. $exception->getCode()); |
|
121 | + $this->throwRunTimeException('An error occurred, received a '.$exception->getCode()); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param string $requestMethod |
129 | 129 | * @return RequestBuilder |
130 | 130 | */ |
131 | - private function buildRequest($requestMethod = 'GET'){ |
|
131 | + private function buildRequest($requestMethod = 'GET') { |
|
132 | 132 | return new RequestBuilder($requestMethod, $this->config); |
133 | 133 | } |
134 | 134 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return Log |
151 | 151 | */ |
152 | - public function log(){ |
|
152 | + public function log() { |
|
153 | 153 | return new Log($this); |
154 | 154 | } |
155 | 155 |
@@ -105,8 +105,7 @@ |
||
105 | 105 | $this->log()->transferLogs(); |
106 | 106 | $this->throwRunTimeException('An error occurred, received a '. $request->getStatusCode()); |
107 | 107 | } |
108 | - } |
|
109 | - catch (\Exception $exception){ |
|
108 | + } catch (\Exception $exception){ |
|
110 | 109 | if($exception instanceof ClientException){ |
111 | 110 | if($exception->getCode() == 404) { |
112 | 111 | $this->log()->info('Received '. $exception->getCode()); |
@@ -45,9 +45,9 @@ |
||
45 | 45 | { |
46 | 46 | foreach ($this->celcatWebAPI->logs as $log) { |
47 | 47 | if ($log['type'] == "info") { |
48 | - Logs::info("Celcat Web API: ". $log['string']); |
|
48 | + Logs::info("Celcat Web API: ".$log['string']); |
|
49 | 49 | } else if ($log['type'] == "error") { |
50 | - Logs::error("Celcat Web API: ". $log['string']); |
|
50 | + Logs::error("Celcat Web API: ".$log['string']); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
@@ -92,6 +92,6 @@ |
||
92 | 92 | */ |
93 | 93 | public function URL($name) |
94 | 94 | { |
95 | - return rtrim($this->config['ServerAddress'], '/') . '/' . $name; |
|
95 | + return rtrim($this->config['ServerAddress'], '/').'/'.$name; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | public function register() |
37 | 37 | { |
38 | 38 | $this->mergeConfigFrom( |
39 | - __DIR__ . '/Config/config.php', |
|
39 | + __DIR__.'/Config/config.php', |
|
40 | 40 | 'celcat' |
41 | 41 | ); |
42 | 42 | |
43 | - $this->app->singleton('CelcatWebAPI', function($app){ |
|
43 | + $this->app->singleton('CelcatWebAPI', function($app) { |
|
44 | 44 | return new CelcatWebAPI($app['config']); |
45 | 45 | }); |
46 | 46 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { |
54 | 54 | $this->publishes([ |
55 | - __DIR__ . '/Config/config.php' => config_path('celcat.php'), |
|
55 | + __DIR__.'/Config/config.php' => config_path('celcat.php'), |
|
56 | 56 | ], "config"); |
57 | 57 | } |
58 | 58 | } |