rest_client_plus 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +14 -1
- data/README.md +19 -1
- data/lib/array_helper.rb +10 -0
- data/lib/requests.rb +11 -9
- data/lib/rest_client_plus.rb +3 -3
- data/rest_client_plus.gemspec +1 -1
- data/tests/array_helper_test.rb +4 -0
- data/tests/rest_client_plus_test.rb +19 -0
- data/tests/webservice_stubs/data.rb +22 -0
- data/tests/webservice_stubs/stubs.rb +20 -0
- metadata +4 -2
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest_client_plus (0.0.
|
4
|
+
rest_client_plus (0.0.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
addressable (2.3.5)
|
10
|
+
crack (0.4.1)
|
11
|
+
safe_yaml (~> 0.9.0)
|
12
|
+
mime-types (2.0)
|
9
13
|
rake (10.1.0)
|
14
|
+
rest-client (1.6.7)
|
15
|
+
mime-types (>= 1.16)
|
16
|
+
safe_yaml (0.9.7)
|
17
|
+
webmock (1.16.1)
|
18
|
+
addressable (>= 2.2.7)
|
19
|
+
crack (>= 0.3.2)
|
10
20
|
|
11
21
|
PLATFORMS
|
22
|
+
ruby
|
12
23
|
x86-mingw32
|
13
24
|
|
14
25
|
DEPENDENCIES
|
15
26
|
bundler
|
16
27
|
rake
|
28
|
+
rest-client
|
17
29
|
rest_client_plus!
|
30
|
+
webmock
|
data/README.md
CHANGED
@@ -5,6 +5,16 @@ Extensions to Ruby's RestClient
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
+
Tested against ruby versions
|
9
|
+
|
10
|
+
not working
|
11
|
+
1.8.7
|
12
|
+
|
13
|
+
working
|
14
|
+
1.9.3-p484
|
15
|
+
2.0.0-p353
|
16
|
+
2.1.0dev (2013-11-23 trunk 43807)
|
17
|
+
|
8
18
|
Add this line to your application's Gemfile:
|
9
19
|
|
10
20
|
gem 'rest_client_plus'
|
@@ -21,11 +31,19 @@ Require using:
|
|
21
31
|
|
22
32
|
$ require 'rest_client_plus'
|
23
33
|
|
34
|
+
## Issues
|
35
|
+
|
36
|
+
Warning: You are using Excon 0.20.1. WebMock supports version >= 0.27.5.
|
37
|
+
|
24
38
|
## Usage
|
25
39
|
|
26
40
|
RestClientPlus provides GET, POST and PUT methods which return a Ruby hash if json is received.
|
27
41
|
|
28
|
-
ArrayHelper.unwrap_from_array will unwrap a hash from a single-element array
|
42
|
+
ArrayHelper.unwrap_from_array(array) will unwrap a hash from a single-element array (array). Array is also extended with
|
43
|
+
Array#unwrap_from_array so:
|
44
|
+
|
45
|
+
[ {:key => "value"} ].unwrap_from_array! #=> {:key => "value"}
|
46
|
+
|
29
47
|
|
30
48
|
## Running Tests
|
31
49
|
|
data/lib/array_helper.rb
CHANGED
data/lib/requests.rb
CHANGED
@@ -3,21 +3,23 @@ module RestClientPlus
|
|
3
3
|
module Requests
|
4
4
|
|
5
5
|
def self.post_json_to_url input_url, json_body
|
6
|
-
|
7
|
-
response.code.should == 200
|
8
|
-
JSON.parse response.body
|
6
|
+
parse_response(RestClient.post(input_url, json_body, :content_type => 'application/json'))
|
9
7
|
end
|
10
8
|
|
11
9
|
def self.put_json_to_url input_url, json_body
|
12
|
-
|
13
|
-
response.code.should == 200
|
14
|
-
JSON.parse response.body
|
10
|
+
parse_response(RestClient.put(input_url, json_body, :content_type => 'application/json'))
|
15
11
|
end
|
16
12
|
|
17
13
|
def self.get_json_from_url input_url
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
parse_response(RestClient.get(input_url))
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.parse_response(response)
|
21
|
+
JSON.parse response.body if response.body.respond_to?(:reverse)
|
22
|
+
response.body
|
21
23
|
end
|
22
24
|
|
23
25
|
end
|
data/lib/rest_client_plus.rb
CHANGED
data/rest_client_plus.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "rest_client_plus"
|
7
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.5"
|
8
8
|
s.authors = ["John Wakeling", "Darren Bown"]
|
9
9
|
s.email = ["jwakeling23@gmail.com", "darren.bown@droidqa.co.uk"]
|
10
10
|
s.description = %q{Extensions to Ruby's RestClient}
|
data/tests/array_helper_test.rb
CHANGED
@@ -21,4 +21,8 @@ class ArrayHelperTest < Test::Unit::TestCase
|
|
21
21
|
assert_equal(@test_string, RestClientPlus::ArrayHelper.unwrap_from_array(@test_string))
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_array_is_extended
|
25
|
+
assert_equal(@test_hash, @hash_wrapped_in_array.unwrap_from_array!)
|
26
|
+
end
|
27
|
+
|
24
28
|
end
|
@@ -1,10 +1,29 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../lib/rest_client_plus'
|
3
|
+
require_relative '../tests/webservice_stubs/data'
|
4
|
+
require_relative 'webservice_stubs/stubs'
|
3
5
|
|
4
6
|
class RestClientPlusTest < Test::Unit::TestCase
|
5
7
|
|
8
|
+
def setup
|
9
|
+
WSStubs.setup_stubs
|
10
|
+
end
|
11
|
+
|
6
12
|
def test_rest_client_plus_is_a_module
|
7
13
|
assert_respond_to(RestClientPlus, :constants)
|
8
14
|
end
|
9
15
|
|
16
|
+
def test_get_json_from_url
|
17
|
+
assert_respond_to(RestClientPlus::Requests.get_json_from_url('http://www.mocks.stub'), :each_key)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_post_json_to_url
|
21
|
+
assert_respond_to(RestClientPlus::Requests.post_json_to_url('http://www.mocks.stub', {:body => "body"}), :each_key)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_put_json_to_url
|
25
|
+
assert_respond_to(RestClientPlus::Requests.put_json_to_url('http://www.mocks.stub', {:body => "body"}), :each_key)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
10
29
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#TODO: Add to config. Shouldn't be parsable ruby.
|
2
|
+
|
3
|
+
RETURN_HEADERS = {}
|
4
|
+
|
5
|
+
RETURN_BODY =
|
6
|
+
{:body =>
|
7
|
+
{:one => "1",
|
8
|
+
:two => "2"}
|
9
|
+
}
|
10
|
+
|
11
|
+
RETURN_OBJECT = {:status => 200, :body => RETURN_BODY, :headers => RETURN_HEADERS}
|
12
|
+
|
13
|
+
REQUEST_HEADERS =
|
14
|
+
{'Accept'=>'*/*; q=0.5, application/xml',
|
15
|
+
'Accept-Encoding'=>'gzip, deflate',
|
16
|
+
'Content-Length'=>'9',
|
17
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
18
|
+
'User-Agent'=>'Ruby'
|
19
|
+
}
|
20
|
+
|
21
|
+
REQUEST_BODY = {"body"=>"body"}
|
22
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'webmock'
|
3
|
+
module WSStubs
|
4
|
+
|
5
|
+
def self.setup_stubs
|
6
|
+
|
7
|
+
WebMock::API.stub_request(:get, "www.mocks.stub").to_return(RETURN_BODY)
|
8
|
+
|
9
|
+
WebMock::API.stub_request(:any, "http://www.mocks.stub/").
|
10
|
+
with(:body => REQUEST_BODY,
|
11
|
+
:request_headers => REQUEST_HEADERS).
|
12
|
+
to_return(RETURN_OBJECT)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
#TODO: refactor into config
|
20
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_client_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- rest_client_plus.gemspec
|
65
65
|
- tests/array_helper_test.rb
|
66
66
|
- tests/rest_client_plus_test.rb
|
67
|
+
- tests/webservice_stubs/data.rb
|
68
|
+
- tests/webservice_stubs/stubs.rb
|
67
69
|
homepage: https://github.com/dazzla/rest_client_plus
|
68
70
|
licenses:
|
69
71
|
- MIT
|