Sha256: d0c879fef1fe400ed51e30e0863f72c132a2a1b2b54520cddb93153e55509734

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'cgi'
require 'uri'

module RTurk
  class ExternalQuestion

    attr_accessor :url, :url_params, :frame_height

    def initialize(url, opts = {})
      @url = url
      self.frame_height = opts.delete(:frame_height) || 400
      self.url_params = opts
    end

    def querystring
      @url_params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&')
    end

    def url
      unless querystring.empty?
        # slam the params onto url, if url already has params, add 'em with a &
        u = @url.index('?') ? "#{@url}&#{querystring}" : "#{@url}?#{querystring}"
      else
        u = @url
      end
      CGI.escapeHTML(u) #URL should be XML/HTML escaped
    end

    def params
      @url_params
    end

    def params=(param_set)
      @url_params = param_set
    end

    def to_params
      raise RTurk::MissingParameters, "needs a url to build an external question" unless @url
      # TODO: update the xmlns schema... maybe
      xml = <<-XML
<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
  <ExternalURL>#{url}</ExternalURL>
  <FrameHeight>#{frame_height}</FrameHeight>
</ExternalQuestion>
      XML
      xml
    end

  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rturk-2.11.1 lib/rturk/builders/external_question_builder.rb
rturk-2.11.0 lib/rturk/builders/external_question_builder.rb