Created
December 6, 2017 05:49
-
-
Save flanker/3e26f2ce53a40873c283a9666f4819b7 to your computer and use it in GitHub Desktop.
This file contains 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
# example ruby code to create entry with table field using jinshuju.com v1 api | |
# help document for the api: https://help.jinshuju.net/articles/entry-api | |
require 'net/http' | |
require 'openssl' | |
subdomain = 'im' # your jinshuju.com subdomain | |
form_token = 'ZsKUgS' # fake token. put your form token here | |
key = 'A9f5kBbFRf71wpJvcaiwkC' # fake key. put your API Key here | |
secret = 'Ch6_XmbaaBr-ResDh0Ga9w' # fake secret. put your API Secret here | |
uri = URI("https://#{subdomain}.jinshuju.com/api/v1/forms/#{form_token}") | |
# table field: field_1. with columns: | |
# field_1: 单行文字 | |
# field_2: 多行文字 | |
# field_3: 下拉框 | |
# field_4: 手机 | |
# field_5: 数字 | |
# field_6: 日期 | |
payload = <<EOF | |
{ | |
"field_1": [ | |
{"field_1": "text", "field_2": "long text", "field_3": "BWmt", "field_4": "13888888888", "field_5": "123456", "field_6": "2017-08-28"}, | |
{"field_1": "text", "field_2": "long text", "field_3": "U3GM", "field_4": "13999999999", "field_5": "0", "field_6": "2017-09-23"} | |
] | |
} | |
EOF | |
Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| | |
request = Net::HTTP::Post.new uri.request_uri | |
request.basic_auth key, secret | |
request.add_field('Content-Type', 'application/json') | |
request.add_field('Accept', 'application/json') | |
request.body = payload | |
response = http.request request | |
puts response | |
puts response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment