ne_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9182e66f1f2d09fe081dd5eb8c2400671e147cf
4
+ data.tar.gz: 37d6059d92170eeaf95390e0109ac0bb0bb4109e
5
+ SHA512:
6
+ metadata.gz: d674c9866a9d55a3f8b45cd044fb81c7460094cffd3a801030f50d356db4294068a7e5bbdc2418f9227bde150ebbf7c6ac63a5c95bac8f04133d4ee788291bfb
7
+ data.tar.gz: 011680c2152c9a18c8bbe5cde8f421df5f8a3da731c06bdc5daf112b1b5069bc0551b3278c3a5099d988a36a4692ebc4119494d126a3018683d4e2e70c881e7d
data/.env ADDED
@@ -0,0 +1,2 @@
1
+ CLIENT_ID="please set client_id"
2
+ CLIENT_SECRET = "please set client_secret"
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ne_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yuuna Kurita
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Next Engine Ruby Gem
2
+
3
+ A Ruby wrapper for the Next Engine API
4
+ <http://api.next-e.jp>
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ne_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ne_api
22
+
23
+ ## How to Use
24
+
25
+ please read [API Document](http://api.next-e.jp/).
26
+
27
+ ## Sample Application
28
+
29
+ ```ruby
30
+ require 'ne_api'
31
+ require 'sinatra/base'
32
+ class MyApp < Sinatra::Base
33
+ enable :sessions
34
+ CLIENT_ID = "XXX"
35
+ CLIENT_SECRET = "XXXX"
36
+ CALLBACK_URI = "https://localhost:3000/callback"
37
+ get "/" do
38
+ "<a href=" + NeAPI::NE_SERVER_HOST + NeAPI::Auth::SIGN_IN_PATH + "?client_id="+CLIENT_ID+"&client_secret="+CLIENT_SECRET+"&redirect_uri="+ CALLBACK_URI + ">Connect with Next Engine</a>"
39
+ end
40
+
41
+ get "/callback" do
42
+ auth = NeAPI::Auth.new redirect_url: CALLBACK_URI
43
+ res = auth.ne_auth params[:uid], params[:state]
44
+ session[:access_token] = res["access_token"]
45
+ session[:refresh_token] = res["refresh_token"]
46
+ redirect "/home"
47
+ end
48
+
49
+ get "/home" do
50
+ redirect "/" if session[:access_token].nil? || session[:refresh_token].nil?
51
+ html =
52
+ """
53
+ <h2>sample for ne api call</h2>
54
+ <ol>
55
+ <li><a href='/login_user/info'>Login User Info</a></li>
56
+ <li><a href='/login_company/info'>Login Company Info</a></li>
57
+ <li><a href='/receiveorder/search'>Login Receive Order Search</a></li>
58
+ </ol>
59
+ """
60
+ end
61
+
62
+ get "/receiveorder/search" do
63
+ content_type :text
64
+ result = (NeAPI::Master.new(access_token: session["access_token"], refresh_token: session["refresh_token"]).receiveorder_base_search)
65
+ result.inspect
66
+ end
67
+
68
+ get "/login_user/info" do
69
+ content_type :text
70
+ result = (NeAPI::Master.new(access_token: session["access_token"], refresh_token: session["refresh_token"]).login_user_info)
71
+ update_token result
72
+ result["data"].first.inspect
73
+ end
74
+
75
+ get "/login_company/info" do
76
+ content_type :text
77
+ result = (NeAPI::Master.new(access_token: session["access_token"], refresh_token: session["refresh_token"]).login_company_info)
78
+ update_token result
79
+ result["data"].first.inspect
80
+ end
81
+
82
+ def update_token res
83
+ session[:access_token] = res["access_token"]
84
+ session[:refresh_token] = res["refresh_token"]
85
+ end
86
+
87
+ end
88
+
89
+
90
+ MyApp.run! host: 'localhost', port: 3000 do |server|
91
+
92
+ ssl_options = {
93
+ :verify_peer => false
94
+ }
95
+ server.ssl = true
96
+ server.ssl_options = ssl_options
97
+ end
98
+
99
+ ```
100
+
101
+ ## Contributing
102
+
103
+ 1. Fork it ( https://github.com/[my-github-username]/ne_api/fork )
104
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
105
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
106
+ 4. Push to the branch (`git push origin my-new-feature`)
107
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/config/api.yaml ADDED
@@ -0,0 +1,231 @@
1
+ ---
2
+ :master_goods:
3
+ :method:
4
+ - count
5
+ - search
6
+ - upload
7
+ :prefix: goods
8
+ :fields: id,name,jan_code
9
+ :master_stock:
10
+ :method:
11
+ - count
12
+ - search
13
+ :prefix: stock
14
+ :fields: goods_id,quantity,allocation_quantity,defective_quantity,remaining_order_quantity,out_quantity,free_quantity,advance_order_quantity,advance_order_allocation_quantity,advance_order_free_quantity
15
+ :master_mailtag:
16
+ :method:
17
+ - count
18
+ - search
19
+ :prefix: mail_tag
20
+ :fields: id,month,name,note,message1,message2,message3,message4,message5,message6
21
+ :master_goodstag:
22
+ :method:
23
+ - count
24
+ - search
25
+ :prefix: goods_tag
26
+ :fields: goods_id,name
27
+ :master_supplier:
28
+ :method:
29
+ - count
30
+ - search
31
+ :prefix: supplier
32
+ :fields: id,name,post
33
+ :master_wholesale:
34
+ :method:
35
+ - count
36
+ - search
37
+ :prefix: wholesale
38
+ :fields: id,name,post_name,destination_no
39
+ :master_stockiohistory:
40
+ :method:
41
+ - count
42
+ - search
43
+ :prefix: stock_io_history
44
+ :fields: id,shop_id,goods_id,date,before_stock_quantity,after_stock_quantity,before_bad_stock_quantity,after_bad_stock_quantity,quantity,cut_form_id,io_flag,io_type_id,io_type_name,reason,pic_id,pic_name
45
+ :master_pagebase:
46
+ :method:
47
+ - count
48
+ - search
49
+ :prefix: page_base
50
+ :fields: goods_id,goods_name
51
+ :master_pagebasevariationoroption:
52
+ :method:
53
+ - count
54
+ - search
55
+ :prefix: page_base_v_o
56
+ :fields: goods_id,option_category,option_name,horizontal_value,vertical_value,horizontal_name,vertical_name,type,display_order
57
+ :master_shop:
58
+ :method:
59
+ - count
60
+ - search
61
+ :prefix: shop
62
+ :fields: id,name,kana,abbreviated_name,handling_goods_name,note,mall_id,authorization_type_id,authorization_type_name,tax_id,tax_name,currency_unit_id,currency_unit_name,tax_calculation_sequence_id,type_id,deleted_flag
63
+ :master_goodsimage:
64
+ :method:
65
+ - count
66
+ - search
67
+ :prefix: goods_image
68
+ :fields: id,goods_id,file_name,url_http,url_https,size,width,height,alt,convert_flg,display_order,status
69
+ :master_goodsimagetag:
70
+ :method:
71
+ - count
72
+ - search
73
+ :prefix: goods_image_tag
74
+ :fields: id,goods_image_id,image_tag_id
75
+ :master_goodscategory:
76
+ :method:
77
+ - count
78
+ - search
79
+ :prefix: goods_category
80
+ :fields: id,goods_id,mall_id,mall_category_id,text
81
+ :login_user:
82
+ :method:
83
+ - info
84
+ :login_company:
85
+ :method:
86
+ - info
87
+ :system_credittype:
88
+ :method:
89
+ - info
90
+ :system_creditauthorizationcenter:
91
+ :method:
92
+ - info
93
+ :system_creditapprovaltype:
94
+ :method:
95
+ - info
96
+ :system_order:
97
+ :method:
98
+ - info
99
+ :system_ordercondition:
100
+ :method:
101
+ - info
102
+ :system_delivery:
103
+ :method:
104
+ - info
105
+ :system_fraction:
106
+ :method:
107
+ - info
108
+ :system_returnedreason:
109
+ :method:
110
+ - info
111
+ :system_canceltype:
112
+ :method:
113
+ - info
114
+ :system_orderstatus:
115
+ :method:
116
+ - info
117
+ :system_importantcheck:
118
+ :method:
119
+ - info
120
+ :system_confirmcheck:
121
+ :method:
122
+ - info
123
+ :system_customertype:
124
+ :method:
125
+ - info
126
+ :system_deposittype:
127
+ :method:
128
+ - info
129
+ :system_iotype:
130
+ :method:
131
+ - info
132
+ :system_select:
133
+ :method:
134
+ - info
135
+ :system_paymentmethod:
136
+ :method:
137
+ - info
138
+ :system_payout:
139
+ :method:
140
+ - info
141
+ :system_socialinsurance:
142
+ :method:
143
+ - info
144
+ :system_goodstype:
145
+ :method:
146
+ - info
147
+ :system_goodsstatus:
148
+ :method:
149
+ - info
150
+ :system_merchandise:
151
+ :method:
152
+ - info
153
+ :system_importtype:
154
+ :method:
155
+ - info
156
+ :system_forwardingmethod:
157
+ :method:
158
+ - info
159
+ :system_tax:
160
+ :method:
161
+ - info
162
+ :system_itemname:
163
+ :method:
164
+ - info
165
+ :system_pagestatus:
166
+ :method:
167
+ - info
168
+ :system_authorizationtype:
169
+ :method:
170
+ - info
171
+ :system_currencyunit:
172
+ :method:
173
+ - info
174
+ :system_que:
175
+ :method:
176
+ - count
177
+ - search
178
+ :prefix: que
179
+ :fields: id,method_name,shop_id,upload_name,client_file_name,file_name,status_id,message
180
+ :system_mall:
181
+ :method:
182
+ - count
183
+ - search
184
+ :prefix: mall
185
+ :fields: id,name,kana,note,country_id
186
+ :system_imagetag:
187
+ :method:
188
+ - count
189
+ - search
190
+ :prefix: image_tag
191
+ :fields: id,mall_id,mall_sub_id,text,auto_register_no,display_order
192
+ :system_mallcategory:
193
+ :method:
194
+ - count
195
+ - search
196
+ :prefix: mall_category
197
+ :fields: id,mall_id,code,parent_mall_category_id,name,full_name
198
+ :receiveorder_uploadpattern:
199
+ :method:
200
+ - info
201
+ :receiveorder_base:
202
+ :method:
203
+ - count
204
+ - search
205
+ - update
206
+ - upload
207
+ - receipted
208
+ - shipped
209
+ - labelprinted
210
+ - divide
211
+ :prefix: receive_order
212
+ :fields: shop_id,id,shop_cut_form_id,date,import_date,important_check_id,important_check_name,confirm_check_id,confirm_check_name,confirm_ids,mail_status,gruoping_tag,import_type_id,import_type_name,cancel_type_id,cancel_type_name,cancel_date,closed_after_edit_date,order_status_id,order_status_name,delivery_id,delivery_name,payment_method_id,payment_method_name,total_amount,tax_amount,charge_amount,delivery_fee_amount,other_amount,point_amount,goods_amount,deposit_amount,deposit_type_id,deposit_type_name,deposit_date,foreign_total_amount,foreign_tax_amount,foreign_charge_amount,foreign_delivery_fee_amount,foreign_other_amount,foreign_goods_amount,foreign_deposit_amount,note,include_possible_order_id,include_to_order_id,multi_delivery_parent_order_id,multi_delivery_parent_flag,statement_delivery_instruct_printing_date,statement_delivery_printing_date,statement_delivery_text,send_date,send_plan_date,send_sequence,worker_text,picking_instruct,picking_min_supplier_id,picking_min_goods_id,label_print_date,label_print_flag,hope_delivery_date,hope_delivery_time_slot_id,hope_delivery_time_slot_name,delivery_method_id,delivery_method_name,seal1_id,seal1_name,seal2_id,seal2_name,seal3_id,seal3_name,seal4_id,seal4_name,business_office_stop_id,business_office_stop_name,invoice_id,invoice_name,temperature_id,temperature_name,business_office_name,gift_flag,delivery_cut_form_id,delivery_cut_form_note,credit_type_id,credit_type_name,credit_approval_no,credit_approval_amount,credit_approval_type_id,credit_approval_type_name,credit_approval_date,credit_approval_rate,credit_number_payments,credit_authorization_center_id,credit_authorization_center_name,credit_approval_fax_printing_date,customer_type_id,customer_type_name,customer_id,purchaser_name,purchaser_kana,purchaser_zip_code,purchaser_address1,purchaser_address2,purchaser_tel,purchaser_fax,purchaser_mail_address,consignee_name,consignee_kana,consignee_zip_code,consignee_address1,consignee_address2,consignee_tel,consignee_fax,reminder_start_date,reminder_last_date,reminder_count,important_check_pic_id,important_check_pic_name,pic_id,pic_name,send_pic_id,send_pic_name,deleted_flag,creation_date,last_modified_date,last_modified_null_safe_date,creator_id,creator_name,last_modified_by_id,last_modified_by_null_safe_id,last_modified_by_name,last_modified_by_null_safe_name
213
+
214
+ :receiveorder_row:
215
+ :method:
216
+ - count
217
+ - search
218
+ :prefix: receive_order_row
219
+ :fields: receive_order_id,shop_cut_form_id,no,shop_row_no,goods_id,goods_name,quantity,unit_price,wholesale_retail_ratio,goods_option
220
+ :receiveorder_forwardingagent:
221
+ :method:
222
+ - count
223
+ - search
224
+ :prefix: forwarding_agent
225
+ :fields: id,type,type_id,type_name,display_order,deleted_flag
226
+ :receiveorder_confirm:
227
+ :method:
228
+ - count
229
+ - search
230
+ :prefix: confirm
231
+ :fields: id,name,display_order,html,value,valid_flag
@@ -0,0 +1,3 @@
1
+ module NeApi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ne_api.rb ADDED
@@ -0,0 +1,126 @@
1
+ require 'oauth'
2
+ require 'faraday'
3
+ require 'yaml'
4
+ require 'json'
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+ require 'dotenv'
8
+
9
+ module NeAPI
10
+ API_SERVER_HOST = "https://api.next-engine.org"
11
+ NE_SERVER_HOST = "https://base.next-engine.org"
12
+
13
+ private
14
+ def conn
15
+ @conn ||= Faraday::Connection.new(url: API_SERVER_HOST) do |builder|
16
+ builder.use Faraday::Request::UrlEncoded
17
+ builder.use Faraday::Response::Logger
18
+ builder.use Faraday::Adapter::NetHttp
19
+ end
20
+ end
21
+
22
+ def response response
23
+ body = JSON.parse response.body
24
+ if body["result"] != "success"
25
+ raise NeAPIException, body["message"]
26
+ return false
27
+ end
28
+ body
29
+ end
30
+
31
+ class Master
32
+ include NeAPI
33
+ attr_accessor :access_token, :refresh_token
34
+ PATH_PREFIX="/api_v1_"
35
+
36
+ def initialize access_token: access_token, refresh_token: refresh_token
37
+ @@params = YAML.load_file(File.join(File.dirname(__FILE__),"../config/api.yaml"))
38
+ @access_token = access_token
39
+ @refresh_token = refresh_token
40
+ end
41
+
42
+ def post method: nil , model: nil, query: nil, fields: nil, get_key: nil, params: {}
43
+ raise NeAPIException, "no token!" if @access_token.nil? || @refresh_token.nil?
44
+
45
+ if fields.present? && query.present?
46
+ res =response(conn.post PATH_PREFIX+model.to_s+ "/" + method, {access_token: @access_token, refresh_token: @refresh_token, fields: fields}.merge(query).merge(params))
47
+ elsif fields.present?
48
+ res =response(conn.post PATH_PREFIX+model.to_s+ "/" + method, {access_token: @access_token, refresh_token: @refresh_token, fields: fields}.merge(params))
49
+ elsif query.present?
50
+ res =response(conn.post PATH_PREFIX+model.to_s+ "/" + method, {access_token: @access_token, refresh_token: @refresh_token}.merge(query).merge(params))
51
+ else
52
+ res =response(conn.post PATH_PREFIX+model.to_s+ "/" + method, {access_token: @access_token, refresh_token: @refresh_token}.merge(params))
53
+ end
54
+
55
+ @access_token = res["access_token"] if res["access_token"].present?
56
+ @referesh_token = res["referesh_token"] if res["referesh_token"].present?
57
+
58
+ get_key.present? ? res[get_key] : res
59
+ end
60
+ def method_missing(path, args={})
61
+ super if @@params.nil? || path.nil?
62
+ unless models = /^(.*)_.*$/.match(path.to_s)
63
+ super
64
+ end
65
+ model = models.captures.first.to_sym
66
+ method = path.to_s.split("_").last
67
+
68
+ if @@params.key?(model) && @@params[model][:method].include?(method)
69
+ get_key = nil
70
+ query = (args[:query].present? ? args[:query] : nil)
71
+ fields = (args[:fields].present? ? args[:fields] : nil)
72
+ params = (args[:params].present? ? args[:params] : {})
73
+ case method
74
+ when "count"
75
+ get_key = "count"
76
+ when "search"
77
+ req= @@params[model]
78
+ query ||= req[:query]
79
+ fields ||= req[:fields].gsub(/^\s*/,req[:prefix]+"_").gsub(/,\s*/,","+@@params[model][:prefix]+"_")
80
+ fields= fields
81
+ get_key = "data"
82
+ when "info"
83
+ query = nil
84
+ when "update", "upload", "receipted", "shipped", "labelprinted"
85
+ get_key = "result"
86
+ when "divide"
87
+ get_key = "receive_order_id"
88
+ else
89
+ super
90
+ end
91
+ self.post method: method, model: model, query: query, fields: fields, get_key: get_key, params: params
92
+ else
93
+ super
94
+ end
95
+ end
96
+ end
97
+
98
+ class Auth
99
+ include NeAPI
100
+ SIGN_IN_PATH = "/users/sign_in/"
101
+ NEAUTH_PATH = "/api_neauth/"
102
+ attr_accessor :redirect_url, :ne_user
103
+
104
+ def initialize redirect_url: nil
105
+ raise NeAPIException, "no redirect_url" if redirect_url.nil?
106
+ @redirect_url = redirect_url
107
+ end
108
+
109
+ #uid/state取得
110
+ def sign_in client_id = ENV["CLIENT_ID"] , client_secret = ENV["CLIENT_SECRET"]
111
+ Launchy.open NE_SERVER_HOST + SIGN_IN_PATH + "?client_id="+client_id+"&client_secret="+client_secret+"&redirect_uri="+@redirect_url
112
+ end
113
+
114
+ #access_token/企業情報取得
115
+ def ne_auth uid, state
116
+ @ne_user = response ( conn.post NEAUTH_PATH, {uid: uid, state: state})
117
+ @ne_user
118
+ end
119
+ def tokens
120
+ @ne_user.nil? ? nil : {access_token: @ne_user["access_token"], refresh_token: @ne_user["refresh_token"]}
121
+ end
122
+ end
123
+ end
124
+ class NeAPIException < StandardError
125
+ end
126
+
data/ne_api.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ne_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ne_api"
8
+ spec.version = NeApi::VERSION
9
+ spec.authors = ["Yuuna Kurita","Mika Koizumi"]
10
+ spec.email = ["yuuna.m@gmail.com"]
11
+ spec.summary = %q{Next Engine API for ruby}
12
+ spec.description = %q{Next Engine API for ruby}
13
+ spec.homepage = "http://github.com/infinity-octaver/ne_api/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency 'faraday'
24
+ spec.add_dependency 'oauth'
25
+ spec.add_dependency 'i18n'
26
+ spec.add_dependency 'activesupport'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_dependency 'dotenv'
29
+ spec.add_dependency 'launchy'
30
+ end
@@ -0,0 +1,170 @@
1
+ require 'yaml'
2
+ require 'ne_api.rb'
3
+
4
+ SEARCH_MODEL=["receiveorder_base", "receiveorder_row", "receiveorder_forwardingagent", "receiveorder_confirm", "master_goods", "master_stock", "master_mailtag", "master_goodstag", "master_supplier", "master_wholesale", "master_stockiohistory", "master_pagebase", "master_pagebasevariationoroption", "master_shop", "master_goodsimage", "master_goodsimagetag", "master_goodscategory", "system_que", "system_mall", "system_imagetag", "system_mallcategory"]
5
+ INFO_MODEL=["login_user", "login_company", "system_credittype", "system_creditauthorizationcenter", "system_creditapprovaltype", "system_order", "system_ordercondition", "system_delivery", "system_fraction", "system_returnedreason", "system_canceltype", "system_orderstatus", "system_importantcheck", "system_confirmcheck", "system_customertype", "system_deposittype", "system_iotype", "system_select", "system_paymentmethod", "system_payout", "system_socialinsurance", "system_goodstype", "system_goodsstatus", "system_merchandise", "system_importtype", "system_forwardingmethod", "system_tax", "system_itemname", "system_pagestatus", "receiveorder_uploadpattern", "system_authorizationtype", "system_currencyunit"]
6
+ describe 'searchについて' do
7
+ before(:all) do
8
+ @params =YAML.load_file("config/api.yaml")
9
+ auth = NeAPI::Auth.new redirect_url: "http://localhost:3000"
10
+ #auth.sign_in
11
+ #@user=auth.api_neauth
12
+ #@access_toen=@user[:access_token]
13
+ #@refresh_token=@user[:refresh_token]
14
+ @access_toen
15
+ @refresh_token
16
+ @master = NeAPI::Master.new access_token: @access_toen, refresh_token: @refresh_token
17
+ end
18
+ context '全てのメソッドについて' do
19
+ SEARCH_MODEL.each do |m|
20
+ it m.to_s+'は存在する' do
21
+ expect(@master.send(m.to_s+"_search")).to be_true
22
+ end
23
+ end
24
+ end
25
+ SEARCH_MODEL.each do |m|
26
+ context m.to_s+'_searchについて' do
27
+ context 'フィールド指定がない場合' do
28
+ it 'デフォルトで指定したフィールドの情報が返ってくる' do
29
+ ret=true
30
+ @params[m.to_sym][:fields].split(",").each {|f| ret=false unless (@master.send(m.to_s+"_search")).first.has_key?(@params[m.to_sym][:prefix]+"_"+f)}
31
+ expect(ret).to be_true
32
+ end
33
+ end
34
+ context 'フィールド指定が複数ある場合' do
35
+ context 'フィールド名が正しい' do
36
+ it '引数で与えたフィールドの情報が返ってくる' do
37
+ field=@params[m.to_sym][:prefix]+"_last_modified_date,"+@params[m.to_sym][:prefix]+"_creation_date"
38
+ ret=true
39
+ field.split(",").each{|f| ret=false unless (@master.send(m.to_s+"_search", {fields: field})).first.has_key?(f)}
40
+ expect(ret).to be_true
41
+ end
42
+ context 'フィールド名が間違っている' do
43
+ it 'エラーが返される' do
44
+ field=@params[m.to_sym][:prefix]+"_last_modified_date, invalid_field"
45
+ expect{@master.send(m.to_s+"_search", {fields: field})}.to raise_error(NeAPIException)
46
+ end
47
+ end
48
+ end
49
+ context 'フィールドの検索条件がある場合' do
50
+ context '存在しないフィールドである' do
51
+ it 'エラーが返される' do
52
+ expect{@master.send(m.to_s+"_search", {"invalid_field-like" => "hoge"})}.to raise_error(NeAPIException)
53
+ end
54
+ end
55
+ context '指定形式が間違っている' do
56
+ it 'エラーが返される' do
57
+ expect{@master.send(m.to_s+"_search", {@params[m.to_sym][:prefix]+"_creation_date_gte"=> Time.now.strftime("%F %T")})}.to raise_error(NeAPIException)
58
+ end
59
+ end
60
+ context '検索条件が正しい' do
61
+ context '検索の結果が複数件ある' do
62
+ it '複数件のデータが返される' do
63
+ expect(@master.send(m.to_s+"_search", {@params[m.to_sym][:prefix]+"_creation_date-lte"=> Time.now.strftime("%F %T")}).count).to be >0
64
+ end
65
+ it '返されるデータはデフォルトのフィールドを持つ' do
66
+ ret=true
67
+ @params[m.to_sym][:fields].split(",").each {|f| ret=false unless (@master.send(m.to_s+"_search", {@params[m.to_sym][:prefix]+"_creation_date-lte"=> Time.now.strftime("%F %T")})).first.has_key?(@params[m.to_sym][:prefix]+"_"+f)}
68
+ expect(ret).to be_true
69
+ end
70
+ end
71
+ context '検索の結果が複数件あり,フィールド指定もされている' do
72
+ it '返されるデータは指定されたフィールドを持つ' do
73
+ expect((@master.send(m.to_s+"_search", {@params[m.to_sym][:prefix]+"_creation_date-lte"=> Time.now.strftime("%F %T"), fields: @params[m.to_sym][:prefix]+"_creation_date"})).first.has_key?(@params[m.to_sym][:prefix]+"_creation_date")).to be_true
74
+ end
75
+ end
76
+ context '検索の結果が0件' do
77
+ it '空の配列が返される' do
78
+ expect(@master.send(m.to_s+"_search", {@params[m.to_sym][:prefix]+"_creation_date-gte"=> Time.now.strftime("%F %T")})).to be_empty
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ describe 'countAPI' do
88
+ before(:all) do
89
+ @params =YAML.load_file("config/api.yaml")
90
+ auth = NeAPI::Auth.new redirect_url: "http://localhost:3000"
91
+ #auth.sign_in
92
+ #@user=auth.api_neauth
93
+ #@access_toen=@user[:access_token]
94
+ #@refresh_token=@user[:refresh_token]
95
+ @access_toen
96
+ @refresh_token
97
+ @master = NeAPI::Master.new access_token: @access_toen, refresh_token: @refresh_token
98
+ end
99
+ context '全てのメソッドについて' do
100
+ SEARCH_MODEL.each do |m|
101
+ it m.to_s+'は存在する' do
102
+ expect(@master.send(m.to_s+"_count")).to be_true
103
+ end
104
+ end
105
+ end
106
+ SEARCH_MODEL.each do |m|
107
+ context m.to_s+'_countについて' do
108
+ context 'フィールドの検索条件がない場合' do
109
+ it '数字が返ってくる' do
110
+ expect(@master.send(m.to_s+"_count")).to match(/\d+/)
111
+ end
112
+ end
113
+ context '存在しないフィールドである' do
114
+ it 'エラーが返される' do
115
+ expect{@master.send(m.to_s+"_count", {"invalid_field-like" => "hoge"})}.to raise_error
116
+ end
117
+ end
118
+ context '指定形式が間違っている' do
119
+ it 'エラーが返される' do
120
+ expect{@master.send(m.to_s+"_count", {@params[m.to_sym][:prefix]+"_creation_date_gte"=> Time.now.strftime("%F %T")})}.to raise_error
121
+ end
122
+ end
123
+ context '検索条件が正しい' do
124
+ context '検索の結果が複数件ある' do
125
+ it '数字が返ってくる' do
126
+ expect(@master.send(m.to_s+"_count", {@params[m.to_sym][:prefix]+"_creation_date-lte"=> Time.now.strftime("%F %T")})).to match(/\d+/)
127
+ end
128
+ end
129
+ context '検索の結果が0件' do
130
+ it '0が返される' do
131
+ expect(@master.send(m.to_s+"_count", {@params[m.to_sym][:prefix]+"_creation_date-gte"=> Time.now.strftime("%F %T")})).to be("0")
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ describe 'infoAPI' do
139
+ before(:all) do
140
+ @access_toen
141
+ @refresh_token
142
+ @params =YAML.load_file("config/api.yaml")
143
+ auth = NeAPI::Auth.new redirect_url: "http://localhost:3000"
144
+ #auth.sign_in
145
+ #@user=auth.api_neauth
146
+ #@access_toen=@user[:access_token]
147
+ #@refresh_token=@user[:refresh_token]
148
+ @master = NeAPI::Master.new access_token: @access_toen, refresh_token: @refresh_token
149
+ end
150
+ context '全てのメソッドについて' do
151
+ INFO_MODEL.each do |m|
152
+ it m.to_s+'は存在する' do
153
+ expect(@master.send(m.to_s+"_info")).to be_true
154
+ end
155
+ end
156
+ end
157
+ INFO_MODEL.each do |m|
158
+ context m.to_s+'_infoについて' do
159
+ it 'resultがsuccess' do
160
+ expect((@master.send(m.to_s+"_info"))["result"]).to match(/success/)
161
+ end
162
+ it 'countがある' do
163
+ expect(@master.send(m.to_s+"_info").has_key?("count")).to be_true
164
+ end
165
+ it 'dataがある' do
166
+ expect(@master.send(m.to_s+"_info").has_key?("data")).to be_true
167
+ end
168
+ end
169
+ end
170
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ne_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuuna Kurita
8
+ - Mika Koizumi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: faraday
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: oauth
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: i18n
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: activesupport
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: dotenv
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: launchy
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: Next Engine API for ruby
141
+ email:
142
+ - yuuna.m@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".env"
148
+ - ".gitignore"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - config/api.yaml
154
+ - lib/ne_api.rb
155
+ - lib/ne_api/version.rb
156
+ - ne_api.gemspec
157
+ - spec/ne_api_spec.rb
158
+ homepage: http://github.com/infinity-octaver/ne_api/
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.2.2
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Next Engine API for ruby
182
+ test_files:
183
+ - spec/ne_api_spec.rb