Sha256: d60a563752108e61bef2653ed603c4a310acecd153b1ca628d5d7c3f497fc1e4

Contents?: true

Size: 879 Bytes

Versions: 2

Compression:

Stored size: 879 Bytes

Contents

module SauceWhisk
  module RestRequestBuilder

    def get(resource_to_fetch=nil)
      resource_url = fully_qualified_resource
      resource_url << "/#{resource_to_fetch}" if resource_to_fetch
      RestClient::Request.execute({:method => :get, :url => resource_url}.merge auth_details)
    end

    def put(resource_id, body)
      url = "#{fully_qualified_resource}/#{resource_id}"
      length = body.length
      headers = {"Content-Length" => length}
      req_params = {
          :method => :put,
          :url => url,
          :payload => body,
          :content_type => "application/json"
      }
      RestClient::Request.execute(req_params.merge auth_details)
    end

    def auth_details
      {:user => SauceWhisk.username, :password => SauceWhisk.password}
    end

    def fully_qualified_resource
      "#{SauceWhisk.base_url}/#{resource}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sauce_whisk-0.0.3 lib/sauce_whisk/rest_request_builder.rb
sauce_whisk-0.0.2 lib/sauce_whisk/rest_request_builder.rb