tsubaiso-sdk 1.2.1 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c0bbf2f5710b7de3360f142a25fdcd8eb59e9a7f
4
- data.tar.gz: eab335d57909cb4e2d1e1f5aad428693198d263f
2
+ SHA256:
3
+ metadata.gz: 7692d60351cf486110092b0504852ade90ab4c232a945033989859b3086733f6
4
+ data.tar.gz: d1a24ea0e75784def364657a318f67b7d1994ba1ef90cc3e14537090f552e90f
5
5
  SHA512:
6
- metadata.gz: 6b318b0cc37320a8490194ee268c37dc7b389528b733f5bd0cbd77648bfd37b0d8e45c304afc1007be0a8351082241f04983d628fe1bab042aa3a06e130827ff
7
- data.tar.gz: 8171a64299a6050899bd91327f4b12b3f6dd10a3dc47734ec2e60a484cadc220e71bf14d27bec63e620b3696127a1444ef723d4718b046167ffac165b062dc6c
6
+ metadata.gz: c7aada144d360b894e23fc6f65aee45f19b56e5abbc8d4a9a652bcec5a052d91d62c7f96b1f0c928e431350e2a08e339597b89a06c760eb808b51b5746fbae80
7
+ data.tar.gz: e7c8d1a4964791d2c013fb8d72a2f9570db1d7955cd19fc717e46bb0bb5196fed886e3ccbe2f89b419cefc34543cc23d43e29e534bbd5e65ff55c76bd4261dd3
@@ -0,0 +1,67 @@
1
+ # ..
2
+ class TsubaisoAPI
3
+ require "net/http"
4
+ require "json"
5
+
6
+ def initialize(options = {})
7
+ @base_url = options[:base_url] || 'https://tsubaiso.net'
8
+ @access_token = options[:access_token]
9
+ end
10
+
11
+ def list(resource, params = {})
12
+ api_request(url_parse(resource + '/list'), "GET", params)
13
+ end
14
+
15
+ def show(resource, params = {})
16
+ api_request(url_parse(resource + "/show/#{params[:id]}"), "GET", params)
17
+ end
18
+
19
+ def create(resource, params = {})
20
+ api_request(url_parse(resource + '/create'), "POST", params)
21
+ end
22
+
23
+ def update(resource, params = {})
24
+ api_request(url_parse(resource + '/update'), "POST", params)
25
+ end
26
+
27
+ def destroy(resource, params = {})
28
+ api_request(url_parse(resource + '/destroy'), "POST", params)
29
+ end
30
+
31
+ def get(url, params = {})
32
+ api_request(url_parse(url), "GET", params)
33
+ end
34
+
35
+ def post(url, params = {})
36
+ api_request(url_parse(url), "POST", params)
37
+ end
38
+
39
+ private
40
+
41
+ def api_request(uri, http_verb, params)
42
+ http = Net::HTTP.new(uri.host, uri.port)
43
+ initheader = {'Content-Type' => 'application/json', "Accept" => "application/json"}
44
+ http.use_ssl = true if @base_url =~ /^https/
45
+ if http_verb == "GET"
46
+ request = Net::HTTP::Get.new(uri.path, initheader)
47
+ else
48
+ request = Net::HTTP::Post.new(uri.path, initheader)
49
+ end
50
+ request["Access-Token"] = @access_token
51
+ request.body = params.to_json
52
+ response = http.request(request)
53
+ if response.body
54
+ begin
55
+ { status: response.code, json: JSON.parse(response.body) }
56
+ rescue
57
+ response.body
58
+ end
59
+ else
60
+ { status: response.code, json: {}.to_json }
61
+ end
62
+ end
63
+
64
+ def url_parse(end_point)
65
+ URI.parse(@base_url + end_point)
66
+ end
67
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: utf-8
2
+ require 'minitest/autorun'
3
+ require 'time'
4
+ require './lib/tsubaiso_api'
5
+
6
+ class TsubaisoAPITest < Minitest::Test
7
+
8
+ def setup
9
+ @api = TsubaisoAPI.new({ base_url: ENV["SDK_BASE_URL"], access_token: ENV["SDK_ACCESS_TOKEN"] })
10
+ @customer_1000 = { name: "テスト株式会社", name_kana: "テストカブシキガイシャ", code: "10000", tax_type_for_remittance_charge: "3", used_in_ar: 1, used_in_ap: 1, is_valid: 1 }
11
+
12
+ @sale_201608 = { price_including_tax: 10800, realization_timestamp: "2016-08-01", customer_master_code: "101", dept_code: "SETSURITSU", reason_master_code: "SALES", dc: 'd', memo: "irfan test", tax_code: 1007, scheduled_memo: "This is a scheduled memo.", scheduled_receive_timestamp: "2016-09-25", data_partner: { link_url: "www.example.com/1", id_code: "1"} }
13
+
14
+ @sale_201702 = { price_including_tax: 10800, realization_timestamp: "2017-02-28", customer_master_code: "105", reason_master_code: "SALES", dc: 'd', memo: "", tax_code: 18, scheduled_memo: "This is a scheduled memo.", scheduled_receive_timestamp: "2017-03-25", data_partner: { link_url: "www.example.com/8", id_code: "8"} }
15
+
16
+ @reimbursement_1 = { applicant: "Matsuno", application_term: "2016-03-01", staff_code: "EP2000", memo: "aaaaaaaa" }
17
+ @reimbursement_tx_1 = { transaction_timestamp: "2016-03-01", price_value: 10000, dc:"c", reason_code:"SUPPLIES", brief:"everyting going well", memo:"easy", data_partner: { link_url: "www.example.com/5", id_code: "5"} }
18
+ end
19
+
20
+ def test_list
21
+ cm = @api.create('customer_masters', @customer_1000)
22
+ assert_equal 200, cm[:status].to_i
23
+ assert @customer_1000[:code], cm[:json]['code']
24
+
25
+ list_customers = @api.list('customer_masters')
26
+ assert_equal 200, list_customers[:status].to_i
27
+
28
+ assert list_customers[:json]&.any? { |x| x['code'] == @customer_1000[:code] }
29
+ ensure
30
+ @api.destroy('customer_masters', id: cm[:json]['id']) if cm[:json]['id']
31
+ end
32
+
33
+ def test_show
34
+ ar = @api.create('ar_receipts', @sale_201608)
35
+ assert 200, ar[:status].to_i
36
+ assert @sale_201608[:customer_master_code], ar[:json]["customer_master_code"]
37
+
38
+ show_ar = @api.show('ar_receipts', id: ar[:json]['id'])
39
+ assert successful?(show_ar[:status])
40
+ assert_equal show_ar[:json], ar[:json]
41
+ ensure
42
+ @api.destroy('ar_receipts', id: ar[:json]['id']) if ar[:json]['id']
43
+ end
44
+
45
+ def test_create_and_destroy
46
+ ar = @api.create('ar_receipts', @sale_201608)
47
+ assert successful?(ar[:status])
48
+ assert @sale_201608[:customer_master_code], ar[:json]['customer_master_code']
49
+
50
+ cm = @api.create('customer_masters', @customer_1000)
51
+ assert successful?(cm[:status])
52
+ assert @customer_1000[:code], cm[:json]['code']
53
+
54
+ reim = @api.create('reimbursements', @reimbursement_1)
55
+ assert successful?(reim[:status])
56
+ assert @reimbursement_1[:staff_code], reim[:json]['staff_code']
57
+
58
+ reim_tx = @api.create('reimbursement_transactions', @reimbursement_tx_1)
59
+ assert successful?(reim[:status])
60
+ assert @reimbursement_tx_1[:reason_code], reim_tx[:json]['reason_code']
61
+ ensure
62
+ @api.destroy('ar_receipts', id: ar[:json]['id']) if ar[:json]['id']
63
+ @api.destroy('customer_masters', id: cm[:json]['id']) if cm[:json]['id']
64
+ @api.destroy('reimbursements', id: reim[:json]['id']) if reim[:json]['id']
65
+ @api.destroy('reimbursement_transactions', id: reim_tx[:json]['id']) if reim_tx[:json]['id']
66
+ end
67
+
68
+ def test_get_and_post
69
+ time = Time.mktime(@sale_201702[:realization_timestamp])
70
+ balance_before = @api.get('ar_receipts/balance', { year: time.year, month: time.month })
71
+ assert successful?(balance_before[:status])
72
+ assert balance_before[:json].count > 0
73
+
74
+ ar1 = @api.post('ar_receipts/create', @sale_201702)
75
+ assert successful?(ar1[:status])
76
+ assert_equal @sale_201702[:scheduled_memo], ar1[:json]['scheduled_memo']
77
+
78
+ cm = @api.post('customer_masters/create', @customer_1000)
79
+ assert successful?(cm[:status])
80
+ assert_equal @customer_1000[:code], cm[:json]['code']
81
+
82
+ balance_after = @api.get('ar_receipts/balance', { year: time.year, month: time.month })
83
+ assert successful?(balance_after[:status])
84
+ assert balance_after[:json].count > 0
85
+ ensure
86
+ @api.destroy('ar_receipts', id: ar1[:json]['id']) if ar1[:json]['id']
87
+ @api.destroy('customer_masters', id: cm[:json]['id']) if cm[:json]['id']
88
+ end
89
+
90
+ def test_update
91
+ cm = @api.create('customer_masters', @customer_1000)
92
+ cm_updated = @api.update('customer_masters', { id: cm[:json]['id'], name: 'TEST_NEW_UPDATED' })
93
+ assert successful?(cm_updated[:status])
94
+ assert cm_updated[:json]['name'] == 'TEST_NEW_UPDATED'
95
+ assert cm_updated[:json]['id'] == cm[:json]['id']
96
+ ensure
97
+ @api.destroy('customer_masters', id: cm[:json]['id']) if cm[:json]['id']
98
+ end
99
+
100
+ private
101
+
102
+ def successful?(status)
103
+ status.to_i == 200
104
+ end
105
+ end
@@ -27,8 +27,8 @@ class TsubaisoSDKTest < Minitest::Test
27
27
  credit: {account_code: 135, price_including_tax: 1000, tax_type: 1, sales_tax: 100} ], data_partner: { link_url: "www.example.com/7", id_code: "7"} }
