Issues (6)

src/Quotation.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace ElePHPant\Quotation;
4
5
use ElePHPant\Quotation\QuotationTraits\QuotationTraits;
6
7
/**
8
 * Class Quotation
9
 * User: Sérgio Danilo Jr ( @sergiodanilojr )
10
 * Date: 15/06/2020
11
 * Time: 18:52
12
 */
13
abstract class Quotation
14
{
15
16
    /**
17
     * JSON RESPONSE FORMAT
18
     */
19
    const RESPONSE_JSON = "json";
20
    /**
21
     * XML RESPONSE FORMAT
22
     */
23
    const RESPONSE_XML = "xml";
24
25
26
    /**
27
     * ALL CURRENCIES SUPPORTED
28
     */
29
    const CURRENCY_DOLAR = "USD-BRL";
30
31
    const CURRENCY_DOLAR_TOURISM = "USDT-BRL";
32
33
    const CURRENCY_EURO = "EUR-BRL";
34
35
    const CURRENCY_CANADIAN_DOLAR = "CAD-BRL";
36
37
    const CURRENCY_AUSTRALIAN_DOLAR = "AUD-BRL";
38
39
    const CURRENCY_STERLING = "GBP-BRL";
40
41
    const CURRENCY_ARGENTINIAN_PESO = "ARS-BRL";
42
43
    const CURRENCY_YEN_JAPAN = "JPY-BRL";
44
45
    const CURRENCY_SWISS_FRANC = "CHF-BRL";
46
47
    const CURRENCY_CHINESE_YUAN = "CNY-BRL";
48
49
    const CURRENCY_ISRAELI_SHEKEL = "YLS-BRL";
50
51
    const CURRENCY_BITCOIN = "BTC-BRL";
52
53
    const CURRENCY_LITECOIN = "LTC-BRL";
54
55
    const CURRENCY_ETHEREUM = "ETH-BRL";
56
57
    const CURRENCY_RIPPLE = "XRP-BRL";
58
59
    use QuotationTraits;
60
61
    /**
62
     * Cotation constructor.
63
     * @param string $currency
64
     * @param string $formatResponse
65
     */
66
    public function __construct(string $currency, string $formatResponse = self::RESPONSE_JSON)
67
    {
68
        $this->currency = $currency;
69
        $this->format = $this->setFormat($formatResponse);
70
        $this->base = "https://economia.awesomeapi.com.br/{$this->format}/";
71
    }
72
73
74
    /**
75
     * @return mixed|null
76
     */
77
    public function today()
78
    {
79
        $this->endpoint = "all/{$this->currency}";
80
        return $this->connect();
81
    }
82
83
84
    /**
85
     * @param int $days
86
     * @return mixed|null
87
     */
88
    public function period(int $days)
89
    {
90
        $this->endpoint = "{$this->currency}/{$days}";
91
        return $this->connect();
92
    }
93
94
95
    /**
96
     * @param DateTime $start
97
     * @param DateTime $end
0 ignored issues
show
The type ElePHPant\Quotation\DateTime was not found. Did you mean DateTime? If so, make sure to prefix the type with \.
Loading history...
98
     * @return mixed|null
99
     */
100
    public function interval(\DateTime $start, \DateTime $end)
101
    {
102
        $start = $start->format("Ymd");
103
        $end = $end->format("Ymd");
104
        $this->endpoint = "daily/{$this->currency}/?start_date={$start}&end_date={$end}";
105
106
        return $this->connect();
107
    }
108
109
}