Skip to content

Commit

Permalink
Merge pull request #276 from dlackty/get-narrowcast-status
Browse files Browse the repository at this point in the history
Implement get_narrowcast_message_status
  • Loading branch information
zenizh authored Feb 8, 2023
2 parents a3ef07d + 5cee5f8 commit 396aa22
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/line/bot/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,18 @@ def get_aggregation_list(limit: nil, start: nil)
get(endpoint, endpoint_path, credentials)
end

# Gets the status of a narrowcast message.
#
# @param request_id [String] The narrowcast message's request ID. Each Messaging API request has a request ID. Find it in the response headers.
#
# @return [Net::HTTPResponse]
def get_narrowcast_message_status(request_id)
channel_token_required

endpoint_path = "/bot/message/progress/narrowcast?requestId=#{request_id}"
get(endpoint, endpoint_path, credentials)
end

# Fetch data, get content of specified URL.
#
# @param endpoint_base [String]
Expand Down
29 changes: 29 additions & 0 deletions spec/line/bot/client_get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@
}
EOS

NARROWCAST_MESSAGE_STATUS_CONTENT = <<"EOS"
{
"phase": "succeeded",
"successCount": 65535,
"failureCount": 128,
"targetCount": 65663,
"acceptedTime": "2020-12-03T10:15:30.121Z",
"completedTime": "2020-12-03T10:15:30.121Z"
}
EOS

describe Line::Bot::Client do
def dummy_config
{
Expand Down Expand Up @@ -477,4 +488,22 @@ def generate_client
markAsReadMode: 'manual'
)
end

it 'get narrowcast message status' do
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/progress/narrowcast?requestId=request_id'
stub_request(:get, uri_template).to_return(body: NARROWCAST_MESSAGE_STATUS_CONTENT, status: 200)

client = generate_client
response = client.get_narrowcast_message_status('request_id')

json = JSON.parse(response.body, symbolize_names: true)
expect(json).to eq(
phase: "succeeded",
successCount: 65535,
failureCount: 128,
targetCount: 65663,
acceptedTime: "2020-12-03T10:15:30.121Z",
completedTime: "2020-12-03T10:15:30.121Z"
)
end
end

0 comments on commit 396aa22

Please sign in to comment.