Module: ShopStyleHelper

Included in:
ShopStyle
Defined in:
lib/shopstyle.rb

Instance Method Summary collapse

Instance Method Details

#escape(value) ⇒ Object



28
29
30
# File 'lib/shopstyle.rb', line 28

def escape value
  CGI::escape(value.to_s)
end

#format_param_pair(key, value) ⇒ Object



24
25
26
# File 'lib/shopstyle.rb', line 24

def format_param_pair key, value
  "%s=%s" % [escape(key),escape(value)]
end

#query_from_params(params) ⇒ Object

If you want to, e.g., request N products you must specificy the relevant parameter N times In that case you’d pass in :prodid => [1,2,3], which this will then map to “prodid=1&prodid=2&prodid=3”



14
15
16
17
18
19
20
21
22
# File 'lib/shopstyle.rb', line 14

def query_from_params params
  params.map do |key,value|
    if value.is_a?(Array)
      query_from_params ([key]*value.size).zip(value)
    else
      format_param_pair key, value
    end
  end.join('&')
end

#url_for(host, method, params) ⇒ Object



32
33
34
# File 'lib/shopstyle.rb', line 32

def url_for host, method, params
  "http://#{host}/action/#{method}?#{query_from_params(params)}"
end