tiny_http_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +21 -0
- data/lib/tiny_http_client.rb +21 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bdf5e8a271c93433bd7d0bdb9d722772f27c3ac2
|
4
|
+
data.tar.gz: b75bdc9f56604c2e3e17e7ba4c65f1937e6956c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1144cf5877de1e5f6828092dcb635242fa92b362677d7d5598889b9d025dac70652dc5d87867415e66038eb33d37e000a32666a75c568dcf0e82e19928d55b2
|
7
|
+
data.tar.gz: 94439be9003cb2d8ea8290c34047a36c8c21c9e0e62ed42f45826e0942d20ade6cda2034bb2907525a5e6dedb771481ec272653dae69be8f26faa34875408af1
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# SimpleHttp
|
2
|
+
|
3
|
+
A really simple http client, get content by url:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
|
7
|
+
html_content = SimpleHttp.get("http://www.google.com")
|
8
|
+
|
9
|
+
```
|
10
|
+
|
11
|
+
or, add basic auth
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
|
15
|
+
html_content = SimpleHttp.get("http://www.google.com") do |req|
|
16
|
+
req.basic_auth 'user', 'pass'
|
17
|
+
end
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
You'll get error when the response is not Net::HTTPSuccess.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module TinyHttpClient
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def get(url, &block)
|
8
|
+
uri = URI(url)
|
9
|
+
http_opts = { use_ssl: uri.scheme == 'https' }
|
10
|
+
Net::HTTP.start uri.host, uri.port, http_opts do |https|
|
11
|
+
req = Net::HTTP::Get.new(uri.path)
|
12
|
+
yield(req) if block_given?
|
13
|
+
case res = https.request(req)
|
14
|
+
when Net::HTTPSuccess
|
15
|
+
res.body
|
16
|
+
else
|
17
|
+
res.error!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_http_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xiao Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Get content by url, or raise error.
|
14
|
+
email:
|
15
|
+
- swing1979@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/tiny_http_client.rb
|
22
|
+
homepage: https://github.com/xli/tiny_http_client
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.0
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A really tiny http client, only do one thing.
|
46
|
+
test_files: []
|