67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/aweber/collection.rb', line 67
def create(attrs={})
params = attrs.merge("ws.op" => "create")
if params.has_key?('custom_fields')
if params['custom_fields'].is_a?(Hash)
params['custom_fields'] = params['custom_fields'].to_json
end
end
response = client.post(path, params)
if response.is_a? Net::HTTPCreated
resource = get(response["location"]).merge(:parent => self)
resource = @klass.new(client, resource)
self[resource.id] = resource
else
if response
raise CreationError, JSON.parse(response.body)['error']['message'], caller
else
raise CreationError, "No response received", caller
end
end
end
|