mechanize-progressbar 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,186 +1,156 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mechanize-progressbar
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - kitamomonga
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-07 00:00:00 +09:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
12
+ date: 2011-07-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: mechanize
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &82111910 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.0.0
35
- requirement: *id001
36
22
  type: :runtime
37
- - !ruby/object:Gem::Dependency
38
23
  prerelease: false
24
+ version_requirements: *82111910
25
+ - !ruby/object:Gem::Dependency
39
26
  name: progressbar
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &82111630 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 59
46
- segments:
47
- - 0
48
- - 9
49
- - 0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
50
32
  version: 0.9.0
51
- requirement: *id002
52
33
  type: :runtime
53
- - !ruby/object:Gem::Dependency
54
34
  prerelease: false
35
+ version_requirements: *82111630
36
+ - !ruby/object:Gem::Dependency
55
37
  name: rspec
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &82111390 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 2
64
- - 3
65
- - 0
40
+ requirements:
41
+ - - ! '>'
42
+ - !ruby/object:Gem::Version
66
43
  version: 2.3.0
67
- requirement: *id003
68
44
  type: :development
69
- - !ruby/object:Gem::Dependency
70
45
  prerelease: false
46
+ version_requirements: *82111390
47
+ - !ruby/object:Gem::Dependency
71
48
  name: bundler
72
- version_requirements: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &82111150 !ruby/object:Gem::Requirement
73
50
  none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 23
78
- segments:
79
- - 1
80
- - 0
81
- - 0
51
+ requirements:
52
+ - - ! '>'
53
+ - !ruby/object:Gem::Version
82
54
  version: 1.0.0
83
- requirement: *id004
84
55
  type: :development
85
- - !ruby/object:Gem::Dependency
86
56
  prerelease: false
57
+ version_requirements: *82111150
58
+ - !ruby/object:Gem::Dependency
87
59
  name: jeweler
88
- version_requirements: &id005 !ruby/object:Gem::Requirement
60
+ requirement: &82110890 !ruby/object:Gem::Requirement
89
61
  none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- hash: 7
94
- segments:
95
- - 1
96
- - 5
97
- - 2
62
+ requirements:
63
+ - - ! '>'
64
+ - !ruby/object:Gem::Version
98
65
  version: 1.5.2
99
- requirement: *id005
100
66
  type: :development
101
- - !ruby/object:Gem::Dependency
102
67
  prerelease: false
68
+ version_requirements: *82110890
69
+ - !ruby/object:Gem::Dependency
103
70
  name: rcov
104
- version_requirements: &id006 !ruby/object:Gem::Requirement
71
+ requirement: &82110650 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *82110650
80
+ - !ruby/object:Gem::Dependency
81
+ name: rdoc
82
+ requirement: &82110400 !ruby/object:Gem::Requirement
105
83
  none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
113
- requirement: *id006
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 2.4.2
114
88
  type: :development
115
- - !ruby/object:Gem::Dependency
116
89
  prerelease: false
90
+ version_requirements: *82110400
91
+ - !ruby/object:Gem::Dependency
117
92
  name: webmock
118
- version_requirements: &id007 !ruby/object:Gem::Requirement
93
+ requirement: &82110150 !ruby/object:Gem::Requirement
119
94
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
127
- requirement: *id007
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 1.6.1
128
99
  type: :development
