FIX: Remove dependency on `rest-client`.

This commit is contained in:
Guo Xiang Tan 2017-06-16 09:08:15 +09:00
parent cae09ee4c8
commit d82dbd565b
10 changed files with 34 additions and 45 deletions

View File

@ -95,7 +95,6 @@ gem 'r2', '~> 0.2.5', require: false
gem 'rake'
gem 'thor', require: false
gem 'rest-client'
gem 'rinku'
gem 'sanitize'
gem 'sidekiq'

View File

@ -86,8 +86,6 @@ GEM
image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
email_reply_trimmer (0.1.6)
ember-data-source (2.2.1)
ember-source (>= 1.8, < 3.0)
@ -130,8 +128,6 @@ GEM
highline (1.7.8)
hiredis (0.6.1)
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
http_accept_language (2.0.5)
i18n (0.8.4)
image_size (1.5.0)
@ -174,7 +170,6 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
mustache (1.0.5)
netrc (0.11.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
nokogumbo (1.4.13)
@ -289,10 +284,6 @@ GEM
redis (3.3.3)
redis-namespace (1.5.3)
redis (~> 3.0, >= 3.0.4)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rinku (2.0.2)
rmmseg-cpp (0.2.9)
rspec (3.6.0)
@ -467,7 +458,6 @@ DEPENDENCIES
rbtrace
redis
redis-namespace
rest-client
rinku
rmmseg-cpp
rspec

View File

@ -20,8 +20,10 @@ module Jobs
})
end
RestClient.send :post, push_url, payload.merge({notifications: notifications}).to_json, content_type: :json, accept: :json
Excon.post(push_url,
body: payload.merge(notifications: notifications).to_json,
headers: { 'Content-Type' => 'application/json', 'Accept' => 'applicaton/json' }
)
end
end

View File

@ -1,4 +1,3 @@
require_dependency 'rest_client'
require_dependency 'version'
module DiscourseHub
@ -41,11 +40,19 @@ module DiscourseHub
end
def self.singular_action(action, rel_url, params={})
JSON.parse RestClient.send(action, "#{hub_base_url}#{rel_url}", {params: params, accept: accepts, referer: referer } )
JSON.parse(Excon.send(action,
"#{hub_base_url}#{rel_url}",
body: params.to_query,
headers: { 'Referer' => referer, 'Accept' => accepts.join(', ') }
).body)
end
def self.collection_action(action, rel_url, params={})
JSON.parse RestClient.send(action, "#{hub_base_url}#{rel_url}", params, content_type: :json, accept: accepts, referer: referer )
JSON.parse(Excon.send(action,
"#{hub_base_url}#{rel_url}",
body: params,
headers: { 'Referer' => referer, 'Accept' => accepts.join(', '), 'Content-Type' => 'applicaton/json' }
).body)
end
def self.hub_base_url
@ -57,7 +64,7 @@ module DiscourseHub
end
def self.accepts
[:json, 'application/vnd.discoursehub.v1']
['application/json', 'application/vnd.discoursehub.v1']
end
def self.referer

View File

@ -1,6 +1,5 @@
require 'base64'
require 'json'
require 'rest-client'
class QuandoraApi
@ -31,10 +30,10 @@ class QuandoraApi
url
end
def request url
JSON.parse(RestClient.get url, auth_header(@username, @password))
def request(url)
JSON.parse(Excon.get(url, headers: auth_header(@username, @password)))
end
def list_bases
response = request list_bases_url
response['data']

View File

@ -1,6 +1,5 @@
require 'base64'
require 'json'
require 'rest-client'
class SocialcastApi
@ -22,7 +21,7 @@ class SocialcastApi
end
def request url
JSON.parse(RestClient.get url, headers)
JSON.parse(Excon.get(url, headers: headers)
end
def list_users(opts={})

View File

@ -5,7 +5,10 @@ describe DiscourseHub do
describe '.discourse_version_check' do
it 'should return just return the json that the hub returns' do
hub_response = {'success' => 'OK', 'latest_version' => '0.8.1', 'critical_updates' => false}
RestClient.stubs(:get).returns( hub_response.to_json )
stub_request(:get, "http://local.hub:3000/api/version_check").
to_return(status: 200, body: hub_response.to_json)
expect(DiscourseHub.discourse_version_check).to eq(hub_response)
end
end

View File

@ -329,7 +329,7 @@ describe PostAlerter do
let(:topic) { mention_post.topic }
it "pushes nothing to suspended users" do
SiteSetting.queue_jobs = true
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
evil_trout.update_columns(suspended_till: 1.year.from_now)
@ -343,8 +343,7 @@ describe PostAlerter do
push_url: "https://site2.com/push")
end
RestClient.expects(:post).never
mention_post
expect { mention_post }.to_not change { Jobs::PushNotification.jobs.count }
end
it "correctly pushes notifications if configured correctly" do
@ -362,14 +361,11 @@ describe PostAlerter do
body = nil
headers = nil
# should only happen once even though we are using 2 keys
RestClient.expects(:post).with{|_req,_body,_headers|
headers = _headers
body = _body
Excon.expects(:post).with{|_req, _body|
headers = _body[:headers]
body = _body[:body]
}.returns("OK")
mention_post
payload = {
"secret_key" => SiteSetting.push_api_secret_key,
"url" => Discourse.base_url,
@ -399,8 +395,10 @@ describe PostAlerter do
]
}
mention_post
expect(JSON.parse(body)).to eq(payload)
expect(headers[:content_type]).to eq(:json)
expect(headers["Content-Type"]).to eq('application/json')
end
end

View File

@ -2,11 +2,6 @@ require 'rails_helper'
require_dependency 'user_destroyer'
describe UserDestroyer do
before do
RestClient.stubs(:delete).returns( {success: 'OK'}.to_json )
end
describe 'new' do
it 'raises an error when user is nil' do
expect { UserDestroyer.new(nil) }.to raise_error(Discourse::InvalidParameters)

View File

@ -1,5 +1,3 @@
require 'rest_client'
# /!\ WARNING /!\
# This plugin has been extracted from the Discourse source code and has not been tested.
# It really needs some love <3
@ -16,10 +14,9 @@ module Imgur
blob = file.read
response = RestClient.post(
SiteSetting.imgur_endpoint,
{ image: Base64.encode64(blob) },
{ 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
response = Excon.post(SiteSetting.imgur_endpoint,
body: { image: Base64.encode64(blob) },
headers: { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
)
json = JSON.parse(response.body)['data'] rescue nil