Skip to content

Commit c8893e3

Browse files
author
蔡耀賢
committed
Merge branch 'modify-to=double-quote' into 'master'
Enforce double quotes for strings See merge request kdanmobile/shared-code-base/gems/json_requester!24
2 parents a8dc641 + 3dc750a commit c8893e3

10 files changed

Lines changed: 140 additions & 118 deletions

.gitlab-ci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ include:
66
stages:
77
- test
88
- sast_upload
9+
- lint
910
- rspec
1011
- publish
1112

13+
rubocop:
14+
stage: lint
15+
image: ruby:3.4.8
16+
tags:
17+
- arm64
18+
script:
19+
- bundle install
20+
- bundle exec rubocop
21+
rules:
22+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
23+
- if: $CI_COMMIT_BRANCH == "master"
24+
1225
rspec:
1326
stage: rspec
1427
image: ruby:3.4.8
@@ -17,8 +30,9 @@ rspec:
1730
script:
1831
- bundle install
1932
- rspec spec
20-
only:
21-
- master
33+
rules:
34+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
35+
- if: $CI_COMMIT_BRANCH == "master"
2236

2337
to_gem:
2438
stage: publish

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Layout/LineLength:
1515
Style/Documentation:
1616
Enabled: false
1717

18+
Style/StringLiterals:
19+
Enabled: true
20+
EnforcedStyle: double_quotes
21+
1822
Metrics/MethodLength:
1923
Max: 25
2024

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.0.7] - 2026-03-30
2+
- Update RuboCop configuration to enforce double quotes for strings.
3+
- Add RuboCop lint stage to CI pipeline.
4+
15
## [2.0.6] - 2026-03-30
26
- Update mcp to version `0.9.2` for [Github GHSA-qvqr-5cv7-wh35](https://github.com/advisories/GHSA-qvqr-5cv7-wh35) security vulnerability warning.
37

Gemfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
gemspec
66

77
# Simple, but flexible HTTP client library, with support for multiple backends.
8-
gem 'faraday', '~> 2.14.1'
8+
gem "faraday", "~> 2.14.1"
99
# Perform multipart-post requests using Faraday.
10-
gem 'faraday-multipart', '~> 1.2.0'
10+
gem "faraday-multipart", "~> 1.2.0"
1111

1212
group :development, :test do
13-
gem 'pry', '~> 0.16.0'
14-
gem 'rspec', '~> 3.13.0'
15-
gem 'rubocop', '~> 1.85.1'
16-
gem 'rubocop-performance', '~> 1.26.1'
17-
gem 'webmock', '~> 3.26', '>= 3.26.0'
13+
gem "pry", "~> 0.16.0"
14+
gem "rspec", "~> 3.13.0"
15+
gem "rubocop", "~> 1.85.1"
16+
gem "rubocop-performance", "~> 1.26.1"
17+
gem "webmock", "~> 3.26", ">= 3.26.0"
1818
end

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
json_requester (2.0.6)
4+
json_requester (2.0.7)
55
faraday (~> 2.0, >= 2.0.1)
66
faraday-multipart (~> 1.2.0)
77

VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.6
1+
2.0.7

json_requester.gemspec

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# frozen_string_literal: true
22

33
Gem::Specification.new do |s|
4-
s.name = 'json_requester'
5-
s.version = File.read('./VERSION.md')
4+
s.name = "json_requester"
5+
s.version = File.read("./VERSION.md")
66
s.platform = Gem::Platform::RUBY
7-
s.summary = 'Basic Wrapper of Faraday'
8-
s.description = 'wrapper of faraday'
9-
s.authors = ['JiaRou Lee']
10-
s.email = 'laura34963@kdanmobile.com'
11-
s.homepage = 'https://github.com/kdan-mobile-software-ltd/json_requester'
12-
s.license = 'MIT'
7+
s.summary = "Basic Wrapper of Faraday"
8+
s.description = "wrapper of faraday"
9+
s.authors = ["JiaRou Lee"]
10+
s.email = "laura34963@kdanmobile.com"
11+
s.homepage = "https://github.com/kdan-mobile-software-ltd/json_requester"
12+
s.license = "MIT"
1313
s.metadata = {
14-
'source_code_uri' => 'https://github.com/kdan-mobile-software-ltd/json_requester',
15-
'changelog_uri' => 'https://github.com/kdan-mobile-software-ltd/json_requester/blob/master/CHANGELOG.md',
16-
'rubygems_mfa_required' => 'true'
14+
"source_code_uri" => "https://github.com/kdan-mobile-software-ltd/json_requester",
15+
"changelog_uri" => "https://github.com/kdan-mobile-software-ltd/json_requester/blob/master/CHANGELOG.md",
16+
"rubygems_mfa_required" => "true"
1717
}
1818

1919
s.files = `git ls-files -- lib/*`.split("\n")
20-
s.extra_rdoc_files = ['README.md']
21-
s.rdoc_options = ['--charset=UTF-8']
22-
s.require_path = 'lib'
20+
s.extra_rdoc_files = ["README.md"]
21+
s.rdoc_options = ["--charset=UTF-8"]
22+
s.require_path = "lib"
2323

24-
s.required_ruby_version = '>= 3.0.0'
25-
s.add_dependency 'faraday', '~> 2.0', '>= 2.0.1'
26-
s.add_dependency 'faraday-multipart', '~> 1.2.0'
24+
s.required_ruby_version = ">= 3.0.0"
25+
s.add_dependency "faraday", "~> 2.0", ">= 2.0.1"
26+
s.add_dependency "faraday-multipart", "~> 1.2.0"
2727
end

lib/json_requester.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# frozen_string_literal: true
22

3-
require 'faraday'
4-
require 'faraday/multipart'
5-
require 'json'
3+
require "faraday"
4+
require "faraday/multipart"
5+
require "json"
66

77
class JsonRequester
88
attr_reader :host, :conn
99

10-
def initialize(host, multipart: false, ssl_verify: true, timeout: 60, user_agent: '')
10+
def initialize(host, multipart: false, ssl_verify: true, timeout: 60, user_agent: "")
1111
@host = host
1212
@multipart = multipart
1313
@ssl_verify = ssl_verify
1414
@timeout = timeout
1515
@user_agent = user_agent.strip.to_s
1616
end
1717

18-
def http_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
18+
def http_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: "utf-8")
1919
puts "send #{http_method} request to #{@host} with\npath: #{path}\nparams: #{params}\nheaders: #{headers}"
2020
if http_method == :get
2121
normal_send(http_method, path, params, headers, sort_params: sort_params, need_response_header: need_response_header)
@@ -36,12 +36,12 @@ def normal_send(http_method, path, params = {}, headers = {}, sort_params: true,
3636
error_response(e)
3737
end
3838

39-
def json_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: 'utf-8')
39+
def json_send(http_method, path, params = {}, headers = {}, sort_params: true, need_response_header: false, content_type_charset: "utf-8")
4040
conn = init_conn(sort_params: sort_params)
4141
res = conn.send(http_method) do |req|
4242
req.url path
4343
req.headers = headers if object_present?(headers)
44-
req.headers['Content-Type'] = object_present?(content_type_charset) ? "application/json;charset=#{content_type_charset}" : 'application/json'
44+
req.headers["Content-Type"] = object_present?(content_type_charset) ? "application/json;charset=#{content_type_charset}" : "application/json"
4545
req.body = params.to_json if object_present?(params)
4646
end
4747
process_response(res, need_response_header: need_response_header)
@@ -54,7 +54,7 @@ def form_send(http_method, path, params = {}, headers = {}, sort_params: true, n
5454
res = conn.send(http_method) do |req|
5555
req.url path
5656
req.headers = headers if object_present?(headers)
57-
req.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'
57+
req.headers["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8"
5858
req.body = URI.encode_www_form(params) if object_present?(params)
5959
end
6060
process_response(res, need_response_header: need_response_header)
@@ -93,21 +93,21 @@ def init_conn(sort_params: true)
9393
end
9494

9595
def process_response(response, need_response_header: false)
96-
result = { 'status' => response.status }
96+
result = { "status" => response.status }
9797
begin
9898
body = JSON.parse(response.body)
99-
body = { 'body' => body } unless body.is_a?(Hash)
100-
body['body_status'] = body.delete('status') unless body['status'].nil?
99+
body = { "body" => body } unless body.is_a?(Hash)
100+
body["body_status"] = body.delete("status") unless body["status"].nil?
101101
rescue StandardError
102-
body = { 'body' => response.body }
102+
body = { "body" => response.body }
103103
end
104104
result.merge!(body)
105-
result['headers'] = response.headers.to_h if need_response_header
105+
result["headers"] = response.headers.to_h if need_response_header
106106
result
107107
end
108108

109109
def error_response(err)
110-
{ 'status' => 500, 'message' => "#{err.class.name}: #{err.message}" }
110+
{ "status" => 500, "message" => "#{err.class.name}: #{err.message}" }
111111
end
112112

113113
def object_present?(object)

0 commit comments

Comments
 (0)