FileUpload::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\FileUpload as FileUploadContract;
4
use Arcanedev\Stripe\Http\RequestOptions;
5
use Arcanedev\Stripe\Http\Requestor;
6
use Arcanedev\Stripe\Stripe;
7
use Arcanedev\Stripe\StripeResource;
8
9
/**
10
 * Class     FileUpload
11
 *
12
 * @package  Arcanedev\Stripe\Resources
13
 * @author   ARCANEDEV <[email protected]>
14
 * @link     https://stripe.com/docs/api/php#file_upload_object
15
 * @link     https://stripe.com/docs/guides/file-upload
16
 *
17
 * @property  string  id
18
 * @property  string  object   // 'file_upload'
19
 * @property  int     created  // timestamp
20
 * @property  string  purpose
21
 * @property  int     size
22
 * @property  string  type      // [pdf|jpeg|png]
23
 * @property  string  url
24
 */
25
class FileUpload extends StripeResource implements FileUploadContract
26
{
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Main Functions
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    /**
32
     * Get FileUpload base URL.
33
     *
34
     * @return string
35
     */
36 6
    public static function baseUrl()
37
    {
38 6
        return Stripe::getUploadBaseUrl();
39
    }
40
41
    /**
42
     * Get object name.
43
     *
44
     * @param  string  $class
45
     *
46
     * @return string
47
     */
48 2
    public static function className($class = '')
49
    {
50 2
        return 'file';
51
    }
52
53
    /**
54
     * Get the endpoint URL for the given class.
55
     *
56
     * @param  string  $class
57
     *
58
     * @return string
59
     */
60 6
    public static function classUrl($class = '')
61
    {
62 6
        return '/v1/files';
63
    }
64
65
    /* ------------------------------------------------------------------------------------------------
66
     |  Main Functions
67
     | ------------------------------------------------------------------------------------------------
68
     */
69
    /**
70
     * Retrieve a File Upload.
71
     * @link   https://stripe.com/docs/api/php#retrieve_file_upload
72
     *
73
     * @param  string             $id
74
     * @param  array|string|null  $options
75
     *
76
     * @return self
77
     *
78
     * @todo: Refactor the FileUpload::retrieve() method
79
     */
80 2
    public static function retrieve($id, $options = null)
81
    {
82 2
        $apiKey = RequestOptions::parse($options)->getApiKey();
83 2
        $file   = new self($id, $apiKey);
84
85
        /** @var \Arcanedev\Stripe\Http\Response $response */
86 2
        list($response, $apiKey) = Requestor::make($apiKey, self::baseUrl())
87 2
            ->get("/v1/files/{$id}", $file->retrieveParameters);
88
89 2
        $file->refreshFrom($response->getJson(), $apiKey);
90 2
        $file->setLastResponse($response);
91
92 2
        return $file;
93
    }
94
95
    /**
96
     * Create/Upload a File Upload.
97
     * @link   https://stripe.com/docs/api/php#create_file_upload
98
     *
99
     * @param  array|null         $params
100
     * @param  array|string|null  $options
101
     *
102
     * @return self|array
103
     */
104 6
    public static function create($params = [], $options = null)
105
    {
106 6
        return self::scopedCreate($params, $options);
107
    }
108
109
    /**
110
     * List all uploaded files.
111
     * @link   https://stripe.com/docs/api/php#list_file_uploads
112
     *
113
     * @param  array|null         $params
114
     * @param  array|string|null  $options
115
     *
116
     * @return \Arcanedev\Stripe\Collection|self[]
117
     */
118
    public static function all($params = [], $options = null)
119
    {
120
        return self::scopedAll($params, $options);
121
    }
122
}
123