yahoo_store_api 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +4 -0
- data/.gitignore +1 -1
- data/Gemfile +1 -1
- data/README.md +9 -0
- data/Rakefile +1 -1
- data/lib/yahoo_store_api/helper.rb +23 -17
- data/lib/yahoo_store_api/item/delete_item.rb +2 -3
- data/lib/yahoo_store_api/item/edit_item.rb +2 -3
- data/lib/yahoo_store_api/item/get_item.rb +3 -4
- data/lib/yahoo_store_api/item/upload_item_file.rb +16 -0
- data/lib/yahoo_store_api/item.rb +4 -3
- data/lib/yahoo_store_api/publish/reserve_publish.rb +2 -3
- data/lib/yahoo_store_api/publish.rb +1 -1
- data/lib/yahoo_store_api/stock/get_stock.rb +1 -2
- data/lib/yahoo_store_api/stock/set_stock.rb +1 -2
- data/lib/yahoo_store_api/stock.rb +2 -2
- data/lib/yahoo_store_api/version.rb +1 -1
- data/lib/yahoo_store_api.rb +18 -18
- data/yahoo_store_api.gemspec +15 -15
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f425884881906edb17b5b1901b37091ca193f0e14190bb6cacc1fc62c3d58856
|
4
|
+
data.tar.gz: 316bd70561649a4a1b7620c754fadc7d04138732fde60b3c46f9aca3421fafdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3338a934453cdff5a9d72c2577784449966f78e50addbeb7fd1b5246200a82c705b2b58ff7c2d0c4358a4e44dc352c753d6e5f5f9b83fafda02e7eda076c6122
|
7
|
+
data.tar.gz: ff49e75c26dfef845a4af1c5cf6948c4763c9bfdbf00e813fe2425e7669b2775a0d875f90174035b9e93c7e75cd3a9a62e059740c6bf3ef6731fd58f24b2fbcd
|
data/.env.sample
ADDED
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,6 +12,7 @@ Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを
|
|
12
12
|
* 商品に関連するAPI
|
13
13
|
* 商品参照API(`get_item`)
|
14
14
|
* 商品登録API(`set_item`)
|
15
|
+
* 商品アップロードAPI(`upload_item_file`)
|
15
16
|
* 商品削除API(`delete_item`)
|
16
17
|
* 在庫に関連するAPI
|
17
18
|
* 在庫参照API(`get_stock`)
|
@@ -103,6 +104,14 @@ item = client.edit_item({
|
|
103
104
|
item.all
|
104
105
|
```
|
105
106
|
|
107
|
+
### 商品情報の一括登録
|
108
|
+
|
109
|
+
csvファイルをアップロードする事で商品情報の一括登録ができます。
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
item = client.upload_item_file("your/upload/file.csv")
|
113
|
+
```
|
114
|
+
|
106
115
|
### 商品情報の更新
|
107
116
|
|
108
117
|
:bangbang: APIの仕様で、更新したいカラムのみ送信して更新が **できません** :bangbang:
|
data/Rakefile
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
module YahooStoreApi
|
2
2
|
module Helper
|
3
|
-
|
4
3
|
ENDPOINT = "https://circus.shopping.yahooapis.jp/ShoppingWebService/V1/".freeze
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
|
5
|
+
def connection(method, with_seller_id: false)
|
6
|
+
url = ENDPOINT + method
|
7
|
+
if with_seller_id
|
8
|
+
url += "?seller_id=#{@seller_id}" if with_seller_id
|
9
|
+
end
|
10
|
+
|
11
|
+
Faraday.new(url: url) do |c|
|
12
|
+
c.request :multipart
|
13
|
+
c.request :url_encoded
|
14
|
+
c.adapter :net_http
|
15
|
+
c.headers["Authorization"] = "Bearer " + @access_token
|
9
16
|
end
|
10
17
|
end
|
11
18
|
|
12
19
|
def handler(response)
|
13
20
|
rexml = REXML::Document.new(response.body)
|
14
|
-
if rexml.elements[
|
15
|
-
response_parser(rexml, xpoint:
|
16
|
-
elsif rexml.elements[
|
17
|
-
response_parser(rexml, xpoint:
|
18
|
-
elsif rexml.elements[
|
21
|
+
if rexml.elements["ResultSet/Result"]
|
22
|
+
response_parser(rexml, xpoint: "ResultSet/Result")
|
23
|
+
elsif rexml.elements["ResultSet/Status"]
|
24
|
+
response_parser(rexml, xpoint: "ResultSet")
|
25
|
+
elsif rexml.elements["Error/Message"]
|
19
26
|
error_parser(rexml)
|
20
27
|
else
|
21
28
|
puts rexml
|
@@ -28,7 +35,7 @@ module YahooStoreApi
|
|
28
35
|
result.children.each do |el|
|
29
36
|
next if el.to_s.strip.blank?
|
30
37
|
if el.has_elements?
|
31
|
-
el_ary = el.children.reject{|v| v.to_s.blank?}.map{|v| v.text.try!(:force_encoding,
|
38
|
+
el_ary = el.children.reject { |v| v.to_s.blank? }.map { |v| v.text.try!(:force_encoding, "utf-8") }.reject { |v| v.to_s.blank? }
|
32
39
|
attributes[el.name.underscore] = el_ary
|
33
40
|
begin
|
34
41
|
self.define_singleton_method(el.name.underscore) {
|
@@ -41,14 +48,14 @@ module YahooStoreApi
|
|
41
48
|
attributes[el.name.underscore] = el.text
|
42
49
|
begin
|
43
50
|
self.define_singleton_method(el.name.underscore) {
|
44
|
-
el.text.try!(:force_encoding,
|
51
|
+
el.text.try!(:force_encoding, "utf-8")
|
45
52
|
}
|
46
53
|
rescue => e
|
47
54
|
puts e
|
48
55
|
end
|
49
56
|
end # if el.has_elements?
|
50
57
|
end # result.children.each
|
51
|
-
self.define_singleton_method(
|
58
|
+
self.define_singleton_method("all") {
|
52
59
|
attributes
|
53
60
|
}
|
54
61
|
end # xml.elements.each(xpoint)
|
@@ -57,15 +64,14 @@ module YahooStoreApi
|
|
57
64
|
|
58
65
|
def error_parser(rexml)
|
59
66
|
result = {
|
60
|
-
status:
|
61
|
-
message: rexml.elements[
|
67
|
+
status: "NG",
|
68
|
+
message: rexml.elements["Error/Message"].text,
|
62
69
|
}
|
63
70
|
result.each do |k, v|
|
64
71
|
self.define_singleton_method(k) { v }
|
65
72
|
end
|
66
|
-
self.define_singleton_method(
|
73
|
+
self.define_singleton_method("all") { result }
|
67
74
|
self
|
68
75
|
end
|
69
|
-
|
70
76
|
end
|
71
77
|
end
|
@@ -4,11 +4,10 @@ module YahooStoreApi
|
|
4
4
|
|
5
5
|
def delete_item(str)
|
6
6
|
request = "seller_id=#{@seller_id}&item_code=#{URI.encode_www_form_component(str)}"
|
7
|
-
|
8
|
-
handler connection(
|
7
|
+
|
8
|
+
handler connection("deleteItem").post { |r|
|
9
9
|
r.body = request
|
10
10
|
}
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
13
|
end
|
@@ -3,11 +3,10 @@ module YahooStoreApi
|
|
3
3
|
include YahooStoreApi::Helper
|
4
4
|
|
5
5
|
def get_item(item_code)
|
6
|
-
handler connection(
|
7
|
-
r.params[
|
8
|
-
r.params[
|
6
|
+
handler connection("getItem").get { |r|
|
7
|
+
r.params["seller_id"] = @seller_id
|
8
|
+
r.params["item_code"] = item_code
|
9
9
|
}
|
10
10
|
end
|
11
|
-
|
12
11
|
end
|
13
12
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module YahooStoreApi
|
2
|
+
module Item
|
3
|
+
include YahooStoreApi::Helper
|
4
|
+
|
5
|
+
def upload_item_file(file_path)
|
6
|
+
request = {
|
7
|
+
type: 1,
|
8
|
+
file: Faraday::UploadIO.new(file_path, "text/csv"),
|
9
|
+
}
|
10
|
+
|
11
|
+
handler connection("uploadItemFile", with_seller_id: true).post { |r|
|
12
|
+
r.body = request
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/yahoo_store_api/item.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "yahoo_store_api/item/get_item"
|
2
|
+
require "yahoo_store_api/item/edit_item"
|
3
|
+
require "yahoo_store_api/item/upload_item_file"
|
4
|
+
require "yahoo_store_api/item/delete_item"
|
@@ -8,10 +8,9 @@ module YahooStoreApi
|
|
8
8
|
request << "mode=#{mode}"
|
9
9
|
request << "seller_id=#{reserve_time}" if reserve_time
|
10
10
|
|
11
|
-
handler connection(
|
12
|
-
r.body = request.join(
|
11
|
+
handler connection("reservePublish").post { |r|
|
12
|
+
r.body = request.join("&")
|
13
13
|
}
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "yahoo_store_api/publish/reserve_publish"
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "yahoo_store_api/stock/get_stock"
|
2
|
+
require "yahoo_store_api/stock/set_stock"
|
data/lib/yahoo_store_api.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require "yahoo_store_api/version"
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
require "yahoo_store_api/helper.rb"
|
3
|
+
require "yahoo_store_api/item.rb"
|
4
|
+
require "yahoo_store_api/stock.rb"
|
5
|
+
require "yahoo_store_api/publish.rb"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
7
|
+
require "rexml/document"
|
8
|
+
require "yaml"
|
9
|
+
require "uri"
|
10
|
+
require "cgi"
|
11
|
+
require "faraday"
|
12
|
+
require "active_support"
|
13
|
+
require "active_support/core_ext"
|
14
|
+
require "active_model"
|
15
15
|
|
16
16
|
module YahooStoreApi
|
17
17
|
class Client
|
@@ -30,18 +30,19 @@ module YahooStoreApi
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
ACCESS_TOKEN_ENDPOINT =
|
33
|
+
ACCESS_TOKEN_ENDPOINT = "https://auth.login.yahoo.co.jp/yconnect/v1/token".freeze
|
34
|
+
|
34
35
|
def access_token_connection
|
35
36
|
Faraday.new(url: ACCESS_TOKEN_ENDPOINT) do |c|
|
36
37
|
c.adapter Faraday.default_adapter
|
37
38
|
c.authorization :Basic, Base64.strict_encode64("#{@application_id}:#{@application_secret}")
|
38
|
-
c.headers[
|
39
|
+
c.headers["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8"
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
def get_access_token(authorization_code)
|
43
44
|
param = "grant_type=authorization_code&code=#{authorization_code}#{@redirect_uri}"
|
44
|
-
obj = access_token_connection.post{|r| r.body = param}
|
45
|
+
obj = access_token_connection.post { |r| r.body = param }
|
45
46
|
result = hash_converter(obj)
|
46
47
|
@refresh_token = result[:refresh_token]
|
47
48
|
result[:access_token]
|
@@ -49,7 +50,7 @@ module YahooStoreApi
|
|
49
50
|
|
50
51
|
def reflesh_access_token(refresh_token)
|
51
52
|
param = "grant_type=refresh_token&refresh_token=#{refresh_token}"
|
52
|
-
obj = access_token_connection.post{|r| r.body = param}
|
53
|
+
obj = access_token_connection.post { |r| r.body = param }
|
53
54
|
result = hash_converter(obj)
|
54
55
|
@refresh_token = refresh_token
|
55
56
|
result[:access_token]
|
@@ -57,8 +58,7 @@ module YahooStoreApi
|
|
57
58
|
|
58
59
|
def hash_converter(str)
|
59
60
|
ary = str.body.delete('"{}').split(/[:,]/)
|
60
|
-
ary.each_slice(2).map{|k, v| [k.to_sym, v]}.to_h
|
61
|
+
ary.each_slice(2).map { |k, v| [k.to_sym, v] }.to_h
|
61
62
|
end
|
62
|
-
|
63
63
|
end
|
64
64
|
end
|
data/yahoo_store_api.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "yahoo_store_api/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = "yahoo_store_api"
|
8
|
+
spec.version = YahooStoreApi::VERSION
|
9
|
+
spec.authors = ["t4traw"]
|
10
|
+
spec.email = ["t4traw@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
12
|
+
spec.summary = %q{Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー}
|
13
|
+
spec.description = %q{Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー}
|
14
|
+
spec.homepage = "https://github.com/t4traw/yahoo_store_api"
|
15
15
|
|
16
|
-
spec.files
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
18
18
|
end
|
19
19
|
|
20
|
-
spec.bindir
|
21
|
-
spec.executables
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "faraday",
|
25
|
-
spec.add_dependency "activesupport",
|
26
|
-
spec.add_dependency "activemodel",
|
24
|
+
spec.add_dependency "faraday", ">= 0.12.1"
|
25
|
+
spec.add_dependency "activesupport", ">= 4.2.8"
|
26
|
+
spec.add_dependency "activemodel", ">= 4.2.8"
|
27
27
|
spec.add_dependency "builder"
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_store_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- t4traw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -185,6 +185,7 @@ executables: []
|
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
+
- ".env.sample"
|
188
189
|
- ".gitignore"
|
189
190
|
- ".travis.yml"
|
190
191
|
- Gemfile
|
@@ -197,6 +198,7 @@ files:
|
|
197
198
|
- lib/yahoo_store_api/item/delete_item.rb
|
198
199
|
- lib/yahoo_store_api/item/edit_item.rb
|
199
200
|
- lib/yahoo_store_api/item/get_item.rb
|
201
|
+
- lib/yahoo_store_api/item/upload_item_file.rb
|
200
202
|
- lib/yahoo_store_api/publish.rb
|
201
203
|
- lib/yahoo_store_api/publish/reserve_publish.rb
|
202
204
|
- lib/yahoo_store_api/stock.rb
|
@@ -222,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
224
|
- !ruby/object:Gem::Version
|
223
225
|
version: '0'
|
224
226
|
requirements: []
|
225
|
-
rubygems_version: 3.1.
|
227
|
+
rubygems_version: 3.1.6
|
226
228
|
signing_key:
|
227
229
|
specification_version: 4
|
228
230
|
summary: Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー
|