require "rubygems"
require "JSON"
require "net/https"
api_key = "1wPBetR9.6bhINO7xO9ypG6iP2aYU8hx"
workspace_id = "5386494137624"
assignee = "craig@theaerialistpress.com"
# set up HTTPS connection
uri = URI.parse("https://app.asana.com/api/1.0/tasks")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# set up the request
header = {
"Content-Type" => "application/json"
}
req = Net::HTTP::Post.new(uri.path, header)
req.basic_auth(api_key, '')
req.body = {
"data" => {
"workspace" => workspace_id,
"name" => "House Order: " + @order.name,
"assignee" => assignee,
"projects" => "35978729781365",
"notes" => "Name: " + @order.name +
"\nEmail: " + @order.email +
"\nEvent Date: " + @date.to_s +
"\nDesign: " + @order.design +
"\n\nPaper Color: " + @order.paper_color +
"\nFont #1: " + @order.font1 +
"\nFont #2: " + @order.font2 +
if @order.card_type1 != "none"
"\n\nCard #1: " + @order.card_type1 + "\nPaper Weight: " + @order.paper_weight1 + "\nQuantity: " + @order.quantity1 + "\nInk Color #1: " + @order.ink_color11 + "\nInk Color #2: " + @order.ink_color12 + "\nWording: " + @order.wording1 + "\nReturn Address Printing: " + @order.return_address1 + "\nGuest Address Printing: " + @order.guest_address1.to_s + "\nEnvelope Liners: " + @order.envelope_liners1
end
if @order.card_type2 != "none"
"\n\nCard #2: " + @order.card_type2 + "\nPaper Weight: " + @order.paper_weight2 + "\nQuantity: " + @order.quantity2 + "\nInk Color #2: " + @order.ink_color21 + "\nInk Color #2: " + @order.ink_color22 + "\nWording: " + @order.wording2 + "\nReturn Address Printing: " + @order.return_address2 + "\nGuest Address Printing: " + @order.guest_address2.to_s + "\nEnvelope Liners: " + @order.envelope_liners2
end
}
}.to_json()
# issue the request
res = http.start { |http| http.request(req) }
# output
body = JSON.parse(res.body)
if body['errors'] then
puts "Server returned an error: #{body['errors'][0]['message']}"
else
puts "Created task with id: #{body['data']['id']}"
end
当我在发送给asana的数据中使用if语句时,我收到语法错误。我是铁杆的新人,不知道我做错了什么。
这是错误:
语法错误,意外的keyword_if,期待'}'如果@ order.card_type2!=“none”^ /Users/craigrinde/Dropbox/top_secret/aerialist/app/controllers/orders_controller.rb:212:语法错误,意外' }',期待keyword_end} ^