simple_request 0.1.3 → 0.1.5
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/.rubocop.yml +34 -12
- data/Changelog.md +15 -1
- data/Gemfile +11 -1
- data/Gemfile.lock +60 -30
- data/README.md +37 -17
- data/bin/rubocop +15 -0
- data/lib/simple_helper/request.rb +24 -7
- data/lib/simple_helper/response_parser.rb +12 -4
- data/lib/simple_helper/version.rb +1 -1
- data/lib/simple_request.rb +39 -18
- data/simple_request.gemspec +14 -20
- metadata +11 -93
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2acd008e5817c9ccc1c75fbbd595c4b34a538a0ebf7541ffa54318b5a2e0bedf
|
|
4
|
+
data.tar.gz: dab64766f17b83c2533384667b572cbfa07eb3141e9faf9165bb9f60a97b8f7e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d695885ec2b8ecfde881ca13bb32e5d614a4f77cbb36ff8bc1b6b94bd24c7382dfcc83790c912ea7bcfc6b6fb24d8dcdf4ff26173dde7cdfdb4ded450e87440
|
|
7
|
+
data.tar.gz: 31ad5b05e73a1ace906d7d6e4dae1d8182d7a920b329957415a5b40a6162c4a6680e0820c50ab688fba86b9452523c92050bdbf4889b0955100c9030ac18fb56
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
inherit_from: .rubocop_todo.yml
|
|
1
|
+
# inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
|
3
3
|
require: rubocop-performance
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Documentation:
|
|
13
|
-
Enabled: false
|
|
5
|
+
AllCops:
|
|
6
|
+
TargetRubyVersion: 3.2.3
|
|
7
|
+
Exclude:
|
|
8
|
+
- bin/**
|
|
9
|
+
- db/**/*
|
|
10
|
+
- node_modules/**/*
|
|
14
11
|
|
|
15
12
|
Style/Documentation:
|
|
16
13
|
Enabled: false
|
|
@@ -24,14 +21,14 @@ Lint/Void:
|
|
|
24
21
|
Metrics/AbcSize:
|
|
25
22
|
Max: 30
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
Layout/LineLength:
|
|
28
25
|
Max: 120
|
|
29
26
|
|
|
30
27
|
Metrics/ClassLength:
|
|
31
28
|
Max: 1500
|
|
32
29
|
|
|
33
30
|
Metrics/MethodLength:
|
|
34
|
-
Max:
|
|
31
|
+
Max: 10
|
|
35
32
|
|
|
36
33
|
Metrics/BlockLength:
|
|
37
34
|
Max: 70
|
|
@@ -39,3 +36,28 @@ Metrics/BlockLength:
|
|
|
39
36
|
Layout/HashAlignment:
|
|
40
37
|
EnforcedHashRocketStyle: table
|
|
41
38
|
EnforcedColonStyle: table
|
|
39
|
+
|
|
40
|
+
Gemspec/DeprecatedAttributeAssignment:
|
|
41
|
+
Enabled: true
|
|
42
|
+
Gemspec/DevelopmentDependencies:
|
|
43
|
+
Enabled: true
|
|
44
|
+
Gemspec/RequireMFA:
|
|
45
|
+
Enabled: true
|
|
46
|
+
Layout/LineContinuationLeadingSpace:
|
|
47
|
+
Enabled: true
|
|
48
|
+
Layout/LineContinuationSpacing:
|
|
49
|
+
Enabled: true
|
|
50
|
+
Layout/LineEndStringConcatenationIndentation:
|
|
51
|
+
Enabled: true
|
|
52
|
+
Layout/SpaceBeforeBrackets:
|
|
53
|
+
Enabled: true
|
|
54
|
+
Lint/AmbiguousAssignment:
|
|
55
|
+
Enabled: true
|
|
56
|
+
Lint/AmbiguousOperatorPrecedence:
|
|
57
|
+
Enabled: true
|
|
58
|
+
Lint/AmbiguousRange:
|
|
59
|
+
Enabled: true
|
|
60
|
+
Lint/ConstantOverwrittenInRescue:
|
|
61
|
+
Enabled: true
|
|
62
|
+
Lint/DeprecatedConstants:
|
|
63
|
+
Enabled: true
|
data/Changelog.md
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
# Changeslog
|
|
2
2
|
|
|
3
3
|
## 2020-02-04
|
|
4
|
+
|
|
4
5
|
- Changed rspec examples from localhost project to JSONPlaceholder API
|
|
5
6
|
- Added `to_csv` in array class to convert array to csv
|
|
6
7
|
- Added `wrap` in array class to convert hash or nill to an array (Powered by rails core repo)
|
|
7
8
|
- Added `keys` in hash class to symbolize and stringify hash keys
|
|
8
9
|
- Added `string_colorize` in String class to colorize any string
|
|
9
|
-
- Supported csv format you can export the response to csv by `request.csv`
|
|
10
|
+
- Supported csv format you can export the response to csv by `request.csv`
|
|
11
|
+
|
|
12
|
+
## 2024-02-04
|
|
13
|
+
|
|
14
|
+
- Upgraded dependencies
|
|
15
|
+
|
|
16
|
+
1. bundler from `~> 2.0` to `~> 2.5", ">= 2.5.4`
|
|
17
|
+
2. rake from `~> 13.0` to `~> 13.1`
|
|
18
|
+
3. byebug from `11.1.3` to `11.1.3`
|
|
19
|
+
4. rspec from to `3.0` to `3.12`
|
|
20
|
+
5. rubocop from `0.93.1` to `1.60`
|
|
21
|
+
6. rubocop-performance from `1.8.1` to `1.20.2`
|
|
22
|
+
7. vcr from `5.0.0` to `6.2`
|
|
23
|
+
8. webmock from `3.6.2` to `3.19.1`
|
data/Gemfile
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
source
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
# Specify your gem's dependencies in simple_request.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
+
group :development do
|
|
7
|
+
gem 'bundler', '~> 2.5', '>= 2.5.4'
|
|
8
|
+
gem 'byebug', '~> 11.1.3'
|
|
9
|
+
gem 'rake', '~> 13.1'
|
|
10
|
+
gem 'rspec', '~> 3.12'
|
|
11
|
+
gem 'rubocop', '~> 1.60', '>= 1.60.1'
|
|
12
|
+
gem 'rubocop-performance', '~> 1.20', '>= 1.20.2'
|
|
13
|
+
gem 'vcr', '~> 6.2'
|
|
14
|
+
gem 'webmock', '~> 3.19', '>= 3.19.1'
|
|
15
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,37 +1,65 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
simple_request (0.1.
|
|
4
|
+
simple_request (0.1.5)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
addressable (2.
|
|
10
|
-
public_suffix (>= 2.0.2, <
|
|
9
|
+
addressable (2.8.6)
|
|
10
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
11
|
+
ast (2.4.2)
|
|
11
12
|
byebug (11.1.3)
|
|
12
|
-
crack (0.4.
|
|
13
|
-
|
|
14
|
-
diff-lcs (1.
|
|
15
|
-
hashdiff (1.0
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
crack (0.4.5)
|
|
14
|
+
rexml
|
|
15
|
+
diff-lcs (1.5.0)
|
|
16
|
+
hashdiff (1.1.0)
|
|
17
|
+
json (2.7.1)
|
|
18
|
+
language_server-protocol (3.17.0.3)
|
|
19
|
+
parallel (1.24.0)
|
|
20
|
+
parser (3.3.0.4)
|
|
21
|
+
ast (~> 2.4.1)
|
|
22
|
+
racc
|
|
23
|
+
public_suffix (5.0.4)
|
|
24
|
+
racc (1.7.3)
|
|
25
|
+
rainbow (3.1.1)
|
|
26
|
+
rake (13.1.0)
|
|
27
|
+
regexp_parser (2.9.0)
|
|
28
|
+
rexml (3.2.6)
|
|
29
|
+
rspec (3.12.0)
|
|
30
|
+
rspec-core (~> 3.12.0)
|
|
31
|
+
rspec-expectations (~> 3.12.0)
|
|
32
|
+
rspec-mocks (~> 3.12.0)
|
|
33
|
+
rspec-core (3.12.2)
|
|
34
|
+
rspec-support (~> 3.12.0)
|
|
35
|
+
rspec-expectations (3.12.3)
|
|
25
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
26
|
-
rspec-support (~> 3.
|
|
27
|
-
rspec-mocks (3.
|
|
37
|
+
rspec-support (~> 3.12.0)
|
|
38
|
+
rspec-mocks (3.12.6)
|
|
28
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
29
|
-
rspec-support (~> 3.
|
|
30
|
-
rspec-support (3.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
rspec-support (~> 3.12.0)
|
|
41
|
+
rspec-support (3.12.1)
|
|
42
|
+
rubocop (1.60.1)
|
|
43
|
+
json (~> 2.3)
|
|
44
|
+
language_server-protocol (>= 3.17.0)
|
|
45
|
+
parallel (~> 1.10)
|
|
46
|
+
parser (>= 3.3.0.2)
|
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
48
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
49
|
+
rexml (>= 3.2.5, < 4.0)
|
|
50
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
51
|
+
ruby-progressbar (~> 1.7)
|
|
52
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
53
|
+
rubocop-ast (1.30.0)
|
|
54
|
+
parser (>= 3.2.1.0)
|
|
55
|
+
rubocop-performance (1.20.2)
|
|
56
|
+
rubocop (>= 1.48.1, < 2.0)
|
|
57
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
58
|
+
ruby-progressbar (1.13.0)
|
|
59
|
+
unicode-display_width (2.5.0)
|
|
60
|
+
vcr (6.2.0)
|
|
61
|
+
webmock (3.19.1)
|
|
62
|
+
addressable (>= 2.8.0)
|
|
35
63
|
crack (>= 0.3.2)
|
|
36
64
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
37
65
|
|
|
@@ -39,13 +67,15 @@ PLATFORMS
|
|
|
39
67
|
ruby
|
|
40
68
|
|
|
41
69
|
DEPENDENCIES
|
|
42
|
-
bundler (~> 2.
|
|
70
|
+
bundler (~> 2.5, >= 2.5.4)
|
|
43
71
|
byebug (~> 11.1.3)
|
|
44
|
-
rake (~> 13.
|
|
45
|
-
rspec (~> 3.
|
|
72
|
+
rake (~> 13.1)
|
|
73
|
+
rspec (~> 3.12)
|
|
74
|
+
rubocop (~> 1.60, >= 1.60.1)
|
|
75
|
+
rubocop-performance (~> 1.20, >= 1.20.2)
|
|
46
76
|
simple_request!
|
|
47
|
-
vcr (~>
|
|
48
|
-
webmock (~> 3.
|
|
77
|
+
vcr (~> 6.2)
|
|
78
|
+
webmock (~> 3.19, >= 3.19.1)
|
|
49
79
|
|
|
50
80
|
BUNDLED WITH
|
|
51
|
-
2.
|
|
81
|
+
2.5.4
|
data/README.md
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
# SimpleRequest
|
|
2
2
|
|
|
3
3
|
`simple_request` founded to make both `HTTP` and `HTTPS` request simple as it should to be
|
|
4
|
+
|
|
5
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
6
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
7
|
+
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [GET Request](#get-request)
|
|
12
|
+
- [POST Request](#post-request)
|
|
13
|
+
- [PUT, Patch Request](#put-patch-request)
|
|
14
|
+
- [DELETE Request](#delete-request)
|
|
15
|
+
- [Development](#development)
|
|
16
|
+
- [Contributing](#contributing)
|
|
17
|
+
- [License](#license)
|
|
18
|
+
- [Code of Conduct](#code-of-conduct)
|
|
19
|
+
|
|
20
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
21
|
+
|
|
4
22
|
## Installation
|
|
5
23
|
|
|
6
24
|
Add this line to your application's Gemfile:
|
|
7
25
|
|
|
8
26
|
```ruby
|
|
9
|
-
gem 'simple_request'
|
|
27
|
+
gem 'simple_request', '~> 0.1.4'
|
|
10
28
|
```
|
|
11
29
|
|
|
12
|
-
|
|
30
|
+
Then bundle it
|
|
13
31
|
|
|
14
|
-
|
|
32
|
+
```powershell
|
|
33
|
+
$ bundle
|
|
34
|
+
```
|
|
15
35
|
|
|
16
|
-
|
|
36
|
+
Install it independently:
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
```powershell
|
|
39
|
+
$ gem install simple_request
|
|
40
|
+
```
|
|
19
41
|
|
|
20
|
-
##
|
|
42
|
+
## Usage
|
|
21
43
|
|
|
22
44
|
#### GET Request
|
|
45
|
+
|
|
23
46
|
```ruby
|
|
24
47
|
request = SimpleRequest.get(url: 'https://api.xxxxx.xxxxxx.com/v1/cities', body: {}, headers: {'API-ACCESSOR' => 'xxxxxxx-xxxxx-xxxx-xxxx-x'})
|
|
25
48
|
request.json
|
|
@@ -51,7 +74,7 @@ request.path # => "/v1/cities"
|
|
|
51
74
|
request.query # => "limit=1"
|
|
52
75
|
```
|
|
53
76
|
|
|
54
|
-
|
|
77
|
+
#### POST Request
|
|
55
78
|
```ruby
|
|
56
79
|
|
|
57
80
|
request = SimpleRequest.post(
|
|
@@ -73,7 +96,7 @@ request.csv('city,data,attributes')
|
|
|
73
96
|
```
|
|
74
97
|
|
|
75
98
|
|
|
76
|
-
|
|
99
|
+
#### PUT, Patch Request
|
|
77
100
|
```ruby
|
|
78
101
|
|
|
79
102
|
request = SimpleRequest.put(
|
|
@@ -96,20 +119,17 @@ request.plain
|
|
|
96
119
|
# "{\"message\":\"City updated successfully\",\"city\":{\"data\":{\"id\":\"10\",\"type\":\"city_details\",\"attributes\":{\"name_en\":\"Hadramut\",\"name_ar\":\"حضرموت\",\"suggested_time\":0,\"suggested\":false,\"status\":\"active\"}}}}"
|
|
97
120
|
```
|
|
98
121
|
|
|
99
|
-
|
|
122
|
+
#### DELETE Request
|
|
100
123
|
```ruby
|
|
101
|
-
request =
|
|
124
|
+
request =
|
|
125
|
+
SimpleRequest.delete(
|
|
102
126
|
url: 'https://api.xxxxx.xxxxxx.com/v1/cities/10',
|
|
103
127
|
body: {},
|
|
104
|
-
headers: {
|
|
105
|
-
)
|
|
128
|
+
headers: { 'Authorization' => 'Bearer xxxxxxxxxxxx.xxxxxxxx.xxxxxxxx' }
|
|
129
|
+
)
|
|
106
130
|
|
|
107
131
|
request.json
|
|
108
|
-
# OUTPUT
|
|
109
|
-
# {"message"=>"City deleted successfully", "id"=>10}
|
|
110
|
-
request.plain
|
|
111
|
-
# OUTPUT
|
|
112
|
-
# "{\"message\":\"City deleted successfully\",\"id\":10}"
|
|
132
|
+
request.plain # "{\"message\":\"City deleted successfully\",\"id\":10}" # OUTPUT
|
|
113
133
|
```
|
|
114
134
|
|
|
115
135
|
## Development
|
data/bin/rubocop
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
|
|
10
|
+
def last_commit_id_of_base_branch
|
|
11
|
+
`git log | sed -n 1p`.split(' ').last
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
puts "== Running rubocop with safe auto correct on modified files after #{last_commit_id_of_base_branch} commit =="
|
|
15
|
+
system("git diff #{last_commit_id_of_base_branch} --name-only | xargs bundle exec rubocop -A")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'uri'
|
|
3
4
|
require 'net/http'
|
|
4
5
|
require 'net/https'
|
|
@@ -18,17 +19,25 @@ module SimpleHelper
|
|
|
18
19
|
req.body = params.to_json
|
|
19
20
|
https.request(req)
|
|
20
21
|
rescue Timeout::Error || Net::OpenTimeout
|
|
21
|
-
|
|
22
|
+
error_handler(message: 'Time out')
|
|
22
23
|
rescue Net::HTTPBadResponse || SocketError
|
|
23
|
-
|
|
24
|
+
error_handler(message: 'Request Failed!')
|
|
24
25
|
rescue StandardError
|
|
25
|
-
|
|
26
|
+
error_handler(message: 'An unknown error occurred!')
|
|
26
27
|
end
|
|
27
28
|
end
|
|
29
|
+
|
|
30
|
+
def error_handler(message: nil)
|
|
31
|
+
{
|
|
32
|
+
"status": 400,
|
|
33
|
+
"error": 'Bad Request',
|
|
34
|
+
"message": message
|
|
35
|
+
}
|
|
36
|
+
end
|
|
28
37
|
end
|
|
29
38
|
end
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
module Http
|
|
32
41
|
class << self
|
|
33
42
|
SimpleHelper::Config.supported_methods.each do |key, http_method|
|
|
34
43
|
define_method key.to_s do |uri, params, headers|
|
|
@@ -37,13 +46,21 @@ module SimpleHelper
|
|
|
37
46
|
req.body = params.to_json
|
|
38
47
|
http.request(req)
|
|
39
48
|
rescue Timeout::Error || Net::OpenTimeout
|
|
40
|
-
|
|
49
|
+
error_handler(message: 'Time out')
|
|
41
50
|
rescue Net::HTTPBadResponse || SocketError
|
|
42
|
-
|
|
51
|
+
error_handler(message: 'Request Failed!')
|
|
43
52
|
rescue StandardError
|
|
44
|
-
|
|
53
|
+
error_handler(message: 'An unknown error occurred!')
|
|
45
54
|
end
|
|
46
55
|
end
|
|
56
|
+
|
|
57
|
+
def error_handler(message: nil)
|
|
58
|
+
{
|
|
59
|
+
"status": 400,
|
|
60
|
+
"error": 'Bad Request',
|
|
61
|
+
"message": message
|
|
62
|
+
}
|
|
63
|
+
end
|
|
47
64
|
end
|
|
48
65
|
end
|
|
49
66
|
end
|
|
@@ -19,9 +19,9 @@ module SimpleHelper
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def parse
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if body.nil? || body == 'null' || (body.valid_encoding? && body.strip.empty?)
|
|
23
|
+
return log(message: 'Invalid response')
|
|
24
|
+
end
|
|
25
25
|
|
|
26
26
|
@body = body.gsub(/\A#{UTF8_BOM}/, '') if body.valid_encoding? && body.encoding == Encoding::UTF_8
|
|
27
27
|
send(format)
|
|
@@ -36,7 +36,7 @@ module SimpleHelper
|
|
|
36
36
|
def json
|
|
37
37
|
JSON.parse(body, quirks_mode: true, allow_nan: true)
|
|
38
38
|
rescue JSON::ParserError
|
|
39
|
-
|
|
39
|
+
log(message: "Response cannot be parsed because it's not a string nor valid JSON. please use .plain to get the the plain response")
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def plain
|
|
@@ -50,6 +50,14 @@ module SimpleHelper
|
|
|
50
50
|
Array.wrap(data).to_csv('file_name.csv')
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def log(message: nil)
|
|
54
|
+
{
|
|
55
|
+
"status": 400,
|
|
56
|
+
"error": 'Bad Request',
|
|
57
|
+
"message": message
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
53
61
|
# def xml
|
|
54
62
|
# MultiXml.parse(body)
|
|
55
63
|
# end
|
data/lib/simple_request.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'simple_helper/hash/keys'
|
|
4
|
-
|
|
5
4
|
%w[config request version exceptions response_parser headers_processor].each do |file_name|
|
|
6
5
|
require_relative "simple_helper/#{file_name}"
|
|
7
6
|
end
|
|
@@ -9,35 +8,50 @@ end
|
|
|
9
8
|
class SimpleRequest
|
|
10
9
|
attr_reader :options, :response
|
|
11
10
|
|
|
12
|
-
def initialize(
|
|
11
|
+
def initialize(options = {})
|
|
13
12
|
@options = options.symbolize_keys!
|
|
14
13
|
validate
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
#
|
|
16
|
+
# def self.get; end
|
|
17
|
+
# def self.post; end
|
|
18
|
+
# def self.patch; end
|
|
19
|
+
# def self.put; end
|
|
20
|
+
# def self.delete; end
|
|
18
21
|
class << self
|
|
19
|
-
SimpleHelper::Config.supported_methods.
|
|
22
|
+
SimpleHelper::Config.supported_methods.each_key do |method_name|
|
|
20
23
|
define_method method_name do |*args|
|
|
21
24
|
new(*args).send(method_name)
|
|
22
25
|
end
|
|
23
26
|
end
|
|
24
27
|
end
|
|
25
28
|
|
|
26
|
-
#
|
|
27
|
-
|
|
29
|
+
# def get; end,
|
|
30
|
+
# def post; end
|
|
31
|
+
# def patch; end
|
|
32
|
+
# def put; end
|
|
33
|
+
# def delete; end
|
|
34
|
+
SimpleHelper::Config.supported_methods.each_key do |method_name|
|
|
28
35
|
define_method method_name do
|
|
29
36
|
@response = requested_class.send(method_name, uri, body, headers_processor)
|
|
30
37
|
self
|
|
31
38
|
end
|
|
32
39
|
end
|
|
33
40
|
|
|
34
|
-
#
|
|
41
|
+
# def scheme; end
|
|
42
|
+
# def host; end
|
|
43
|
+
# def port; end
|
|
44
|
+
# def request_uri; end
|
|
45
|
+
# def path; end
|
|
46
|
+
# def query; end
|
|
35
47
|
SimpleHelper::Config.reference.each do |key|
|
|
36
48
|
define_method key do
|
|
37
49
|
uri.instance_eval(key)
|
|
38
50
|
end
|
|
39
51
|
end
|
|
40
52
|
|
|
53
|
+
# def json; end
|
|
54
|
+
# def plain; end
|
|
41
55
|
SimpleHelper::Config.supported_format.each do |key|
|
|
42
56
|
define_method key do
|
|
43
57
|
SimpleHelper::ResponseParser.perform(body_response, key, nil)
|
|
@@ -48,6 +62,10 @@ class SimpleRequest
|
|
|
48
62
|
SimpleHelper::ResponseParser.perform(body_response, 'csv', path)
|
|
49
63
|
end
|
|
50
64
|
|
|
65
|
+
def code
|
|
66
|
+
response&.code
|
|
67
|
+
end
|
|
68
|
+
|
|
51
69
|
private
|
|
52
70
|
|
|
53
71
|
def requested_class
|
|
@@ -79,7 +97,7 @@ class SimpleRequest
|
|
|
79
97
|
end
|
|
80
98
|
|
|
81
99
|
def validate
|
|
82
|
-
# raise SimpleHelper::RedirectionTooDeep
|
|
100
|
+
# raise SimpleHelper::RedirectionTooDeep, 'HTTP redirects too deep' if options[:limit].to_i <= 0
|
|
83
101
|
|
|
84
102
|
# unless SimpleHelper::Config.supported_methods.include?(http_method)
|
|
85
103
|
# raise ArgumentError, 'only get, post, patch, put, and delete methods are supported'
|
|
@@ -87,20 +105,23 @@ class SimpleRequest
|
|
|
87
105
|
|
|
88
106
|
raise ArgumentError, ':headers must be a hash' unless headers.respond_to?(:to_hash)
|
|
89
107
|
|
|
90
|
-
|
|
91
|
-
raise SimpleHelper::UnsupportedURIScheme, ' URL Must start with http:// or https://'
|
|
92
|
-
end
|
|
108
|
+
# return if SimpleHelper::Config.supported_schemes.include? scheme
|
|
93
109
|
|
|
94
|
-
|
|
95
|
-
# raise ArgumentError, ':basic_auth must be a hash'
|
|
96
|
-
# end
|
|
110
|
+
return if SimpleHelper::Config.supported_schemes.include? scheme
|
|
97
111
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
raise SimpleHelper::UnsupportedURIScheme, 'URL Must start with http:// or https://'
|
|
113
|
+
# raise ArgumentError, ':body must be a hash' if !body.nil? && !body.respond_to?(:to_hash)
|
|
114
|
+
|
|
115
|
+
# if options[:basic_auth] && !options[:basic_auth].respond_to?(:to_hash)
|
|
116
|
+
# raise ArgumentError, ':basic_auth must be a hash'
|
|
117
|
+
# end
|
|
118
|
+
|
|
119
|
+
# if options[:digest_auth] && !options[:digest_auth].respond_to?(:to_hash)
|
|
120
|
+
# raise ArgumentError, ':digest_auth must be a hash'
|
|
121
|
+
# end
|
|
101
122
|
|
|
102
123
|
# if post? && !options[:query].nil? && !options[:query].respond_to?(:to_hash)
|
|
103
124
|
# raise ArgumentError, ':query must be hash if using HTTP Post'
|
|
104
|
-
#
|
|
125
|
+
# end
|
|
105
126
|
end
|
|
106
127
|
end
|
data/simple_request.gemspec
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
lib = File.expand_path(
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require
|
|
3
|
+
require 'simple_helper/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name =
|
|
6
|
+
spec.name = 'simple_request'
|
|
7
7
|
spec.version = SimpleHelper::VERSION
|
|
8
|
-
spec.authors = [
|
|
9
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['MaJeD BoJaN']
|
|
9
|
+
spec.email = ['bojanmajed@gmail.com']
|
|
10
10
|
|
|
11
11
|
spec.summary = 'Simple ruby gem that helps to make HTTP and HTTPS request from ruby projects.'
|
|
12
|
-
spec.homepage =
|
|
13
|
-
spec.license =
|
|
12
|
+
spec.homepage = 'https://github.com/MajedBojan/simple_request'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
14
|
|
|
15
15
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
16
16
|
|
|
17
|
-
spec.metadata[
|
|
18
|
-
spec.metadata[
|
|
19
|
-
spec.metadata[
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/MajedBojan/simple_request'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/MajedBojan/simple_request/blob/main/Changelog.md'
|
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
20
21
|
|
|
21
22
|
# Specify which files should be added to the gem when it is released.
|
|
22
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
-
spec.files
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
25
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
26
|
end
|
|
26
|
-
spec.bindir =
|
|
27
|
+
spec.bindir = 'exe'
|
|
27
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
-
spec.require_paths = [
|
|
29
|
-
|
|
30
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
|
31
|
-
spec.add_development_dependency 'byebug', '~> 11.1.3'
|
|
32
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
|
33
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
|
34
|
-
spec.add_development_dependency 'vcr', '~> 5.0.0'
|
|
35
|
-
spec.add_development_dependency 'webmock', '~> 3.6.2'
|
|
29
|
+
spec.require_paths = ['lib']
|
|
36
30
|
end
|
metadata
CHANGED
|
@@ -1,100 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_request
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- MaJeD BoJaN
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
14
|
-
name: bundler
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '2.0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '2.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: byebug
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 11.1.3
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 11.1.3
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rake
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '13.0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '13.0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rspec
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '3.0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '3.0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: vcr
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: 5.0.0
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: 5.0.0
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: webmock
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: 3.6.2
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: 3.6.2
|
|
97
|
-
description:
|
|
11
|
+
date: 2024-02-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
98
14
|
email:
|
|
99
15
|
- bojanmajed@gmail.com
|
|
100
16
|
executables: []
|
|
@@ -114,6 +30,7 @@ files:
|
|
|
114
30
|
- README.md
|
|
115
31
|
- Rakefile
|
|
116
32
|
- bin/console
|
|
33
|
+
- bin/rubocop
|
|
117
34
|
- bin/setup
|
|
118
35
|
- lib/simple_helper/array/to_csv.rb
|
|
119
36
|
- lib/simple_helper/array/wrap.rb
|
|
@@ -135,8 +52,9 @@ licenses:
|
|
|
135
52
|
metadata:
|
|
136
53
|
homepage_uri: https://github.com/MajedBojan/simple_request
|
|
137
54
|
source_code_uri: https://github.com/MajedBojan/simple_request
|
|
138
|
-
changelog_uri: https://github.com/MajedBojan/simple_request/blob/
|
|
139
|
-
|
|
55
|
+
changelog_uri: https://github.com/MajedBojan/simple_request/blob/main/Changelog.md
|
|
56
|
+
rubygems_mfa_required: 'true'
|
|
57
|
+
post_install_message:
|
|
140
58
|
rdoc_options: []
|
|
141
59
|
require_paths:
|
|
142
60
|
- lib
|
|
@@ -151,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
151
69
|
- !ruby/object:Gem::Version
|
|
152
70
|
version: '0'
|
|
153
71
|
requirements: []
|
|
154
|
-
rubygems_version: 3.
|
|
155
|
-
signing_key:
|
|
72
|
+
rubygems_version: 3.4.10
|
|
73
|
+
signing_key:
|
|
156
74
|
specification_version: 4
|
|
157
75
|
summary: Simple ruby gem that helps to make HTTP and HTTPS request from ruby projects.
|
|
158
76
|
test_files: []
|