arest 0.9.1.0 → 0.9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arest.rb +38 -6
- data/spec/arest_spec.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52a141387baf882b38ee1ce92ebc79f28f63a929
|
4
|
+
data.tar.gz: 57dee78d3f09ec0bcb7b195d42fc34167aed34d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 734e64b754b1af6ec9f6f38298a014b3f30ae84de28db3e25316b59f5f99d370a12618c9cda8c26945a7659f94c2754a9626184966ecfdf36d3cd507d533d34c
|
7
|
+
data.tar.gz: a1fb4d68fe77bc1a21d51df9c174561f3226e419f7d10468fdc095f2ba16978a9edab3f6c49b4e5ad882cc981ca494a45441f8836a7ef9a40f3a116766c29930
|
data/lib/arest.rb
CHANGED
@@ -8,9 +8,9 @@ class Net::HTTPResponse
|
|
8
8
|
def deserialize
|
9
9
|
case content_type
|
10
10
|
when "application/xml"
|
11
|
-
Hash.from_xml
|
11
|
+
Hash.from_xml(body).deep_symbolize_keys
|
12
12
|
when "application/json"
|
13
|
-
JSON.parse body
|
13
|
+
JSON.parse body, symbolize_names: true
|
14
14
|
else
|
15
15
|
body
|
16
16
|
end
|
@@ -46,25 +46,57 @@ class ARest
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Perform a HTTP GET request. Requires a path to current operation
|
49
|
-
#
|
49
|
+
# If given, headers and http authentication can be override
|
50
|
+
#
|
51
|
+
# Input
|
52
|
+
# * path - relative to URI given in constructor
|
53
|
+
# Options Hash
|
54
|
+
# * headers - overrides the header given in constructor
|
55
|
+
# * username, password - overrides the http authentication
|
56
|
+
# * token - overrides authorization token
|
57
|
+
# * form_data - hash with HTML form data
|
50
58
|
def get(path, **options)
|
51
59
|
execute :get, path, options
|
52
60
|
end
|
53
61
|
|
54
62
|
# Perform a HTTP POST request. Requires a path to current operation
|
55
|
-
#
|
63
|
+
# If given, headers and http authentication can be override
|
64
|
+
#
|
65
|
+
# Input
|
66
|
+
# * path - relative to URI given in constructor
|
67
|
+
# Options Hash
|
68
|
+
# * headers - overrides the header given in constructor
|
69
|
+
# * username, password - overrides the http authentication
|
70
|
+
# * token - overrides authorization token
|
71
|
+
# * form_data - hash with HTML form data
|
56
72
|
def post(path, **options)
|
57
73
|
execute :post, path, options
|
58
74
|
end
|
59
75
|
|
60
76
|
# Perform a HTTP PUT request. Requires a path to current operation
|
61
|
-
#
|
77
|
+
# If given, headers and http authentication can be override
|
78
|
+
#
|
79
|
+
# Input
|
80
|
+
# * path - relative to URI given in constructor
|
81
|
+
# Options Hash
|
82
|
+
# * headers - overrides the header given in constructor
|
83
|
+
# * username, password - overrides the http authentication
|
84
|
+
# * token - overrides authorization token
|
85
|
+
# * form_data - hash with HTML form data
|
62
86
|
def put(path, **options)
|
63
87
|
execute :put, path, options
|
64
88
|
end
|
65
89
|
|
66
90
|
# Perform a HTTP DELETE request. Requires a path to current operation
|
67
|
-
#
|
91
|
+
# If given, headers and http authentication can be override
|
92
|
+
#
|
93
|
+
# Input
|
94
|
+
# * path - relative to URI given in constructor
|
95
|
+
# Options Hash
|
96
|
+
# * headers - overrides the header given in constructor
|
97
|
+
# * username, password - overrides the http authentication
|
98
|
+
# * token - overrides authorization token
|
99
|
+
# * form_data - hash with HTML form data
|
68
100
|
def delete(path, **options)
|
69
101
|
execute :delete, path, options
|
70
102
|
end
|
data/spec/arest_spec.rb
CHANGED
@@ -13,19 +13,19 @@ describe ARest do
|
|
13
13
|
end
|
14
14
|
it "should be able to GET fake user" do
|
15
15
|
user = @client.get('users/1').deserialize
|
16
|
-
expect(user[
|
16
|
+
expect(user[:name]).to eq "Leanne Graham"
|
17
17
|
end
|
18
18
|
it "should be able to POST fake post" do
|
19
19
|
posts_res = @client.post('posts', form_data: { title: 'foo', body: 'bar', userId: 1 })
|
20
20
|
expect(posts_res).to be_ok
|
21
21
|
post = posts_res.deserialize
|
22
|
-
expect(post[
|
22
|
+
expect(post[:title]).to eq 'foo'
|
23
23
|
end
|
24
24
|
it "should be able to PUT fake post" do
|
25
25
|
posts_res = @client.put('posts/1', form_data: { id: 1, title: 'foo', body: 'bar', userId: 1 })
|
26
26
|
expect(posts_res).to be_ok
|
27
27
|
post = posts_res.deserialize
|
28
|
-
expect(post[
|
28
|
+
expect(post[:title]).to eq 'foo'
|
29
29
|
end
|
30
30
|
it "should be able to DELETE fake post" do
|
31
31
|
posts_res = @client.delete('posts/1')
|
@@ -54,7 +54,7 @@ describe ARest do
|
|
54
54
|
end
|
55
55
|
it "should be able to get password with form authentication" do
|
56
56
|
pass = @arest.post('/db/prod/oracle/scott.json', form_data: { email: 'user@example.com', password: 'password0'}).deserialize
|
57
|
-
expect(pass[
|
57
|
+
expect(pass[:password]).to eq 't1ger'
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -77,8 +77,8 @@ describe ARest do
|
|
77
77
|
@client = ARest.new 'http://www.thomas-bayer.com/sqlrest'
|
78
78
|
end
|
79
79
|
it "should be able to get the fake customer" do
|
80
|
-
customer = @client.get('CUSTOMER/3').deserialize[
|
81
|
-
expect(customer[
|
80
|
+
customer = @client.get('CUSTOMER/3').deserialize[:CUSTOMER]
|
81
|
+
expect(customer[:FIRSTNAME]).to eq "Michael"
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|