Class: Disqussed::Api
- Inherits:
-
Object
- Object
- Disqussed::Api
- Defined in:
- lib/disqussed/api.rb
Constant Summary collapse
- ROOT =
'https://disqus.com/api'
- API_VERSION =
'3.0'
Class Method Summary collapse
- .remote_auth_s3(data) ⇒ Object
- .request(method, endpoint, action, opts = {}, authenticate_as_self = false, user = {}) ⇒ Object
Class Method Details
.remote_auth_s3(data) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/disqussed/api.rb', line 33 def remote_auth_s3(data) digest = OpenSSL::Digest::Digest.new('sha1') data = Base64.urlsafe_encode64(MultiJson.dump(data)) = Time.now.to_i sha1 = OpenSSL::HMAC.hexdigest(digest, Disqussed::defaults[:secret_key], "#{data} #{}") "#{data} #{sha1} #{}" end |
.request(method, endpoint, action, opts = {}, authenticate_as_self = false, user = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/disqussed/api.rb', line 10 def request(method, endpoint, action, opts = {}, authenticate_as_self = false, user = {}) throw "Missing API Key" if Disqussed::defaults[:api_key].nil? opts[:api_key] = Disqussed::defaults[:api_key] opts[:api_secret] = Disqussed::defaults[:secret_key] if authenticate_as_self opts[:access_token] = Disqussed::defaults[:access_token] elsif Disqussed::defaults[:sso] throw "Missing API Secret" if Disqussed::defaults[:secret_key].nil? user.slice!(:id, :username, :email, :avatar, :url) opts[:remote_auth] = remote_auth_s3(user) end if method === "post" HTTParty.post([ROOT, API_VERSION, endpoint, action + '.json'].join('/'), { :body => opts }) elsif method === "get" HTTParty.get([ROOT, API_VERSION, endpoint, action + '.json'].join('/'), { :query => opts }) end end |