Overview

Namespaces

  • SmsOrange
    • Cruise

Classes

  • SmsOrange\Cruise
  • SmsOrange\Cruise\CostaCruisesWebservice
  • SmsOrange\Cruise\ManualCruisesWebservice
  • SmsOrange\Dispatcher
  • SmsOrange\Main

Interfaces

  • SmsOrange\Bookable
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace SmsOrange;
 3: 
 4: use \Unirest\Request;
 5: use \Illuminate\Config\FileLoader;
 6: use \Illuminate\Config\Repository;
 7: use \Illuminate\Filesystem\Filesystem;
 8: 
 9: /**
10:  * Class Main
11:  *
12:  * Main abstract class for all booking services.
13:  *
14:  * @package SmsOrange
15:  */
16: abstract class Main
17: {
18:     protected $config;
19:     protected $headers = [];
20: 
21:     /**
22:      * Main constructor.
23:      *
24:      * Loads up the config.
25:      *
26:      * Utilizes 'illuminate/config' package.
27:      */
28:     protected function __construct()
29:     {
30:         $basePath = str_finish(dirname(__DIR__), '/');
31: 
32:         $configPath = $basePath . 'config';
33: 
34:         $loader = new FileLoader(new Filesystem, $configPath);
35: 
36:         $this->config = new Repository($loader, null);
37:     }
38: 
39:     /**
40:      * Returns an API method mapped to the current action.
41:      *
42:      * Mappings are read from the config file.
43:      *
44:      * @param string $serviceName Cruise, Tour
45:      * @param string $callerMethod caller function name bound by the Bookable contract
46:      * @return string name of the API method
47:      */
48:     final protected function getApiMethod( $serviceName, $callerMethod )
49:     {
50:         return $this->config->get( "app.{$serviceName}.methods." . $callerMethod );
51:     }
52: 
53:     /**
54:      * Executes a HTTP Request using the Unirest library (http://unirest.io)
55:      *
56:      * @param string $url API base url
57:      * @param string $method API method
58:      * @param array $body body of the request
59:      * @return \Unirest\Response object
60:      */
61:     final protected function executeRequest($url, $method, $body)
62:     {
63:         $resp = Request::get(
64:             $url . $method,
65:             $this->headers,
66:             $body
67:         );
68: 
69:         return $resp;
70:     }
71: }
72: 
API documentation generated by ApiGen