首页
/ NetSuite SuiteTalk API Ruby Gem 技术文档

NetSuite SuiteTalk API Ruby Gem 技术文档

2024-12-26 19:50:44作者:毕习沙Eudora

本文档旨在帮助用户了解和使用 NetSuite SuiteTalk API Ruby Gem 项目。文档内容包括安装指南、使用说明、API 使用文档以及项目安装方式。

1. 安装指南

1.1 通过 Gemfile 安装

在您的应用程序的 Gemfile 中添加以下行:

gem 'netsuite'

如果您需要更精确的时间转换支持,可以同时包含 tzinfo gem。

1.2 安装依赖

在项目目录下运行以下命令以安装依赖:

bundle install

1.3 测试安装

在贡献代码之前,请确保所有现有测试通过:

git clone git://github.com/NetSweet/netsuite.git
cd netsuite
bundle exec rspec

2. 项目的使用说明

2.1 配置

在使用 NetSuite SuiteTalk API 之前,您需要进行一些配置。最重要的配置项是您的 NetSuite 账户 ID。以下是一个配置示例:

NetSuite.configure do
  reset!

  account  'TSTDRV1576318'
  api_version '2018_2'

  email 'email@example.com'
  password 'password'
  role 10

  wsdl_domain 'tstdrv1576318.suitetalk.api.netsuite.com'
  endpoint "https://#{wsdl_domain}/services/NetSuitePort_#{api_version}"
end

2.2 认证方式

推荐使用 Token Based Authentication 进行认证。以下是配置示例:

NetSuite.configure do
  reset!

  account       ENV['NETSUITE_ACCOUNT']
  consumer_key     ENV['NETSUITE_CONSUMER_KEY']
  consumer_secret  ENV['NETSUITE_CONSUMER_SECRET']
  token_id         ENV['NETSUITE_TOKEN_ID']
  token_secret     ENV['NETSUITE_TOKEN_SECRET']
  api_version      '2016_2'
  endpoint "https://#{wsdl_domain}/services/NetSuitePort_#{api_version}"
end

3. 项目 API 使用文档

3.1 CRUD 操作

以下是一些常见的 CRUD 操作示例:

# 获取客户信息
customer = NetSuite::Records::Customer.get(:internal_id => 4)
customer.is_person

# 获取客户列表
customers = NetSuite::Records::Customer.get_list(:list => [4, 5, 6])

# 创建任务
task = NetSuite::Records::Task.new(
  :title => 'Take Care of a Customer',
  :assigned => NetSuite::Records::RecordRef.new(internal_id: customer_support_reps.sample),
  :due_date => DateTime.now + 1,
  :message => "Take care of this"
)
task.add

# 更新任务
task.update(message: 'New Message')

# 删除任务
task.delete

# 刷新任务
task.refresh

3.2 文件上传与附件

以下是如何上传文件并将其附加到记录的示例:

file = NetSuite::Records::File.new(
  content: Base64.encode64(File.read('/path/to/file')),
  name: 'Invoice.pdf',
)
file.add

invoice = NetSuite::Records::Invoice.get(internal_id: 1)
invoice.attach_file(NetSuite::Records::RecordRef.new(internal_id: file.internal_id))

3.3 自定义记录与字段

以下是如何更新自定义字段列表的示例:

# 更新记录上的自定义字段列表
# 您需要推送所有自定义字段的所有值,不能只推送您想要更新的字段值

4. 项目安装方式

4.1 通过 Gemfile 安装

在您的应用程序的 Gemfile 中添加以下行:

gem 'netsuite'

然后运行 bundle install 安装依赖。

4.2 手动安装

您也可以通过以下命令手动安装 gem:

gem install netsuite

4.3 测试安装

在贡献代码之前,请确保所有现有测试通过:

git clone git://github.com/NetSweet/netsuite.git
cd netsuite
bundle exec rspec

通过本文档,您应该能够顺利安装、配置并使用 NetSuite SuiteTalk API Ruby Gem 项目。如有任何问题,请参考项目的 Wiki 或加入 Slack 频道获取帮助。

登录后查看全文
热门项目推荐