discourse/lib/discourse_hub.rb

61 lines
1.3 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
require_dependency 'rest_client'
require_dependency 'version'
2013-02-05 14:16:51 -05:00
module DiscourseHub
2013-02-05 14:16:51 -05:00
2014-05-11 19:06:28 -04:00
def self.version_check_payload
{
2014-08-11 15:41:56 -04:00
installed_version: Discourse::VERSION::STRING
2014-05-11 19:06:28 -04:00
}
end
def self.discourse_version_check
get('/version_check', version_check_payload)
2013-02-05 14:16:51 -05:00
end
private
def self.get(rel_url, params={})
singular_action :get, rel_url, params
2013-02-05 14:16:51 -05:00
end
def self.post(rel_url, params={})
collection_action :post, rel_url, params
2013-02-05 14:16:51 -05:00
end
def self.put(rel_url, params={})
collection_action :put, rel_url, params
end
def self.delete(rel_url, params={})
singular_action :delete, rel_url, params
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 } )
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 )
end
def self.hub_base_url
2013-02-05 14:16:51 -05:00
if Rails.env == 'production'
'http://api.discourse.org/api'
else
ENV['HUB_BASE_URL'] || 'http://local.hub:3000/api'
2013-02-05 14:16:51 -05:00
end
end
def self.accepts
[:json, 'application/vnd.discoursehub.v1']
end
def self.referer
Discourse.base_url
end
end