api_tools 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/api_tools.gemspec +4 -4
- data/lib/api_tools/default_rest.rb +1 -1
- data/lib/api_tools/default_rest_module.rb +13 -10
- data/lib/api_tools/version.rb +3 -1
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5375a4ba2ebc5fb2e679f359e123d6d52c9ca9a91105a885cb3b0be50ab4b99
|
4
|
+
data.tar.gz: 39ae0597a908411a2f0a9f048a94c21c95fe02be2980be03055c68f43dbefbc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db6205a5c9c3e4652d5edb6dd3ec9aafd8776357c26d08f9ebbc535542a0b80efb0f480b8809bcdf54da17d93f717b58617c37d5947f78d4ab9aeb0402ad077
|
7
|
+
data.tar.gz: c73926f4a30791ce69f430f4b5ef275ec951ae34469380bcd6da66bb69ac5e4087f1b993bf17c6c167de624264772c02ed53c5d8aa484250fbad0eee6d7074cb
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/api_tools.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["atpking"]
|
10
10
|
spec.email = ["atpking@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
12
|
+
spec.summary = 'rest 的常用请求'
|
13
|
+
spec.description = '简单点'
|
14
14
|
spec.homepage = "http://jicheng1014.cnblogs.com"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "byebug"
|
32
32
|
spec.add_development_dependency "webmock"
|
33
33
|
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency "rest-client", '
|
34
|
+
spec.add_dependency 'multi_json'
|
35
|
+
spec.add_dependency "rest-client", '~> 2.0'
|
36
36
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ApiTools
|
2
4
|
module DefaultRestModule
|
3
5
|
%w[get delete head].each do |word|
|
@@ -47,11 +49,12 @@ module ApiTools
|
|
47
49
|
def build_whole_url(path)
|
48
50
|
web = basic_url
|
49
51
|
return web if path.length.zero?
|
50
|
-
return path if path.start_with?(
|
51
|
-
|
52
|
-
|
52
|
+
return path if path.start_with?('http') # path 是一个绝对路径
|
53
|
+
|
54
|
+
if web[-1] == '/'
|
55
|
+
path = path[1..-1] if path[0] == '/'
|
53
56
|
else
|
54
|
-
path = "/#{path}" if path[0] !=
|
57
|
+
path = "/#{path}" if path[0] != '/'
|
55
58
|
end
|
56
59
|
web + path
|
57
60
|
end
|
@@ -61,21 +64,22 @@ module ApiTools
|
|
61
64
|
user_options[:retry_times].times do
|
62
65
|
begin
|
63
66
|
response = ::RestClient::Request.execute(request_dict)
|
64
|
-
return
|
67
|
+
return MultiJson.load(response.body, symbolize_keys: true) if user_options[:response_json]
|
68
|
+
|
65
69
|
return response.body
|
66
70
|
rescue RestClient::Exception => e
|
67
|
-
|
68
71
|
exception = e
|
69
72
|
next
|
70
73
|
end
|
71
74
|
end
|
72
75
|
puts "Restclient error, body = #{exception.response.body}" if exception.respond_to? :response
|
73
76
|
raise exception unless user_options[:ensure_no_exception]
|
77
|
+
|
74
78
|
{
|
75
79
|
status: false,
|
76
80
|
message: exception.message,
|
77
|
-
response_code: exception
|
78
|
-
response_body: exception
|
81
|
+
response_code: exception&.response&.code,
|
82
|
+
response_body: exception&.response&.body
|
79
83
|
}
|
80
84
|
end
|
81
85
|
|
@@ -100,5 +104,4 @@ module ApiTools
|
|
100
104
|
{} # 子类中复写
|
101
105
|
end
|
102
106
|
end
|
103
|
-
|
104
|
-
end
|
107
|
+
end
|
data/lib/api_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_tools
|
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
|
- atpking
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,34 +95,34 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: multi_json
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rest-client
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2.0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
125
|
-
description:
|
124
|
+
version: '2.0'
|
125
|
+
description: 简单点
|
126
126
|
email:
|
127
127
|
- atpking@gmail.com
|
128
128
|
executables: []
|
@@ -164,9 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.6.14
|
167
|
+
rubygems_version: 3.0.1
|
169
168
|
signing_key:
|
170
169
|
specification_version: 4
|
171
|
-
summary:
|
170
|
+
summary: rest 的常用请求
|
172
171
|
test_files: []
|