magnum-pi 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +2 -2
- data/CHANGELOG.rdoc +5 -0
- data/MIT-LICENSE +20 -0
- data/VERSION +1 -1
- data/lib/magnum-pi/api/consumer.rb +6 -2
- data/lib/magnum-pi/gem_ext/oj/aj.rb +1 -1
- data/lib/magnum-pi/gem_ext/ox/ax.rb +1 -1
- data/lib/magnum-pi/version.rb +1 -1
- data/test/test_helper.rb +1 -3
- data/test/unit/api/test_consumer.rb +38 -11
- data/test/unit/test_magnum-pi.rb +1 -1
- metadata +3 -4
- data/test/test_helper/minitest.rb +0 -10
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzE1MzRhM2ZiZGYyOWVkN2Q3NmJhMjY5OTc5NjMyNjY1MjRhYTllMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTBlNjUzOTM3NTE0NWMwMTQwYTdiZTU5YTI4NjdiZDEzNDE5YWFlZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTYzZWI2MmMxZDEwOTJhZTY3MzI1NWRjODU2ZTQ4ZWMxYjkyNDU2ZTdmMDRm
|
10
|
+
YjQwYjQ0MzQ4MTAwYTUzMzEyMTZjYmFlNWU3ZmM3NmFmYzM5Yzg5NmNiNjll
|
11
|
+
OGI1M2FlYTE3ZjdmZWIzODFiMWI5MGZjMTQ1YjFkMDI0M2RkZjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDYwZTA4MDE2NjE0MTZhMDIzZTIyYjQ3NTllODQ5N2NiN2MzZDY4N2RjMDk1
|
14
|
+
NWRlZWNhMjQ1NmZiYzc4MWNmYWNiZTEwYzljNzNjMDc3YjUwNDdkNTEyMzJm
|
15
|
+
ZDVkZWYyZTk0NDY0N2E0YTczYjE3M2I2OTY3MTE3ODAzZWZjY2U=
|
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Paul Engel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.9
|
@@ -19,7 +19,7 @@ module MagnumPI
|
|
19
19
|
FileUtils.mkdir_p File.dirname(target)
|
20
20
|
file = File.open target, "w"
|
21
21
|
begin
|
22
|
-
options = {:method => method, :headers => {"User-Agent" => agent.user_agent}}
|
22
|
+
options = {:method => method, :headers => {"User-Agent" => agent.user_agent}.merge(request_headers(method, url, params))}
|
23
23
|
if method.to_s.downcase == "get"
|
24
24
|
options[:params] = params
|
25
25
|
else
|
@@ -49,11 +49,15 @@ module MagnumPI
|
|
49
49
|
|
50
50
|
def request(method, url, params)
|
51
51
|
puts "#{method.upcase} #{url} #{"(#{params.inspect[1..-2]})" if params && params.size > 0}" if MagnumPI.debug_output?
|
52
|
-
agent.send method, url, params
|
52
|
+
agent.send method, url, params, nil, request_headers(method, url, params)
|
53
53
|
rescue Mechanize::ResponseCodeError => e
|
54
54
|
raise Error, e.message, e.backtrace
|
55
55
|
end
|
56
56
|
|
57
|
+
def request_headers(method, url, params)
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
|
57
61
|
def agent
|
58
62
|
@agent ||= begin
|
59
63
|
Mechanize.new.tap do |agent|
|
data/lib/magnum-pi/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -43,16 +43,43 @@ module Unit
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
describe "#download" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
describe "using GET method" do
|
47
|
+
it "downloads using Typhoeus" do
|
48
|
+
file, request = mock, mock
|
49
|
+
FileUtils.expects(:mkdir_p).with("path/to")
|
50
|
+
File.expects(:open).with("path/to/target", "w").returns(file)
|
51
|
+
Mechanize::HTTP::Agent.any_instance.expects(:user_agent).returns("FooBar v.1.2.3")
|
52
|
+
Typhoeus::Request.expects(:new).with(
|
53
|
+
"http://foo.bar",
|
54
|
+
:method => :get,
|
55
|
+
:headers => {"User-Agent" => "FooBar v.1.2.3"},
|
56
|
+
:params => {:foo => "bar"}
|
57
|
+
).returns(request)
|
58
|
+
file.expects(:close)
|
59
|
+
request.expects(:on_headers)
|
60
|
+
request.expects(:on_body)
|
61
|
+
request.expects(:run)
|
62
|
+
@consumer.download "path/to/target", :get, :foo => "bar"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "using POST method" do
|
66
|
+
it "downloads using Typhoeus" do
|
67
|
+
file, request = mock, mock
|
68
|
+
FileUtils.expects(:mkdir_p).with("path/to")
|
69
|
+
File.expects(:open).with("path/to/target", "w").returns(file)
|
70
|
+
Mechanize::HTTP::Agent.any_instance.expects(:user_agent).returns("FooBar v.1.2.3")
|
71
|
+
Typhoeus::Request.expects(:new).with(
|
72
|
+
"http://foo.bar",
|
73
|
+
:method => :post,
|
74
|
+
:headers => {"User-Agent" => "FooBar v.1.2.3"},
|
75
|
+
:body => {:foo => "bar"}
|
76
|
+
).returns(request)
|
77
|
+
file.expects(:close)
|
78
|
+
request.expects(:on_headers)
|
79
|
+
request.expects(:on_body)
|
80
|
+
request.expects(:run)
|
81
|
+
@consumer.download "path/to/target", :post, :foo => "bar"
|
82
|
+
end
|
56
83
|
end
|
57
84
|
end
|
58
85
|
describe "#resource" do
|
@@ -82,7 +109,7 @@ module Unit
|
|
82
109
|
end
|
83
110
|
describe "#request" do
|
84
111
|
it "is delegated to the Mechanize agent" do
|
85
|
-
@consumer.send(:agent).expects(:send).with(:get, :foo, :bar)
|
112
|
+
@consumer.send(:agent).expects(:send).with(:get, :foo, :bar, nil, {})
|
86
113
|
@consumer.send(:request, :get, :foo, :bar)
|
87
114
|
end
|
88
115
|
it "raises an error when a Mechanize::ResponseCodeError occurs" do
|
data/test/unit/test_magnum-pi.rb
CHANGED
@@ -9,7 +9,7 @@ module Unit
|
|
9
9
|
|
10
10
|
describe MagnumPI do
|
11
11
|
it "has the current version" do
|
12
|
-
version = File.read
|
12
|
+
version = File.read(path("VERSION")).strip
|
13
13
|
assert_equal version, MagnumPI::VERSION
|
14
14
|
assert File.read(path "CHANGELOG.rdoc").include?("Version #{version}")
|
15
15
|
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.
|
4
|
+
version: 0.2.9
|
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-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- .travis.yml
|
176
176
|
- CHANGELOG.rdoc
|
177
177
|
- Gemfile
|
178
|
+
- MIT-LICENSE
|
178
179
|
- README.rdoc
|
179
180
|
- Rakefile
|
180
181
|
- VERSION
|
@@ -203,7 +204,6 @@ files:
|
|
203
204
|
- script/console
|
204
205
|
- test/test_helper.rb
|
205
206
|
- test/test_helper/coverage.rb
|
206
|
-
- test/test_helper/minitest.rb
|
207
207
|
- test/unit/api/test_consumer.rb
|
208
208
|
- test/unit/api/test_instance.rb
|
209
209
|
- test/unit/api/test_resources.rb
|
@@ -240,7 +240,6 @@ summary: Create an easy interface to talk with APIs
|
|
240
240
|
test_files:
|
241
241
|
- test/test_helper.rb
|
242
242
|
- test/test_helper/coverage.rb
|
243
|
-
- test/test_helper/minitest.rb
|
244
243
|
- test/unit/api/test_consumer.rb
|
245
244
|
- test/unit/api/test_instance.rb
|
246
245
|
- test/unit/api/test_resources.rb
|