Method: MySpace::EndPoint#compute_path

Defined in:
lib/myspace/end_point.rb

#compute_path(params) ⇒ Object

Computes the path to the EndPoint by substituting parameters from params into the path.

WARNING: This function DESTRUCTIVELY modifies the params hash that you pass to it. This is normally what you want, since you don’t want to substitute a parameter into the path and also pass it in the query string, but make sure to make a copy first if you’re just passing in parameters from another caller.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/myspace/end_point.rb', line 61

def compute_path(params)
  path = @components.inject("") do |result, cur|
    if cur.class == String
      result + cur
    elsif cur.class == Symbol
      val = params.delete(cur)
      raise "Required parameter '#{cur}' omitted" unless val
      result + val
    else
      raise "Bad path component: #{cur}"
    end
  end
  path << '.json' if @v1_json && params[:v1_json]
  path
end