|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2016 Algolia |
| 5 | + * http://www.algolia.com/ |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +package algolia.definitions |
| 27 | + |
| 28 | +import algolia.http.{DELETE, GET, HttpPayload, POST} |
| 29 | +import algolia.objects.{RequestOptions, SetStrategyRequest} |
| 30 | +import org.json4s.Formats |
| 31 | +import org.json4s.native.Serialization.write |
| 32 | + |
| 33 | +case class GeStrategyDefinition( |
| 34 | + requestOptions: Option[RequestOptions] = None |
| 35 | +)(implicit val formats: Formats) |
| 36 | + extends Definition { |
| 37 | + |
| 38 | + override type T = GeStrategyDefinition |
| 39 | + |
| 40 | + override def options( |
| 41 | + requestOptions: RequestOptions |
| 42 | + ): GeStrategyDefinition = |
| 43 | + copy(requestOptions = Some(requestOptions)) |
| 44 | + |
| 45 | + override private[algolia] def build(): HttpPayload = { |
| 46 | + HttpPayload( |
| 47 | + GET, |
| 48 | + Seq("1", "strategies", "personalization"), |
| 49 | + isSearch = false, |
| 50 | + isPersonalization = true, |
| 51 | + requestOptions = requestOptions |
| 52 | + ) |
| 53 | + } |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +case class SetStrategyDefinition( |
| 58 | + s: SetStrategyRequest, |
| 59 | + requestOptions: Option[RequestOptions] = None |
| 60 | +)(implicit val formats: Formats) |
| 61 | + extends Definition { |
| 62 | + |
| 63 | + override type T = SetStrategyDefinition |
| 64 | + |
| 65 | + override def options( |
| 66 | + requestOptions: RequestOptions |
| 67 | + ): SetStrategyDefinition = |
| 68 | + copy(requestOptions = Some(requestOptions)) |
| 69 | + |
| 70 | + override private[algolia] def build(): HttpPayload = { |
| 71 | + HttpPayload( |
| 72 | + POST, |
| 73 | + Seq("1", "strategies", "personalization"), |
| 74 | + body = Some(write(s)), |
| 75 | + isSearch = false, |
| 76 | + isPersonalization = true, |
| 77 | + requestOptions = requestOptions |
| 78 | + ) |
| 79 | + } |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +case class GetPersonalizationProfileDefinition( |
| 84 | + userToken: String, |
| 85 | + requestOptions: Option[RequestOptions] = None |
| 86 | +)(implicit val formats: Formats) |
| 87 | + extends Definition { |
| 88 | + override type T = GetPersonalizationProfileDefinition |
| 89 | + |
| 90 | + override def options( |
| 91 | + requestOptions: RequestOptions |
| 92 | + ): GetPersonalizationProfileDefinition = |
| 93 | + copy(requestOptions = Some(requestOptions)) |
| 94 | + |
| 95 | + override private[algolia] def build() = { |
| 96 | + HttpPayload( |
| 97 | + GET, |
| 98 | + Seq("1", "profiles", "personalization", userToken), |
| 99 | + isSearch = false, |
| 100 | + isPersonalization = true, |
| 101 | + requestOptions = requestOptions |
| 102 | + ) |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +case class DeletePersonalizationProfileDefinition( |
| 107 | + userToken: String, |
| 108 | + requestOptions: Option[RequestOptions] = None |
| 109 | +)(implicit val formats: Formats) |
| 110 | + extends Definition { |
| 111 | + override type T = DeletePersonalizationProfileDefinition |
| 112 | + |
| 113 | + override def options( |
| 114 | + requestOptions: RequestOptions |
| 115 | + ): DeletePersonalizationProfileDefinition = |
| 116 | + copy(requestOptions = Some(requestOptions)) |
| 117 | + |
| 118 | + override private[algolia] def build() = { |
| 119 | + HttpPayload( |
| 120 | + DELETE, |
| 121 | + Seq("1", "profiles", userToken), |
| 122 | + isSearch = false, |
| 123 | + isPersonalization = true, |
| 124 | + requestOptions = requestOptions |
| 125 | + ) |
| 126 | + } |
| 127 | +} |
0 commit comments