magnum-pi 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmZmNzlhZDM5ZWU1NjRjNGY1NDFlN2I1NGQ2YjU4OGU2MGM5NjZhZA==
4
+ MDRjMjBkMWFjOTk2YjMzMDJhMGVmMmM3OTNiMDQ4N2ExNDI1ZTI2YQ==
5
5
  data.tar.gz: !binary |-
6
- MTQ2ZTFhOTc3Y2ZiYjdlNWM0YzgzOGQzMDcwNDY0YjZhMWQxZDVjMQ==
6
+ NDYzODBlY2VmYmQxMTViNTc3MjYxNjM3MjljNTJhNjgxOTUyODNhYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGY2YjE2NzVkNzE5MjUxMGNiNzMyZTVhNDI5NWJlN2MwMDljYzRiZDFhYjcy
10
- ZjlmNGYwMzYwNzFiNjBjM2QwMmNhNjZhMzU5M2MxYmEzYmM0YTU2MDM0NDg3
11
- NjlkMjYyZDcxMWZlOGQ1NjY0ODA3ODc0YTg3NDZkNWViMTY2ODc=
9
+ ZWNiMWExYzFmNDVkOGRkNmRmNmY5MjRiMDA1OWQyYjFhZWY3YjRmYjNlMmYx
10
+ ODI3Yzg2NmIyMmQ2NGM3MjA5YWZkZGRkYWMxNjVlOWNkNjhiZTRmNjcxNDYz
11
+ ZDUzMWEwMTdmYzljZDRlNDc2NzdhN2FkNTViNTIzYWI3Zjc1YmY=
12
12
  data.tar.gz: !binary |-
13
- ODVmMmE1MzQzNDY4YWVlNjMxOTE1MjhlMDM0NDM2ZjFiNjNhNDM4YWE4YWIy
14
- MmMxMDQzMTNlMTVmN2Y0YmJkMDQ4NDkyNTljNDQyZDFkZWQzMGJmNTAxMTA3
15
- YTcwOGE1OGYwZTMxNjhkOGNmODMzMzljZDMxZDY3ZmQ1YWNhZmE=
13
+ OWY3YzFiOGVhYWU5MmE0ODk4ZjM0NjgwMGQ0YmY1MzgzMTA1NmQ2YzA1NWUx
14
+ NjRkMzUwZDJhMmFhZDAyNGNlNTk5Mzk1YzE5ZWZhNzEzOWYwZTEzNmUxYTBl
15
+ YTNhYmUyZGIxZDA1ZmZmYmMxYTc1M2ViZDlmMmU2ZDIwMjIzZTk=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = MagnumPI CHANGELOG
2
2
 
3
+ == Version 0.2.6 (August 5, 2014)
4
+
5
+ * Using Typhoeus for downloading files
6
+
3
7
  == Version 0.2.5 (July 16, 2014)
4
8
 
5
9
  * Added Aj parsing fix
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/lib/magnum-pi.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "mechanize"
2
+ require "typhoeus"
2
3
  require "oj"
3
4
  require "ox"
4
5
  require "active_support/core_ext/object/to_query"
@@ -16,7 +16,16 @@ module MagnumPI
16
16
  def download(target, method, *args)
17
17
  url, params = parse_args *args
18
18
  File.delete target if File.exists? target
19
- request(method, url, params).save_as target
19
+ FileUtils.mkdir_p File.dirname(target)
20
+ file = File.open target, "w"
21
+ begin
22
+ request = Typhoeus::Request.new url, :method => method, :params => params
23
+ request.on_headers {|response| raise "Failed to download #{target}" unless (response.response_code / 200) == 1}
24
+ request.on_body {|chunk| file.write chunk.force_encoding("UTF-8")}
25
+ request.run
26
+ ensure
27
+ file.close
28
+ end
20
29
  true
21
30
  end
22
31
 
@@ -1,7 +1,7 @@
1
1
  module MagnumPI
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- TINY = 5
4
+ TINY = 6
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
data/magnum-pi.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = MagnumPI::VERSION
17
17
 
18
18
  gem.add_dependency "mechanize"
19
+ gem.add_dependency "typhoeus"
19
20
  gem.add_dependency "oj"
20
21
  gem.add_dependency "ox"
21
22
  gem.add_dependency "activesupport"
@@ -44,9 +44,14 @@ module Unit
44
44
  end
45
45
  describe "#download" do
46
46
  it "downloads using the Mechanize agent" do
47
- response = mock
48
- response.expects(:save_as).with("path/to/target")
49
- @consumer.expects(:request).with(:get, "http://foo.bar", :foo => "bar").returns(response)
47
+ file, request = mock, mock
48
+ FileUtils.expects(:mkdir_p).with("path/to")
49
+ File.expects(:open).with("path/to/target", "w").returns(file)
50
+ Typhoeus::Request.expects(:new).with("http://foo.bar", :method => :get, :params => {:foo => "bar"}).returns(request)
51
+ file.expects(:close)
52
+ request.expects(:on_headers)
53
+ request.expects(:on_body)
54
+ request.expects(:run)
50
55
  @consumer.download "path/to/target", :get, :foo => "bar"
51
56
  end
52
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnum-pi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: oj
29
43
  requirement: !ruby/object:Gem::Requirement