tiny_grabber 0.0.6 → 0.0.7
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/.gitignore +1 -0
- data/README.md +18 -4
- data/lib/tiny_grabber/http.rb +6 -0
- data/lib/tiny_grabber/version.rb +1 -1
- data/lib/tiny_grabber.rb +25 -10
- data/tiny_grabber.gemspec +12 -19
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab45d7456aafa8950adab83118a361262dedbe36
|
4
|
+
data.tar.gz: 53d8c891ba604d1cbc36902e26936aff799caaac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4c98e942cd4e60e107d5855752b5feea73394f74efb189e3e8d126f687add4f41fb44a4401190a28b43648618cce413ceb2d44711b44da291db6c8aacb0d684
|
7
|
+
data.tar.gz: 264df5fb5380e658f1f4c508c973d385a90a61fe08afd9c13baa9c51cab9eb5ba1d306b138ec9800bd2cfe508b627b88fd45249ff5ea5240f9f8a8fc29dce6cc
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -34,10 +34,18 @@ url = 'https://github.com/moroznoeytpo/tiny_grabber'
|
|
34
34
|
headers = { 'Content-Type' => 'application/json' }
|
35
35
|
|
36
36
|
# Set http(s)/socks4(5) proxy
|
37
|
+
# Proxy type by default is http. You can change it to socks, with setting params proxy_type equal socks
|
37
38
|
proxy = { ip: 'xx.xx.xx.xx', port: xx, proxy_type: :socks }
|
38
39
|
|
40
|
+
# Set Basic Authentication
|
41
|
+
auth = { username: '', password: '' }
|
42
|
+
|
43
|
+
# Set POST data
|
44
|
+
# Request HTTP type by default is GET. You can send POST request with setting post params. Also you cat send empty POST request.
|
45
|
+
post = { some_data: '' }
|
46
|
+
|
39
47
|
# Get response
|
40
|
-
response = TinyGrabber.get url, headers: headers, proxy: proxy
|
48
|
+
response = TinyGrabber.get url, headers: headers, proxy: proxy, auth: auth, post: post
|
41
49
|
|
42
50
|
# HTTP answer code
|
43
51
|
p response.code
|
@@ -47,16 +55,22 @@ p response.body
|
|
47
55
|
|
48
56
|
# Nokogiri object
|
49
57
|
p response.ng
|
58
|
+
|
59
|
+
# Response cookies
|
60
|
+
p response.cookies
|
50
61
|
```
|
51
62
|
|
52
63
|
## Changelog
|
53
64
|
|
54
|
-
*
|
65
|
+
* *v 0.0.7*
|
66
|
+
* Add POST request
|
67
|
+
* Add Basic Authentication
|
68
|
+
* *v 0.0.6*
|
55
69
|
* Add Net::HTTPOK modify file for Nokogiri response
|
56
|
-
*
|
70
|
+
* *v 0.0.5*
|
57
71
|
* Fix work with non ascii url
|
58
72
|
* Add new `ng` response method for getting Nokogiri object
|
59
|
-
*
|
73
|
+
* *v 0.0.4*
|
60
74
|
* Fix work with socks4(5) proxy
|
61
75
|
|
62
76
|
## Development
|
data/lib/tiny_grabber/http.rb
CHANGED
data/lib/tiny_grabber/version.rb
CHANGED
data/lib/tiny_grabber.rb
CHANGED
@@ -12,13 +12,17 @@ class TinyGrabber
|
|
12
12
|
# Get Net::HTTP object for content from remote single page
|
13
13
|
# [url (string)] Link on content
|
14
14
|
# [params (hash)] Addition setting
|
15
|
-
# * [proxy] Configuration of remote proxy server
|
15
|
+
# * [proxy (hash)] Configuration of remote proxy server
|
16
16
|
# * *ip* address of remote proxy server
|
17
17
|
# * *port* of remote proxy server
|
18
18
|
# * *proxy_type* of remote proxy server
|
19
19
|
# * *http* for http(s) proxy servers (by default)
|
20
20
|
# * *socks* for socks4/5 proxy servers
|
21
|
-
# * [headers] Headers
|
21
|
+
# * [headers (hash)] Headers
|
22
|
+
# * [auth (hash)] Basic Authentication
|
23
|
+
# * *username* Authenticate username
|
24
|
+
# * *password* Authenticate password
|
25
|
+
# * [post (hash)] POST data
|
22
26
|
#
|
23
27
|
# = Example
|
24
28
|
# TinyGrabber.get url, headers: { 'Content-Type' => 'application/json' }, proxy: { ip: 'xx.xx.xx.xx', port: xx, proxy_type: :socks }
|
@@ -30,25 +34,36 @@ class TinyGrabber
|
|
30
34
|
uri = URI(URI.escape(url))
|
31
35
|
|
32
36
|
params = convert_params_to_sym params
|
37
|
+
|
38
|
+
# Use proxy for request
|
33
39
|
if params[:proxy]
|
34
|
-
# Socks4(5) proxy
|
35
40
|
if ['socks', :socks].include?(params[:proxy][:proxy_type])
|
36
41
|
http = Net::HTTP.SOCKSProxy(params[:proxy][:ip], params[:proxy][:port])
|
37
|
-
# Http(s) proxy
|
38
42
|
else
|
39
43
|
http = Net::HTTP::Proxy(params[:proxy][:ip], params[:proxy][:port])
|
40
44
|
end
|
41
45
|
else
|
42
46
|
http = Net::HTTP
|
43
47
|
end
|
44
|
-
response = http.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
45
|
-
request = Net::HTTP::Get.new uri
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
# Set HTTP request type
|
50
|
+
if params[:post] or params.key?(:post)
|
51
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
52
|
+
request.set_form_data(params[:post])
|
53
|
+
else
|
54
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set Basic Auth
|
58
|
+
if params[:auth]
|
59
|
+
request.basic_auth params[:auth][:username], params[:auth][:password]
|
50
60
|
end
|
51
|
-
|
61
|
+
|
62
|
+
# Set headers
|
63
|
+
params[:headers].each { |k, v| request.add_field(String(k), v) } if params[:headers]
|
64
|
+
|
65
|
+
# Get response
|
66
|
+
http.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
|
52
67
|
end
|
53
68
|
|
54
69
|
private
|
data/tiny_grabber.gemspec
CHANGED
@@ -4,33 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'tiny_grabber/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'tiny_grabber'
|
8
8
|
spec.version = TinyGrabber::VERSION
|
9
9
|
spec.authors = ["Aleksandr Chernyshev"]
|
10
|
-
spec.email = [
|
10
|
+
spec.email = ['moroznoeytpo@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = %q{Tiny grabber}
|
13
13
|
spec.description = %q{Simple gem for grabbing remote web page.}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "https://rubygems.org/gems/tiny_grabber"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
14
|
+
spec.homepage = 'https://github.com/moroznoeytpo/tiny_grabber'
|
15
|
+
spec.license = 'MIT'
|
24
16
|
|
25
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
# spec.bindir = "exe"
|
27
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '~> 2.3.0'
|
29
22
|
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
23
|
+
spec.add_dependency 'socksify', '~> 1.7'
|
24
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
32
25
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_grabber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksandr Chernyshev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: socksify
|
@@ -112,9 +112,9 @@ require_paths:
|
|
112
112
|
- lib
|
113
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 2.3.0
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - ">="
|