129
- description: Mechanize-Progressbar shows ProgressBar when HTTP GET access of Mechanize(Mechanize#get, Page::Link#click, response of Form#submit). It requires 'progressbar' gem. HTTP POST is not supported.
100
+ prerelease: false
101
+ version_requirements: *82110150
102
+ description: Mechanize-Progressbar shows ProgressBar when HTTP GET access of Mechanize(Mechanize#get,
103
+ Page::Link#click, response of Form#submit). It requires 'progressbar' gem. HTTP
104
+ POST is not supported.
130
105
  email: kitamomonga@gmail.com
131
106
  executables: []
132
-
133
107
  extensions: []
134
-
135
- extra_rdoc_files:
108
+ extra_rdoc_files:
136
109
  - LICENSE.txt
137
110
  - README.rdoc
138
- files:
139
- - .document
140
- - .rspec
111
+ - README.rdoc.ja
112
+ files:
113
+ - CHANGELOG
141
114
  - Gemfile
142
115
  - LICENSE.txt
143
116
  - README.rdoc
117
+ - README.rdoc.ja
144
118
  - Rakefile
145
119
  - VERSION
146
120
  - lib/mechanize/progressbar.rb
147
- - lib/mechanize/progressbar/mech_progressbar.rb
121
+ - lib/mechanize/progressbar/api.rb
122
+ - lib/mechanize/progressbar/mechanize_1_0.rb
123
+ - lib/mechanize/progressbar/mechanize_2_0.rb
124
+ - lib/mechanize/progressbar/mechanize_progressbar.rb
148
125
  - spec/mechanize/progressbar/mech_progressbar_spec.rb
149
126
  - spec/spec_helper.rb
150
- has_rdoc: true
151
127
  homepage: http://github.com/kitamomonga/mechanize-progressbar
152
- licenses:
153
- - GPL-2
128
+ licenses:
129
+ - MIT
154
130
  post_install_message:
155
131
  rdoc_options: []
156
-
157
- require_paths:
132
+ require_paths:
158
133
  - lib
159
- required_ruby_version: !ruby/object:Gem::Requirement
134
+ required_ruby_version: !ruby/object:Gem::Requirement
160
135
  none: false
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- hash: 3
165
- segments:
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ segments:
166
141
  - 0
167
- version: "0"
168
- required_rubygems_version: !ruby/object:Gem::Requirement
142
+ hash: 783892257
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
144
  none: false
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
175
- - 0
176
- version: "0"
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
177
149
  requirements: []
178
-
179
150
  rubyforge_project:
180
- rubygems_version: 1.3.7
151
+ rubygems_version: 1.8.3
181
152
  signing_key:
182
153
  specification_version: 3
183
- summary: Mechanize-Progressbar provides ProgressBar for Mechanize#get and Link#click. requires 'progressbar' gem.
184
- test_files:
185
- - spec/mechanize/progressbar/mech_progressbar_spec.rb
186
- - spec/spec_helper.rb
154
+ summary: Mechanize-Progressbar provides ProgressBar for Mechanize#get and Link#click.
155
+ requires 'progressbar' gem.
156
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,149 +0,0 @@
1
- module MechanizeProgressBarAPI
2
- ### Usage:
3
- ### require 'mechanize'
4
- ### require 'mechanize/progressbar'
5
- ### agent = Mechanize.new
6
- ### agent.progressbar{ agent.get(large_file) }
7
- ### agent.get(some_page)
8
- ### agent.progressbar{ agent.page.link_with(:text => 'download here').click }
9
- ###
10
- ### If you want to set parameters to ProgressBar object,
11
- ### agent.progressbar(:title => 'large_file', :format_arguments => @fmt) do
12
- ### agent.get(large_file)
13
- ### end
14
- ### ProgressBar is gem lib. Please install with 'gem install progressbar'.
15
- ###
16
- ### options:
17
- ### [:single] enables single line mode, original ProgressBar gem behavior. default is false
18
- ### [:title] ProgressBar.new(*title*, total, out), default is empty
19
- ### [:total] ProgressBar.new(title, *total*, out), default is 'Content-Length' response header
20
- ### [:out] ProgressBar.new(title, total, *out*), default is $stderr
21
- ### [:format] ProgressBar.new(*args).format=*format*, default is nil
22
- ### [:format_arguments] ProgressBar.new(*args).format_arguments=*format_arguments*, default is nil
23
- ### [:reversed] ReversedProgressBar.new(*args), default is false
24
- ### [:file_transfer_mode] enables ProgressBar#file_transfer_mode, default is true
25
- ### [:suppress_logger] makes Logger's output and Progressbar's output independent
26
- def progressbar(agent_or_pbar_opts = self, pbar_opts = {})
27
- if agent_or_pbar_opts.kind_of?(Hash) then
28
- agent, pbar_opts = self, agent_or_pbar_opts
29
- else
30
- agent = agent_or_pbar_opts
31
- end
32
- MechanizeProgressBar.register(agent, pbar_opts)
33
- if block_given?
34
- begin
35
- yield agent
36
- rescue Exception, Mechanize::ResponseCodeError
37
- MechanizeProgressBar.unregister(agent)
38
- raise
39
- end
40
- MechanizeProgressBar.unregister(agent)
41
- else
42
- MechanizeProgressBar.reserve_pseudo_unregisteration(agent)
43
- end
44
- agent
45
- end
46
- end
47
-
48
- module MechanizeProgressBar
49
- def self.pbar_hooks ; @pbar_hooks ||= []; end
50
- def self.default_out ; @default_out ||= $stderr; end
51
- def self.default_out=(out); @default_out = out; end
52
-
53
- def self.build(chain_params)
54
- pbar_opts = chain_params[:progressbar]
55
-
56
- out = pbar_opts[:out] || pbar_opts[:output] || self.default_out
57
- if pbar_opts[:single] then
58
- title = pbar_opts[:title] || chain_params[:uri].host
59
- format = pbar_opts[:format]
60
- format_arguments = pbar_opts[:format_arguments]
61
- else
62
- title = pbar_opts[:title] || ""
63
- format = pbar_opts[:format] || "%3d%% %s %s"
64
- format_arguments = pbar_opts[:format_arguments] || [:percentage, :bar, :stat_for_file_transfer]
65
- out.print "#{pbar_opts[:title]||chain_params[:uri]}\n"
66
- end
67
- total = pbar_opts[:total] || filesize(chain_params)
68
- pbar_class = pbar_opts[:reversed] ? ReversedProgressBar : ProgressBar
69
-
70
- progressbar = pbar_class.new(title, total, out)
71
- progressbar.file_transfer_mode unless pbar_opts[:file_transfer_mode]
72
- progressbar.format = format if format
73
- progressbar.format_arguments = format_arguments if format_arguments
74
- return progressbar
75
- end
76
-
77
- def self.filesize(chain_params)
78
- content_length = chain_params[:response]['content-length']
79
- content_length ? content_length.to_i : 0
80
- end
81
-
82
- def self.register(agent, pbar_opts)
83
- pre_hook = lambda{|options| options[:progressbar] = pbar_opts}
84
- self.pbar_hooks << pre_hook
85
- agent.pre_connect_hooks << pre_hook
86
- end
87
-
88
- def self.unregister(agent)
89
- agent.pre_connect_hooks.each do |pr|
90
- agent.pre_connect_hooks.delete_if{ self.pbar_hooks.delete(pr)}
91
- end
92
- end
93
-
94
- def self.reserve_pseudo_unregisteration(agent)
95
- agent.post_connect_hooks << lambda{|options|
96
- MechanizeProgressBar.unregister(agent) if options[:agent] && options[:progressbar]
97
- }
98
- end
99
-
100
- def self.http_ok?(params)
101
- params[:progressbar] && params[:response].code == '200'
102
- end
103
-
104
- def self.suppress_logger?(params)
105
- params[:progressbar] && params[:progressbar][:suppress_logger]
106
- end
107
- end
108
-
109
-
110
-
111
- class Mechanize # has 6 added/modified lines
112
- include MechanizeProgressBarAPI # (1of6)a
113
- class Chain
114
- class ResponseReader
115
- def handle(ctx, params)
116
- params[:response] = @response
117
- body = StringIO.new
118
- total = 0
119
- pbar = MechanizeProgressBar.build(params) if MechanizeProgressBar.http_ok?(params) # (2of6)a
120
- @response.read_body { |part|
121
- total += part.length
122
- body.write(part)
123
- # Mechanize.log.debug("Read #{total} bytes") if Mechanize.log
124
- Mechanize.log.debug("Read #{total} bytes") if Mechanize.log && !MechanizeProgressBar.suppress_logger?(params) # (3of6)m
125
- pbar.inc(part.length) if MechanizeProgressBar.http_ok?(params) # (4of6)a
126
- }
127
- body.rewind
128
- pbar.finish if MechanizeProgressBar.http_ok?(params) # (5of6)a
129
- Mechanize.log.debug("Read #{total} bytes") if Mechanize.log && MechanizeProgressBar.suppress_logger?(params) # (6of6)a
130
-
131
- res_klass = Net::HTTPResponse::CODE_TO_OBJ[@response.code.to_s]
132
- raise ResponseCodeError.new(@response) unless res_klass
133
-
134
- # Net::HTTP ignores EOFError if Content-length is given, so we emulate it here.
135
- unless res_klass <= Net::HTTPRedirection
136
- raise EOFError if (!params[:request].is_a?(Net::HTTP::Head)) && @response.content_length() && @response.content_length() != total
137
- end
138
-
139
- @response.each_header { |k,v|
140
- Mechanize.log.debug("response-header: #{ k } => #{ v }")
141
- } if Mechanize.log
142
-
143
- params[:response_body] = body
144
- params[:res_klass] = res_klass
145
- super
146
- end
147
- end
148
- end
149
- end