dech 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f36e6b9750c050e367733b9edf16626d82783b84
4
- data.tar.gz: a048e92ecc2d2142afbe6c7229b54ba90fb10be2
3
+ metadata.gz: 616d6829ec3eac2ee411e098b60d383570e56790
4
+ data.tar.gz: 762ee5f6c4ac69009b39239e72d38b7f89e1a7d9
5
5
  SHA512:
6
- metadata.gz: 0f38ccc1618487ecd62f480b1704b3e35c74bade0dd4fec8fc91bef97b4a226e0bcb3c1c98d2a500f21cccc5f467120b14d257dec9e4d67659c690963f2e7e86
7
- data.tar.gz: 3bac0655573dba667df21ec5c68fa8a59372027a39118d8f8c339456950781cfa44cb5c4a871f0e63250499000222dc5b6a7a2cfe6f73fd6f5855691d73227e3
6
+ metadata.gz: f3969c78544589f3182f234382c14e6d64609bfacf0375b1e756962f68ce2ca3eba8e66bb6e085c18bc74b89033246417bf733ebc78a97391841ac60cfedaa93
7
+ data.tar.gz: 078104e6104c4ce3663fa4a4211eb91c05948518721b0b79434241214709cd9ec64f704ab58d9cb3ad1354796cb89a8a130794ae93791ef67c3913f58dd13915
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.2
3
+ - 2.2.0
4
+ - 2.1.0
4
5
  - 2.0.0
