nice_http 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/nice_http.rb +127 -97
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9b49c01fe08f66ea2b11685cec0f92ebad01b896e5327d6f96609a15a464f4a
4
- data.tar.gz: 0652c424dde8b32091185c6ff2b090f606a7e61b997640c07dffa9d8f72a84d1
3
+ metadata.gz: 4b7b94ecb393c3395796636b8e9308bcea20dde7ca9e314ddeae7dd3129ac8bd
4
+ data.tar.gz: c760b6830a3f2f6a1d681ef731df55d47f555c67a2a5b38709f1a61af5943ce9
5
5
  SHA512:
6
- metadata.gz: 7b6505198b381f04496de8eccfe2c37a4417d15b27177d3c6b8dbabb1e8a01e63f16f9913255700da77c478494869eb5cf6986358a71edc549724083c09bef40
7
- data.tar.gz: 6110309157b30597cd6931a6a9adae7787e29254bcd2a375bdb948f2d20879017f10efeb5653fe7f58b71a11d9f9de639bb1530067cd431ef5f7b486ba90e1d4
6
+ metadata.gz: 87ab72b2e991b77c83a82a12e114ed070544202805afa5aeceec1ae07fa0cd28a2ca514e5118b2a5bfb5a5832cb39477feeeb57df1f8bf156394a5e5a76b3db3
7
+ data.tar.gz: 30bbd18f121e0502e83ea5bacce0c998cc1aafcb7fa23162333028484873379653c054dfc7f203dadd74e37d5d2702913e453abe721a4d03ec5c45ee02ef8c39
data/README.md CHANGED
@@ -73,6 +73,7 @@ NiceHttp.ssl = true
73
73
  NiceHttp.port = 443
74
74
  NiceHttp.debug = false
75
75
  NiceHttp.log = "./my_logs.log"
76
+ NiceHttp.headers = {"api-key": "the api key"}
76
77
 
77
78
  http1 = NiceHttp.new()
78
79
 
data/lib/nice_http.rb CHANGED
@@ -41,26 +41,49 @@ class NiceHttp
41
41
  end
42
42
 
43
43
  ######################################################
44
- # input:
45
- # no parameters:
46
- # By default will access how is setup on defaults
47
- # one parameter:
48
- # String
49
- # "https://www.example.com"
50
- # "example.com:8999"
51
- # "localhost:8322"
52
- # Hash containing these possible keys
44
+ # Creates a new http connection.
45
+ #
46
+ # @param args [] If no parameter supplied, by default will access how is setup on defaults
47
+ # @example
48
+ # http = NiceHttp.new()
49
+ # @param args [String]. The url to create the connection.
50
+ # @example
51
+ # http = NiceHttp.new("https://www.example.com")
52
+ # @example
53
+ # http = NiceHttp.new("example.com:8999")
54
+ # @example
55
+ # http = NiceHttp.new("localhost:8322")
56
+ # @param args [Hash] containing these possible keys:
57
+ #
53
58
  # host -- example.com. (default blank screen)
59
+ #
54
60
  # port -- port for the connection. 80 (default)
61
+ #
55
62
  # ssl -- true, false (default)
63
+ #
56
64
  # headers -- hash with the header key:values
65
+ #
57
66
  # debug -- true, false (default)
67
+ #
58
68
  # log -- :no, :screen, :file, :fix_file (default).
69
+ #
59
70
  # A string with a path can be supplied.
71
+ #
60
72
  # If :fix_file: nice_http.log
73
+ #
61
74
  # In case :file it will be generated a log file with name: nice_http_YY-mm-dd-HHMMSS.log
75
+ #
62
76
  # proxy_host
77
+ #
63
78
  # proxy_port
79
+ # @example
80
+ # http2 = NiceHttp.new( host: "reqres.in", port: 443, ssl: true )
81
+ # @example
82
+ # my_server = {host: "example.com",
83
+ # port: 80,
84
+ # headers: {"api-key": "zdDDdjkck"}
85
+ # }
86
+ # http3 = NiceHttp.new my_server
64
87
  ######################################################
65
88
  def initialize(args = {})
66
89
  require 'net/http'
@@ -175,20 +198,25 @@ class NiceHttp
175
198
 
176
199
  ######################################################
177
200
  # Get data from path
