level_travel 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44502eb17d2849d9a9d31728b28a69828a010bb6559ae40760f6c7f785e4e52f
4
- data.tar.gz: f46cc798104dc43a16e6c5c0bd968c8de07554c0bb4a3226bd53ba554d0f6cfd
3
+ metadata.gz: b0844303ab184bf8b8ceaa7896691acf40a9489fe03ef48985a6e359aa492e84
4
+ data.tar.gz: 2ee5a79a248d9848570897a952da85031df371bcc934df1e691d202c5000c098
5
5
  SHA512:
6
- metadata.gz: 5090859c773f9d38d6d2232fb3dcc55d6283ef38964c27021235cf3aec9f09e4ddbcafd229ac2ece60fa23fefd46c5fae911820f4cf28d2611b4eb635e16041a
7
- data.tar.gz: 21d6a7b21f23746149df5e9aff98ca21e8c51d54cbcaa6992b68e10c6fe6aa2a12cec98bec78e374a1aa3b30363473e80306721b00cb8bc8bc6c3fa076b9f8a8
6
+ metadata.gz: c31fab7d9e96887687307a12e93d577b168eb41134bd18fe5655f5d43a5302ed34f1ffc167126019dbc41b754b821c82ec699cc8de1b9a999bb82769b9fc22ea
7
+ data.tar.gz: 46267bd8d0b94ee6862e8ef1bef36f7e8fff56cbfe9b894b7653c999adb5aedec0c5cb9fce896a8ef15ab47ad41dca9d285dad2fc2ca328be10daf900f778502
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ module HotTours
5
+ class Get
6
+ # @param hot_tours_params [LevelTravel::HotTours::Params] Request params for getting hot tours
7
+ def self.call(hot_tours_params)
8
+ ::LevelTravel::Request.get('/hot/tours', hot_tours_params.to_h)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ module HotTours
5
+ class Params < Dry::Struct
6
+ attribute? :countries, Types::Array.of(Types::Strict::String)
7
+ attribute :start_date, Types::Strict::Date
8
+ attribute :end_date, Types::Strict::Date
9
+ attribute? :nights, Types::Array.of(Types::Strict::Integer)
10
+ attribute? :stars, Types::Array.of(Types::Strict::Integer)
11
+ attribute? :adults, Types::Strict::Integer
12
+ attribute? :pansions, Types::Array.of(Types::Strict::String)
13
+ attribute :sort_by, ParamsContract::SORT_VARIANTS
14
+ attribute? :min_price, Types::Strict::Integer
15
+ attribute? :max_price, Types::Strict::Integer
16
+ attribute? :per_page, Types::Strict::Integer
17
+ attribute? :page, Types::Strict::Integer
18
+
19
+ def to_h
20
+ result = super.merge(
21
+ start_date: start_date.strftime('%d.%m.%Y'),
22
+ end_date: end_date.strftime('%d.%m.%Y')
23
+ )
24
+
25
+ %i[countries nights stars pansions].each do |attr|
26
+ result = result.merge(attr => public_send(attr).join(',')) if result[attr]
27
+ end
28
+
29
+ result
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ module HotTours
5
+ # :reek:RepeatedConditional
6
+ class ParamsContract < Dry::Validation::Contract
7
+ config.messages.default_locale = :en
8
+ config.messages.top_namespace = 'level_travel'
9
+ config.messages.load_paths << File.expand_path('../../../config/errors.yml', __dir__).freeze
10
+
11
+ RANGES = {
12
+ stars: (1..5).freeze,
13
+ nights: (0..30).freeze
14
+ }.freeze
15
+ PANSIONS = {
16
+ RO: 'Без питания',
17
+ BB: 'Завтрак',
18
+ HB: 'Завтрак и ужин',
19
+ FB: 'Завтрак, обед, ужин',
20
+ AI: 'Всё включено',
21
+ UAI: 'Ультра всё включено',
22
+ AI24: 'Всё включено 24 часа',
23
+ 'HB+': 'Завтрак и ужин +',
24
+ BBL: 'Континентальный завтрак (лёгкий)',
25
+ HBL: 'Завтрак и обед',
26
+ DNR: 'Ужин'
27
+ }.freeze
28
+ PANSIONS_VARIANTS = PANSIONS.keys.map(&:to_s).freeze
29
+ SORT_VARIANTS = Types::String.enum('prices', 'dates')
30
+
31
+ # TODO: from_city, to_country, and to_city are also possible to be an ID
32
+ params do
33
+ optional(:countries).value(Types::Array.of(Types::Strict::String))
34
+ required(:start_date).value(:date)
35
+ required(:end_date).value(:date)
36
+ optional(:nights).value(Types::ArrayOfIntegers)
37
+ optional(:stars).value(Types::ArrayOfIntegers)
38
+ optional(:adults).value(:integer)
39
+ optional(:pansions).filled(Types::Array.of(Types::Strict::String))
40
+ required(:sort_by).filled(SORT_VARIANTS)
41
+ optional(:min_price).filled(:integer)
42
+ optional(:max_price).value(:integer)
43
+ optional(:per_page).value(:integer)
44
+ optional(:page).value(:integer)
45
+ end
46
+
47
+ rule(:start_date) do
48
+ key.failure(:invalid) if value <= Date.today
49
+ end
50
+
51
+ rule(:end_date) do
52
+ key.failure(:invalid) if value <= values[:start_date]
53
+ end
54
+
55
+ rule(:adults) do
56
+ if key?
57
+ key.failure(:invalid) unless value.positive?
58
+ key.failure(:invalid) if value > 10
59
+ end
60
+ end
61
+
62
+ rule(:pansions) do
63
+ key.failure(:invalid) if key? && value.any? { |pansion| !PANSIONS_VARIANTS.include?(pansion) }
64
+ end
65
+
66
+ rule(:stars) do
67
+ if key? && value.any? { |rating| !RANGES.fetch(:stars).include?(rating) }
68
+ key.failure(:not_in_range, range: RANGES.fetch(:stars))
69
+ end
70
+ end
71
+
72
+ rule(:min_price) do
73
+ key.failure(:invalid) if key? && !value.positive?
74
+ end
75
+
76
+ rule(:max_price) do
77
+ if key?
78
+ key.failure(:invalid) unless value.positive?
79
+ key.failure(:invalid) if value < values[:min_price]
80
+ end
81
+ end
82
+
83
+ rule(:nights) do
84
+ if key?
85
+ key.failure(:invalid) if value.size != 2
86
+ key.failure(:invalid) if value[0] > value[1]
87
+
88
+ if value.any? { |nights| !RANGES.fetch(:nights).include?(nights) }
89
+ key.failure(:not_in_range, range: RANGES.fetch(:nights))
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -3,17 +3,17 @@
3
3
  module LevelTravel
