ease_http 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGES.md +14 -0
- data/README.md +49 -1
- data/lib/ease_http/connection.rb +2 -2
- data/lib/ease_http/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a31408da214d90fd4f6c560fd9516c88d12a01
|
4
|
+
data.tar.gz: 2d30163e14df5fa76d380a0e9e418f5634283822
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f86f9ec0a8eb1e0152e00d686bcafe424c536ae2cb76e454cb326905ab3902d780a1c1290eef2a23590bb05bb46b19bbdb2c2e0cfb26a133f5e3ee7fc00a0f
|
7
|
+
data.tar.gz: 20e71dd5cfecc81b7a2fb9e1ef4860480bacceef4be299f76757c92341bd63a3d368deec9eb9b2d88796be7a85e7dedf811475d0631c428421912f0f391d076a
|
data/CHANGES.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
* EaseHTTP::Connection can config timeout now, default is 0.2s
|
6
|
+
|
7
|
+
## 0.2.0
|
8
|
+
|
9
|
+
* EaseHTTP::Connection#post can upload file now
|
10
|
+
|
11
|
+
## 0.1.0
|
12
|
+
|
13
|
+
* Add EaseHTTP::Connection#get method
|
14
|
+
* Add EaseHTTP::Connection#post method
|
data/README.md
CHANGED
@@ -22,7 +22,55 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
We have a test sinatra app located in `test/web.rb`, start as our backend server:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
# Start test sinatra app
|
29
|
+
ruby test/web.rb
|
30
|
+
|
31
|
+
# Start console
|
32
|
+
bin/console
|
33
|
+
```
|
34
|
+
|
35
|
+
### Get
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'json'
|
39
|
+
conn = EaseHTTP::Connection.new('http://localhost:4567')
|
40
|
+
|
41
|
+
# Get with 'query' option
|
42
|
+
res = conn.get '/', query: { hello: 'world' }
|
43
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
44
|
+
JSON.parse res.body
|
45
|
+
=> {"hello": "world"}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
### Post
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'json'
|
53
|
+
conn = EaseHTTP::Connection.new('http://localhost:4567')
|
54
|
+
|
55
|
+
# Post with 'data' option as 'application/x-www-form-urlencoded'
|
56
|
+
res = conn.post '/', data: { hello: 'world' }
|
57
|
+
=> #<Net::HTTPCreated 201 Created readbody=true>
|
58
|
+
JSON.parse res.body
|
59
|
+
=> {"hello": "world"}
|
60
|
+
|
61
|
+
# Post with 'data' option as 'multipart/form-data'
|
62
|
+
file = File.new '/etc/hosts'
|
63
|
+
res = conn.post '/', data: { hello: 'world', file: file }
|
64
|
+
=> #<Net::HTTPCreated 201 Created readbody=true>
|
65
|
+
JSON.parse res.body
|
66
|
+
=> {"hello"=>"world",
|
67
|
+
"file"=>
|
68
|
+
{"filename"=>"hosts",
|
69
|
+
"type"=>"text/plain",
|
70
|
+
"name"=>"file",
|
71
|
+
"tempfile"=>"#<File:0x0055d0877a8520>",
|
72
|
+
"head"=>"Content-Disposition: form-data; name=\"file\"; filename=\"hosts\"\r\nContent-Type: text/plain\r\n"}}
|
73
|
+
```
|
26
74
|
|
27
75
|
## Development
|
28
76
|
|
data/lib/ease_http/connection.rb
CHANGED
@@ -8,11 +8,11 @@ module EaseHTTP
|
|
8
8
|
def initialize(endpoint, options={})
|
9
9
|
@endpoint = endpoint
|
10
10
|
uri = URI(endpoint)
|
11
|
-
|
11
|
+
timeout = options.delete(:timeout) || 0.2
|
12
12
|
|
13
13
|
@http = Net::HTTP.new(uri.host, uri.port)
|
14
14
|
@http.use_ssl = uri.scheme == 'https'
|
15
|
-
|
15
|
+
@http.read_timeout = timeout
|
16
16
|
end
|
17
17
|
|
18
18
|
# path - path to request
|
data/lib/ease_http/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ease_http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reyesyang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ".rbenv-gemsets"
|
78
78
|
- ".ruby-version"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGES.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE
|
82
83
|
- README.md
|