trailer_vote-api 0.8.2 → 0.8.3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +5 -3
- data/README.md +13 -12
- data/lib/trailer_vote/api/autoload.rb +3 -0
- data/lib/trailer_vote/api/issue/create.rb +72 -0
- data/lib/trailer_vote/api/issue/find.rb +42 -0
- data/lib/trailer_vote/api/issue.rb +31 -0
- data/lib/trailer_vote/api/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4ad9b6f52cdb85e1ccfda2c56f47483326b7af
|
4
|
+
data.tar.gz: 9647720f9c87abf3e54cc0e8c1682f1fec0b3eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca335c29541ad3333016bdf76abfaee34a73819599e5ff825c55ef04cbeac59b66add6e3efed6300fa2c768fdbc6a8f9be81f88262375cf38b7320d26e625d30
|
7
|
+
data.tar.gz: 9e3fa02068a7d4e94c3d40e11d64f6d9b05052fc26bdacd9d362292ba30c2388133805baea0ac89db4a7a68d93a87518ea37adf524d5192e4d21a1ee1261a174
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trailer_vote-api (0.8.
|
4
|
+
trailer_vote-api (0.8.3)
|
5
5
|
http (>= 3.3.0, < 4.x)
|
6
6
|
oj (>= 3.6, < 4.x)
|
7
7
|
trailer_vote-media_types (>= 0.6.1, < 1)
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
builder
|
40
40
|
minitest (>= 5.0)
|
41
41
|
ruby-progressbar
|
42
|
-
oj (3.6.
|
42
|
+
oj (3.6.12)
|
43
43
|
public_suffix (3.0.3)
|
44
44
|
rake (10.5.0)
|
45
45
|
ruby-progressbar (1.10.0)
|
@@ -49,10 +49,11 @@ GEM
|
|
49
49
|
json (>= 1.8, < 3)
|
50
50
|
simplecov-html (~> 0.10.0)
|
51
51
|
simplecov-html (0.10.2)
|
52
|
-
trailer_vote-media_types (0.
|
52
|
+
trailer_vote-media_types (0.8.0)
|
53
53
|
media_types (>= 0.6.0, < 1)
|
54
54
|
unf (0.1.4)
|
55
55
|
unf_ext
|
56
|
+
unf_ext (0.0.7.5)
|
56
57
|
unf_ext (0.0.7.5-x64-mingw32)
|
57
58
|
webmock (3.4.2)
|
58
59
|
addressable (>= 2.3.6)
|
@@ -60,6 +61,7 @@ GEM
|
|
60
61
|
hashdiff
|
61
62
|
|
62
63
|
PLATFORMS
|
64
|
+
ruby
|
63
65
|
x64-mingw32
|
64
66
|
|
65
67
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
[](https://travis-ci.com/TrailerVote/trailervote-api-clients)
|
3
3
|
[](https://badge.fury.io/rb/trailer_vote-api)
|
4
4
|
[](https://codeclimate.com/github/TrailerVote/trailervote-api-clients/maintainability)
|
5
|
+
[](https://depfu.com/github/TrailerVote/trailervote-api-clients?project_id=5890)
|
5
6
|
|
6
7
|
The TrailerVote Api gem is the official interface to communicate with the TrailerVote product service. It allows you to
|
7
|
-
keep your code simple and not deal with the HTTP suite.
|
8
|
+
keep your code simple and not deal with the HTTP suite.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -36,7 +37,7 @@ configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
|
36
37
|
# => TrailerVote::Api::Configuration
|
37
38
|
```
|
38
39
|
|
39
|
-
The TrailerVote API Client for Ruby uses a lazy chainable API and does **NOT** make any requests until it's absolutely necessary.
|
40
|
+
The TrailerVote API Client for Ruby uses a lazy chainable API and does **NOT** make any requests until it's absolutely necessary.
|
40
41
|
It is recommended that you re-use the configuration instance, as well as other results, in order to reduce network requests.
|
41
42
|
|
42
43
|
The common interface is:
|
@@ -52,7 +53,7 @@ Unless data is being posted, `#call` is not necessary:
|
|
52
53
|
```Ruby
|
53
54
|
configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
54
55
|
configuration.links
|
55
|
-
# => TrailerVote::Api::Links # Makes the HTTP call if necessary
|
56
|
+
# => TrailerVote::Api::Links # Makes the HTTP call if necessary
|
56
57
|
```
|
57
58
|
|
58
59
|
In case of an error, a `TrailerVote::Api::Error` is raised, with subclasses defining what went wrong. If the API gives back an error (HTTP status `(400..599)`), the error is parsed and turned into a `ErrorsResponse < Error` error.
|
@@ -81,9 +82,9 @@ require 'trailer_vote/api/product/lookup'
|
|
81
82
|
|
82
83
|
lookup = configuration.product.lookup
|
83
84
|
# => TrailerVote::Api::Product::Lookup
|
84
|
-
|
85
|
+
|
85
86
|
lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }, { authority: 'tmdb', identifier: '12345678' }])
|
86
|
-
# => TrailerVote::Api::Product::Find
|
87
|
+
# => TrailerVote::Api::Product::Find
|
87
88
|
```
|
88
89
|
|
89
90
|
### `configuration.product.update`
|
@@ -98,7 +99,7 @@ require 'trailer_vote/api/product/update'
|
|
98
99
|
lookup = configuration.product.lookup
|
99
100
|
product = lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
100
101
|
# => TrailerVote::Api::Product::Find
|
101
|
-
|
102
|
+
|
102
103
|
current_product_data = product.data
|
103
104
|
next_product_data = make_changes_to_product_data(current_product_data)
|
104
105
|
product.update.call(data: next_product_data)
|
@@ -109,7 +110,7 @@ If the update call fails with a `409 Conflict` or `412 Precondition Failed`, it
|
|
109
110
|
|
110
111
|
### `configuration.product.create`
|
111
112
|
Creating a product is similar to looking up a product. If successful, returns an actual `Product::Find`.
|
112
|
-
|
113
|
+
|
113
114
|
The `data` argument is wrapped in `{ product: data }` and then needs to match `application/vnd.trailervote.product.v2.create+json`
|
114
115
|
|
115
116
|
```Ruby
|
@@ -123,7 +124,7 @@ configuration.product.create(data: { title: 'My product', ... })
|
|
123
124
|
To attach an video to a product, you first need to find the product. This can be done by:
|
124
125
|
- `configuration.product.create`: creating a new product
|
125
126
|
- `configuration.product.lookup`: looking up an existing product
|
126
|
-
|
127
|
+
|
127
128
|
Once you have it, the video operations are available on the result.
|
128
129
|
|
129
130
|
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
@@ -134,7 +135,7 @@ require 'trailer_vote/api/product/video/create'
|
|
134
135
|
|
135
136
|
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
136
137
|
# => TrailerVote::Api::Product::Find
|
137
|
-
|
138
|
+
|
138
139
|
product.video.create(data: { source_url: '', ... })
|
139
140
|
# => TrailerVote::Api::Product::Video::Find
|
140
141
|
```
|
@@ -148,7 +149,7 @@ Gets all the image urls for a product
|
|
148
149
|
To attach an video to a product, you first need to find the product. This can be done by:
|
149
150
|
- `configuration.product.create`: creating a new product
|
150
151
|
- `configuration.product.lookup`: looking up an existing product
|
151
|
-
|
152
|
+
|
152
153
|
Once you have it, the video operations are available on the result.
|
153
154
|
|
154
155
|
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
@@ -159,7 +160,7 @@ require 'trailer_vote/api/product/video/create'
|
|
159
160
|
|
160
161
|
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
161
162
|
# => TrailerVote::Api::Product::Find
|
162
|
-
|
163
|
+
|
163
164
|
product.video.create(data: { source_url: '', ... })
|
164
165
|
# => TrailerVote::Api::Product::Video::Find
|
165
166
|
```
|
@@ -179,7 +180,7 @@ also run `bin/console` for an interactive prompt that will allow you to experime
|
|
179
180
|
|
180
181
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
181
182
|
version number in `version.rb`, and then run `bundle update trailer_vote-api` in any repository that depends on
|
182
|
-
this gem. If you have push rights, you may call `bundle exec rake release` to create a new git tag, push
|
183
|
+
this gem. If you have push rights, you may call `bundle exec rake release` to create a new git tag, push
|
183
184
|
git commits and tags, and push the `.gem` file to the rubygems gem server.
|
184
185
|
|
185
186
|
## Contributing
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'trailer_vote/api'
|
4
4
|
|
5
|
+
require 'trailer_vote/api/issue'
|
6
|
+
require 'trailer_vote/api/issue/create'
|
7
|
+
require 'trailer_vote/api/issue/find'
|
5
8
|
require 'trailer_vote/api/place'
|
6
9
|
require 'trailer_vote/api/place/create'
|
7
10
|
require 'trailer_vote/api/place/find'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/api/composable/common'
|
4
|
+
require 'trailer_vote/api/issue'
|
5
|
+
require 'trailer_vote/api/issue/find'
|
6
|
+
|
7
|
+
module TrailerVote
|
8
|
+
module Api
|
9
|
+
class Issue
|
10
|
+
|
11
|
+
def create
|
12
|
+
Create.new(configuration: configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Create
|
16
|
+
include Composable::Common
|
17
|
+
|
18
|
+
CONTENT = MediaTypes::Issue.to_constructable.version(1).view('create')
|
19
|
+
SUCCESS = MediaTypes::Issue.to_constructable.version(1)
|
20
|
+
FAILURE = MediaTypes::Errors.to_constructable.version(1)
|
21
|
+
|
22
|
+
ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
|
23
|
+
|
24
|
+
# @private
|
25
|
+
def initialize(configuration:)
|
26
|
+
self.configuration = configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def back
|
30
|
+
configuration.issue
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create an issue
|
34
|
+
#
|
35
|
+
# @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/Issue TrailerVote::MediaTypes::Issue
|
36
|
+
#
|
37
|
+
# @param [String, Hash] data the data conform to the Issue media type
|
38
|
+
# @param [String] url (#resolve_url result) the url to post to
|
39
|
+
#
|
40
|
+
# @return [TrailerVote::Api::Issue]
|
41
|
+
def call(data:, url: resolve_url)
|
42
|
+
guard_network_errors do
|
43
|
+
body = encode(data)
|
44
|
+
branch(
|
45
|
+
resolve_client.headers(
|
46
|
+
Headers::ACCEPT => ACCEPT,
|
47
|
+
Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
|
48
|
+
).post(url, body: body),
|
49
|
+
data: data
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_accessor :configuration
|
57
|
+
|
58
|
+
def resolve_url
|
59
|
+
configuration.links.issues
|
60
|
+
end
|
61
|
+
|
62
|
+
def encode(data)
|
63
|
+
TrailerVote::Api.encode(CONTENT, issue: data)
|
64
|
+
end
|
65
|
+
|
66
|
+
def redirect_klazz
|
67
|
+
Find
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/api/composable/get'
|
4
|
+
require 'trailer_vote/api/issue'
|
5
|
+
|
6
|
+
module TrailerVote
|
7
|
+
module Api
|
8
|
+
class Issue
|
9
|
+
class Find
|
10
|
+
include Composable::Get
|
11
|
+
|
12
|
+
SUCCESS = MediaTypes::Issue.to_constructable.version(1)
|
13
|
+
FAILURE = MediaTypes::Errors.to_constructable.version(1)
|
14
|
+
|
15
|
+
ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
|
16
|
+
|
17
|
+
def initialize(configuration:, result: nil)
|
18
|
+
self.configuration = configuration
|
19
|
+
self.result = result
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [TrailerVote::Api::Configuration, TrailerVote::Api::Issue::Create]
|
23
|
+
def back
|
24
|
+
backtrack = result
|
25
|
+
backtrack = result.back while backtrack&.is_a?(self.class)
|
26
|
+
backtrack || configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(url: nil)
|
30
|
+
return self if ok? || !url
|
31
|
+
guard_network_errors do
|
32
|
+
branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def data
|
37
|
+
to_h[:issue]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/media_types'
|
4
|
+
require 'trailer_vote/api/configuration'
|
5
|
+
|
6
|
+
module TrailerVote
|
7
|
+
module Api
|
8
|
+
class Configuration
|
9
|
+
# @return [TrailerVote::Api::Issue::Find] issues attached to the credentials
|
10
|
+
def issue
|
11
|
+
Issue.new(configuration: self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Issue
|
16
|
+
def initialize(configuration:)
|
17
|
+
self.configuration = configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def back
|
21
|
+
configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_accessor :configuration
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
TrailerVote::MediaTypes::Issue.register
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailer_vote-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -205,6 +205,9 @@ files:
|
|
205
205
|
- lib/trailer_vote/api/configuration.rb
|
206
206
|
- lib/trailer_vote/api/errors.rb
|
207
207
|
- lib/trailer_vote/api/fallback_content_types.rb
|
208
|
+
- lib/trailer_vote/api/issue.rb
|
209
|
+
- lib/trailer_vote/api/issue/create.rb
|
210
|
+
- lib/trailer_vote/api/issue/find.rb
|
208
211
|
- lib/trailer_vote/api/links.rb
|
209
212
|
- lib/trailer_vote/api/place.rb
|
210
213
|
- lib/trailer_vote/api/place/create.rb
|