lib/fanforce/utils.rb in fanforce-0.4.6 vs lib/fanforce/utils.rb in fanforce-0.4.7

- old
+ new

@@ -1,10 +1,11 @@ require 'uri' require 'rack/utils' +require 'forwardable' module Fanforce::Utils - def self.included(base) base.extend(self) end + extend Fanforce::Utils def is_blank?(obj) obj.respond_to?(:empty?) ? obj.empty? : !obj end @@ -139,9 +140,24 @@ templates = matches.inject({}) {|t,m| t[m[0]] = m[1]; t } if format == :jsonp "#{options[:callback]}(#{templates.to_json})" else templates.to_json + end + end + + def curl_command(method, url, req_params) + case method + when :get + "curl \"#{url}?#{to_param(req_params)}\"" + when :post + "curl -X POST -d \"#{to_param(req_params)}\" #{url}" + when :put + "curl -X PUT -d \"#{to_param(req_params)}\" #{url.to_json}" + when :delete + "curl --request DELETE \"#{url}?#{to_param(req_params)}\"" + else + raise 'Unknown request method' end end end