webclient 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -0
- data/README.md +7 -5
- data/Rakefile +3 -3
- data/lib/webclient.rb +18 -0
- data/lib/webclient/version.rb +2 -2
- data/lib/webclient/webclient.rb +85 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341993a1bad956dda14de5a33dfa94355e7df6a3
|
4
|
+
data.tar.gz: 3063bac3858324ac7cbcd650e88cf332ce46f5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4819baa4904dba19cbdc898fb6244806db8fccaffcdc396027f7fe6e0be08b366b40e171f71b972e5c5ccd739e46461074acfc6b7d4edc9d6787d95dcb5244f3
|
7
|
+
data.tar.gz: 042b1cd3a09e94ca0c791dfe19d9ccecd48a440435a131fdbad4e779c1d68d1d450d82b2eaa7e744fb61b832ce7cf1ba65815901ffa25c6067b1f225b339a171
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# webclient
|
2
2
|
|
3
|
-
webclient gem - yet (another) network client for world wide web (www) requests via HTTP
|
3
|
+
webclient gem - yet (another) universal network client interface for world wide web (www) requests via HTTP
|
4
|
+
|
5
|
+
|
6
|
+
* home :: [github.com/rubycoco/webclient](https://github.com/rubycoco/webclient)
|
7
|
+
* bugs :: [github.com/rubycoco/webclient/issues](https://github.com/rubycoco/webclient/issues)
|
8
|
+
* gem :: [rubygems.org/gems/webclient](https://rubygems.org/gems/webclient)
|
9
|
+
* rdoc :: [rubydoc.info/gems/webclient](http://rubydoc.info/gems/webclient)
|
4
10
|
|
5
|
-
* home :: [github.com/rubylibs/fotos](https://github.com/rubylibs/fotos)
|
6
|
-
* bugs :: [github.com/rubylibs/fotos/issues](https://github.com/rubylibs/fotos/issues)
|
7
|
-
* gem :: [rubygems.org/gems/fotos](https://rubygems.org/gems/fotos)
|
8
|
-
* rdoc :: [rubydoc.info/gems/fotos](http://rubydoc.info/gems/fotos)
|
9
11
|
|
10
12
|
|
11
13
|
## Usage
|
data/Rakefile
CHANGED
@@ -5,10 +5,10 @@ Hoe.spec 'webclient' do
|
|
5
5
|
|
6
6
|
self.version = Webclient::VERSION
|
7
7
|
|
8
|
-
self.summary = 'webclient gem - yet (another) network client for world wide web (www) requests '
|
8
|
+
self.summary = 'webclient gem - yet (another) universal network client interface for world wide web (www) requests via HTTP'
|
9
9
|
self.description = summary
|
10
10
|
|
11
|
-
self.urls = { home: 'https://github.com/
|
11
|
+
self.urls = { home: 'https://github.com/rubycoco/webclient' }
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
14
|
self.email = 'ruby-talk@ruby-lang.org'
|
@@ -22,7 +22,7 @@ Hoe.spec 'webclient' do
|
|
22
22
|
self.licenses = ['Public Domain']
|
23
23
|
|
24
24
|
self.spec_extras = {
|
25
|
-
required_ruby_version: '>=
|
25
|
+
required_ruby_version: '>= 2.2.2'
|
26
26
|
}
|
27
27
|
|
28
28
|
end
|
data/lib/webclient.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'time'
|
3
|
+
require 'date'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'uri'
|
7
|
+
require 'net/http'
|
8
|
+
require 'net/https'
|
9
|
+
|
10
|
+
require 'json'
|
11
|
+
require 'yaml'
|
12
|
+
|
1
13
|
|
2
14
|
# our own code
|
3
15
|
require 'webclient/version' # note: let version always go first
|
16
|
+
require 'webclient/webclient'
|
17
|
+
|
18
|
+
|
19
|
+
############
|
20
|
+
## add convenience alias for camel case / alternate different spelling
|
21
|
+
WebClient = Webclient
|
4
22
|
|
5
23
|
|
6
24
|
# say hello
|
data/lib/webclient/version.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
class Webclient
|
3
|
+
|
4
|
+
class Response # nested class - wrap Net::HTTP::Response
|
5
|
+
def initialize( response )
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
def raw() @response; end
|
9
|
+
|
10
|
+
|
11
|
+
def text
|
12
|
+
# note: Net::HTTP will NOT set encoding UTF-8 etc.
|
13
|
+
# will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
|
14
|
+
# thus, set/force encoding to utf-8
|
15
|
+
text = @response.body.to_s
|
16
|
+
text = text.force_encoding( Encoding::UTF_8 )
|
17
|
+
text
|
18
|
+
end
|
19
|
+
|
20
|
+
## convenience helper; returns parsed json data
|
21
|
+
def json() JSON.parse( text ); end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
class Headers # nested (nested) class
|
26
|
+
def initialize( response )
|
27
|
+
@response = response
|
28
|
+
end
|
29
|
+
def each( &blk )
|
30
|
+
@response.each_header do |key, value| # Iterate all response headers
|
31
|
+
blk.call( key, value )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def headers() @headers ||= Headers.new( @response ); end
|
36
|
+
|
37
|
+
class Status # nested (nested) class
|
38
|
+
def initialize( response )
|
39
|
+
@response = response
|
40
|
+
end
|
41
|
+
def code() @response.code.to_i; end
|
42
|
+
def ok?() code == 200; end
|
43
|
+
def nok?() code != 200; end
|
44
|
+
def message() @response.message; end
|
45
|
+
end
|
46
|
+
def status() @status ||= Status.new( @response ); end
|
47
|
+
end # (nested) class Response
|
48
|
+
|
49
|
+
|
50
|
+
def self.get( url, headers: {} )
|
51
|
+
|
52
|
+
uri = URI.parse( url )
|
53
|
+
http = Net::HTTP.new( uri.host, uri.port )
|
54
|
+
|
55
|
+
if uri.instance_of? URI::HTTPS
|
56
|
+
http.use_ssl = true
|
57
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
58
|
+
end
|
59
|
+
|
60
|
+
request = Net::HTTP::Get.new( uri.request_uri )
|
61
|
+
|
62
|
+
### add (custom) headers if any
|
63
|
+
## check/todo: is there are more idiomatic way for Net::HTTP ???
|
64
|
+
## use
|
65
|
+
## request = Net::HTTP::Get.new( uri.request_uri, headers )
|
66
|
+
## why? why not?
|
67
|
+
## instead of e.g.
|
68
|
+
## request['X-Auth-Token'] = 'xxxxxxx'
|
69
|
+
## request['User-Agent'] = 'ruby'
|
70
|
+
## request['Accept'] = '*/*'
|
71
|
+
if headers && headers.size > 0
|
72
|
+
headers.each do |key,value|
|
73
|
+
request[ key ] = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
response = http.request( request )
|
79
|
+
|
80
|
+
## note: return "unified" wrapped response
|
81
|
+
Response.new( response )
|
82
|
+
end # method self.get
|
83
|
+
|
84
|
+
end # class Webclient
|
85
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -44,8 +44,8 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.22'
|
47
|
-
description:
|
48
|
-
requests
|
47
|
+
description: webclient gem - yet (another) universal network client interface for
|
48
|
+
world wide web (www) requests via HTTP
|
49
49
|
email: ruby-talk@ruby-lang.org
|
50
50
|
executables: []
|
51
51
|
extensions: []
|
@@ -60,7 +60,8 @@ files:
|
|
60
60
|
- Rakefile
|
61
61
|
- lib/webclient.rb
|
62
62
|
- lib/webclient/version.rb
|
63
|
-
|
63
|
+
- lib/webclient/webclient.rb
|
64
|
+
homepage: https://github.com/rubycoco/webclient
|
64
65
|
licenses:
|
65
66
|
- Public Domain
|
66
67
|
metadata: {}
|
@@ -74,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
+
version: 2.2.2
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - ">="
|
@@ -85,5 +86,6 @@ rubyforge_project:
|
|
85
86
|
rubygems_version: 2.5.2
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
|
-
summary: webclient gem - yet (another) network client for world
|
89
|
+
summary: webclient gem - yet (another) universal network client interface for world
|
90
|
+
wide web (www) requests via HTTP
|
89
91
|
test_files: []
|