netprint 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/netprint +35 -0
- data/lib/netprint/agent.rb +2 -1
- data/lib/netprint/version.rb +1 -1
- data/netprint.gemspec +4 -3
- data/spec/netprint/agent_spec.rb +38 -23
- data/spec//343/201/202/343/201/204/343/201/206/343/201/210/343/201/212.pdf +0 -0
- metadata +28 -8
data/bin/netprint
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'netprint'
|
4
|
+
require 'docopt'
|
5
|
+
|
6
|
+
program_name = File.basename($0)
|
7
|
+
doc =<<-EOS
|
8
|
+
Usage:
|
9
|
+
#{program_name} [--user=<userid:password>] [--email=<email>] [--secret=<secret>] <filename>
|
10
|
+
#{program_name} -h | --help
|
11
|
+
|
12
|
+
Options:
|
13
|
+
-h --help Show this screen.
|
14
|
+
-v --version Show version information.
|
15
|
+
-u --user=<userid:password> User account. if not specified, use ENV['NETPRINT_(USERID|PASSWORD)']
|
16
|
+
-e --email=<email> Email address to notify
|
17
|
+
-s --secret=<secret> Secret code
|
18
|
+
EOS
|
19
|
+
|
20
|
+
begin
|
21
|
+
options = Docopt::docopt(doc, :version => Netprint::VERSION)
|
22
|
+
userid, password = options['--user'].split(':') if options['--user']
|
23
|
+
netprint = Netprint::Agent.new(
|
24
|
+
userid || ENV['NETPRINT_USERID'],
|
25
|
+
password || ENV['NETPRINT_PASSWORD'])
|
26
|
+
|
27
|
+
netprint.login
|
28
|
+
code = netprint.upload(options['<filename>'],
|
29
|
+
:email => options['--email'] || ENV['NETPRINT_EMAIL'],
|
30
|
+
:secret_code => options['--secret'])
|
31
|
+
|
32
|
+
puts code
|
33
|
+
rescue Docopt::Exit => e
|
34
|
+
puts e.message
|
35
|
+
end
|
data/lib/netprint/agent.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "tmpdir"
|
3
3
|
require "fileutils"
|
4
4
|
require "pathname"
|
5
|
+
require 'digest/md5'
|
5
6
|
|
6
7
|
module Netprint
|
7
8
|
class Agent
|
@@ -25,7 +26,7 @@ module Netprint
|
|
25
26
|
options = Options.new(options)
|
26
27
|
|
27
28
|
Dir.mktmpdir do |dir|
|
28
|
-
upload_filename = (Pathname(dir) + ([Time.now.to_f.to_s,
|
29
|
+
upload_filename = (Pathname(dir) + ([Time.now.to_f.to_s, Digest::MD5.hexdigest(filename).to_s].join('_'))).to_s
|
29
30
|
cp filename, upload_filename
|
30
31
|
|
31
32
|
page = mechanize.get(url.upload)
|
data/lib/netprint/version.rb
CHANGED
data/netprint.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.homepage = ""
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\
|
13
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\
|
12
|
+
gem.files = `git ls-files -z`.split("\0")
|
13
|
+
gem.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\0")
|
14
14
|
gem.name = "netprint"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Netprint::VERSION
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_development_dependency('rake')
|
20
20
|
gem.add_development_dependency('netprint')
|
21
21
|
gem.add_development_dependency('webmock')
|
22
|
-
gem.add_dependency('mechanize', '2.
|
22
|
+
gem.add_dependency('mechanize', '2.7.0')
|
23
23
|
gem.add_dependency('addressable')
|
24
|
+
gem.add_dependency('docopt')
|
24
25
|
end
|
data/spec/netprint/agent_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
3
|
|
3
4
|
include Netprint
|
@@ -18,34 +19,48 @@ describe Agent do
|
|
18
19
|
@agent.should be_login
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
shared_examples_for '#upload' do
|
23
|
+
it 'should upload' do
|
24
|
+
stub_request(:get, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=1&s=qwertyuiopoiuytrewq').
|
25
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../upload.html')).read)
|
26
|
+
stub_request(:post, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=1&s=qwertyuiopoiuytrewq').
|
27
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../list.html')).read)
|
28
|
+
stub_request(:get, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=0&s=qwertyuiopoiuytrewq').
|
29
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../list.html')).read)
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
filename = File.expand_path(pdf_filename)
|
32
|
+
@agent.login
|
33
|
+
|
34
|
+
code = @agent.upload(filename)
|
35
|
+
code.should match(/^[0-9A-Z]{8}$/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should handle registration error' do
|
39
|
+
stub_request(:get, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=1&s=qwertyuiopoiuytrewq').
|
40
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../upload.html')).read)
|
41
|
+
stub_request(:post, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=1&s=qwertyuiopoiuytrewq').
|
42
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../list.html')).read)
|
43
|
+
stub_request(:get, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=0&s=qwertyuiopoiuytrewq').
|
44
|
+
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../error.html')).read)
|
31
45
|
|
32
|
-
|
33
|
-
|
46
|
+
filename = File.expand_path(pdf_filename)
|
47
|
+
@agent.login
|
48
|
+
|
49
|
+
lambda {
|
50
|
+
@agent.upload(filename)
|
51
|
+
}.should raise_error(RegistrationError)
|
52
|
+
end
|
34
53
|
end
|
35
54
|
|
36
|
-
|
37
|
-
|
38
|
-
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../upload.html')).read)
|
39
|
-
stub_request(:post, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=1&s=qwertyuiopoiuytrewq').
|
40
|
-
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../list.html')).read)
|
41
|
-
stub_request(:get, 'https://www.printing.ne.jp/cgi-bin/mn.cgi?c=0&m=0&s=qwertyuiopoiuytrewq').
|
42
|
-
to_return(open(File.expand_path(File.dirname(__FILE__) + '/../error.html')).read)
|
55
|
+
context 'filename is ASCII only' do
|
56
|
+
let(:pdf_filename) { File.dirname(__FILE__) + '/../foo.pdf' }
|
43
57
|
|
44
|
-
|
45
|
-
|
58
|
+
it_should_behave_like '#upload'
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'filename has non-ASCII characters' do
|
62
|
+
let(:pdf_filename) { File.dirname(__FILE__) + '/../あいうえお.pdf' }
|
46
63
|
|
47
|
-
|
48
|
-
@agent.upload(filename)
|
49
|
-
}.should raise_error(RegistrationError)
|
64
|
+
it_should_behave_like '#upload'
|
50
65
|
end
|
51
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
requirements:
|
83
83
|
- - '='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 2.
|
85
|
+
version: 2.7.0
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - '='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2.
|
93
|
+
version: 2.7.0
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: addressable
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,10 +107,27 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: docopt
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: A library to upload file to netprint
|
111
127
|
email:
|
112
128
|
- youpy@buycheapviagraonlinenow.com
|
113
|
-
executables:
|
129
|
+
executables:
|
130
|
+
- netprint
|
114
131
|
extensions: []
|
115
132
|
extra_rdoc_files: []
|
116
133
|
files:
|
@@ -120,6 +137,7 @@ files:
|
|
120
137
|
- LICENSE
|
121
138
|
- README.md
|
122
139
|
- Rakefile
|
140
|
+
- bin/netprint
|
123
141
|
- lib/netprint.rb
|
124
142
|
- lib/netprint/agent.rb
|
125
143
|
- lib/netprint/constants.rb
|
@@ -136,6 +154,7 @@ files:
|
|
136
154
|
- spec/netprint/url_spec.rb
|
137
155
|
- spec/spec_helper.rb
|
138
156
|
- spec/upload.html
|
157
|
+
- spec/あいうえお.pdf
|
139
158
|
homepage: ''
|
140
159
|
licenses: []
|
141
160
|
post_install_message:
|
@@ -150,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
169
|
version: '0'
|
151
170
|
segments:
|
152
171
|
- 0
|
153
|
-
hash: -
|
172
|
+
hash: -565048395014736693
|
154
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
174
|
none: false
|
156
175
|
requirements:
|
@@ -159,10 +178,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
178
|
version: '0'
|
160
179
|
segments:
|
161
180
|
- 0
|
162
|
-
hash: -
|
181
|
+
hash: -565048395014736693
|
163
182
|
requirements: []
|
164
183
|
rubyforge_project:
|
165
|
-
rubygems_version: 1.8.
|
184
|
+
rubygems_version: 1.8.25
|
166
185
|
signing_key:
|
167
186
|
specification_version: 3
|
168
187
|
summary: A library to upload file to netprint
|
@@ -175,3 +194,4 @@ test_files:
|
|
175
194
|
- spec/netprint/url_spec.rb
|
176
195
|
- spec/spec_helper.rb
|
177
196
|
- spec/upload.html
|
197
|
+
- spec/あいうえお.pdf
|