trailer_vote-api 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rubocop.yml +29 -0
  4. data/CHANGELOG.md +56 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +77 -0
  7. data/README.md +188 -0
  8. data/Rakefile +12 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/lib/trailer_vote/api.rb +67 -0
  12. data/lib/trailer_vote/api/autoload.rb +28 -0
  13. data/lib/trailer_vote/api/composable/common.rb +91 -0
  14. data/lib/trailer_vote/api/composable/get.rb +66 -0
  15. data/lib/trailer_vote/api/configuration.rb +69 -0
  16. data/lib/trailer_vote/api/errors.rb +113 -0
  17. data/lib/trailer_vote/api/fallback_content_types.rb +50 -0
  18. data/lib/trailer_vote/api/issue.rb +29 -0
  19. data/lib/trailer_vote/api/issue/create.rb +72 -0
  20. data/lib/trailer_vote/api/issue/find.rb +42 -0
  21. data/lib/trailer_vote/api/links.rb +54 -0
  22. data/lib/trailer_vote/api/place.rb +22 -0
  23. data/lib/trailer_vote/api/place/children.rb +33 -0
  24. data/lib/trailer_vote/api/place/children/urls.rb +67 -0
  25. data/lib/trailer_vote/api/place/create.rb +83 -0
  26. data/lib/trailer_vote/api/place/find.rb +60 -0
  27. data/lib/trailer_vote/api/place/lookup.rb +72 -0
  28. data/lib/trailer_vote/api/product.rb +31 -0
  29. data/lib/trailer_vote/api/product/create.rb +63 -0
  30. data/lib/trailer_vote/api/product/find.rb +55 -0
  31. data/lib/trailer_vote/api/product/image.rb +36 -0
  32. data/lib/trailer_vote/api/product/image/create.rb +83 -0
  33. data/lib/trailer_vote/api/product/image/find.rb +54 -0
  34. data/lib/trailer_vote/api/product/image/urls.rb +66 -0
  35. data/lib/trailer_vote/api/product/lookup.rb +95 -0
  36. data/lib/trailer_vote/api/product/place.rb +38 -0
  37. data/lib/trailer_vote/api/product/place/link.rb +75 -0
  38. data/lib/trailer_vote/api/product/update.rb +80 -0
  39. data/lib/trailer_vote/api/product/video.rb +36 -0
  40. data/lib/trailer_vote/api/product/video/create.rb +80 -0
  41. data/lib/trailer_vote/api/product/video/find.rb +56 -0
  42. data/lib/trailer_vote/api/product/video/urls.rb +66 -0
  43. data/lib/trailer_vote/api/push_recipe_android.rb +37 -0
  44. data/lib/trailer_vote/api/push_recipe_ios.rb +37 -0
  45. data/lib/trailer_vote/api/type_registry.rb +95 -0
  46. data/lib/trailer_vote/api/version.rb +7 -0
  47. data/lib/trailer_vote/api/vista_config.rb +37 -0
  48. data/trailer_vote-api.gemspec +45 -0
  49. metadata +261 -0
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types'
4
+
5
+ module TrailerVote
6
+ module Api
7
+ class PushRecipeIos
8
+ include Composable::Get
9
+
10
+ attr_accessor :client
11
+
12
+ SUCCESS = MediaTypes::PushRecipeIos.to_constructable.version(1)
13
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
14
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
15
+
16
+ def initialize(configuration: nil, result: nil)
17
+ self.configuration = configuration
18
+ self.result = result
19
+ end
20
+
21
+ def call(url: nil)
22
+ return self if ok? || !url
23
+
24
+ local_client = client
25
+ unless client
26
+ uri = URI(url)
27
+ local_client = TrailerVote::Api.default_unauthenticated_client
28
+ local_client = local_client.basic_auth(user: uri.user, pass: uri.password)
29
+ end
30
+
31
+ guard_network_errors do
32
+ branch(local_client.headers(Headers::ACCEPT => ACCEPT).get(url))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oj'
4
+ require 'media_types'
5
+ require 'trailer_vote/media_types'
6
+
7
+ module TrailerVote
8
+ module Api
9
+
10
+ module TypeRegistry
11
+ class << self
12
+ attr_accessor :registry, :registry_shortcuts
13
+ end
14
+
15
+ self.registry = {}
16
+ self.registry_shortcuts = {}
17
+
18
+ module_function
19
+
20
+ def [](key)
21
+ registry.fetch(key) { registry.fetch(registry_shortcuts.fetch(key)) }
22
+ rescue KeyError
23
+ raise UnknownMediaType, format('Unknown media type %<type>s', type: key)
24
+ end
25
+
26
+ def []=(key, value)
27
+ registry[key] = value
28
+ end
29
+
30
+ def shortcut(key, alias_name)
31
+ registry_shortcuts[alias_name] = key
32
+ end
33
+
34
+ def register(registerable)
35
+ mime_type = registerable.to_s
36
+
37
+ self[mime_type] = AdapterFor(registerable)
38
+ shortcut(mime_type, registerable.to_s)
39
+
40
+ registerable.available_validations.each do |alias_mime_type|
41
+ shortcut(mime_type, alias_mime_type)
42
+ end
43
+ end
44
+
45
+ class << self
46
+ private
47
+
48
+ # noinspection RubyClassMethodNamingConvention
49
+ def AdapterFor(media_type) # rubocop:disable Naming/MethodName
50
+ adapter_name = generate_adapter_name(media_type.identifier)
51
+
52
+ if const_defined?(adapter_name)
53
+ return const_get(adapter_name)
54
+ end
55
+
56
+ const_set(adapter_name, Module.new).tap do |adapter|
57
+ define_encode(adapter, media_type)
58
+ define_decode(adapter, media_type)
59
+ end
60
+ end
61
+
62
+ def generate_adapter_name(media_type)
63
+ media_type.split(%r{[./_+-]}).map(&:capitalize).join('').tr('^A-z0-9', '_')
64
+ end
65
+
66
+ def define_encode(adapter, media_type)
67
+ adapter.define_singleton_method(:encode) do |obj|
68
+ begin
69
+ media_type.validate!(obj)
70
+ Oj.dump(obj, mode: :compat)
71
+ rescue Oj::Error, ::MediaTypes::Scheme::ValidationError => err
72
+ raise EncodeError.new(media_type: media_type, source: err)
73
+ end
74
+ end
75
+ end
76
+
77
+ def define_decode(adapter, media_type)
78
+ adapter.define_singleton_method('decode') do |str|
79
+ begin
80
+ Oj.load(str, mode: :strict, symbol_keys: true).tap do |result|
81
+ begin
82
+ media_type.validate!(result)
83
+ rescue ::MediaTypes::Scheme::ValidationError => err
84
+ warn format('Decode error! API might now be in an invalid or incomplete state. %<err>s', err: err)
85
+ end
86
+ end
87
+ rescue Oj::Error => err
88
+ raise DecodeError.new(media_type: media_type, source: err)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrailerVote
4
+ module Api
5
+ VERSION = '3.1.0'
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types'
4
+
5
+ module TrailerVote
6
+ module Api
7
+ class VistaConfig
8
+ include Composable::Get
9
+
10
+ attr_accessor :client
11
+
12
+ SUCCESS = MediaTypes::VistaConfig.to_constructable.version(1).view(:collection)
13
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
14
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
15
+
16
+ def initialize(configuration: nil, result: nil)
17
+ self.configuration = configuration
18
+ self.result = result
19
+ end
20
+
21
+ def call(url: nil)
22
+ return self if ok? || !url
23
+
24
+ local_client = client
25
+ unless client
26
+ uri = URI(url)
27
+ local_client = TrailerVote::Api.default_unauthenticated_client
28
+ local_client = local_client.basic_auth(user: uri.user, pass: uri.password)
29
+ end
30
+
31
+ guard_network_errors do
32
+ branch(local_client.headers(Headers::ACCEPT => ACCEPT).get(url))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'trailer_vote/api/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'trailer_vote-api'
9
+ spec.version = TrailerVote::Api::VERSION
10
+ spec.authors = ['Derk-Jan Karrenbeld']
11
+ spec.email = ['dj@trailervote.com']
12
+ spec.homepage = 'https://github.com/TrailerVote/trailervote-api-clients'
13
+ spec.summary = 'Provides a client to interact with the TrailerVote API'
14
+
15
+ # noinspection RubyStringKeysInHashInspection
16
+ spec.metadata = {
17
+ 'bug_tracker_uri' => 'https://github.com/TrailerVote/trailervote-api-clients/issues',
18
+ 'changelog_uri' => 'https://github.com/TrailerVote/trailervote-api-clients/blob/master/ruby/CHANGELOG.md',
19
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/trailer_vote-api',
20
+ 'homepage_uri' => 'https://github.com/trailervote/trailervote-api-clients',
21
+ 'source_code_uri' => 'https://github.com/trailervote/trailervote-api-clients/blob/master/ruby',
22
+ 'wiki_uri' => 'https://docs.trailervote.com/reference/media-types'
23
+ }
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # spec.add_runtime_dependency 'httpx'
33
+ spec.add_runtime_dependency 'http', '>= 3.3.0', '<= 4.1.1'
34
+ spec.add_runtime_dependency 'oj', '>= 3.6', '< 4.x'
35
+ spec.add_runtime_dependency 'trailer_vote-media_types', '~> 3.0'
36
+
37
+ spec.add_development_dependency 'awesome_print', '~> 1.8'
38
+ spec.add_development_dependency 'bundler', '~> 1.16'
39
+ spec.add_development_dependency 'minitest', '~> 5.11'
40
+ spec.add_development_dependency 'minitest-ci', '~> 3.4'
41
+ spec.add_development_dependency 'minitest-reporters', '~> 1.3'
42
+ spec.add_development_dependency 'rake', '~> 13.0'
43
+ spec.add_development_dependency 'simplecov', '~> 0.16'
44
+ spec.add_development_dependency 'webmock', '~> 3.4'
45
+ end
metadata ADDED
@@ -0,0 +1,261 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trailer_vote-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Derk-Jan Karrenbeld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.0
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.1.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.3.0
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.1.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: oj
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3.6'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 4.x
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.6'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 4.x
53
+ - !ruby/object:Gem::Dependency
54
+ name: trailer_vote-media_types
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: awesome_print
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.8'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.8'
81
+ - !ruby/object:Gem::Dependency
82
+ name: bundler
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.16'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.16'
95
+ - !ruby/object:Gem::Dependency
96
+ name: minitest
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '5.11'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '5.11'
109
+ - !ruby/object:Gem::Dependency
110
+ name: minitest-ci
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.4'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.4'
123
+ - !ruby/object:Gem::Dependency
124
+ name: minitest-reporters
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.3'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '1.3'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rake
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '13.0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '13.0'
151
+ - !ruby/object:Gem::Dependency
152
+ name: simplecov
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0.16'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '0.16'
165
+ - !ruby/object:Gem::Dependency
166
+ name: webmock
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '3.4'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '3.4'
179
+ description:
180
+ email:
181
+ - dj@trailervote.com
182
+ executables: []
183
+ extensions: []
184
+ extra_rdoc_files: []
185
+ files:
186
+ - ".gitignore"
187
+ - ".rubocop.yml"
188
+ - CHANGELOG.md
189
+ - Gemfile
190
+ - Gemfile.lock
191
+ - README.md
192
+ - Rakefile
193
+ - bin/console
194
+ - bin/setup
195
+ - lib/trailer_vote/api.rb
196
+ - lib/trailer_vote/api/autoload.rb
197
+ - lib/trailer_vote/api/composable/common.rb
198
+ - lib/trailer_vote/api/composable/get.rb
199
+ - lib/trailer_vote/api/configuration.rb
200
+ - lib/trailer_vote/api/errors.rb
201
+ - lib/trailer_vote/api/fallback_content_types.rb
202
+ - lib/trailer_vote/api/issue.rb
203
+ - lib/trailer_vote/api/issue/create.rb
204
+ - lib/trailer_vote/api/issue/find.rb
205
+ - lib/trailer_vote/api/links.rb
206
+ - lib/trailer_vote/api/place.rb
207
+ - lib/trailer_vote/api/place/children.rb
208
+ - lib/trailer_vote/api/place/children/urls.rb
209
+ - lib/trailer_vote/api/place/create.rb
210
+ - lib/trailer_vote/api/place/find.rb
211
+ - lib/trailer_vote/api/place/lookup.rb
212
+ - lib/trailer_vote/api/product.rb
213
+ - lib/trailer_vote/api/product/create.rb
214
+ - lib/trailer_vote/api/product/find.rb
215
+ - lib/trailer_vote/api/product/image.rb
216
+ - lib/trailer_vote/api/product/image/create.rb
217
+ - lib/trailer_vote/api/product/image/find.rb
218
+ - lib/trailer_vote/api/product/image/urls.rb
219
+ - lib/trailer_vote/api/product/lookup.rb
220
+ - lib/trailer_vote/api/product/place.rb
221
+ - lib/trailer_vote/api/product/place/link.rb
222
+ - lib/trailer_vote/api/product/update.rb
223
+ - lib/trailer_vote/api/product/video.rb
224
+ - lib/trailer_vote/api/product/video/create.rb
225
+ - lib/trailer_vote/api/product/video/find.rb
226
+ - lib/trailer_vote/api/product/video/urls.rb
227
+ - lib/trailer_vote/api/push_recipe_android.rb
228
+ - lib/trailer_vote/api/push_recipe_ios.rb
229
+ - lib/trailer_vote/api/type_registry.rb
230
+ - lib/trailer_vote/api/version.rb
231
+ - lib/trailer_vote/api/vista_config.rb
232
+ - trailer_vote-api.gemspec
233
+ homepage: https://github.com/TrailerVote/trailervote-api-clients
234
+ licenses: []
235
+ metadata:
236
+ bug_tracker_uri: https://github.com/TrailerVote/trailervote-api-clients/issues
237
+ changelog_uri: https://github.com/TrailerVote/trailervote-api-clients/blob/master/ruby/CHANGELOG.md
238
+ documentation_uri: https://www.rubydoc.info/gems/trailer_vote-api
239
+ homepage_uri: https://github.com/trailervote/trailervote-api-clients
240
+ source_code_uri: https://github.com/trailervote/trailervote-api-clients/blob/master/ruby
241
+ wiki_uri: https://docs.trailervote.com/reference/media-types
242
+ post_install_message:
243
+ rdoc_options: []
244
+ require_paths:
245
+ - lib
246
+ required_ruby_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ required_rubygems_version: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - ">="
254
+ - !ruby/object:Gem::Version
255
+ version: '0'
256
+ requirements: []
257
+ rubygems_version: 3.1.2
258
+ signing_key:
259
+ specification_version: 4
260
+ summary: Provides a client to interact with the TrailerVote API
261
+ test_files: []