lib/idonethis/use_cases/new.rb in idonethis-cli-0.15.0 vs lib/idonethis/use_cases/new.rb in idonethis-cli-0.19.0
- old
+ new
@@ -1,10 +1,10 @@
-module Idonethis::UseCases
+module Idonethis::UseCases
module New
class << self
def apply(credential, args={})
- log = args[:log] || fail("You need to supply :internet adapter")
+ log = args[:log] || fail("You need to supply :internet adapter")
internet = args[:internet] || fail("You need to supply :internet adapter")
team = args[:team]
date = args[:date]
log.call "args: #{args}"
@@ -13,24 +13,33 @@
body = {
"raw_text" => args[:message],
"team" => (team || credential[:team])
}
- body = body.merge({"done_date" => Time.parse(date).strftime("%F")}) if date
-
+ if date
+ date = Calendar.yesterday.to_s if date == 'yesterday'
+ body = body.merge({"done_date" => Calendar.day_string(Time.parse(date))})
+ end
+
log.call body
parse internet.post(
Idonethis::Index.dones,
{ "Authorization" => "Token #{credential[:token]}", accept: "application/json"},
body
)
end
+
+ def usage
+ %Q{new -m "Birthday shopping + sushi lunch" --date 1-Oct-2015}
+ end
private
def parse(reply)
require 'json'
+
+ fail reply.body unless reply.code == 201
JSON.parse(reply.body)
end
end
end