28
28
  @dept_1= {sort_no: 12345678, code: 'test_code', name: 'テスト部門', name_abbr: 'テストブモン', color: '#ffffff', memo: 'テストメモ', start_date: '2016-01-01', finish_date: '2016-01-02'}
29
29
  @tag_1 = {code: 'test_code', name: 'テストタグ', sort_no: 10000, tag_group_code: "DEFAULT", start_ymd: '2016-01-01', finish_ymd: '2016-12-31'}
30
- @journal_distribution_1 = { title: 'title', start_date: "2016-09-01", finish_date: "2016-09-30", account_codes: ["135~999","604"], dept_code: "SETSURITSU", memo: "",
31
- criteria: "dept", target_timestamp: "2017-02-01", distribution_conditions: { "SETSURITSU" => "1", "SYSTEM" => "1" } }
30
+ @journal_distribution_1 = { title: 'title', start_date: "2012-07-01", finish_date: "2012-07-31", account_codes: ["135~999","604"], dept_code: "SETSURITSU", memo: "",
31
+ criteria: "dept", target_timestamp: "2017-02-01", distribution_conditions: { "SETSURITSU" => "1", "COMMON" => "1" } }
32
32
  end
33
33
 
34
34
  def test_failed_request
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsubaiso-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsubaiso, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -58,8 +58,10 @@ extra_rdoc_files: []
58
58
  files:
59
59
  - README.md
60
60
  - Rakefile
61
+ - lib/tsubaiso_api.rb
61
62
  - lib/tsubaiso_sdk.rb
62
63
  - sample.rb
64
+ - test/test_tsubaiso_api.rb
63
65
  - test/test_tsubaiso_sdk.rb
64
66
  homepage: https://github.com/tsubaiso/tsubaiso-sdk-ruby
65
67
  licenses:
@@ -81,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  version: '0'
82
84
  requirements: []
83
85
  rubyforge_project:
84
- rubygems_version: 2.6.13
86
+ rubygems_version: 2.7.6
85
87
  signing_key:
86
88
  specification_version: 4
87
89
  summary: SDK for the Tsubaiso API