dech 0.0.7 → 0.1.0

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
2
  SHA1:
3
- metadata.gz: a298dba8dc5995a1a411bb5c7f51a46cf9e97a61
4
- data.tar.gz: d1c7288d35568fc22f1b91f58cf435c8daa00288
3
+ metadata.gz: f36e6b9750c050e367733b9edf16626d82783b84
4
+ data.tar.gz: a048e92ecc2d2142afbe6c7229b54ba90fb10be2
5
5
  SHA512:
6
- metadata.gz: fe95dfc6dc917b601e92a453ad8d4a414733702d08ce18df8698ab8b93cf81bdc9fbc83e2075af8ad9348560571d7be20c0e29b0bde0f00ea5472ab58645f0c6
7
- data.tar.gz: 10aece1245ad3cf0eba3a0e29ddc2bed670a3e70b25ab33445b2ab1bba92b1b2e314430115fe9ce82ed1f733426c5e8fbe10ad665560cb392f44d2bb500723b1
6
+ metadata.gz: 0f38ccc1618487ecd62f480b1704b3e35c74bade0dd4fec8fc91bef97b4a226e0bcb3c1c98d2a500f21cccc5f467120b14d257dec9e4d67659c690963f2e7e86
7
+ data.tar.gz: 3bac0655573dba667df21ec5c68fa8a59372027a39118d8f8c339456950781cfa44cb5c4a871f0e63250499000222dc5b6a7a2cfe6f73fd6f5855691d73227e3
data/lib/dech.rb CHANGED
@@ -8,9 +8,5 @@ require "dech/ponpare"
8
8
  require "dech/rakuten"
9
9
  require "dech/yahoo"
10
10
 
11
- # deprecated classes
12
- require "dech/price_uploader"
13
- require "dech/csvio"
14
-
15
11
  module Dech
16
12
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require 'net/ftp'
2
+ require 'double_bag_ftps'
3
3
  require 'dech/ponpare/csv'
4
4
 
5
5
  module Dech
data/lib/dech/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Dech
4
- VERSION = "0.0.7"
4
+ VERSION = "0.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OSA Shunsuke
@@ -112,7 +112,6 @@ files:
112
112
  - dech.gemspec
113
113
  - lib/dech.rb
114
114
  - lib/dech/csv.rb
115
- - lib/dech/csvio.rb
116
115
  - lib/dech/dena.rb
117
116
  - lib/dech/dena/csv.rb
118
117
  - lib/dech/dena/ftp.rb
@@ -121,10 +120,6 @@ files:
121
120
  - lib/dech/ponpare/csv.rb
122
121
  - lib/dech/ponpare/ftps.rb
123
122
  - lib/dech/price_uploader.rb
124
- - lib/dech/price_uploader/dena.rb
125
- - lib/dech/price_uploader/dena/ftp.rb
126
- - lib/dech/price_uploader/ponpare.rb
127
- - lib/dech/price_uploader/ponpare/ftps.rb
128
123
  - lib/dech/rakuten.rb
129
124
  - lib/dech/rakuten/csv.rb
130
125
  - lib/dech/rakuten/ftp.rb
@@ -133,7 +128,6 @@ files:
133
128
  - lib/dech/yahoo/csv.rb
134
129
  - lib/dech/yahoo/ftp.rb
135
130
  - spec/dech/csv_spec.rb
136
- - spec/dech/csvio_spec.rb
137
131
  - spec/dech/dena/csv_spec.rb
138
132
  - spec/dech/dena/ftp_spec.rb
139
133
  - spec/dech/dena_spec.rb
@@ -141,8 +135,6 @@ files:
141
135
  - spec/dech/ponpare/csv_spec.rb
142
136
  - spec/dech/ponpare/ftps_spec.rb
143
137
  - spec/dech/ponpare_spec.rb
144
- - spec/dech/price_uploader/dena/ftp_spec.rb
145
- - spec/dech/price_uploader/ponpare/ftps_spec.rb
146
138
  - spec/dech/rakuten/csv_spec.rb
147
139
  - spec/dech/rakuten/ftp_spec.rb
148
140
  - spec/dech/rakuten_spec.rb
@@ -177,7 +169,6 @@ specification_version: 4
177
169
  summary: Utilities gem for e-commerce mall in Japan.
178
170
  test_files:
179
171
  - spec/dech/csv_spec.rb
180
- - spec/dech/csvio_spec.rb
181
172
  - spec/dech/dena/csv_spec.rb
182
173
  - spec/dech/dena/ftp_spec.rb
183
174
  - spec/dech/dena_spec.rb
@@ -185,8 +176,6 @@ test_files:
185
176
  - spec/dech/ponpare/csv_spec.rb
186
177
  - spec/dech/ponpare/ftps_spec.rb
