mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
FIX: Remove dependency on rest-client
.
This commit is contained in:
parent
cae09ee4c8
commit
d82dbd565b
1
Gemfile
1
Gemfile
@ -95,7 +95,6 @@ gem 'r2', '~> 0.2.5', require: false
|
|||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
|
||||||
gem 'thor', require: false
|
gem 'thor', require: false
|
||||||
gem 'rest-client'
|
|
||||||
gem 'rinku'
|
gem 'rinku'
|
||||||
gem 'sanitize'
|
gem 'sanitize'
|
||||||
gem 'sidekiq'
|
gem 'sidekiq'
|
||||||
|
10
Gemfile.lock
10
Gemfile.lock
@ -86,8 +86,6 @@ GEM
|
|||||||
image_size (~> 1.5)
|
image_size (~> 1.5)
|
||||||
in_threads (~> 1.3)
|
in_threads (~> 1.3)
|
||||||
progress (~> 3.0, >= 3.0.1)
|
progress (~> 3.0, >= 3.0.1)
|
||||||
domain_name (0.5.20170404)
|
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
|
||||||
email_reply_trimmer (0.1.6)
|
email_reply_trimmer (0.1.6)
|
||||||
ember-data-source (2.2.1)
|
ember-data-source (2.2.1)
|
||||||
ember-source (>= 1.8, < 3.0)
|
ember-source (>= 1.8, < 3.0)
|
||||||
@ -130,8 +128,6 @@ GEM
|
|||||||
highline (1.7.8)
|
highline (1.7.8)
|
||||||
hiredis (0.6.1)
|
hiredis (0.6.1)
|
||||||
htmlentities (4.3.4)
|
htmlentities (4.3.4)
|
||||||
http-cookie (1.0.3)
|
|
||||||
domain_name (~> 0.5)
|
|
||||||
http_accept_language (2.0.5)
|
http_accept_language (2.0.5)
|
||||||
i18n (0.8.4)
|
i18n (0.8.4)
|
||||||
image_size (1.5.0)
|
image_size (1.5.0)
|
||||||
@ -174,7 +170,6 @@ GEM
|
|||||||
multi_xml (0.6.0)
|
multi_xml (0.6.0)
|
||||||
multipart-post (2.0.0)
|
multipart-post (2.0.0)
|
||||||
mustache (1.0.5)
|
mustache (1.0.5)
|
||||||
netrc (0.11.0)
|
|
||||||
nokogiri (1.8.0)
|
nokogiri (1.8.0)
|
||||||
mini_portile2 (~> 2.2.0)
|
mini_portile2 (~> 2.2.0)
|
||||||
nokogumbo (1.4.13)
|
nokogumbo (1.4.13)
|
||||||
@ -289,10 +284,6 @@ GEM
|
|||||||
redis (3.3.3)
|
redis (3.3.3)
|
||||||
redis-namespace (1.5.3)
|
redis-namespace (1.5.3)
|
||||||
redis (~> 3.0, >= 3.0.4)
|
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)
|
rinku (2.0.2)
|
||||||
rmmseg-cpp (0.2.9)
|
rmmseg-cpp (0.2.9)
|
||||||
rspec (3.6.0)
|
rspec (3.6.0)
|
||||||
@ -467,7 +458,6 @@ DEPENDENCIES
|
|||||||
rbtrace
|
rbtrace
|
||||||
redis
|
redis
|
||||||
redis-namespace
|
redis-namespace
|
||||||
rest-client
|
|
||||||
rinku
|
rinku
|
||||||
rmmseg-cpp
|
rmmseg-cpp
|
||||||
rspec
|
rspec
|
||||||
|
@ -20,8 +20,10 @@ module Jobs
|
|||||||
})
|
})
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
require_dependency 'rest_client'
|
|
||||||
require_dependency 'version'
|
require_dependency 'version'
|
||||||
|
|
||||||
module DiscourseHub
|
module DiscourseHub
|
||||||
@ -41,11 +40,19 @@ module DiscourseHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.singular_action(action, rel_url, params={})
|
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
|
end
|
||||||
|
|
||||||
def self.collection_action(action, rel_url, params={})
|
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
|
end
|
||||||
|
|
||||||
def self.hub_base_url
|
def self.hub_base_url
|
||||||
@ -57,7 +64,7 @@ module DiscourseHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.accepts
|
def self.accepts
|
||||||
[:json, 'application/vnd.discoursehub.v1']
|
['application/json', 'application/vnd.discoursehub.v1']
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.referer
|
def self.referer
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
require 'base64'
|
require 'base64'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'rest-client'
|
|
||||||
|
|
||||||
class QuandoraApi
|
class QuandoraApi
|
||||||
|
|
||||||
@ -31,10 +30,10 @@ class QuandoraApi
|
|||||||
url
|
url
|
||||||
end
|
end
|
||||||
|
|
||||||
def request url
|
def request(url)
|
||||||
JSON.parse(RestClient.get url, auth_header(@username, @password))
|
JSON.parse(Excon.get(url, headers: auth_header(@username, @password)))
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_bases
|
def list_bases
|
||||||
response = request list_bases_url
|
response = request list_bases_url
|
||||||
response['data']
|
response['data']
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
require 'base64'
|
require 'base64'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'rest-client'
|
|
||||||
|
|
||||||
class SocialcastApi
|
class SocialcastApi
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ class SocialcastApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
def request url
|
def request url
|
||||||
JSON.parse(RestClient.get url, headers)
|
JSON.parse(Excon.get(url, headers: headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_users(opts={})
|
def list_users(opts={})
|
||||||
|
@ -5,7 +5,10 @@ describe DiscourseHub do
|
|||||||
describe '.discourse_version_check' do
|
describe '.discourse_version_check' do
|
||||||
it 'should return just return the json that the hub returns' 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}
|
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)
|
expect(DiscourseHub.discourse_version_check).to eq(hub_response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -329,7 +329,7 @@ describe PostAlerter do
|
|||||||
let(:topic) { mention_post.topic }
|
let(:topic) { mention_post.topic }
|
||||||
|
|
||||||
it "pushes nothing to suspended users" do
|
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"
|
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
|
||||||
|
|
||||||
evil_trout.update_columns(suspended_till: 1.year.from_now)
|
evil_trout.update_columns(suspended_till: 1.year.from_now)
|
||||||
@ -343,8 +343,7 @@ describe PostAlerter do
|
|||||||
push_url: "https://site2.com/push")
|
push_url: "https://site2.com/push")
|
||||||
end
|
end
|
||||||
|
|
||||||
RestClient.expects(:post).never
|
expect { mention_post }.to_not change { Jobs::PushNotification.jobs.count }
|
||||||
mention_post
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "correctly pushes notifications if configured correctly" do
|
it "correctly pushes notifications if configured correctly" do
|
||||||
@ -362,14 +361,11 @@ describe PostAlerter do
|
|||||||
body = nil
|
body = nil
|
||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
# should only happen once even though we are using 2 keys
|
Excon.expects(:post).with{|_req, _body|
|
||||||
RestClient.expects(:post).with{|_req,_body,_headers|
|
headers = _body[:headers]
|
||||||
headers = _headers
|
body = _body[:body]
|
||||||
body = _body
|
|
||||||
}.returns("OK")
|
}.returns("OK")
|
||||||
|
|
||||||
mention_post
|
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"secret_key" => SiteSetting.push_api_secret_key,
|
"secret_key" => SiteSetting.push_api_secret_key,
|
||||||
"url" => Discourse.base_url,
|
"url" => Discourse.base_url,
|
||||||
@ -399,8 +395,10 @@ describe PostAlerter do
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mention_post
|
||||||
|
|
||||||
expect(JSON.parse(body)).to eq(payload)
|
expect(JSON.parse(body)).to eq(payload)
|
||||||
expect(headers[:content_type]).to eq(:json)
|
expect(headers["Content-Type"]).to eq('application/json')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,11 +2,6 @@ require 'rails_helper'
|
|||||||
require_dependency 'user_destroyer'
|
require_dependency 'user_destroyer'
|
||||||
|
|
||||||
describe UserDestroyer do
|
describe UserDestroyer do
|
||||||
|
|
||||||
before do
|
|
||||||
RestClient.stubs(:delete).returns( {success: 'OK'}.to_json )
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'new' do
|
describe 'new' do
|
||||||
it 'raises an error when user is nil' do
|
it 'raises an error when user is nil' do
|
||||||
expect { UserDestroyer.new(nil) }.to raise_error(Discourse::InvalidParameters)
|
expect { UserDestroyer.new(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
require 'rest_client'
|
|
||||||
|
|
||||||
# /!\ WARNING /!\
|
# /!\ WARNING /!\
|
||||||
# This plugin has been extracted from the Discourse source code and has not been tested.
|
# This plugin has been extracted from the Discourse source code and has not been tested.
|
||||||
# It really needs some love <3
|
# It really needs some love <3
|
||||||
@ -16,10 +14,9 @@ module Imgur
|
|||||||
|
|
||||||
blob = file.read
|
blob = file.read
|
||||||
|
|
||||||
response = RestClient.post(
|
response = Excon.post(SiteSetting.imgur_endpoint,
|
||||||
SiteSetting.imgur_endpoint,
|
body: { image: Base64.encode64(blob) },
|
||||||
{ image: Base64.encode64(blob) },
|
headers: { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
|
||||||
{ 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
json = JSON.parse(response.body)['data'] rescue nil
|
json = JSON.parse(response.body)['data'] rescue nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user