webclient 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5691c3a408aba34be572800dcaacef7426b49c49
4
- data.tar.gz: 80e99652e7a014a159b5d307afc9cae9cd9aa602
2
+ SHA256:
3
+ metadata.gz: 19d01c484b19fd633a6e73b3710d38dad056bd066e7c2dc9c613ddd1eae4c28f
4
+ data.tar.gz: 7140effe816c143e7ff9e336dadd9b1bd7b424ee6ca0c1b4ff75a12021fe0979
5
5
  SHA512:
6
- metadata.gz: 80882b99915833bc9d42083c2252af6a3205ead8c1c6ddf22d2e9d7467f93379a94e005f2d6788f8731d64398b363a0b82e9a0bb50918179b5f5a3322a960c10
7
- data.tar.gz: ebdf4df154cb51815280a753b1f26791d2d99dce586c1b3b2e037ab1b64dfdd7cea668c06736a9fc28a1ce32d6f04a84a850f7a439d3e3af5394947cf330fedd
6
+ metadata.gz: aa8feda707d1e1c79bcaf9205e768465e21d2c39b8cba9143387816bd17d5df34f7e871d43ece9a3780a1a3577b701017633823e5e695635eb73d4f8ec954f0d
7
+ data.tar.gz: af08cb829652c2ba30600dd7163bba31dd9bc1e5bdbfc8d5f9d289ac285fcde5f878de541f4523e07906cdbb41bb25ebca632bae28df4113e741aa4b9e160512
data/lib/webclient.rb CHANGED
@@ -22,4 +22,4 @@ WebClient = Webclient
22
22
 
23
23
 
24
24
  # say hello
25
- puts Webclient.banner if defined?( $RUBYLIBS_DEBUG )
25
+ puts Webclient.banner ## if defined?( $RUBYLIBS_DEBUG )
@@ -2,7 +2,7 @@
2
2
  class Webclient
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
@@ -10,11 +10,11 @@ class Webclient
10
10
  end
11
11
 
12
12
  def self.banner
13
- "webclient/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
13
+ "webclient/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
14
14
  end
15
15
 
16
16
  def self.root
17
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
17
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
18
18
  end
19
19
  end # module Webclient
20
20
 
@@ -113,5 +113,58 @@ def self.get( url, headers: {}, auth: [] )
113
113
  Response.new( response )
114
114
  end # method self.get
115
115
 
116
+
117
+ def self.post( url, headers: {},
118
+ body: nil,
119
+ json: nil ## json - convenience shortcut (for body & encoding)
120
+ )
121
+
122
+ uri = URI.parse( url )
123
+ http = Net::HTTP.new( uri.host, uri.port )
124
+
125
+ if uri.instance_of? URI::HTTPS
126
+ http.use_ssl = true
127
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
128
+ end
129
+
130
+ request = Net::HTTP::Post.new( uri.request_uri )
131
+
132
+ ### add (custom) headers if any
133
+ ## check/todo: is there are more idiomatic way for Net::HTTP ???
134
+ ## use
135
+ ## request = Net::HTTP::Get.new( uri.request_uri, headers )
136
+ ## why? why not?
137
+ ## instead of e.g.
138
+ ## request['X-Auth-Token'] = 'xxxxxxx'
139
+ ## request['User-Agent'] = 'ruby'
140
+ ## request['Accept'] = '*/*'
141
+ if headers && headers.size > 0
142
+ headers.each do |key,value|
143
+ request[ key ] = value
144
+ end
145
+ end
146
+
147
+ if body
148
+ request.body = body.to_s
149
+ end
150
+
151
+ if json
152
+ # note: the body needs to be a JSON string - use pretty generate and NOT "compact" style - why? why not?
153
+ request.body = JSON.pretty_generate( json )
154
+
155
+ ## move (auto-set) header content-type up (before custom headers) - why? why not?
156
+ request['Content-Type'] = 'application/json'
157
+ end
158
+
159
+
160
+ puts "POST #{uri}..."
161
+
162
+ response = http.request( request )
163
+
164
+ ## note: return "unified" wrapped response
165
+ Response.new( response )
166
+ end # method self.post
167
+
168
+
116
169
  end # class Webclient
117
170
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2021-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -65,7 +65,7 @@ homepage: https://github.com/rubycoco/webclient
65
65
  licenses:
66
66
  - Public Domain
67
67
  metadata: {}
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options:
70
70
  - "--main"
71
71
  - README.md
@@ -82,9 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.5.2
87
- signing_key:
85
+ rubygems_version: 3.1.4
86
+ signing_key:
88
87
  specification_version: 4
89
88
  summary: webclient gem - yet (another) universal network client interface for world
90
89
  wide web (www) requests via HTTP