178
- # input:
179
- # 1 argument
180
- # Hash containing at least key :path
181
- # 1 argument
182
- # path (string)
183
- # output:
184
- # response -> Hash including at least the symbol keys:
185
- # :data = the response data body
186
- # :message = plain text response
187
- # :code = code response (200=ok,500=wrong...)
188
- # *All keys in response are lowercase
189
- # data, message and code can also be accessed as attributes like .message .code .data, for example:
190
- # resp=@http.get(Requests::Customer.get_profile)
191
- # assert resp.code==200
201
+ #
202
+ # @param arg [Hash] containing at least key :path
203
+ # @param arg [String] the path
204
+ #
205
+ # @return [Hash] response
206
+ # Including at least the symbol keys:
207
+ # :data = the response data body.
208
+ # :message = plain text response.
209
+ # :code = code response (200=ok,500=wrong...).
210
+ # All keys in response are lowercase.
211
+ # data, message and code can also be accessed as attributes like .message .code .data
212
+ # @return [Symbol] in case of error returns :error
213
+ #
214
+ # @example
215
+ # resp = @http.get(Requests::Customer.get_profile)
216
+ # assert resp.code == 200
217
+ # @example
218
+ # resp = @http.get("/customers/1223")
219
+ # assert resp.message == "OK"
192
220
  ######################################################
193
221
  def get(arg)
194
222
  begin
@@ -287,22 +315,28 @@ class NiceHttp
287
315
 
288
316
  ######################################################
289
317
  # Post data to path
290
- # input:
291
- # 1 argument
292
- # Hash containing at least keys :data, :path
293
- # 3 arguments
294
- # path (string)
295
- # data (json data for example)
296
- # additional_headers (Hash key=>value)
297
- # output:
298
- # response -> Hash including at least the symbol keys:
299
- # :data = the response data body
300
- # :message = plain text response
301
- # :code = code response (200=ok,500=wrong...)
302
- # *All keys in response are lowercase
303
- # data, message and code can also be accessed as attributes like .message .code .data, for example:
304
- # resp=@http.post(Requests::Customer.update_customer)
305
- # assert resp.code==201
318
+ # @param arguments [Hash] containing at least keys :data and :path
319
+ # @param arguments [Array<path, data ,additional_headers]
320
+ # path (string)
321
+ # data (json data for example)
322
+ # additional_headers (Hash key=>value)
323
+ # @return [Hash] response
324
+ # Including at least the symbol keys:
325
+ # :data = the response data body.
326
+ # :message = plain text response.
327
+ # :code = code response (200=ok,500=wrong...).
328
+ # All keys in response are lowercase.
329
+ # data, message and code can also be accessed as attributes like .message .code .data
330
+ # @return [Symbol] in case of error returns :error
331
+ # @example
332
+ # resp = @http.post(Requests::Customer.update_customer)
333
+ # assert resp.code == 201
334
+ # @example
335
+ # resp = http.post( {
336
+ # path: "/api/users",
337
+ # data: {name: "morpheus", job: "leader"}
338
+ # } )
339
+ # pp resp.data.json
306
340
  ######################################################
307
341
  def post(*arguments)
308
342
  begin
@@ -375,25 +409,23 @@ class NiceHttp
375
409
 
376
410
  end
377
411
 
378
-
379
412
  ######################################################
380
413
  # Put data to path
381
- # input:
382
- # 1 argument
383
- # Hash containing at least keys :data, :path
384
- # 3 arguments
385
- # path (string)
386
- # data (json data for example)
387
- # additional_headers (Hash key=>value)
388
- # output:
389
- # response -> Hash including at least the symbol keys:
390
- # :data = the response data body
391
- # :message = plain text response
392
- # :code = code response (200=ok,500=wrong...)
393
- # *All keys in response are lowercase
394
- # data, message and code can also be accessed as attributes like .message .code .data, for example:
395
- # resp=@http.put(Requests::Customer.remove_phone)
396
- # assert resp.code==200
414
+ # @param arguments [Hash] containing at least keys :data and :path
415
+ # @param arguments [Array<path, data ,additional_headers]
416
+ # path (string)
417
+ # data (json data for example)
418
+ # additional_headers (Hash key=>value)
419
+ # @return [Hash] response
420
+ # Including at least the symbol keys:
421
+ # :data = the response data body.
422
+ # :message = plain text response.
423
+ # :code = code response (200=ok,500=wrong...).
424
+ # All keys in response are lowercase.
425
+ # data, message and code can also be accessed as attributes like .message .code .data
426
+ # @return [Symbol] in case of error returns :error
427
+ # @example
428
+ # resp = @http.put(Requests::Customer.remove_phone)
397
429
  ######################################################
