|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +"""linebot.models.filter module.""" |
| 16 | + |
| 17 | +from __future__ import unicode_literals |
| 18 | + |
| 19 | +from abc import ABCMeta |
| 20 | + |
| 21 | +from future.utils import with_metaclass |
| 22 | + |
| 23 | +from .base import Base |
| 24 | + |
| 25 | + |
| 26 | +class Filter(with_metaclass(ABCMeta, Base)): |
| 27 | + """Filter. |
| 28 | +
|
| 29 | + https://developers.line.biz/en/reference/messaging-api/#narrowcast-demographic-filter |
| 30 | +
|
| 31 | + A filter is the top-level structure of a demographic element. |
| 32 | + """ |
| 33 | + |
| 34 | + def __init__(self, demographic=None, **kwargs): |
| 35 | + """__init__ method. |
| 36 | +
|
| 37 | + :param demographic: Combination of different criteria using logical |
| 38 | + operator objects. |
| 39 | + :type demographic: :py:class:`linebot.model.DemographicFilter` | |
| 40 | + :py:class:`linebot.model.Operator` |
| 41 | + :param kwargs: |
| 42 | + """ |
| 43 | + super(Filter, self).__init__(**kwargs) |
| 44 | + |
| 45 | + self.demographic = demographic |
| 46 | + |
| 47 | + |
| 48 | +class DemographicFilter(Filter): |
| 49 | + """DemographicFilter. |
| 50 | +
|
| 51 | + https://developers.line.biz/en/reference/messaging-api/#narrowcast-demographic-filter |
| 52 | +
|
| 53 | + Demographic filter objects represent criteria (e.g. age, gender, OS, region, |
| 54 | + and friendship duration) on which to filter the list of recipients. |
| 55 | + You can filter recipients based on a combination of different criteria using |
| 56 | + logical operator objects. |
| 57 | + """ |
| 58 | + |
| 59 | + def __init__(self, **kwargs): |
| 60 | + """__init__ method. |
| 61 | +
|
| 62 | + :param kwargs: |
| 63 | + """ |
| 64 | + super(DemographicFilter, self).__init__(**kwargs) |
| 65 | + |
| 66 | + self.type = None |
| 67 | + |
| 68 | + |
| 69 | +class GenderFilter(DemographicFilter): |
| 70 | + """GenderFilter.""" |
| 71 | + |
| 72 | + def __init__(self, one_of=[], **kwargs): |
| 73 | + """__init__ method. |
| 74 | +
|
| 75 | + :param one_of: Send messages to users of a given gender. One of: |
| 76 | + male: Users who identify as male |
| 77 | + female: Users who identify as female |
| 78 | + :type one_of: list[str] |
| 79 | + """ |
| 80 | + super(GenderFilter, self).__init__(**kwargs) |
| 81 | + |
| 82 | + self.type = "gender" |
| 83 | + self.one_of = one_of |
| 84 | + |
| 85 | + |
| 86 | +class AppTypeFilter(DemographicFilter): |
| 87 | + """AppTypeFilter.""" |
| 88 | + |
| 89 | + def __init__(self, one_of=[], **kwargs): |
| 90 | + """__init__ method. |
| 91 | +
|
| 92 | + :param one_of: Send messages to users of the specified OS. One of: |
| 93 | + ios: Users who using iOS. |
| 94 | + android: Users who using Android. |
| 95 | + :type one_of: list[str] |
| 96 | + """ |
| 97 | + super(AppTypeFilter, self).__init__(**kwargs) |
| 98 | + |
| 99 | + self.type = "appType" |
| 100 | + self.one_of = one_of |
| 101 | + |
| 102 | + |
| 103 | +class AreaFilter(DemographicFilter): |
| 104 | + """AreaFilter.""" |
| 105 | + |
| 106 | + def __init__(self, one_of=[], **kwargs): |
| 107 | + """__init__ method. |
| 108 | +
|
| 109 | + :param one_of: Send messages to users in the specified region. |
| 110 | + :type one_of: list[str] |
| 111 | + """ |
| 112 | + super(AreaFilter, self).__init__(**kwargs) |
| 113 | + |
| 114 | + self.type = "area" |
| 115 | + self.one_of = one_of |
| 116 | + |
| 117 | + |
| 118 | +class AgeFilter(DemographicFilter): |
| 119 | + """AgeFilter. |
| 120 | +
|
| 121 | + This lets you filter recipients with a given age range. |
| 122 | + """ |
| 123 | + |
| 124 | + def __init__(self, gte=None, lt=None, **kwargs): |
| 125 | + """__init__ method. |
| 126 | +
|
| 127 | + Be sure to specify either gte, lt, or both. |
| 128 | +
|
| 129 | + :param gte: Send messages to users at least as old as the specified age. |
| 130 | + :type gte: str |
| 131 | + :param lt: Send messages to users younger than the specified age. |
| 132 | + You can specify the same values as for the gte property. |
| 133 | + :type lt: str |
| 134 | + """ |
| 135 | + super(AgeFilter, self).__init__(**kwargs) |
| 136 | + |
| 137 | + self.type = "age" |
| 138 | + self.gte = gte |
| 139 | + self.lt = lt |
| 140 | + |
| 141 | + |
| 142 | +class SubscriptionPeriodFilter(DemographicFilter): |
| 143 | + """SubscriptionPeriodFilter. |
| 144 | +
|
| 145 | + This lets you filter recipients with a given range of friendship durations. |
| 146 | + """ |
| 147 | + |
| 148 | + def __init__(self, gte=None, lt=None, **kwargs): |
| 149 | + """__init__ method. |
| 150 | +
|
| 151 | + Be sure to specify either gte, lt, or both. |
| 152 | +
|
| 153 | + :param gte: Send messages to users who have been friends of yours for |
| 154 | + at least the specified number of days |
| 155 | + :type gte: str |
| 156 | + :param lt: Send messages to users who have been friends of yours for |
| 157 | + less than the specified number of days. |
| 158 | + You can specify the same values as for the gte property. |
| 159 | + :type lt: str |
| 160 | + """ |
| 161 | + super(SubscriptionPeriodFilter, self).__init__(**kwargs) |
| 162 | + |
| 163 | + self.type = "subscriptionPeriod" |
| 164 | + self.gte = gte |
| 165 | + self.lt = lt |
0 commit comments