trailer_vote-api 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +13 -13
- data/.rubocop.yml +29 -29
- data/CHANGELOG.md +56 -56
- data/Gemfile +6 -6
- data/Gemfile.lock +10 -11
- data/README.md +188 -188
- data/Rakefile +12 -12
- data/bin/console +15 -15
- data/bin/setup +8 -8
- data/lib/trailer_vote/api.rb +43 -43
- data/lib/trailer_vote/api/autoload.rb +24 -22
- data/lib/trailer_vote/api/composable/common.rb +91 -91
- data/lib/trailer_vote/api/composable/get.rb +66 -66
- data/lib/trailer_vote/api/configuration.rb +71 -71
- data/lib/trailer_vote/api/errors.rb +115 -115
- data/lib/trailer_vote/api/fallback_content_types.rb +50 -50
- data/lib/trailer_vote/api/issue.rb +31 -31
- data/lib/trailer_vote/api/issue/create.rb +72 -72
- data/lib/trailer_vote/api/issue/find.rb +42 -42
- data/lib/trailer_vote/api/links.rb +54 -54
- data/lib/trailer_vote/api/place.rb +24 -24
- data/lib/trailer_vote/api/place/children.rb +33 -0
- data/lib/trailer_vote/api/place/children/urls.rb +67 -0
- data/lib/trailer_vote/api/place/create.rb +83 -83
- data/lib/trailer_vote/api/place/find.rb +60 -59
- data/lib/trailer_vote/api/product.rb +33 -33
- data/lib/trailer_vote/api/product/create.rb +63 -63
- data/lib/trailer_vote/api/product/find.rb +55 -55
- data/lib/trailer_vote/api/product/image.rb +38 -38
- data/lib/trailer_vote/api/product/image/create.rb +83 -83
- data/lib/trailer_vote/api/product/image/find.rb +54 -54
- data/lib/trailer_vote/api/product/image/urls.rb +66 -66
- data/lib/trailer_vote/api/product/lookup.rb +97 -97
- data/lib/trailer_vote/api/product/place.rb +40 -40
- data/lib/trailer_vote/api/product/place/link.rb +75 -75
- data/lib/trailer_vote/api/product/update.rb +80 -80
- data/lib/trailer_vote/api/product/video.rb +38 -38
- data/lib/trailer_vote/api/product/video/create.rb +80 -80
- data/lib/trailer_vote/api/product/video/find.rb +56 -56
- data/lib/trailer_vote/api/product/video/urls.rb +66 -66
- data/lib/trailer_vote/api/type_registry.rb +99 -99
- data/lib/trailer_vote/api/version.rb +7 -7
- data/trailer_vote-api.gemspec +45 -45
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: baf64ce0088b018665613dcc161724f231bf472d337c1211d8c4d667c071779b
|
4
|
+
data.tar.gz: a268451a8680cd70159046acf5b586ee79ef132ae508b9c73d16b374f33b5aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ce14102cbd477234327f251c29e837212df319e3306601a25e39de7706302eb53f34ed6745996c6b3895e081af55c6bff9d502c14a95372e3d16171d8427a1d
|
7
|
+
data.tar.gz: 4257f218530a0d488923e3eb6ea8479350356c1c8d32d066afd46e123e037ff029a9530d7bbe74e16e6eb68f76f58d9664f81e96152db018fb6fc88f34fac10f
|
data/.gitignore
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/test/reports/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
/bin/c
|
11
|
-
/.byebug_history
|
12
|
-
/.rakeTasks
|
13
|
-
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/test/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
/bin/c
|
11
|
+
/.byebug_history
|
12
|
+
/.rakeTasks
|
13
|
+
|
data/.rubocop.yml
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
AllCops:
|
2
|
-
Include:
|
3
|
-
- '**/Rakefile'
|
4
|
-
- 'lib/**/*.rb'
|
5
|
-
Exclude:
|
6
|
-
- 'Gemfile'
|
7
|
-
- 'bin/**/*'
|
8
|
-
TargetRubyVersion: 2.4
|
9
|
-
|
10
|
-
Layout/EmptyLinesAroundClassBody:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Layout/EndOfLine:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Metrics/LineLength:
|
17
|
-
Max: 120
|
18
|
-
|
19
|
-
Metrics/MethodLength:
|
20
|
-
Max: 15
|
21
|
-
|
22
|
-
Style/Documentation:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/EmptyMethod:
|
26
|
-
EnforcedStyle: expanded
|
27
|
-
|
28
|
-
Style/IfUnlessModifier:
|
29
|
-
Enabled: false
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/Rakefile'
|
4
|
+
- 'lib/**/*.rb'
|
5
|
+
Exclude:
|
6
|
+
- 'Gemfile'
|
7
|
+
- 'bin/**/*'
|
8
|
+
TargetRubyVersion: 2.4
|
9
|
+
|
10
|
+
Layout/EmptyLinesAroundClassBody:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout/EndOfLine:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 15
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/EmptyMethod:
|
26
|
+
EnforcedStyle: expanded
|
27
|
+
|
28
|
+
Style/IfUnlessModifier:
|
29
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
# 0.8.4
|
2
|
-
|
3
|
-
- Add `#inspect` and `#to_s` to response errors
|
4
|
-
- Add `#status` and `#to_i` to response errors
|
5
|
-
- Add `UnprocessibleEntity` as defined response error (`ClientError`)
|
6
|
-
|
7
|
-
# 0.8.3
|
8
|
-
|
9
|
-
- Add `Issue` media create API
|
10
|
-
|
11
|
-
# 0.8.2
|
12
|
-
|
13
|
-
- Add a fallback if the `errors` is decoded correctly, but not the correct format.
|
14
|
-
|
15
|
-
# 0.8.1
|
16
|
-
|
17
|
-
- Add a fallback if the `errors` key does not exist for error messages
|
18
|
-
- Fix decoding error messages (use symbol instead of string)
|
19
|
-
|
20
|
-
# 0.8.0
|
21
|
-
|
22
|
-
- Symbolize all keys to ensure interopt. with TrailerVote ingestion, and Ruby hash defaults
|
23
|
-
- Add warning to STDERR when decoding yields a validation error (server response does not match media type)
|
24
|
-
|
25
|
-
# 0.7.0
|
26
|
-
|
27
|
-
- Guards network errors during all API calls
|
28
|
-
- Add `NetworkError` and the subclasses `TimeoutError`, `ConnectionError`
|
29
|
-
- Add `back` links to most API calls
|
30
|
-
- Add `MediaTypeUnknown` error for decoding (and encoding) unknown media types
|
31
|
-
- Add `application/json` fallback support for hostile server responses
|
32
|
-
- Add `text/html` fallback support
|
33
|
-
- Fix a bug with a missing `product` attribute
|
34
|
-
- Fix an unsupported media type causing `ErrorsResponse` to break
|
35
|
-
|
36
|
-
# 0.6.1
|
37
|
-
|
38
|
-
- Always coerce body into string first because `Oj` might choke on chunked body.
|
39
|
-
|
40
|
-
# 0.6.0
|
41
|
-
|
42
|
-
- Add error classes for common errors
|
43
|
-
- Add error message decoding from server (and pass onto error message)
|
44
|
-
|
45
|
-
# 0.5.2
|
46
|
-
|
47
|
-
- Fix a bug with the `media_types` integration
|
48
|
-
|
49
|
-
# 0.5.1
|
50
|
-
|
51
|
-
- Loosen Gem dependency versions to allow any minor update, except for dogfooded gems, which are allowed major updates, until they hit 1.0.0
|
52
|
-
- Add metadata urls for gemspec
|
53
|
-
|
54
|
-
# 0.5.0
|
55
|
-
|
56
|
-
:baby: Initial public release
|
1
|
+
# 0.8.4
|
2
|
+
|
3
|
+
- Add `#inspect` and `#to_s` to response errors
|
4
|
+
- Add `#status` and `#to_i` to response errors
|
5
|
+
- Add `UnprocessibleEntity` as defined response error (`ClientError`)
|
6
|
+
|
7
|
+
# 0.8.3
|
8
|
+
|
9
|
+
- Add `Issue` media create API
|
10
|
+
|
11
|
+
# 0.8.2
|
12
|
+
|
13
|
+
- Add a fallback if the `errors` is decoded correctly, but not the correct format.
|
14
|
+
|
15
|
+
# 0.8.1
|
16
|
+
|
17
|
+
- Add a fallback if the `errors` key does not exist for error messages
|
18
|
+
- Fix decoding error messages (use symbol instead of string)
|
19
|
+
|
20
|
+
# 0.8.0
|
21
|
+
|
22
|
+
- Symbolize all keys to ensure interopt. with TrailerVote ingestion, and Ruby hash defaults
|
23
|
+
- Add warning to STDERR when decoding yields a validation error (server response does not match media type)
|
24
|
+
|
25
|
+
# 0.7.0
|
26
|
+
|
27
|
+
- Guards network errors during all API calls
|
28
|
+
- Add `NetworkError` and the subclasses `TimeoutError`, `ConnectionError`
|
29
|
+
- Add `back` links to most API calls
|
30
|
+
- Add `MediaTypeUnknown` error for decoding (and encoding) unknown media types
|
31
|
+
- Add `application/json` fallback support for hostile server responses
|
32
|
+
- Add `text/html` fallback support
|
33
|
+
- Fix a bug with a missing `product` attribute
|
34
|
+
- Fix an unsupported media type causing `ErrorsResponse` to break
|
35
|
+
|
36
|
+
# 0.6.1
|
37
|
+
|
38
|
+
- Always coerce body into string first because `Oj` might choke on chunked body.
|
39
|
+
|
40
|
+
# 0.6.0
|
41
|
+
|
42
|
+
- Add error classes for common errors
|
43
|
+
- Add error message decoding from server (and pass onto error message)
|
44
|
+
|
45
|
+
# 0.5.2
|
46
|
+
|
47
|
+
- Fix a bug with the `media_types` integration
|
48
|
+
|
49
|
+
# 0.5.1
|
50
|
+
|
51
|
+
- Loosen Gem dependency versions to allow any minor update, except for dogfooded gems, which are allowed major updates, until they hit 1.0.0
|
52
|
+
- Add metadata urls for gemspec
|
53
|
+
|
54
|
+
# 0.5.0
|
55
|
+
|
56
|
+
:baby: Initial public release
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in trailer_vote-api.gemspec
|
6
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in trailer_vote-api.gemspec
|
6
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trailer_vote-api (0.
|
4
|
+
trailer_vote-api (0.9.0)
|
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)
|
@@ -30,18 +30,18 @@ GEM
|
|
30
30
|
http-form_data (2.1.1)
|
31
31
|
http_parser.rb (0.6.0)
|
32
32
|
json (2.1.0)
|
33
|
-
media_types (0.6.
|
33
|
+
media_types (0.6.2)
|
34
34
|
minitest (5.11.3)
|
35
35
|
minitest-ci (3.4.0)
|
36
36
|
minitest (>= 5.0.6)
|
37
|
-
minitest-reporters (1.3.
|
37
|
+
minitest-reporters (1.3.6)
|
38
38
|
ansi
|
39
39
|
builder
|
40
40
|
minitest (>= 5.0)
|
41
41
|
ruby-progressbar
|
42
|
-
oj (3.
|
42
|
+
oj (3.7.12)
|
43
43
|
public_suffix (3.0.3)
|
44
|
-
rake (
|
44
|
+
rake (12.3.2)
|
45
45
|
ruby-progressbar (1.10.0)
|
46
46
|
safe_yaml (1.0.4)
|
47
47
|
simplecov (0.16.1)
|
@@ -49,13 +49,12 @@ 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.11.1)
|
53
53
|
media_types (>= 0.6.0, < 1)
|
54
54
|
unf (0.1.4)
|
55
55
|
unf_ext
|
56
|
-
unf_ext (0.0.7.
|
57
|
-
|
58
|
-
webmock (3.4.2)
|
56
|
+
unf_ext (0.0.7.6)
|
57
|
+
webmock (3.5.1)
|
59
58
|
addressable (>= 2.3.6)
|
60
59
|
crack (>= 0.3.2)
|
61
60
|
hashdiff
|
@@ -70,10 +69,10 @@ DEPENDENCIES
|
|
70
69
|
minitest (~> 5.11)
|
71
70
|
minitest-ci (~> 3.4)
|
72
71
|
minitest-reporters (~> 1.3)
|
73
|
-
rake (~>
|
72
|
+
rake (~> 12.3)
|
74
73
|
simplecov (~> 0.16)
|
75
74
|
trailer_vote-api!
|
76
75
|
webmock (~> 3.4)
|
77
76
|
|
78
77
|
BUNDLED WITH
|
79
|
-
1.
|
78
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,188 +1,188 @@
|
|
1
|
-
# TrailerVote::Api
|
2
|
-
[![Build Status](https://travis-ci.com/TrailerVote/trailervote-api-clients.svg?branch=master)](https://travis-ci.com/TrailerVote/trailervote-api-clients)
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/trailer_vote-api.svg)](https://badge.fury.io/rb/trailer_vote-api)
|
4
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/da722ca43c5811db5926/maintainability)](https://codeclimate.com/github/TrailerVote/trailervote-api-clients/maintainability)
|
5
|
-
[![Depfu](https://badges.depfu.com/badges/abcb16e9c6a98f7ce7ce9f8379f8b2c7/overview.svg)](https://depfu.com/github/TrailerVote/trailervote-api-clients?project_id=5890)
|
6
|
-
|
7
|
-
The TrailerVote Api gem is the official interface to communicate with the TrailerVote product service. It allows you to
|
8
|
-
keep your code simple and not deal with the HTTP suite.
|
9
|
-
|
10
|
-
## Installation
|
11
|
-
|
12
|
-
Add this line to your application's Gemfile:
|
13
|
-
|
14
|
-
```ruby
|
15
|
-
gem 'trailer_vote-api'
|
16
|
-
```
|
17
|
-
|
18
|
-
And then execute:
|
19
|
-
|
20
|
-
$ bundle
|
21
|
-
|
22
|
-
Or install it yourself as:
|
23
|
-
|
24
|
-
$ gem install trailer_vote-api
|
25
|
-
|
26
|
-
## Usage
|
27
|
-
|
28
|
-
By default only the configuration api calls are available and you need to require which ever calls you want to make. A call always loads it dependencies. If you want to load everything you can `require 'trailer_vote/api/autoload'`.
|
29
|
-
|
30
|
-
In order to call any of the APIs, you need to configure the api first:
|
31
|
-
```Ruby
|
32
|
-
key = '<TrailerVote API Client key>'
|
33
|
-
secret = '<TrailerVote API Client secret>'
|
34
|
-
url = '<TrailerVote API environment url>'
|
35
|
-
|
36
|
-
configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
37
|
-
# => TrailerVote::Api::Configuration
|
38
|
-
```
|
39
|
-
|
40
|
-
The TrailerVote API Client for Ruby uses a lazy chainable API and does **NOT** make any requests until it's absolutely necessary.
|
41
|
-
It is recommended that you re-use the configuration instance, as well as other results, in order to reduce network requests.
|
42
|
-
|
43
|
-
The common interface is:
|
44
|
-
- `#call(*args)`: Make the call and return an object that has results
|
45
|
-
- `#data`: Return the inner data (`#to_h`) without the wrapping key
|
46
|
-
- `#to_i`: Return the HTTP status code
|
47
|
-
- `#to_h`: Return the response (`#call`), parsed (if parsable, like JSON) and validated (according to the media type)
|
48
|
-
- `#etag`: Return the HTTP ETag header value, if any
|
49
|
-
- `#links`: Return the HTTP Link header / inner `_links` as `Links` object
|
50
|
-
|
51
|
-
Unless data is being posted, `#call` is not necessary:
|
52
|
-
|
53
|
-
```Ruby
|
54
|
-
configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
55
|
-
configuration.links
|
56
|
-
# => TrailerVote::Api::Links # Makes the HTTP call if necessary
|
57
|
-
```
|
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.
|
60
|
-
|
61
|
-
## Interface
|
62
|
-
|
63
|
-
Only the call available to the current link in the chain, if `required` are available on each object.
|
64
|
-
|
65
|
-
### `configuration`
|
66
|
-
You don't need to require this, it's always loaded.
|
67
|
-
|
68
|
-
```Ruby
|
69
|
-
require 'trailer_vote/api/configuration'
|
70
|
-
|
71
|
-
configuration = TrailerVote::Api.configure(key: '', secret: '', url: '')
|
72
|
-
# => TrailerVote::Api::Configuration
|
73
|
-
```
|
74
|
-
|
75
|
-
### `configuration.product.lookup`
|
76
|
-
Used to lookup products by authority:identifier pairs. If found, returns the actual `Product::Find`.
|
77
|
-
|
78
|
-
The `data` argument is wrapped in `{ product_identifiers: data }` and then needs to match `application/vnd.trailervote.product.lookup.v1+json`
|
79
|
-
|
80
|
-
```Ruby
|
81
|
-
require 'trailer_vote/api/product/lookup'
|
82
|
-
|
83
|
-
lookup = configuration.product.lookup
|
84
|
-
# => TrailerVote::Api::Product::Lookup
|
85
|
-
|
86
|
-
lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }, { authority: 'tmdb', identifier: '12345678' }])
|
87
|
-
# => TrailerVote::Api::Product::Find
|
88
|
-
```
|
89
|
-
|
90
|
-
### `configuration.product.update`
|
91
|
-
Used to update a product. Is only available on `Product::Find`, because we require updates to be non-stale, that is you need to ensure that you are the last one updating the product, so merging data can be done correctly.
|
92
|
-
|
93
|
-
The `data` argument is wrapped in `{ product: data }` and then needs to match `application/vnd.trailervote.product.v2+json`
|
94
|
-
|
95
|
-
```Ruby
|
96
|
-
require 'trailer_vote/api/product/lookup'
|
97
|
-
require 'trailer_vote/api/product/update'
|
98
|
-
|
99
|
-
lookup = configuration.product.lookup
|
100
|
-
product = lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
101
|
-
# => TrailerVote::Api::Product::Find
|
102
|
-
|
103
|
-
current_product_data = product.data
|
104
|
-
next_product_data = make_changes_to_product_data(current_product_data)
|
105
|
-
product.update.call(data: next_product_data)
|
106
|
-
# => TrailerVote::Api::Product::Find
|
107
|
-
```
|
108
|
-
|
109
|
-
If the update call fails with a `409 Conflict` or `412 Precondition Failed`, it means the product was updated in the meanwhile. You want to fetch the product again by doing another lookup and then running your strategy again.
|
110
|
-
|
111
|
-
### `configuration.product.create`
|
112
|
-
Creating a product is similar to looking up a product. If successful, returns an actual `Product::Find`.
|
113
|
-
|
114
|
-
The `data` argument is wrapped in `{ product: data }` and then needs to match `application/vnd.trailervote.product.v2.create+json`
|
115
|
-
|
116
|
-
```Ruby
|
117
|
-
require 'trailer_vote/api/product/create'
|
118
|
-
|
119
|
-
configuration.product.create(data: { title: 'My product', ... })
|
120
|
-
# => TrailerVote::Api::Product::Find
|
121
|
-
```
|
122
|
-
|
123
|
-
### `configuration.product.<>.video.create`
|
124
|
-
To attach an video to a product, you first need to find the product. This can be done by:
|
125
|
-
- `configuration.product.create`: creating a new product
|
126
|
-
- `configuration.product.lookup`: looking up an existing product
|
127
|
-
|
128
|
-
Once you have it, the video operations are available on the result.
|
129
|
-
|
130
|
-
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
131
|
-
|
132
|
-
```Ruby
|
133
|
-
require 'trailer_vote/api/product/lookup'
|
134
|
-
require 'trailer_vote/api/product/video/create'
|
135
|
-
|
136
|
-
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
137
|
-
# => TrailerVote::Api::Product::Find
|
138
|
-
|
139
|
-
product.video.create(data: { source_url: '', ... })
|
140
|
-
# => TrailerVote::Api::Product::Video::Find
|
141
|
-
```
|
142
|
-
|
143
|
-
You can see in this example the `product` result is cached in a variable, so that if you want to create *many* videos, the product isn't looked up each call.
|
144
|
-
|
145
|
-
### `configuration.product.<>.image.urls`
|
146
|
-
Gets all the image urls for a product
|
147
|
-
|
148
|
-
### `configuration.product.<>.video.create`
|
149
|
-
To attach an video to a product, you first need to find the product. This can be done by:
|
150
|
-
- `configuration.product.create`: creating a new product
|
151
|
-
- `configuration.product.lookup`: looking up an existing product
|
152
|
-
|
153
|
-
Once you have it, the video operations are available on the result.
|
154
|
-
|
155
|
-
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
156
|
-
|
157
|
-
```Ruby
|
158
|
-
require 'trailer_vote/api/product/lookup'
|
159
|
-
require 'trailer_vote/api/product/video/create'
|
160
|
-
|
161
|
-
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
162
|
-
# => TrailerVote::Api::Product::Find
|
163
|
-
|
164
|
-
product.video.create(data: { source_url: '', ... })
|
165
|
-
# => TrailerVote::Api::Product::Video::Find
|
166
|
-
```
|
167
|
-
|
168
|
-
You can see in this example the `product` result is cached in a variable, so that if you want to create *many* videos, the product isn't looked up each call.
|
169
|
-
|
170
|
-
### `configuration.product.<>.video.urls`
|
171
|
-
Gets all the image urls for a product
|
172
|
-
|
173
|
-
### `configuration.product.<>.place.link`
|
174
|
-
Links a place to a product
|
175
|
-
|
176
|
-
## Development
|
177
|
-
|
178
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
179
|
-
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
180
|
-
|
181
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
182
|
-
version number in `version.rb`, and then run `bundle update trailer_vote-api` in any repository that depends on
|
183
|
-
this gem. If you have push rights, you may call `bundle exec rake release` to create a new git tag, push
|
184
|
-
git commits and tags, and push the `.gem` file to the rubygems gem server.
|
185
|
-
|
186
|
-
## Contributing
|
187
|
-
|
188
|
-
Bug reports and pull requests are welcome on GitHub at [TrailerVote/trailervote-api-clients](https://github.com/trailervote/trailervote-api-clients)
|
1
|
+
# TrailerVote::Api
|
2
|
+
[![Build Status](https://travis-ci.com/TrailerVote/trailervote-api-clients.svg?branch=master)](https://travis-ci.com/TrailerVote/trailervote-api-clients)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/trailer_vote-api.svg)](https://badge.fury.io/rb/trailer_vote-api)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/da722ca43c5811db5926/maintainability)](https://codeclimate.com/github/TrailerVote/trailervote-api-clients/maintainability)
|
5
|
+
[![Depfu](https://badges.depfu.com/badges/abcb16e9c6a98f7ce7ce9f8379f8b2c7/overview.svg)](https://depfu.com/github/TrailerVote/trailervote-api-clients?project_id=5890)
|
6
|
+
|
7
|
+
The TrailerVote Api gem is the official interface to communicate with the TrailerVote product service. It allows you to
|
8
|
+
keep your code simple and not deal with the HTTP suite.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'trailer_vote-api'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install trailer_vote-api
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
By default only the configuration api calls are available and you need to require which ever calls you want to make. A call always loads it dependencies. If you want to load everything you can `require 'trailer_vote/api/autoload'`.
|
29
|
+
|
30
|
+
In order to call any of the APIs, you need to configure the api first:
|
31
|
+
```Ruby
|
32
|
+
key = '<TrailerVote API Client key>'
|
33
|
+
secret = '<TrailerVote API Client secret>'
|
34
|
+
url = '<TrailerVote API environment url>'
|
35
|
+
|
36
|
+
configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
37
|
+
# => TrailerVote::Api::Configuration
|
38
|
+
```
|
39
|
+
|
40
|
+
The TrailerVote API Client for Ruby uses a lazy chainable API and does **NOT** make any requests until it's absolutely necessary.
|
41
|
+
It is recommended that you re-use the configuration instance, as well as other results, in order to reduce network requests.
|
42
|
+
|
43
|
+
The common interface is:
|
44
|
+
- `#call(*args)`: Make the call and return an object that has results
|
45
|
+
- `#data`: Return the inner data (`#to_h`) without the wrapping key
|
46
|
+
- `#to_i`: Return the HTTP status code
|
47
|
+
- `#to_h`: Return the response (`#call`), parsed (if parsable, like JSON) and validated (according to the media type)
|
48
|
+
- `#etag`: Return the HTTP ETag header value, if any
|
49
|
+
- `#links`: Return the HTTP Link header / inner `_links` as `Links` object
|
50
|
+
|
51
|
+
Unless data is being posted, `#call` is not necessary:
|
52
|
+
|
53
|
+
```Ruby
|
54
|
+
configuration = TrailerVote::Api.configure(url: url, key: key, secret: secret)
|
55
|
+
configuration.links
|
56
|
+
# => TrailerVote::Api::Links # Makes the HTTP call if necessary
|
57
|
+
```
|
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.
|
60
|
+
|
61
|
+
## Interface
|
62
|
+
|
63
|
+
Only the call available to the current link in the chain, if `required` are available on each object.
|
64
|
+
|
65
|
+
### `configuration`
|
66
|
+
You don't need to require this, it's always loaded.
|
67
|
+
|
68
|
+
```Ruby
|
69
|
+
require 'trailer_vote/api/configuration'
|
70
|
+
|
71
|
+
configuration = TrailerVote::Api.configure(key: '', secret: '', url: '')
|
72
|
+
# => TrailerVote::Api::Configuration
|
73
|
+
```
|
74
|
+
|
75
|
+
### `configuration.product.lookup`
|
76
|
+
Used to lookup products by authority:identifier pairs. If found, returns the actual `Product::Find`.
|
77
|
+
|
78
|
+
The `data` argument is wrapped in `{ product_identifiers: data }` and then needs to match `application/vnd.trailervote.product.lookup.v1+json`
|
79
|
+
|
80
|
+
```Ruby
|
81
|
+
require 'trailer_vote/api/product/lookup'
|
82
|
+
|
83
|
+
lookup = configuration.product.lookup
|
84
|
+
# => TrailerVote::Api::Product::Lookup
|
85
|
+
|
86
|
+
lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }, { authority: 'tmdb', identifier: '12345678' }])
|
87
|
+
# => TrailerVote::Api::Product::Find
|
88
|
+
```
|
89
|
+
|
90
|
+
### `configuration.product.update`
|
91
|
+
Used to update a product. Is only available on `Product::Find`, because we require updates to be non-stale, that is you need to ensure that you are the last one updating the product, so merging data can be done correctly.
|
92
|
+
|
93
|
+
The `data` argument is wrapped in `{ product: data }` and then needs to match `application/vnd.trailervote.product.v2+json`
|
94
|
+
|
95
|
+
```Ruby
|
96
|
+
require 'trailer_vote/api/product/lookup'
|
97
|
+
require 'trailer_vote/api/product/update'
|
98
|
+
|
99
|
+
lookup = configuration.product.lookup
|
100
|
+
product = lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
101
|
+
# => TrailerVote::Api::Product::Find
|
102
|
+
|
103
|
+
current_product_data = product.data
|
104
|
+
next_product_data = make_changes_to_product_data(current_product_data)
|
105
|
+
product.update.call(data: next_product_data)
|
106
|
+
# => TrailerVote::Api::Product::Find
|
107
|
+
```
|
108
|
+
|
109
|
+
If the update call fails with a `409 Conflict` or `412 Precondition Failed`, it means the product was updated in the meanwhile. You want to fetch the product again by doing another lookup and then running your strategy again.
|
110
|
+
|
111
|
+
### `configuration.product.create`
|
112
|
+
Creating a product is similar to looking up a product. If successful, returns an actual `Product::Find`.
|
113
|
+
|
114
|
+
The `data` argument is wrapped in `{ product: data }` and then needs to match `application/vnd.trailervote.product.v2.create+json`
|
115
|
+
|
116
|
+
```Ruby
|
117
|
+
require 'trailer_vote/api/product/create'
|
118
|
+
|
119
|
+
configuration.product.create(data: { title: 'My product', ... })
|
120
|
+
# => TrailerVote::Api::Product::Find
|
121
|
+
```
|
122
|
+
|
123
|
+
### `configuration.product.<>.video.create`
|
124
|
+
To attach an video to a product, you first need to find the product. This can be done by:
|
125
|
+
- `configuration.product.create`: creating a new product
|
126
|
+
- `configuration.product.lookup`: looking up an existing product
|
127
|
+
|
128
|
+
Once you have it, the video operations are available on the result.
|
129
|
+
|
130
|
+
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
131
|
+
|
132
|
+
```Ruby
|
133
|
+
require 'trailer_vote/api/product/lookup'
|
134
|
+
require 'trailer_vote/api/product/video/create'
|
135
|
+
|
136
|
+
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
137
|
+
# => TrailerVote::Api::Product::Find
|
138
|
+
|
139
|
+
product.video.create(data: { source_url: '', ... })
|
140
|
+
# => TrailerVote::Api::Product::Video::Find
|
141
|
+
```
|
142
|
+
|
143
|
+
You can see in this example the `product` result is cached in a variable, so that if you want to create *many* videos, the product isn't looked up each call.
|
144
|
+
|
145
|
+
### `configuration.product.<>.image.urls`
|
146
|
+
Gets all the image urls for a product
|
147
|
+
|
148
|
+
### `configuration.product.<>.video.create`
|
149
|
+
To attach an video to a product, you first need to find the product. This can be done by:
|
150
|
+
- `configuration.product.create`: creating a new product
|
151
|
+
- `configuration.product.lookup`: looking up an existing product
|
152
|
+
|
153
|
+
Once you have it, the video operations are available on the result.
|
154
|
+
|
155
|
+
The `data` argument is wrapped in `{ product_video: data }` and then needs to match `application/vnd.trailervote.product.video.v1.create+json`
|
156
|
+
|
157
|
+
```Ruby
|
158
|
+
require 'trailer_vote/api/product/lookup'
|
159
|
+
require 'trailer_vote/api/product/video/create'
|
160
|
+
|
161
|
+
product = configuration.product.lookup.call(data: [{ authority: 'imdb', identifier: 'tt01010101' }])
|
162
|
+
# => TrailerVote::Api::Product::Find
|
163
|
+
|
164
|
+
product.video.create(data: { source_url: '', ... })
|
165
|
+
# => TrailerVote::Api::Product::Video::Find
|
166
|
+
```
|
167
|
+
|
168
|
+
You can see in this example the `product` result is cached in a variable, so that if you want to create *many* videos, the product isn't looked up each call.
|
169
|
+
|
170
|
+
### `configuration.product.<>.video.urls`
|
171
|
+
Gets all the image urls for a product
|
172
|
+
|
173
|
+
### `configuration.product.<>.place.link`
|
174
|
+
Links a place to a product
|
175
|
+
|
176
|
+
## Development
|
177
|
+
|
178
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
179
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
180
|
+
|
181
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
182
|
+
version number in `version.rb`, and then run `bundle update trailer_vote-api` in any repository that depends on
|
183
|
+
this gem. If you have push rights, you may call `bundle exec rake release` to create a new git tag, push
|
184
|
+
git commits and tags, and push the `.gem` file to the rubygems gem server.
|
185
|
+
|
186
|
+
## Contributing
|
187
|
+
|
188
|
+
Bug reports and pull requests are welcome on GitHub at [TrailerVote/trailervote-api-clients](https://github.com/trailervote/trailervote-api-clients)
|