Creates api resource

@param string $key Rule api key
@param string $resource Resource name [subscriber, campaign, customization, suppression, tag, template, transaction]
@return Api
196129
public static function make($key, $resource, $version = 'v2')
    {
        $client = new Client($key, $version);

        $namespace = 'Rule\\ApiWrapper\\Api\\' . strtoupper($version) . '\\' . ucfirst($resource) . '\\';
        $classname = $namespace . ucfirst($resource);

        if (!class_exists($classname)) {
            throw new InvalidResourceException("Invalid resource name providen or api version not supported");
        }

        return new $classname($client);
    }
1061597
public static function createKey($resource, $context, $action) {
    return $resource.self::$actionDelimiter.$context.self::$actionDelimiter.$action;
  }
722210
public function make($key)
    {
        // If you are using Cartalyst Sentinel instead of Laravel native Auth then you will want
        // to include this alias in your config/app.php aliases array:
        // 'Auth'      => Cartalyst\Sentinel\Laravel\Facades\Sentinel::class,
        // If you are using native Laravel auth then use this instead:
        // 'Auth'      => Illuminate\Support\Facades\Auth::class,
        $user = Auth::getUser();
        $view = 'blocks.' . $key;

        // Set the user specific query parameters
        // for_logged in: 0 == non-members only, 1 == members only, 2 == OK for everyone
        /** @var Builder $carousel_query */
        if ($user) {
            // left join carousel_user pivot table
            // if there is no entry then user_id will be null, which is fine
            // if there is an entry and display_days is not null then check that this carousel falls within display_days
            $carousel_query = Carousel::whereIn('for_logged_in', [1, 2]);
            $carousel_query->leftJoin('carousel_user', function ($join) use ($user) {
                $join->on('carousels.id', '=', 'carousel_user.carousel_id');
                $join->where('carousel_user.user_id', '=', $user->id);
            });
            $carousel_query->where(function ($query) {
                $query->where(function ($query) {
                    $query->whereNull('carousels.display_days');
                    $query->orWhereRaw('CURDATE() <= DATE_ADD(carousel_user.created_at, INTERVAL carousels.display_days DAY)');
                });
                $query->orWhereNull('carousel_user.user_id');
            });
        } else {
            $carousel_query = Carousel::whereIn('for_logged_in', [0, 2]);
        }

        // Set the common query parameters
        // Order by is by carousel end date ascending (newest end dates first) but with NULLs last
        // if there is a tie on end date then go by carousels.updated_at -- most recently updated carousel wins
        $carousel_query->where('key', $key)
            ->where(function ($query) {
                $query->where('start_date', '<=', Carbon::today())
                    ->orWhereNull('start_date');
            })
            ->where(function ($query) {
                $query->where('end_date', '>=', Carbon::today())
                    ->orWhereNull('end_date');
            })
            ->where('status', '=', 'active')
            ->select('carousels.*')
            ->orderByRaw('CASE WHEN carousels.end_date IS NULL THEN 1 ELSE 0 END, carousels.end_date ASC, carousels.updated_at DESC');

        // Debug
        Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
            'Carousel query = ' . $carousel_query->toSql());

        // Debug output
        // Delatbabel\ViewPages\Services\CarouselService::
        // /var/www/socialdiary/app/Modules/Carousel/Services/CarouselService.php:70:make:
        //
        // Carousel query =
        // select `carousels`.*
        //     from `carousels`
        //     where `for_logged_in` in (?, ?)
        //     and `key` = ?
        //     and (`start_date` <= ? or `start_date` is null)
        //     and (`end_date` >= ? or `end_date` is null)
        //     and `status` = ?
        //     order by
        //         CASE WHEN carousels.end_date IS NULL THEN 1 ELSE 0 END,
        //         carousels.end_date ASC,
        //         carousels.updated_at DESC
        //
        // Carousel query =
        // select `carousels`.*
        //     from `carousels`
        //     left join `carousel_user` on `carousels`.`id` = `carousel_user`.`carousel_id`
        //         and `carousel_user`.`user_id` = ?
        //     where `for_logged_in` in (?, ?)
        //     and (
        //         (`carousels`.`display_days` is null or CURDATE() <= DATE_ADD(carousel_user.created_at, INTERVAL carousels.display_days DAY))
        //         or `carousel_user`.`user_id` is null)
        //     and `key` = ?
        //     and (`start_date` <= ? or `start_date` is null)
        //     and (`end_date` >= ? or `end_date` is null)
        //     and `status` = ?
        //     order by
        //         CASE WHEN carousels.end_date IS NULL THEN 1 ELSE 0 END,
        //         carousels.end_date ASC,
        //         carousels.updated_at DESC

        // Fetch the winning carousel by the common query parameters
        /** @var Carousel $carousel */
        $carousel = $carousel_query->first();
        if (! empty($carousel)) {
            Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
                'Found carousel ID ' . $carousel->id);
        } else {
            Log::debug(__CLASS__ . ':' . __TRAIT__ . ':' . __FILE__ . ':' . __LINE__ . ':' . __FUNCTION__ . ':' .
                'Did not find carousel matching ' . $key);
        }

        // Update the carousel_user join table with a record that shows this has been viewed.
        if (! empty($carousel) && ! empty($user)) {
            try {
                $carousel->users()->attach($user->id);
            } catch (\Exception $e) {
                // NO-OP
            }
        }

        return view($view, ['carousel' => $carousel])->render();
    }