398
430
  def put(*arguments)
399
431
  begin
@@ -446,22 +478,21 @@ class NiceHttp
446
478
 
447
479
  ######################################################
448
480
  # Patch data to path
449
- # input:
450
- # 1 argument
451
- # Hash containing at least keys :data, :path
452
- # 3 arguments
453
- # path (string)
454
- # data (json data for example)
455
- # additional_headers (Hash key=>value)
456
- # output:
457
- # response -> Hash including at least the symbol keys:
458
- # :data = the response data body
459
- # :message = plain text response
460
- # :code = code response (200=ok,500=wrong...)
461
- # *All keys in response are lowercase
462
- # data, message and code can also be accessed as attributes like .message .code .data, for example:
463
- # resp=@http.patch(Requests::Customer.unrelease_account)
464
- # assert resp.code==200
481
+ # @param arguments [Hash] containing at least keys :data and :path
482
+ # @param arguments [Array<path, data ,additional_headers]
483
+ # path (string)
484
+ # data (json data for example)
485
+ # additional_headers (Hash key=>value)
486
+ # @return [Hash] response
487
+ # Including at least the symbol keys:
488
+ # :data = the response data body.
489
+ # :message = plain text response.
490
+ # :code = code response (200=ok,500=wrong...).
491
+ # All keys in response are lowercase.
492
+ # data, message and code can also be accessed as attributes like .message .code .data
493
+ # @return [Symbol] in case of error returns :error
494
+ # @example
495
+ # resp = @http.patch(Requests::Customer.unrelease_account)
465
496
  ######################################################
466
497
  def patch(*arguments)
467
498
  begin
@@ -526,23 +557,22 @@ class NiceHttp
526
557
 
527
558
  end
528
559
 
529
-
530
560
  ######################################################
531
561
  # Delete an existing resource
532
- # input:
533
- # 1 argument
534
- # Hash containing at least key :path
535
- # 1 argument
536
- # String giving the path
537
- # output:
538
- # response -> Hash including at least the symbol keys:
539
- # :data = the response data body
540
- # :message = plain text response
541
- # :code = code response (200=ok,500=wrong...)
542
- # *All keys in response are lowercase
543
- # data, message and code can also be accessed as attributes like .message .code .data, for example:
544
- # resp=@http.delete(Requests::Customer.remove_session)
545
- # assert resp.code==204
562
+ # @param arg [Hash] containing at least key :path
563
+ # @param arg [String] the path
564
+ #
565
+ # @return [Hash] response
566
+ # Including at least the symbol keys:
567
+ # :data = the response data body.
568
+ # :message = plain text response.
569
+ # :code = code response (200=ok,500=wrong...).
570
+ # All keys in response are lowercase.
571
+ # data, message and code can also be accessed as attributes like .message .code .data
572
+ # @return [Symbol] in case of error returns :error
573
+ # @example
574
+ # resp = @http.delete(Requests::Customer.remove_session)
575
+ # assert resp.code == 204
546
576
  ######################################################
547
577
  def delete(argument)
548
578
  begin
@@ -599,16 +629,16 @@ class NiceHttp
599
629
  # Implementation of the http HEAD method.
600
630
  # Asks for the response identical to the one that would correspond to a GET request, but without the response body.
601
631
  # This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
602
- # input:
603
- # 1 argument
604
- # Hash containing at least key :path
605
- # 1 argument
606
- # String giving the path
607
- # output:
608
- # response -> Hash including the symbol keys:
609
- # :message = plain text response
610
- # :code = code response (200=ok,500=wrong...)
611
- # *All keys in response are lowercase
632
+ # @param arg [Hash] containing at least key :path
633
+ # @param arg [String] the path
634
+ #
635
+ # @return [Hash] response
636
+ # Including at least the symbol keys:
637
+ # :message = plain text response.
638
+ # :code = code response (200=ok,500=wrong...).
639
+ # All keys in response are lowercase.
640
+ # message and code can also be accessed as attributes like .message .code
641
+ # @return [Symbol] in case of error returns :error
612
642
  ######################################################
613
643
  def head(argument)
614
644
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash