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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWE5Y2ZlZmRhNGRiZDA0YjllZDYxNTRjOTVkYWY5YWM1MWY1NDdiYw==
4
+ MzE1MzRhM2ZiZGYyOWVkN2Q3NmJhMjY5OTc5NjMyNjY1MjRhYTllMQ==
5
5
  data.tar.gz: !binary |-
6
- M2EyZmFmYjc1NTZkNjcwNTBjNDYwNDg2MGFiYmIyZThmODAwYjg0Yg==
6
+ OTBlNjUzOTM3NTE0NWMwMTQwYTdiZTU5YTI4NjdiZDEzNDE5YWFlZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmQ4NWIzNTFjYzhiYmJkN2NmNDc4MGNiZjZlZjk2ODMxZGNjYWNjMjJkZTE4
10
- ODIwZDcyMjU1NDVjMjNmNWQyNWYwYzdjMzY1MGQwZjMwZjM5OGUwYzY2ZTQw
11
- ZDgxNGZlMDljYzgxNGJhNTMwNzA0ODIxMjk5M2Q1YTE0MTA4MWY=
9
+ OTYzZWI2MmMxZDEwOTJhZTY3MzI1NWRjODU2ZTQ4ZWMxYjkyNDU2ZTdmMDRm
10
+ YjQwYjQ0MzQ4MTAwYTUzMzEyMTZjYmFlNWU3ZmM3NmFmYzM5Yzg5NmNiNjll
11
+ OGI1M2FlYTE3ZjdmZWIzODFiMWI5MGZjMTQ1YjFkMDI0M2RkZjA=
12
12
  data.tar.gz: !binary |-
13
- NTg1NTM2ODU3NzY2NjBiNjFmYjI5NTA3Mzc2ODkzNjlhOGI0OWJiNTIzOTc2
14
- YmFjNGY4ZWI2NGQxZDVjN2I3MWJjNjEyYTg2ZTg0NzVlOGZkMmFkMzIzNDNl
15
- NTE1MzlkZDc1NjNmNTRmZjBjYTljNjc3MDIzZGIxNjM0ZmRhOWE=
13
+ ZDYwZTA4MDE2NjE0MTZhMDIzZTIyYjQ3NTllODQ5N2NiN2MzZDY4N2RjMDk1
14
+ NWRlZWNhMjQ1NmZiYzc4MWNmYWNiZTEwYzljNzNjMDc3YjUwNDdkNTEyMzJm
15
+ ZDVkZWYyZTk0NDY0N2E0YTczYjE3M2I2OTY3MTE3ODAzZWZjY2U=
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.2
3
4
  - 2.0.0
4
- - 1.9.3
5
- - 1.9.2
5
+ - 1.9.3
@@ -1,5 +1,10 @@
1
1
  = MagnumPI CHANGELOG
2
2
 
3
+ == Version 0.2.9 (October 29, 2014)
4
+
5
+ * Being able to add request headers
6
+ * Being able to pass StringIO’s directly to Aj and Ax
7
+
3
8
  == Version 0.2.8 (August 14, 2014)
4
9
 
5
10
  * Corrected parameters when downloading with POST requests
@@ -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.8
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|
@@ -3,7 +3,7 @@ require "stringio"
3
3
  class Aj < Oj::Saj
4
4
 
5
5
  def initialize(json)
6
- @stringio = StringIO.new json
6
+ @stringio = json.is_a?(StringIO) ? json : StringIO.new(json)
7
7
  end
8
8
 
9
9
  def each(pattern, &block)
@@ -3,7 +3,7 @@ require "stringio"
3
3
  class Ax < Ox::Sax
4
4
 
5
5
  def initialize(xml)
6
- @stringio = StringIO.new xml
6
+ @stringio = xml.is_a?(StringIO) ? xml : StringIO.new(xml)
7
7
  end
8
8
 
9
9
  def each(pattern, &block)
@@ -1,7 +1,7 @@
1
1
  module MagnumPI
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- TINY = 8
4
+ TINY = 9
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -10,6 +10,4 @@ end
10
10
 
11
11
  require "bundler"
12
12
  Bundler.require :default, :development, :test
13
- require "xmlsimple"
14
-
15
- require_relative "test_helper/minitest"
13
+ require "xmlsimple"
@@ -43,16 +43,43 @@ module Unit
43
43
  end
44
44
  end
45
45
  describe "#download" do
46
- it "downloads using the Mechanize agent" do
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)
55
- @consumer.download "path/to/target", :get, :foo => "bar"
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
@@ -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 path("VERSION")
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.8
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-08-14 00:00:00.000000000 Z
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
@@ -1,10 +0,0 @@
1
- # class MiniTest::Test
2
- # def setup
3
- # $stringio ||= StringIO.new
4
- # $stdout = $stringio
5
- # end
6
- # def teardown
7
- # $stdout = STDOUT
8
- # $stringio.truncate $stringio.rewind
9
- # end
10
- # end