block-ops / directscale-sdk-php
DirectScale API 的类库
1.0.4
2020-03-30 19:55 UTC
Requires
- php: >=5.6.0
- block-ops/common-mlm-interface: *
- rasclatt/nubersoft: 1.*
README
要创建连接,当前的方法是在您的应用程序中创建一个包含您的API密钥的 define()
。
随着框架的成熟,此连接方法将进行更新,但目前需要使用 define()
。值得注意的是,在创建连接时将 $env
设置为 'dev'
将将连接设置为开发者模式。为了适应开发者模式,您需要有一个标记为 DIRECTSCALE_DEVAPIKEY
的开发者常量。您还可以在任何版本的 Model
中手动设置密钥。
另外需要注意的是,此框架需要 Nubersoft 框架。
以下是一个获取用户数据的示例
# Create define define('DIRECTSCALE_APIKEY', 'your123prod456key543here210'); # Create instance $DirectScale = new \DirectScale\User(54321); # Get distributor details print_r($DirectScale->getDistInfo());
常见数据函数的示例
use \DirectScale\ { User, User\Subscription, Orders, Products, Stores }; try { $User = new User('15F92'); $Subscription = new Subscription($User); $Orders = new Orders($User); $Products = new Products(); $Stores = new Stores($Products); print_r([ # Notice here that the autoship is appended to the user data # when creating instance of Subscription $User->getData(), # This will just fetch the autoship by itself $Subscription->getOrder(), # Fetches a list of all products $Products->get(), # Fetches a specific sku $Products->getBySku('EXAMPLESKU123'), # Fetches the store regions $Stores->getRegions(), # Fetches the store cateories $Stores->getCategories() ]); } catch(\DirectScale\Exception $e) { # It is worth noting that getting a single product by sku requires the "optional" params # or it will return an error from DirectScale echo $e->getErrorTransactionId(); }
设置开发者模式
在实例化之前,使用带 dev
参数的静态方法
use \DirectScale\ { Model as Connection, User }; # You will need a "dev" version of the API key define('DIRECTSCALE_DEVAPIKEY', 'your123dev456key654here321'); # You can also save your regular key define('DIRECTSCALE_APIKEY', 'your123prod456key543here210'); # Set the dev mode here Connection::setMode('dev'); # <--- Comment out this line to make live # Alternately, you can set the API key using the Model # If using this method to set the API key, uncomment this line below, comment out the defines # Connection::setApiKey('your123dev456key654here321'); # Start a user class $User = new User(12345); # Fetch the data $info = $User->getDistInfo(); # Write out the api url echo $User->getConnection()->getUrl();
这应该产生 dev
url
https://dsapi-dev.directscale.com/v1/customers/?backofficeid=12345