470005
private static function mapCollection($resource, $object)
    {
        if ($object == false || is_string($object)) {
            return $object;
        }

        $baseResource = __NAMESPACE__ . '\\' . $resource;
        self::$resource = (class_exists($baseResource)) ? $baseResource : 'Bigcommerce\\Api\\Resources\\' . $resource;

        return array_map(array('self', 'mapCollectionObject'), $object);
    }
921072
public function get($key, $default = null)
    {
        $resource = $this->getAll();

        $keys = explode('.', $key);
        foreach ($keys as $key) {
            if (!isset($resource[$key])) {
                $resource = $default;
                break;
            }
            $resource = &$resource[$key];
        }

        return $resource;
    }
331614
public function makeUrl($resource)
    {
        $host     = trim(str_replace(['http://', 'https://'], null, $this->host), '/');
        $resource = trim($resource, '/');
        //Create URI
        $uri = $host . ':' . $this->port . '/' . $resource;

        return $uri;
    }
573509
public function getPolicy($resource)
    {
        if (!is_object($resource)) {
            $message = sprintf('Resource must be an object, `%s` given.', gettype($resource));
            throw new InvalidArgumentException($message);
        }

        $class = get_class($resource);

        if (!isset($this->map[$class])) {
            throw new MissingPolicyException($resource);
        }

        $policy = $this->map[$class];

        if (is_callable($policy)) {
            return $policy($resource, $this);
        }

        if (is_object($policy)) {
            return $policy;
        }

        return new $policy();
    }
847179
public function item($resourceKey, array $data)
    {
        if (is_null($resourceKey)) $resourceKey = static::RESOURCE_KEY;
        return $resourceKey ? [$resourceKey => $data]: $data;
    }
631835
protected function createResourcesSection(array $resources = array())
    {
        $builder = new TreeBuilder();
        $node = $builder->root('resources');
        $node->addDefaultsIfNotSet();
        $resourceNodes = $node->children();

        foreach ($resources as $resource => $defaults) {
            $resourceNode = $resourceNodes
                ->arrayNode($resource)
                ->addDefaultsIfNotSet()
            ;

            $this->addClassesSection($resourceNode, $defaults['classes']);

            if (isset($defaults['options'])) {
                $this->createOptionsNode($resourceNode, $defaults['options']);
            }

            if (!isset($defaults['validation_groups'])) {
                $defaults['validation_groups'] = array(
                    'default' => array()
                );
            }

            $this->addValidationGroupsSection($resourceNode, $defaults['validation_groups']);

            if (isset($defaults['translation'])) {
                $this->createTranslationNode($resourceNode, $defaults['translation']);
            }
        }

        return $node;
    }
1204688
public function requestUrl(ApiResourceInterface $resource)
    {
        $resourcePath = $this->resourcePath().'/'.$this->getResourceId();

        return $resource->apiUrl($resourcePath);
    }
578783
public function make(array $rules, AppliesToResource $resource=null)
    {

        if (!$resource) {
            return null;
        }

        $rules = array_merge($this->detectRules($resource), $rules);

        return $this->createObject(GenericValidator::class)->setRules($rules);

    }
948444
protected function createSignature($resource)
    {
        if (!$this->key)
        {
            throw new Exception('Missing api key');
        }
        if (!$this->secret)
        {
            throw new Exception('Missing api secret');
        }
        if (!$this->workspace)
        {
            throw new Exception('Missing workspace id');
        }

        $data = [
          'key' => $this->key,
          'workspace' => $this->workspace,
          'resource' => $resource
        ];

        ksort($data);

        return hash_hmac('sha256', implode('', $data), $this->secret);
    }
461765
public function postAction( $resource )
	{
		$response = $this->createAdmin( $resource )->post( $this->getPsrRequest(), new Response() );
		return $this->setPsrResponse( $response );
	}
1024034
public static function createFromResource($resource): Stream
    {
        if (!\is_resource($resource))
        {
            throw new \InvalidArgumentException('Stream must be a resource');
        }

        $obj           = new self();
        $obj->stream   = $resource;
        $meta          = stream_get_meta_data($obj->stream);
        $obj->seekable = $meta['seekable'];
        $obj->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
        $obj->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
        $obj->uri      = $obj->getMetadata('uri');

        return $obj;
    }
77084
public static function getResource($path, $resource = 'Resource')
    {
        $response = self::connection()->get(self::$api_path . $path);

        return self::mapResource($resource, $response);
    }
702566
public function make(array $rules, AppliesToResource $resource=null)
    {

        if (!$resource) {
            $validator = $this->firstNotNullResultOrFail('make', $rules, $resource);
            return $this->configureAndReturn($validator, $rules, $resource);
        }

        $resourceName = $resource->resourceName();

        if (!isset($this->resourceFactories[$resourceName])) {
            return $this->firstNotNullResultOrFail('make', $rules, $resource);
        }

        $validator = call_user_func($this->resourceFactories[$resourceName]);

        return $this->configureAndReturn($validator, $rules, $resource);

    }
88245
private function buildUrl($resource, $args)
    {
        //Merge args(apiKey, Format, noJsonCallback)
        $args = array_merge($args, $this->args);
        $query = http_build_query($args);

        $url = $this->url;
        $url .= $resource . '?' . $query;

        return $url;
    }