-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathGetAllCoursesCommand.php
More file actions
61 lines (55 loc) · 1.25 KB
/
GetAllCoursesCommand.php
File metadata and controls
61 lines (55 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace App\CurrikiGo\Canvas\Commands;
use App\CurrikiGo\Canvas\Contracts\Command;
/**
* This class handles fetching courses in Canvas LMS
*/
class GetAllCoursesCommand implements Command
{
/**
* API URL
*
* @var string
*/
public $apiURL;
/**
* Access Token for api requests
*
* @var string
*/
public $accessToken;
/**
* HTTP Client instance
*
* @var \GuzzleHttp\Client
*/
public $httpClient;
/**
* Creates an instance of the command class
*
* @param int $accountId
* @param string $programName
* @return void
*/
public function __construct()
{
}
/**
* Execute an API request for getting courses
*
* @return string|null
*/
public function execute()
{
$response = null;
try {
$url = $this->apiURL . '/courses' . '?per_page=1000';
$response = $this->httpClient->request('GET', $url, [
'headers' => ['Authorization' => "Bearer {$this->accessToken}", 'Accept' => 'application/json']
])->getBody()->getContents();
$response = json_decode($response);
} catch (Exception $ex) {
}
return $response;
}
}