revolution/laravel-dmm-api

This package is abandoned and no longer maintained. No replacement package was suggested.

DMM API for Laravel

2.4.0 2021-01-01 09:02 UTC

This package is auto-updated.

Last update: 2023-01-29 03:29:37 UTC


README

Laravel 用のシンプルなラッパー。
https://github.com/dmmlabo/dmm-php-sdk

Requirements

  • PHP >= 7.3
  • Laravel >= 6.0

Installation

Composer

composer require revolution/laravel-dmm-api

config/services.php

    'dmm' => [
        'affiliate_id' => env('DMM_AFFILIATE_ID', ''),
        'api_id'       => env('DMM_APP_ID', ''),
    ],

.env

DMM_AFFILIATE_ID=
DMM_APP_ID=

Usage

Dmm::dmm()\Dmm\Dmm のインスタンスと同じ。後は元のライブラリと同じ使い方。

<?php
use Revolution\Dmm\Facades\Dmm;

$response = Dmm::dmm()->api('')->find('');

$result = $response->getDecodedBody();

dd($result);

Macroable

マクロで好きなように拡張できる。便利なショートカットメソッドなどは用意してないので必要に応じて各自で作る想定。

AppServiceProvider などで登録

    public function boot()
    {
        \Dmm::macro('search', function ($keyword) {
            $response = $this->dmm()->api('product')->findGeneral[
                'keyword' => $keyword,
            ]);

            return $response->getDecodedBody();
        });
    }

使う時

$response = \Dmm::search('test');

LICENSE

MIT
Copyright kawax