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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b2637610408853515f08ec127020ca41ee97547f
4
- data.tar.gz: 7da01e10d454e98cc3adeb017df3f3f4d34c8d3d
2
+ SHA256:
3
+ metadata.gz: a5375a4ba2ebc5fb2e679f359e123d6d52c9ca9a91105a885cb3b0be50ab4b99
4
+ data.tar.gz: 39ae0597a908411a2f0a9f048a94c21c95fe02be2980be03055c68f43dbefbc1
5
5
  SHA512:
6
- metadata.gz: 721b5c4644d526693adc6db0e8212ac697d649e02669fb756825c676f210de66965f57ec9257364e6d71305093a650748330d973bce81065f5c8a62d79bcf71f
7
- data.tar.gz: 7bc85b4e20ddaf2712bde23b70d2f78feac221f32ba29768bb82c949a70d8f3e4774725fb1f08e127167d9b80604d50245f1c406414c65ca7221180c7b8050c0
6
+ metadata.gz: 5db6205a5c9c3e4652d5edb6dd3ec9aafd8776357c26d08f9ebbc535542a0b80efb0f480b8809bcdf54da17d93f717b58617c37d5947f78d4ab9aeb0402ad077
7
+ data.tar.gz: c73926f4a30791ce69f430f4b5ef275ec951ae34469380bcd6da66bb69ac5e4087f1b993bf17c6c167de624264772c02ed53c5d8aa484250fbad0eee6d7074cb
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ pkg
14
14
 
15
15
  # rspec failure tracking
16
16
  .rspec_status
17
+ TAGS
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  if ENV["USING_OFFICIAL_GEM"]
2
2
  source "https://rubygems.org"
3
3
  else
4
- source "https://gems.ruby-china.org"
4
+ source "https://gems.ruby-china.com"
5
5
  end
6
6
 
7
7
  # Specify your gem's dependencies in api_tools.gemspec
@@ -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 "oj", '> 2.0'
35
- spec.add_dependency "rest-client", '> 1.0'
34
+ spec.add_dependency 'multi_json'
35
+ spec.add_dependency "rest-client", '~> 2.0'
36
36
  end
@@ -3,7 +3,7 @@ require_relative './default_rest_module.rb'
3
3
  require 'json'
4
4
  require 'uri'
5
5
  require 'rest-client'
6
- require 'oj'
6
+ require 'multi_json'
7
7
 
8
8
  class DefaultRest
9
9
  extend ApiTools::DefaultRestModule
@@ -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?("http") # path 是一个绝对路径
51
- if web[-1] == "/"
52
- path = path[1..-1] if path[0] == "/"
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 ::Oj.load(response.body, symbol_keys: true) if user_options[:response_json]
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 && exception.response.code,
78
- response_body: exception && exception.response.body
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApiTools
2
- VERSION = "0.0.6"
4
+ VERSION = '0.1.0'
3
5
  end
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.6
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: 2018-03-24 00:00:00.000000000 Z
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: oj
98
+ name: multi_json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '2.0'
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: '2.0'
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: '1.0'
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: '1.0'
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
- rubyforge_project:
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: []