5
- - 1.9.3
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec do
1
+ guard :rspec, :cmd => "bundle exec rspec" do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Dech
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/dech.svg)](http://badge.fury.io/rb/dech)
4
- ![travis](https://travis-ci.org/e-maido/dech.svg?branch=master)
4
+ [![Build Status](https://travis-ci.org/e-maido/dech.svg?branch=master)](https://travis-ci.org/e-maido/dech)
5
5
  [![Coverage Status](https://coveralls.io/repos/e-maido/dech/badge.png?branch=master)](https://coveralls.io/r/e-maido/dech?branch=master)
6
6
 
7
7
  ## Installation
@@ -20,9 +20,12 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "double-bag-ftps"
22
22
  spec.add_dependency "emmental"
23
+ spec.add_dependency "rms_web_service"
24
+ spec.add_dependency "net-ftp-port_command"
23
25
 
24
26
  spec.add_development_dependency "bundler", "~> 1.5"
25
27
  spec.add_development_dependency "rake"
26
28
  spec.add_development_dependency "rspec"
27
29
  spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "webmock"
28
31
  end
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  require 'net/ftp'
3
+ require 'net/ftp/port_command'
3
4
  require 'dech/dena/csv'
4
5
 
5
6
  module Dech
@@ -16,6 +17,8 @@ module Dech
16
17
  @password = args[:password]
17
18
  @host = args[:host] || DEFAULT_HOST
18
19
  @path = args[:path] || DEFAULT_PATH
20
+ @local_address = args[:local_address]
21
+ @local_port = args[:local_port]
19
22
  end
20
23
 
21
24
  def csv
@@ -38,7 +41,10 @@ module Dech
38
41
  private
39
42
 
40
43
  def ftp_connection
41
- Net::FTP.open(@host, @username, @password){|ftp| yield(ftp) }
44
+ Net::FTP.open(@host, @username, @password) do |ftp|
45
+ ftp.port(@local_address, @local_port) if @local_address || @local_port
46
+ yield(ftp)
47
+ end
42
48
  end
43
49
  end
44
50
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ require 'dech/rakuten/api'
2
3
  require 'dech/rakuten/ftp'
3
4
 
4
5
  module Dech
@@ -0,0 +1,45 @@
1
+ require 'rms_web_service'
2
+
3
+ class RakutenUploadError < StandardError; end
4
+
5
+ module Dech
6
+ class Rakuten
7
+ class API
8
+ HEADER_MAPPINGS = {
9
+ id: "item_url",
10
+ price: "item_price"
11
+ }
12
+
13
+ def initialize(args)
14
+ @client = ::RmsWebService::Client::Item.new(
15
+ :service_secret => args[:service_secret],
16
+ :license_key => args[:license_key],
17
+ :endpoint => args[:endpoint]
18
+ )
19
+ @products = args[:products]
20
+ end
21
+
22
+ def upload
23
+ upload! rescue false
24
+ end
25
+
26
+ def upload!
27
+ formatted_products.each do |product|
28
+ item = @client.update(product)
29
+ raise RakutenUploadError, "#{item.errors}" unless item.success?
30
+ end
31
+ true
32
+ end
33
+
34
+ def ready?
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def formatted_products
41
+ @products.map{|product| Dech::HashKeyMapper.map(product, HEADER_MAPPINGS) }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -38,7 +38,10 @@ module Dech
38
38
  private
39
39
 
40
40
  def ftp_connection
41
- Net::FTP.open(@host, @username, @password){|ftp| yield(ftp) }
41
+ Net::FTP.open(@host, @username, @password) do |ftp|
42
+ ftp.passive = true
43
+ yield(ftp)
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Dech
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -38,7 +38,10 @@ module Dech
38
38
  private
39
39
 
40
40
  def ftp_connection
41
- Net::FTP.open(@host, @username, @password){|ftp| yield(ftp) }
41
+ Net::FTP.open(@host, @username, @password) do |ftp|
42
+ ftp.passive = true
43
+ yield(ftp)
44
+ end
42
45
  end
43
46
  end
44
47
  end
@@ -16,7 +16,7 @@ describe Dech::CSV do
16
16
  it { is_expected.to be(Encoding::Windows_31J) }
17
17
  end
18
18
 
19
- context :given, Encoding::UTF_8 do
19
+ context :given, Encoding::UTF_8.to_s do
20
20
  subject{ Dech::CSV.new([], encoding: Encoding::UTF_8).external_encoding }
21
21
  it { is_expected.to be(Encoding::UTF_8) }
22
22
  end
@@ -25,12 +25,12 @@ describe Dech::CSV do
25
25
  describe "headers" do
26
26
  array = [[:col1, :col2, :col3], [1, 2, 3]]
27
27
 
28
- context "default with", array.first do
28
+ context "default with", array.first.to_s do
29
29
  subject{ Dech::CSV.new(array).headers }
30
30
  it { is_expected.to eq(array.first) }
31
31
  end
32
32
 
33
- context "given false with", array.first do
33
+ context "given false with", array.first.to_s do
34
34
  subject{ Dech::CSV.new(array, headers: false).headers }
35
35
  it { is_expected.to eq(nil) }
36
36
  end
@@ -44,7 +44,7 @@ describe Dech::CSV do
44
44
 
45
45
  it { is_expected.to be_an_instance_of(Array) }
46
46
 
47
- context :given, array do
47
+ context :given, array.to_s do
48
48
  it { is_expected.to eq(array) }
49
49
  end
50
50
  end
@@ -55,7 +55,7 @@ describe Dech::CSV do
55
55
 
56
56
  it { is_expected.to be_an_instance_of(String) }
57
57
 
58
- context :given, array do
58
+ context :given, array.to_s do
59
59
  array.each do |row|
60
60
  row.each do |cell|
61
61
  it { is_expected.to include(cell.to_s) }
@@ -13,7 +13,6 @@ describe Dech::Dena::FTP do
13
13
 
14
14
  let(:net_ftp) {
15
15
  net_ftp = double("net_ftp")
16
- allow(net_ftp).to receive(:passive=)
17
16
  allow(net_ftp).to receive(:connect)
18
17
  allow(net_ftp).to receive(:login)
19
18
  allow(net_ftp).to receive(:close)
@@ -14,7 +14,7 @@ describe Dech::Ponpare::FTPS do
14
14
 
15
15
  let(:ftps) {
16
16
  ftps = double("ftps")
17
- allow(ftps).to receive(:passive=)
17
+ expect(ftps).to receive(:passive=).with(true)
18
18
  allow(ftps).to receive(:ssl_context=)
19
19
  allow(ftps).to receive(:connect)
20
20
  allow(ftps).to receive(:login)
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+ require "webmock/rspec"
3
+
4
+ describe Dech::Rakuten::API do
5
+ let(:api) {
6
+ described_class.new(
7
+ products: [{id: "PRODUCT-CODE", price: 9800, "item_name" => 'PRODUCT-NAME'}],
8
+ service_secret: "service_secret",
9
+ license_key: "license_key"
10
+ )
11
+ }
12
+ let(:response) {"<itemUpdateResult><code>N000</code></itemUpdateResult>"}
13
+
14
+ describe "initialize" do
15
+ subject {api}
16
+ it { is_expected.to be_a Dech::Rakuten::API}
17
+ end
18
+
19
+ describe "#formatted_products (private)" do
20
+ let(:formatted_products){ [{'item_url'=> 'PRODUCT-CODE', 'item_price'=> 9800, 'item_name' => 'PRODUCT-NAME'}] }
21
+ subject{ api.send(:formatted_products) }
22
+ it{ is_expected.to eq(formatted_products)}
23
+ end
24
+
25
+ describe "#ready?" do
26
+ subject {api.ready?}
27
+ it { is_expected.to be true }
28
+ end
29
+
30
+ describe "#upload!" do
31
+ let!(:request){stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/update")}
32
+
33
+ it "should access to API" do
34
+ api.upload! rescue true
35
+ expect(request).to have_been_made
36
+ end
37
+
38
+ context 'API access is success' do
39
+ before do
40
+ stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/update").to_return(:body => response)
41
+ end
42
+
43
+ it "" do
44
+ expect(api.upload!).to be true
45
+ end
46
+ end
47
+
48
+ context 'API access is failure' do
49
+ it "should raise RakuteUploadError" do
50
+ expect{api.upload!}.to raise_error ::RakutenUploadError
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "#upload" do
56
+ let!(:request){stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/update")}
57
+ it 'should access to API' do
58
+ api.upload
59
+ expect(request).to have_been_made
60
+ end
61
+
62
+ context 'API access is success' do
63
+ before do
64
+ stub_request(:post, "https://api.rms.rakuten.co.jp/es/1.0/item/update").to_return(:body => response)
65
+ end
66
+
67
+ it "" do
68
+ expect(api.upload).to be true
69
+ end
70
+ end
71
+
72
+ context 'API access is failure' do
73
+ it "" do
74
+ expect(api.upload).to be false
75
+ end
76
+ end
77
+ end
78
+ end
@@ -14,7 +14,7 @@ describe Dech::Rakuten::FTP do
14
14
 
15
15
  let(:net_ftp) {
16
16
  net_ftp = double("net_ftp")
17
- allow(net_ftp).to receive(:passive=)
17
+ expect(net_ftp).to receive(:passive=).with(true)
18
18
  allow(net_ftp).to receive(:connect)
19
19
  allow(net_ftp).to receive(:login)
20
20
  allow(net_ftp).to receive(:close)
@@ -13,7 +13,7 @@ describe Dech::Yahoo::FTP do
13
13
 
14
14
  let(:net_ftp) {
15
15
  net_ftp = double("net_ftp")
16
- allow(net_ftp).to receive(:passive=)
16
+ expect(net_ftp).to receive(:passive=).with(true)
17
17
  allow(net_ftp).to receive(:connect)
18
18
  allow(net_ftp).to receive(:login)
19
19
  allow(net_ftp).to receive(:close)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OSA Shunsuke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-21 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: double-bag-ftps
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rms_web_service
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ftp-port_command
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +122,20 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description: Dech enables to upload product information easily.
98
140
  email:
99
141
  - hhelibebcnofnenamg@gmail.com
@@ -121,6 +163,7 @@ files:
121
163
  - lib/dech/ponpare/ftps.rb
122
164
  - lib/dech/price_uploader.rb
123
165
  - lib/dech/rakuten.rb
166
+ - lib/dech/rakuten/api.rb
124
167
  - lib/dech/rakuten/csv.rb
125
168
  - lib/dech/rakuten/ftp.rb
126
169
  - lib/dech/version.rb
@@ -135,6 +178,7 @@ files:
135
178
  - spec/dech/ponpare/csv_spec.rb
136
179
  - spec/dech/ponpare/ftps_spec.rb
137
180
  - spec/dech/ponpare_spec.rb
181
+ - spec/dech/rakuten/api_spec.rb
138
182
  - spec/dech/rakuten/csv_spec.rb
139
183
  - spec/dech/rakuten/ftp_spec.rb
140
184
  - spec/dech/rakuten_spec.rb
@@ -176,6 +220,7 @@ test_files:
176
220
  - spec/dech/ponpare/csv_spec.rb
177
221
  - spec/dech/ponpare/ftps_spec.rb
178
222
  - spec/dech/ponpare_spec.rb
223
+ - spec/dech/rakuten/api_spec.rb
179
224
  - spec/dech/rakuten/csv_spec.rb
180
225
  - spec/dech/rakuten/ftp_spec.rb
181
226
  - spec/dech/rakuten_spec.rb