Skip to content

Commit

Permalink
implement basic feature (#5)
Browse files Browse the repository at this point in the history
* implement main.rb

* add comma

* remove space

* use Env#fetch

* use single quote

* use to_s

* fix raising error syntax
  • Loading branch information
okuzawats authored Jul 18, 2024
1 parent 8b385d9 commit 596ef79
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'net/http'

params = {
token: ENV.fetch('API_TOKEN', nil),
room_id: ENV.fetch('ROOM_ID', nil),
user_ids: ENV.fetch('USER_IDS', nil),
body: ENV.fetch('BODY', nil).delete_prefix('"').delete_suffix('"')
}

uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/tasks")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

body = "body=#{params[:body]}&to_ids=#{params[:user_ids]}"
headers = { 'X-ChatWorkToken' => params[:token].to_s }

response = http.post(uri.path, body, headers)

if response.code == '200'
puts response.body
else
raise StandardError, "action failed! #{response.body}"
end

0 comments on commit 596ef79

Please sign in to comment.