yahoo_store_api 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47cd02e692b7fcc3579822fd5f0a0791511780e55f99f9ab31236c8dfda17f9e
4
- data.tar.gz: 7950d25213442f499447b2359d9c51f4ed48cb275e021d85d418140432446a5d
3
+ metadata.gz: f425884881906edb17b5b1901b37091ca193f0e14190bb6cacc1fc62c3d58856
4
+ data.tar.gz: 316bd70561649a4a1b7620c754fadc7d04138732fde60b3c46f9aca3421fafdb
5
5
  SHA512:
6
- metadata.gz: 54a18a5461f9e4c447265d634f0f457194e2ccb45a9a8987b3b4c314367a77f549dc23a338b9cbb942fd402b9a5327cc8c0c771f69b8343e8af210bf613a0acd
7
- data.tar.gz: af11055de003b61f67113f22144f5bbfc27e40db89e4792b61a046d788368059fb7e2f5e4e5ed692ec3e9e51e14c50ae63816654b14277fc5abc228388d8edea
6
+ metadata.gz: 3338a934453cdff5a9d72c2577784449966f78e50addbeb7fd1b5246200a82c705b2b58ff7c2d0c4358a4e44dc352c753d6e5f5f9b83fafda02e7eda076c6122
7
+ data.tar.gz: ff49e75c26dfef845a4af1c5cf6948c4763c9bfdbf00e813fe2425e7669b2775a0d875f90174035b9e93c7e75cd3a9a62e059740c6bf3ef6731fd58f24b2fbcd
data/.env.sample ADDED
@@ -0,0 +1,4 @@
1
+ YOUR_SELLER_ID=YOUR_SELLER_ID
2
+ YOUR_APPLICATION_ID=YOUR_APPLICATION_ID
3
+ YOUR_APPLICATION_SECRET=YOUR_APPLICATION_SECRET
4
+ YOUR_REFRESH_TOKEN=foobar
data/.gitignore CHANGED
@@ -10,4 +10,4 @@
10
10
 
11
11
  .env
12
12
  .rbenv-gemsets
13
- sample.rb
13
+ sample.rb
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in yahoo_store_api.gemspec
4
4
  gemspec
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
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
10
  task :default => :test
@@ -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
- def connection(method)
6
- Faraday.new(url: ENDPOINT + method) do |c|
7
- c.adapter Faraday.default_adapter
8
- c.headers['Authorization'] = "Bearer " + @access_token
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['ResultSet/Result']
15
- response_parser(rexml, xpoint: 'ResultSet/Result')
16
- elsif rexml.elements['ResultSet/Status']
17
- response_parser(rexml, xpoint: 'ResultSet')
18
- elsif rexml.elements['Error/Message']
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, 'utf-8')}.reject{|v| v.to_s.blank?}
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, 'utf-8')
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('all') {
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: 'NG',
61
- message: rexml.elements['Error/Message'].text
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('all') { result }
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('deleteItem').post { |r|
7
+
8
+ handler connection("deleteItem").post { |r|
9
9
  r.body = request
10
10
  }
11
11
  end
12
-
13
12
  end
14
13
  end
@@ -4,11 +4,10 @@ module YahooStoreApi
4
4
 
5
5
  def edit_item(hash)
6
6
  request = "seller_id=#{@seller_id}&#{URI.encode_www_form(hash)}"
7
-
8
- handler connection('editItem').post { |r|
7
+
8
+ handler connection("editItem").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('getItem').get { |r|
7
- r.params['seller_id'] = @seller_id
8
- r.params['item_code'] = item_code
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
@@ -1,3 +1,4 @@
1
- require 'yahoo_store_api/item/get_item'
2
- require 'yahoo_store_api/item/edit_item'
3
- require 'yahoo_store_api/item/delete_item'
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('reservePublish').post { |r|
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 'yahoo_store_api/publish/reserve_publish'
1
+ require "yahoo_store_api/publish/reserve_publish"
@@ -3,10 +3,9 @@ module YahooStoreApi
3
3
  include YahooStoreApi::Helper
4
4
 
5
5
  def get_stock(item_code)
6
- handler connection('getStock').post { |r|
6
+ handler connection("getStock").post { |r|
7
7
  r.body = "seller_id=#{@seller_id}&item_code=#{item_code}"
8
8
  }
9
9
  end
10
-
11
10
  end
12
11
  end
@@ -5,10 +5,9 @@ module YahooStoreApi
5
5
  def set_stock(hash)
6
6
  request = "seller_id=#{@seller_id}&#{URI.encode_www_form(hash)}"
7
7
 
8
- handler connection('setStock').post { |r|
8
+ handler connection("setStock").post { |r|
9
9
  r.body = request
10
10
  }
11
11
  end
12
-
13
12
  end
14
13
  end
@@ -1,2 +1,2 @@
1
- require 'yahoo_store_api/stock/get_stock'
2
- require 'yahoo_store_api/stock/set_stock'
1
+ require "yahoo_store_api/stock/get_stock"
2
+ require "yahoo_store_api/stock/set_stock"
@@ -1,3 +1,3 @@
1
1
  module YahooStoreApi
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,17 +1,17 @@
1
1
  require "yahoo_store_api/version"
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'
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 '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'
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 = 'https://auth.login.yahoo.co.jp/yconnect/v1/token'.freeze
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['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
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
@@ -1,29 +1,29 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'yahoo_store_api/version'
4
+ require "yahoo_store_api/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "yahoo_store_api"
8
- spec.version = YahooStoreApi::VERSION
9
- spec.authors = ["t4traw"]
10
- spec.email = ["t4traw@gmail.com"]
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 = %q{Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー}
13
- spec.description = %q{Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー}
14
- spec.homepage = "https://github.com/t4traw/yahoo_store_api"
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 = `git ls-files -z`.split("\x0").reject do |f|
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 = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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", '>= 0.12.1'
25
- spec.add_dependency "activesupport", '>= 4.2.8'
26
- spec.add_dependency "activemodel", '>= 4.2.8'
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.1.4
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-04-05 00:00:00.000000000 Z
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.4
227
+ rubygems_version: 3.1.6
226
228
  signing_key:
227
229
  specification_version: 4
228
230
  summary: Yahoo!ショッピング プロフェッショナル出店ストア向けAPIを簡単に叩けるrubyラッパー