Sha256: 17610a023fc9881fccee98a089df9b9ec5e287f6daf0619567868c2e0fc66c4f

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

require 'em-http'
require 'simple_oauth'

module Weeter
  module Plugins
    module Net
      class OauthHttp
        def self.get(config, url, params = {})
          request(config, :get, url, params)
        end

        def self.put(config, url, params = {})
          request(config, :put, url, params)
        end

        def self.post(config, url, params = {})
          request(config, :post, url, params)
        end

        def self.delete(config, url, params = {})
          request(config, :delete, url, params)
        end

        def self.request(config, method, url, params = {})
          if method == :post
            request_options = {:body => params}
          else
            request_options = {:query => params}
          end
          request_options.merge!(:head => {"Authorization" => oauth_header(config, url, params, method.to_s.upcase)}) if config.oauth
          EM::HttpRequest.new(url).send(method, request_options)
        end

        def self.oauth_header(config, uri, params, http_method)
          ::SimpleOAuth::Header.new(http_method, uri, params, config.oauth).to_s
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
weeter-0.19.4 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.19.3 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.19.2 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.19.1 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.19.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.18.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.17.0 lib/weeter/plugins/lib/oauth_http.rb