Module: Transifex::CrudRequests

Defined in:
lib/transifex/crud_requests.rb

Defined Under Namespace

Modules: Create, Delete, Fetch, Update

Class Method Summary collapse

Class Method Details

.add_param(url, param_name, param_value) ⇒ Object



18
19
20
21
22
23
# File 'lib/transifex/crud_requests.rb', line 18

def add_param(url, param_name, param_value)
  uri = URI(url)
  params = URI.decode_www_form(uri.query || "") << [param_name, param_value]
  uri.query = URI.encode_www_form(params)
  uri.to_s
end

.generate_url(object, params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/transifex/crud_requests.rb', line 4

def generate_url(object, params = {})
  class_name_string = object.class.name.split("::").last.downcase.to_s
  url = ""
  if object.class.respond_to?(:authors)
    object.class.authors.map{|author| url += "/" + author.to_s + "/" + object.instance_variable_get("@" + author.to_s + "_slug")}
  end
  url += "/" + class_name_string
  url += "/" + object.instance_variable_get("@" + class_name_string + "_slug") if object.instance_variable_defined?("@" + class_name_string + "_slug")
  params.each do |param|
    url = add_param(url, param[0], param[1])
  end
  url
end