Last active
May 28, 2020 11:19
-
-
Save DannyvdSluijs/6c4203e95a997a85f9b403a35f0b818a to your computer and use it in GitHub Desktop.
Map Bitstamp using automaker plus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use App\TradingPair; | |
| use Illuminate\Console\Command; | |
| use Illuminate\Support\Facades\Http; | |
| use AutoMapperPlus\Configuration\AutoMapperConfig; | |
| use AutoMapperPlus\AutoMapper; | |
| use AutoMapperPlus\NameConverter\NamingConvention\CamelCaseNamingConvention; | |
| use AutoMapperPlus\NameConverter\NamingConvention\SnakeCaseNamingConvention; | |
| class TradingPair { | |
| public string $name; | |
| public string $description; | |
| public int $baseDecimals; | |
| public int $counterDecimals; | |
| public string $minimumOrder; | |
| public string $trading; | |
| public string $urlSymbol; | |
| } | |
| $response = Http::get('https://www.bitstamp.net/api/v2/trading-pairs-info/'); | |
| $config = new AutoMapperConfig(); | |
| $config | |
| ->registerMapping(TradingPair::class, \stdClass::class) | |
| ->withNamingConventions( | |
| new CamelCaseNamingConvention(), // The naming convention of the source class. | |
| new SnakeCaseNamingConvention() // The naming convention of the destination class. | |
| ) | |
| ->reverseMap(); | |
| $mapper = new AutoMapper($config); | |
| $pairs = $this->mapper->mapMultiple($response->object(), TradingPair::class); | |
| dd($pairs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment