Skip to content

Commit

Permalink
NON-ISSUE Support RedeliveryRecipient. (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki-ma authored Oct 12, 2020
1 parent ed911a9 commit 6ae80da
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
@JsonTypeInfo(use = Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(AudienceRecipient.class),
@JsonSubTypes.Type(LogicalOperatorRecipient.class)
@JsonSubTypes.Type(LogicalOperatorRecipient.class),
@JsonSubTypes.Type(RedeliveryRecipient.class)
})
public interface Recipient {
String getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/

package com.linecorp.bot.model.narrowcast.recipient;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import lombok.Builder;
import lombok.Value;

/**
* By setting the request ID (X-Line-Request-Id) obtained when the narrowcast message was delivered to the
* requestId property, you can specify the users who received the narrowcast message as the target.
*
* @see <a href="https://developers.line.biz/en/docs/messaging-api/sending-messages/#redelivery-object">Redelivery object</a>
*/
@Value
@Builder
@JsonTypeName("redelivery")
@JsonDeserialize(builder = RedeliveryRecipient.RedeliveryRecipientBuilder.class)
public class RedeliveryRecipient implements Recipient {
String requestId;

@Override
public String getType() {
return "redelivery";
}

@JsonPOJOBuilder(withPrefix = "")
public static class RedeliveryRecipientBuilder {
// Filled by lombok
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.linecorp.bot.model.narrowcast.recipient.AudienceRecipient;
import com.linecorp.bot.model.narrowcast.recipient.LogicalOperatorRecipient;
import com.linecorp.bot.model.narrowcast.recipient.Recipient;
import com.linecorp.bot.model.narrowcast.recipient.RedeliveryRecipient;
import com.linecorp.bot.model.objectmapper.ModelObjectMapper;

public class NarrowcastTest {
Expand Down Expand Up @@ -90,6 +91,23 @@ public void testRecipientDeserializeOperator() throws JsonProcessingException {
assertThat(((LogicalOperatorRecipient) recipient).getAnd())
.isEqualTo(singletonList(AudienceRecipient.builder()
.audienceGroupId(5963L)
.build()));
.build()));
}

@Test
public void testRecipientDeserializeRedelivery() throws JsonProcessingException {
ObjectMapper objectMapper = ModelObjectMapper.createNewObjectMapper();
Recipient recipient = objectMapper.readValue(
//language=JSON
"{\n"
+ " \"type\": \"redelivery\",\n"
+ " \"requestId\": \"5b59509c-c57b-11e9-aa8c-2a2ae2dbcce4\"\n"
+ "}", Recipient.class);

assertThat(recipient)
.isInstanceOf(RedeliveryRecipient.class)
.isEqualTo(RedeliveryRecipient.builder()
.requestId("5b59509c-c57b-11e9-aa8c-2a2ae2dbcce4")
.build());
}
}

0 comments on commit 6ae80da

Please sign in to comment.