187
178
  - spec/dech/ponpare_spec.rb
188
- - spec/dech/price_uploader/dena/ftp_spec.rb
189
- - spec/dech/price_uploader/ponpare/ftps_spec.rb
190
179
  - spec/dech/rakuten/csv_spec.rb
191
180
  - spec/dech/rakuten/ftp_spec.rb
192
181
  - spec/dech/rakuten_spec.rb
data/lib/dech/csvio.rb DELETED
@@ -1,15 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'csv'
4
- require 'stringio'
5
-
6
- module Dech
7
- class CSVIO < StringIO
8
- class << self
9
- def generate(args={})
10
- csv_string = ::CSV.generate{|csv| yield(csv) if block_given? }
11
- self.new(csv_string.encode(args[:encoding] || Encoding::Windows_31J))
12
- end
13
- end
14
- end
15
- end
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "dech/price_uploader/dena/ftp"
4
-
5
- module Dech
6
- module PriceUploader
7
- module Dena
8
- end
9
- end
10
- end
@@ -1,65 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'dech/csvio'
4
- require 'net/ftp'
5
-
6
- module Dech
7
- module PriceUploader
8
- module Dena
9
- class FTP
10
- HEADERS = %w(Code exhibittype Price KtaiPrice)
11
-
12
- attr_accessor :username, :host, :path
13
-
14
- def initialize(args={})
15
- @products = args[:products] || []
16
- @username = args[:username]
17
- @password = args[:password]
18
- @host = args[:host] || "bcmaster1.dena.ne.jp"
19
- @path = args[:path] || "/data.csv"
20
- end
21
-
22
- def ready?
23
- true
24
- end
25
-
26
- def csv
27
- Dech::CSVIO.generate do |csv|
28
- csv << HEADERS
29
- @products.each do |product|
30
- csv << [product[:id], "MX", product[:price], product[:price]]
31
- end
32
- end
33
- end
34
-
35
- def save_csv_as(filename)
36
- FileUtils.mkdir_p(File.dirname(filename))
37
- File.open(filename, "w:windows-31j") do |file|
38
- file << csv.string
39
- end
40
- end
41
-
42
- def upload!
43
- ftp_connection{|ftp| ftp.storlines("STOR #{@path}", csv) }
44
- true
45
- end
46
-
47
- def upload
48
- ready? && upload!
49
- end
50
-
51
- private
52
-
53
- def ftp_connection(&block)
54
- ftp = Net::FTP.new
55
- ftp.connect(@host)
56
- ftp.login(@username, @password)
57
-
58
- yield(ftp)
59
- ensure
60
- ftp.close
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "dech/price_uploader/ponpare/ftps"
4
-
5
- module Dech
6
- module PriceUploader
7
- module Ponpare
8
- end
9
- end
10
- end
@@ -1,67 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "dech/csvio"
4
- require "double_bag_ftps"
5
-
6
- module Dech
7
- module PriceUploader
8
- module Ponpare
9
- class FTPS
10
- HEADERS = %w(コントロールカラム 商品管理ID(商品URL) 販売価格)
11
-
12
- attr_accessor :username, :host, :path
13
-
14
- def initialize(args={})
15
- @products = args[:products] || []
16
- @username = args[:username]
17
- @password = args[:password]
18
- @host = args[:host] || "ftps.ponparemall.com"
19
- @path = args[:path] || "/item.csv"
20
- end
21
-
22
- def ready?
23
- ftps_connection{|ftps| !ftps.nlst(File.dirname(@path)).include?(@path) }
24
- end
25
-
26
- def csv
27
- Dech::CSVIO.generate do |csv|
28
- csv << HEADERS
29
- @products.each do |product|
30
- csv << ["u", product[:id].to_s.downcase, product[:price]]
31
- end
32
- end
33
- end
34
-
35
- def save_csv_as(filename)
36
- FileUtils.mkdir_p(File.dirname(filename))
37
- File.open(filename, "w:windows-31j") do |file|
38
- file << csv.string
39
- end
40
- end
41
-
42
- def upload!
43
- ftps_connection{|ftps| ftps.storlines("STOR #{@path}", csv) }
44
- true
45
- end
46
-
47
- def upload
48
- ready? && upload!
49
- end
50
-
51
- private
52
-
53
- def ftps_connection(&block)
54
- ftps = DoubleBagFTPS.new
55
- ftps.passive = true
56
- ftps.ssl_context = DoubleBagFTPS.create_ssl_context(verify_mode: OpenSSL::SSL::VERIFY_NONE)
57
- ftps.connect(@host)
58
- ftps.login(@username, @password)
59
-
60
- yield(ftps)
61
- ensure
62
- ftps.close
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,44 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Dech::CSVIO do
6
- describe ".generate" do
7
- describe "class" do
8
- it "should return an instance of StringIO" do
9
- actual = Dech::CSVIO.generate
10
- expect(actual).to be_is_a(StringIO)
11
- end
12
-
13
- it "should return an instance of Dech::CSVIO" do
14
- actual = Dech::CSVIO.generate
15
- expect(actual).to be_is_a(Dech::CSVIO)
16
- end
17
- end
18
-
19
- describe "encoding" do
20
- it "should have windows-31j external_encoding as default" do
21
- actual = Dech::CSVIO.generate
22
- expect(actual.external_encoding).to eq(Encoding::Windows_31J)
23
- end
24
-
25
- it "should have given external_encoding" do
26
- actual = Dech::CSVIO.generate(encoding: Encoding::UTF_8)
27
- expect(actual.external_encoding).to eq(Encoding::UTF_8)
28
- end
29
- end
30
-
31
- describe "headers" do
32
- before do
33
- @headers = %w(a b c d e)
34
- io = Dech::CSVIO.generate{|csv| csv << @headers }
35
- @csv = CSV.new(io, headers: true)
36
- @csv.readlines
37
- end
38
-
39
- it "should be able to set headers" do
40
- expect(@csv.headers).to eq(@headers)
41
- end
42
- end
43
- end
44
- end
@@ -1,111 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Dech::PriceUploader::Dena::FTP do
6
- let(:dech) {
7
- Dech::PriceUploader::Dena::FTP.new(
8
- products: [{id: "PRODUCT-CODE", price: 9800}],
9
- username: "username",
10
- password: "password",
11
- host: "example.com"
12
- )
13
- }
14
-
15
- let(:ftp) {
16
- ftp = double("ftp")
17
- allow(ftp).to receive(:passive=)
18
- allow(ftp).to receive(:connect)
19
- allow(ftp).to receive(:login)
20
- allow(ftp).to receive(:close)
21
- ftp
22
- }
23
-
24
- describe "initialize" do
25
- context "given no args" do
26
- it "should create an instance successfully" do
27
- expect(dech).to be_an_instance_of(Dech::PriceUploader::Dena::FTP)
28
- end
29
- end
30
-
31
- context "given some args" do
32
- it "should create an instance successfully" do
33
- expect(dech).to be_an_instance_of(Dech::PriceUploader::Dena::FTP)
34
- end
35
- end
36
- end
37
-
38
- describe "#ready?" do
39
- it "should be false" do
40
- expect(dech.ready?).to be true
41
- end
42
- end
43
-
44
- describe "#csv" do
45
- headers = {
46
- "Code" => String,
47
- "exhibittype" => /\AMX\Z/,
48
- "KtaiPrice" => /\d+/
49
- }
50
-
51
- describe "headers" do
52
- let(:csv){ CSV.new(dech.csv, headers: true) }
53
-
54
- headers.each_key.map{|h| h.encode(Encoding::Windows_31J) }.each do |header|
55
- it "should have '#{header}' header" do
56
- csv.readlines
57
- expect(csv.headers).to be_include(header)
58
- end
59
- end
60
- end
61
-
62
- describe "columns" do
63
- let(:csv){ CSV.new(dech.csv, headers: true).read }
64
-
65
- headers.each do |header, type|
66
- it "should have #{type} in '#{header}'" do
67
- expect(csv[header.encode(Encoding::Windows_31J)]).to be_all{|c| type === c }
68
- end
69
- end
70
- end
71
-
72
- describe "encoding" do
73
- let(:io){ dech.csv }
74
-
75
- it "should have windows-31j as external_encoding" do
76
- expect(io.external_encoding).to eq(Encoding::Windows_31J)
77
- end
78
- end
79
- end
80
-
81
- describe "#save_csv_as" do
82
- let(:filename){ "tmp/#{Time.now.strftime("%Y%m%d_%H%M%S_%N")}.csv" }
83
-
84
- it "should save CSV file as given name" do
85
- dech.save_csv_as(filename)
86
- expect(Dir.glob("tmp/*")).to be_include(filename)
87
- end
88
-
89
- it "should save CSV file in Shift_JIS" do
90
- dech.save_csv_as(filename)
91
- CSV.open(filename, "r:windows-31j:utf-8", headers: true) do |csv|
92
- expect{csv.readlines}.not_to raise_error
93
- expect(csv.headers).to eq(Dech::PriceUploader::Dena::FTP::HEADERS)
94
- end
95
- end
96
- end
97
-
98
- describe "#upload" do
99
- context "server is ready" do
100
- before do
101
- allow(ftp).to receive(:nlst).and_return([])
102
- expect(ftp).to receive(:storlines)
103
- expect(Net::FTP).to receive(:new).and_return(ftp).at_least(:once)
104
- end
105
-
106
- it "should upload CSV file to the path on FTP server" do
107
- expect(dech.upload).to be true
108
- end
109
- end
110
- end
111
- end
@@ -1,141 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Dech::PriceUploader::Ponpare::FTPS do
6
- let(:dech) {
7
- Dech::PriceUploader::Ponpare::FTPS.new(
8
- products: [{id: "PRODUCT-CODE", price: 9800}],
9
- username: "username",
10
- password: "password",
11
- host: "example.com"
12
- )
13
- }
14
-
15
- let(:ftps) {
16
- ftps = double("ftps")
17
- allow(ftps).to receive(:passive=)
18
- allow(ftps).to receive(:ssl_context=)
19
- allow(ftps).to receive(:connect)
20
- allow(ftps).to receive(:login)
21
- allow(ftps).to receive(:close)
22
- ftps
23
- }
24
-
25
- describe "initialize" do
26
- context "given no args" do
27
- it "should create an instance successfully" do
28
- expect(dech).to be_an_instance_of(Dech::PriceUploader::Ponpare::FTPS)
29
- end
30
- end
31
-
32
- context "given some args" do
33
- it "should create an instance successfully" do
34
- expect(dech).to be_an_instance_of(Dech::PriceUploader::Ponpare::FTPS)
35
- end
36
- end
37
- end
38
-
39
- describe "#ready?" do
40
- context "some files in the server" do
41
- before do
42
- expect(ftps).to receive(:nlst).and_return([dech.path])
43
- expect(DoubleBagFTPS).to receive(:new).and_return(ftps)
44
- end
45
-
46
- it "should be false" do
47
- expect(dech.ready?).to be false
48
- end
49
- end
50
-
51
- context "any files in the server" do
52
- before do
53
- expect(ftps).to receive(:nlst).and_return([])
54
- expect(DoubleBagFTPS).to receive(:new).and_return(ftps)
55
- end
56
-
57
- it "should be true" do
58
- expect(dech.ready?).to be true
59
- end
60
- end
61
- end
62
-
63
- describe "#csv" do
64
- headers = {
65
- "コントロールカラム" => /\Au\Z/,
66
- "商品管理ID(商品URL)" => String,
67
- "販売価格" => /\d+/
68
- }
69
-
70
- describe "headers" do
71
- let(:csv){ CSV.new(dech.csv, headers: true) }
72
-
73
- headers.each_key.map{|h| h.encode(Encoding::Windows_31J) }.each do |header|
74
- it "should have '#{header}' header" do
75
- csv.readlines
76
- expect(csv.headers).to be_include(header)
77
- end
78
- end
79
- end
80
-
81
- describe "columns" do
82
- let(:csv){ CSV.new(dech.csv, headers: true).read }
83
-
84
- headers.each do |header, type|
85
- it "should have #{type} in '#{header}'" do
86
- expect(csv[header.encode(Encoding::Windows_31J)]).to be_all{|c| type === c }
87
- end
88
- end
89
- end
90
-
91
- describe "encoding" do
92
- let(:io){ dech.csv }
93
-
94
- it "should have windows-31j as external_encoding" do
95
- expect(io.external_encoding).to eq(Encoding::Windows_31J)
96
- end
97
- end
98
- end
99
-
100
- describe "#save_csv_as" do
101
- let(:filename){ "tmp/#{Time.now.strftime("%Y%m%d_%H%M%S_%N")}.csv" }
102
-
103
- it "should save CSV file as given name" do
104
- dech.save_csv_as(filename)
105
- expect(Dir.glob("tmp/*")).to be_include(filename)
106
- end
107
-
108
- it "should save CSV file in Shift_JIS" do
109
- dech.save_csv_as(filename)
110
- CSV.open(filename, "r:windows-31j:utf-8", headers: true) do |csv|
111
- expect{csv.readlines}.not_to raise_error
112
- expect(csv.headers).to eq(Dech::PriceUploader::Ponpare::FTPS::HEADERS)
113
- end
114
- end
115
- end
116
-
117
- describe "#upload" do
118
- context "server is ready" do
119
- before do
120
- allow(ftps).to receive(:nlst).and_return([])
121
- expect(ftps).to receive(:storlines)
122
- expect(DoubleBagFTPS).to receive(:new).and_return(ftps).at_least(:once)
123
- end
124
-
125
- it "should upload CSV file to the path on FTPS server" do
126
- expect(dech.upload).to be true
127
- end
128
- end
129
-
130
- context "server is not ready" do
131
- before do
132
- allow(ftps).to receive(:nlst).and_return([dech.path])
133
- expect(DoubleBagFTPS).to receive(:new).and_return(ftps)
134
- end
135
-
136
- it "should not upload CSV file to the path on FTPS server" do
137
- expect(dech.upload).to be false
138
- end
139
- end
140
- end
141
- end