Module: ChatWork::Client::TaskMethods

Included in:
ChatWork::Client
Defined in:
lib/chatwork/client/task_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_task(room_id:, body:, to_ids:, limit: nil, limit_type: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash

Add a new task to the chat

Examples:

response format

{
  "task_ids": [123,124]
}

Parameters:

  • room_id (Integer)
  • body (String)

    Task description

  • to_ids (Array<Integer>, String)

    Account ID of the person/people responsible to complete the task

  • limit (Time, Integer) (defaults to: nil)

    When the task is due

  • limit_type (String) (defaults to: nil)

    Type of task deadline (e.g. none, date, time)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



66
67
68
69
70
71
72
73
74
75
# File 'lib/chatwork/client/task_methods.rb', line 66

def create_task(room_id:, body:, to_ids:, limit: nil, limit_type: nil, &block)
  params = {
    body:       body,
    to_ids:     Array(to_ids).join(","),
    limit_type: limit_type,
  }
  params[:limit] = limit.to_i if limit

  post("/rooms/#{room_id}/tasks", params, &block)
end

#find_task(room_id:, task_id:) {|response_body, response_header| ... } ⇒ Hashie::Mash

Get information about the specified task

Examples:

response format

{
  "task_id": 3,
  "account": {
    "account_id": 123,
    "name": "Bob",
    "avatar_image_url": "https://example.com/abc.png"
  },
  "assigned_by_account": {
    "account_id": 456,
    "name": "Anna",
    "avatar_image_url": "https://example.com/def.png"
  },
  "message_id": "13",
  "body": "buy milk",
  "limit_time": 1384354799,
  "status": "open",
  "limit_type": "date"
}

Parameters:

  • room_id (Integer)
  • task_id (Integer)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



110
111
112
# File 'lib/chatwork/client/task_methods.rb', line 110

def find_task(room_id:, task_id:, &block)
  get("/rooms/#{room_id}/tasks/#{task_id}", &block)
end

#get_tasks(room_id:, account_id:, assigned_by_account_id: nil, status: nil) {|response_body, response_header| ... } ⇒ Array<Hashie::Mash>

Get the list of tasks associated with the specified chat

(*This method returns up to 100 entries. We are planning to implement pagination to support larger number of data retrieval)

Examples:

response format

[
  {
    "task_id": 3,
    "account": {
      "account_id": 123,
      "name": "Bob",
      "avatar_image_url": "https://example.com/abc.png"
    },
    "assigned_by_account": {
      "account_id": 456,
      "name": "Anna",
      "avatar_image_url": "https://example.com/def.png"
    },
    "message_id": "13",
    "body": "buy milk",
    "limit_time": 1384354799,
    "status": "open",
    "limit_type": "date"
  }
]

Parameters:

  • room_id (Integer)
  • account_id (Integer)
  • assigned_by_account_id (Integer) (defaults to: nil)

    Account ID of the person who assigned task

  • status (String) (defaults to: nil)

    Task status (open, done)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Array<Hashie::Mash>)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Array<Hashie::Mash>)

See Also:



41
42
43
# File 'lib/chatwork/client/task_methods.rb', line 41

def get_tasks(room_id:, account_id:, assigned_by_account_id: nil, status: nil, &block)
  get("/rooms/#{room_id}/tasks", account_id: , assigned_by_account_id: , status: status, &block)
end

#update_task_status(room_id:, task_id:, body:) {|response_body, response_header| ... } ⇒ Hashie::Mash

Update task completion status

Examples:

response format

{
  "task_id": 1234
}

Parameters:

  • room_id (Integer)
  • task_id (Integer)
  • body (String)

    Task completion status (e.g. open, done)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



133
134
135
# File 'lib/chatwork/client/task_methods.rb', line 133

def update_task_status(room_id:, task_id:, body:, &block)
  put("/rooms/#{room_id}/tasks/#{task_id}/status", body: body, &block)
end