Sha256: 64d067b1004708c30e81ae407783fa7e687194193ea70df3b35861158ab1f2df

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 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

8 entries across 8 versions & 1 rubygems

Version Path
weeter-0.15.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.14.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.13.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.11.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.10.0 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.9.2 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.9.1 lib/weeter/plugins/lib/oauth_http.rb
weeter-0.9.0 lib/weeter/plugins/lib/oauth_http.rb