4
4
  module Search
5
5
  class Params < Dry::Struct
6
- attribute :from_city, ::LevelTravel::Types::Strict::String
7
- attribute :to_country, ::LevelTravel::Types::Strict::String
8
- attribute? :to_city, ::LevelTravel::Types::Strict::String.optional
9
- attribute? :hotel_ids, ::LevelTravel::Types.Array(::LevelTravel::Types::Strict::Integer).optional
10
- attribute :nights, ::LevelTravel::Types::Strict::Integer
11
- attribute :adults, ::LevelTravel::Types::Strict::Integer
12
- attribute :start_date, ::LevelTravel::Types::Strict::Date
13
- attribute? :kids, ::LevelTravel::Types::Strict::Integer.optional
14
- attribute? :kids_ages, ::LevelTravel::Types.Array(::LevelTravel::Types::Strict::Integer).optional
15
- attribute? :stars_from, ::LevelTravel::Types::Strict::Integer.optional
16
- attribute? :stars_to, ::LevelTravel::Types::Strict::Integer.optional
6
+ attribute :from_city, Types::Strict::String
7
+ attribute :to_country, Types::Strict::String
8
+ attribute? :to_city, Types::Strict::String
9
+ attribute? :hotel_ids, Types.Array(Types::Strict::Integer)
10
+ attribute :nights, Types::Strict::Integer
11
+ attribute :adults, Types::Strict::Integer
12
+ attribute :start_date, Types::Strict::Date
13
+ attribute? :kids, Types::Strict::Integer
14
+ attribute? :kids_ages, Types.Array(Types::Strict::Integer)
15
+ attribute? :stars_from, Types::Strict::Integer
16
+ attribute? :stars_to, Types::Strict::Integer
17
17
 
18
18
  def to_h
19
19
  result = super.merge(start_date: start_date.strftime('%d.%m.%Y'))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LevelTravel
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/level_travel.rb CHANGED
@@ -16,3 +16,7 @@ require 'level_travel/references'
16
16
  require 'level_travel/search/params_contract'
17
17
  require 'level_travel/search/params'
18
18
  require 'level_travel/search/request'
19
+
20
+ require 'level_travel/hot_tours/params_contract'
21
+ require 'level_travel/hot_tours/params'
22
+ require 'level_travel/hot_tours/get'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: level_travel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Rodionov
@@ -220,6 +220,9 @@ files:
220
220
  - bin/setup
221
221
  - bin/test
222
222
  - lib/level_travel.rb
223
+ - lib/level_travel/hot_tours/get.rb
224
+ - lib/level_travel/hot_tours/params.rb
225
+ - lib/level_travel/hot_tours/params_contract.rb
223
226
  - lib/level_travel/references.rb
224
227
  - lib/level_travel/request.rb
225
228
  - lib/level_travel/search/params.rb