Sha256: c356c7b437d1b45f6551307fed166bba64952b6d1cf044fcfaf0bab0c131eddd

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

module Idonethis::UseCases
  module New
    class << self
      def apply(credential, args={})
        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}"
        log.call "overriding team <#{credential[:team]}> with <#{team}>"

        body = { 
            "raw_text"  => args[:message], 
            "team"      => (team || credential[:team])
        }

        body = body.merge({"done_date" => Time.parse(date).strftime("%F")}) if date

        log.call body
        
        parse internet.post(
          Idonethis::Index.dones,
          { "Authorization" => "Token #{credential[:token]}", accept: "application/json"},
          body
        )
      end

      private

      def parse(reply)
        require 'json'
        
        JSON.parse(reply.body)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
idonethis-cli-0.15.0 lib/idonethis/use_cases/new.rb