Module: ChatWork::Client::RoomMethods

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

Instance Method Summary collapse

Instance Method Details

#create_room(description: nil, icon_preset: nil, members_admin_ids:, members_member_ids: nil, members_readonly_ids: nil, name:, link: nil, link_code: nil, link_need_acceptance: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash

Create a new group chat

Examples:

response format

{
  "room_id": 1234
}

Parameters:

  • description (String) (defaults to: nil)

    Description of the group chat

  • icon_preset (String) (defaults to: nil)

    Type of the group chat icon (group, check, document, meeting, event, project, business, study, security, star, idea, heart, magcup, beer, music, sports, travel)

  • members_admin_ids (Array<Integer>, String)

    List of user IDs who will be given administrator permission for the group chat. At least one user must be specified as an administrator.

  • members_member_ids (Array<Integer>, String) (defaults to: nil)

    List of user IDs who will be given member permission for the group chat.

  • members_readonly_ids (Array<Integer>, String) (defaults to: nil)

    List of user IDs who will be given read-only permission for the group chat.

  • name (String)

    Title of the group chat.

  • link (Boolean) (defaults to: nil)

    whether create invitation link

  • link_code (String) (defaults to: nil)

    link path (default. random string)

  • link_need_acceptance (Boolean) (defaults to: nil)

    Approval necessity. Whether participation requires administrator approval.

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:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chatwork/client/room_methods.rb', line 64

def create_room(description: nil, icon_preset: nil, members_admin_ids:, members_member_ids: nil, members_readonly_ids: nil, name:,
                link: nil, link_code: nil, link_need_acceptance: nil, &block)
  params = {
    description:          description,
    icon_preset:          icon_preset,
    members_admin_ids:    Array(members_admin_ids).join(","),
    name:                 name,
    link:                 boolean_to_integer(link),
    link_need_acceptance: boolean_to_integer(link_need_acceptance),
    link_code:            link_code,
  }
  params[:members_member_ids] = Array(members_member_ids).join(",") if members_member_ids
  params[:members_readonly_ids] = Array(members_readonly_ids).join(",") if members_readonly_ids

  post("/rooms", params, &block)
end

#destroy_room(room_id:, action_type:) {|response_body, response_header| ... } ⇒ Object

Leave/Delete a group chat

Parameters:

  • room_id (Integer)
  • action_type (String)

    leave from a room or delete a room (leave, delete)

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)

See Also:



153
154
155
# File 'lib/chatwork/client/room_methods.rb', line 153

def destroy_room(room_id:, action_type:, &block)
  delete("/rooms/#{room_id}", action_type: action_type, &block)
end

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

Get chat name, icon, and Type (my, direct, or group)

Examples:

response format

{
  "room_id": 123,
  "name": "Group Chat Name",
  "type": "group",
  "role": "admin",
  "sticky": false,
  "unread_num": 10,
  "mention_num": 1,
  "mytask_num": 0,
  "message_num": 122,
  "file_num": 10,
  "task_num": 17,
  "icon_path": "https://example.com/ico_group.png",
  "last_update_time": 1298905200,
  "description": "room description text"
}

Parameters:

  • room_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:



113
114
115
# File 'lib/chatwork/client/room_methods.rb', line 113

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

#get_rooms {|response_body, response_header| ... } ⇒ Array<Hashie::Mash>

Get the list of all chats on your account

Examples:

response format

[
  {
    "room_id": 123,
    "name": "Group Chat Name",
    "type": "group",
    "role": "admin",
    "sticky": false,
    "unread_num": 10,
    "mention_num": 1,
    "mytask_num": 0,
    "message_num": 122,
    "file_num": 10,
    "task_num": 17,
    "icon_path": "https://example.com/ico_group.png",
    "last_update_time": 1298905200
  }
]

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:



31
32
33
# File 'lib/chatwork/client/room_methods.rb', line 31

def get_rooms(&block)
  get("/rooms", &block)
end

#update_room(room_id:, description: nil, icon_preset: nil, name: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash

Change the title and icon type of the specified chat

Examples:

response format

{
  "room_id": 1234
}

Parameters:

  • room_id (Integer)
  • description (String) (defaults to: nil)

    Description of the group chat

  • icon_preset (String) (defaults to: nil)

    Type of the group chat icon (group, check, document, meeting, event, project, business, study, security, star, idea, heart, magcup, beer, music, sports, travel)

  • name (String) (defaults to: nil)

    Title of the group chat.

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:



138
139
140
# File 'lib/chatwork/client/room_methods.rb', line 138

def update_room(room_id:, description: nil, icon_preset: nil, name: nil, &block)
  put("/rooms/#{room_id}", description: description, icon_preset: icon_preset, name: name, &block)
end