Method: CTM::Base.create

Defined in:
lib/ctm/base.rb

.create(options) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ctm/base.rb', line 48

def self.create(options)
  list_type_path = options.delete(:list_type_path)
  list_token_type = options.delete(:list_token_type)
   = options.delete(:account_id)
  token = options.delete(:token)
  path_str = "/api/v1/#{list_type_path}.json"
  #puts "create: #{self}(#{path_str}) -> #{options.inspect}"
  res = self.post(path_str, :body => options.merge(:auth_token => token))
  #puts "result: #{res.parsed_response.inspect}"
  #puts "properties: #{list_type_path.inspect} -> #{list_token_type.inspect} -> #{account_id}"
  if res.parsed_response['status'] == 'error'
    raise CTM::Error::Create.new(res.parsed_response['reason'])
  else
    self.new(res.parsed_response[list_token_type.singularize], token)
  end
end