365farmnet 中文文档教程

发布于 4年前 浏览 24 项目主页 更新于 3年前

365FarmNet Connect - Node.js client

365FarmNet Connect REST API 的一个简单的基于承诺的客户端。

Quick start

npm install 365farmnet

注意:这个库需要 Node.js > v.10.0

导入库,并传递你从中获得的合作伙伴ID和秘密 在 https://devcon.365farmnet.com/ 注册。

const farmnet = require('365farmnet')({
  partnerId: 'yourPartnerId',
  secret: 'yourPartnerSecret'
})

通过调用导入函数向365FarmNet Connect REST API发起请求 (farmnet 如果您遵循此示例)以下列方式进行:

// farmnettoken is the JWT that is passed to the iframe within the 
// 365FarmNet main application
farmnet('fields', {
  token: farmnettoken,
  params: {
    includeGeometry: false,
    includeSoilType: true
  }
}).then(data => {
  // data will contain all fields of the farm
}).catch(err => {
  console.log(err)
})

API

该模块导出一个默认函数。 它有两个参数:

farmnet('endpoint', options)

NameDescription
endpoint string requiredThe REST API endpoint to call. See documentation for all available endpoints.
options.token string requiredThe token property of the options object needs to be a valid JWT farmnettoken.
options.params objectOptional query params for the API call.
options.data objectOptional body params for the API call (for POST/PUT requests).
options.method stringDefault: 'GET'. Can be any HTTP request method valid for the given endpoint.

Testing

Fork 这个 repo,然后将 credentials.js 文件放在根目录中,其中包含以下内容。

// content of the credentials.js file, which needs to be placed at the root of this repo
module.exports = {
  partnerId: 'your_partner_id',
  secret: 'your_secret'
}

然后运行

npm test

​​这将在 http://localhost:3000/ 上启动一个 Express.js 服务器。

在 https://devcon.365farmnet.com/ 登录您的帐户, 单击“开发人员”选项卡 -> 开发者游乐场。 如果所有测试都通过,您应该看到 All test passed!,如果没有,请检查您的控制台 ?????

Contribution

请随时提交问题或请求请求!

License

麻省理工学院

365FarmNet Connect - Node.js client

A simple promise based client for the 365FarmNet Connect REST API.

Quick start

npm install 365farmnet

Note: This library requires Node.js > v.10.0

Import the library, and pass the partner ID and secret that you got from registering at https://devcon.365farmnet.com/.

const farmnet = require('365farmnet')({
  partnerId: 'yourPartnerId',
  secret: 'yourPartnerSecret'
})

Make requests to the 365FarmNet Connect REST API by calling the imported function (farmnet if you follow this example) in the following manner:

// farmnettoken is the JWT that is passed to the iframe within the 
// 365FarmNet main application
farmnet('fields', {
  token: farmnettoken,
  params: {
    includeGeometry: false,
    includeSoilType: true
  }
}).then(data => {
  // data will contain all fields of the farm
}).catch(err => {
  console.log(err)
})

API

The module exports a default function. It takes two arguments:

farmnet('endpoint', options)

NameDescription
endpoint string requiredThe REST API endpoint to call. See documentation for all available endpoints.
options.token string requiredThe token property of the options object needs to be a valid JWT farmnettoken.
options.params objectOptional query params for the API call.
options.data objectOptional body params for the API call (for POST/PUT requests).
options.method stringDefault: 'GET'. Can be any HTTP request method valid for the given endpoint.

Testing

Fork this repo, then put a credentials.js file in the root directory with the following content.

// content of the credentials.js file, which needs to be placed at the root of this repo
module.exports = {
  partnerId: 'your_partner_id',
  secret: 'your_secret'
}

Then run

npm test

This will spin up an Express.js server on http://localhost:3000/.

Login to your account at https://devcon.365farmnet.com/, click on the Developer tab -> Developer Playground. If all tests pass, you should see All test passed!, if not, check your console ????

Contribution

Please feel free to submit an issue or a pull request!

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文