level_travel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6463a5dd4e26e45033296ba9d8002e6a7171f2c8f48c47243a7496456b31a29b
4
+ data.tar.gz: ce029033e6ab06c9375e6794c465a79b1de13aa933af84594ee99891f03f178e
5
+ SHA512:
6
+ metadata.gz: 9c992179ae33396f1d544c04df20a2a0893a0b7af3516a2ecb9d4db5f88add232229f52e7c70a633d24b781e1f60ef9c3c86abb2a7ad4b53b81ea9465f4e30dc
7
+ data.tar.gz: 57d108e758d90a6cd548422e79a3d55b2f8e315cba6b1303eab91643df2721a3a94cf3b639b646054927891c959927d9b399c923986439538147784d781fe07a
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'level_travel'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/bin/test ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle exec reek
7
+ bundle exec rubocop --parallel --extra-details --display-style-guide
8
+ bundle exec rspec
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ class References
5
+ def self.departures(prioritized_count: 0)
6
+ get('departures', prioritized_count: prioritized_count)
7
+ end
8
+
9
+ def self.destinations
10
+ get('destinations')
11
+ end
12
+
13
+ def self.operators
14
+ get('operators')
15
+ end
16
+
17
+ def self.airlines
18
+ get('airlines')
19
+ end
20
+
21
+ def self.airports
22
+ get('airports')
23
+ end
24
+
25
+ def self.hotel_dump
26
+ get('hotel_dump')
27
+ end
28
+
29
+ def self.hotel_room_dump
30
+ get('hotel_room_dump')
31
+ end
32
+
33
+ # :reek:BooleanParameter
34
+ def self.hotels(hotel_ids: [], region_ids: [], csv: false)
35
+ get(
36
+ 'hotels',
37
+ hotel_ids: hotel_ids, region_ids: region_ids, csv: csv
38
+ )
39
+ end
40
+
41
+ # :reek:LongParameterList
42
+ def self.flights_and_nights(city_from:, country_to:, start_date:, end_date:)
43
+ get(
44
+ 'flights_and_nights',
45
+ city_from: city_from, country_to: country_to, start_date: start_date, end_date: end_date
46
+ )
47
+ end
48
+
49
+ def self.get(data, params = {})
50
+ ::LevelTravel::Request.get('/references/' + data, params)
51
+ end
52
+
53
+ private_class_method :get
54
+ end
55
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'oj'
5
+ require 'dry-struct'
6
+
7
+ module LevelTravel
8
+ class Request
9
+ HOST = 'https://api.level.travel'
10
+
11
+ class Response < Dry::Struct
12
+ attribute :code, ::LevelTravel::Types::Strict::Integer
13
+ attribute :error, ::LevelTravel::Types::Strict::String.optional
14
+ attribute :body, ::LevelTravel::Types::Strict::Hash
15
+
16
+ def success?
17
+ code == 200
18
+ end
19
+
20
+ def failure?
21
+ !success?
22
+ end
23
+ end
24
+
25
+ def self.get(url, params = {})
26
+ response = request_client.get(url) do |request|
27
+ request.params = params
28
+ request.options.timeout = LevelTravel::Settings.timeout
29
+ end
30
+
31
+ body = Oj.load(response.body, symbol_keys: true, mode: :compat)
32
+ Response.new(code: response.status, error: body[:error], body: body)
33
+ end
34
+
35
+ def self.headers
36
+ {
37
+ Accept: 'application/vnd.leveltravel.v3',
38
+ Authorization: format('Token token="%<api_token>s"', api_token: LevelTravel::Settings.api_token)
39
+ }
40
+ end
41
+
42
+ def self.request_client
43
+ Faraday.new(url: HOST, headers: headers)
44
+ end
45
+
46
+ private_class_method :headers, :request_client
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ module Settings
5
+ module_function
6
+
7
+ DEFAULT_TIMEOUT = 10
8
+
9
+ def api_token
10
+ @api_token
11
+ end
12
+
13
+ def api_token=(token)
14
+ @api_token = token
15
+ end
16
+
17
+ def timeout
18
+ @timeout || DEFAULT_TIMEOUT
19
+ end
20
+
21
+ def timeout=(seconds)
22
+ @timeout = seconds
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-types'
4
+
5
+ module LevelTravel
6
+ module Types
7
+ include Dry.Types(:params, :strict, default: :strict)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LevelTravel
4
+ end
5
+
6
+ require 'level_travel/version'
7
+ require 'level_travel/types'
8
+ require 'level_travel/settings'
9
+ require 'level_travel/request'
10
+ require 'level_travel/references'
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: level_travel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Rodionov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: reek
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 5.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 5.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.78.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.78.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.37'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.37'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '3.7'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '3.7'
195
+ description: Wrapper for level.travel API
196
+ email:
197
+ - pasha.rod@mail.ru
198
+ executables:
199
+ - console
200
+ - setup
201
+ - test
202
+ extensions: []
203
+ extra_rdoc_files: []
204
+ files:
205
+ - bin/console
206
+ - bin/setup
207
+ - bin/test
208
+ - lib/level_travel.rb
209
+ - lib/level_travel/references.rb
210
+ - lib/level_travel/request.rb
211
+ - lib/level_travel/settings.rb
212
+ - lib/level_travel/types.rb
213
+ - lib/level_travel/version.rb
214
+ homepage: https://github.com/lookmytour/level_travel
215
+ licenses:
216
+ - MIT
217
+ metadata:
218
+ allowed_push_host: https://rubygems.org
219
+ homepage_uri: https://github.com/lookmytour/level_travel
220
+ source_code_uri: https://github.com/lookmytour/level_travel
221
+ changelog_uri: https://github.com/lookmytour/level_travel/blob/master/CHANGELOG.md
222
+ post_install_message:
223
+ rdoc_options: []
224
+ require_paths:
225
+ - lib
226
+ required_ruby_version: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ required_rubygems_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ requirements: []
237
+ rubygems_version: 3.1.2
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: Wrapper for level.travel API
241
+ test_files: []