wes-data-api 10.12.0 → 11.0.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 +4 -4
- data/lib/wes/data/api/base.rb +8 -0
- data/lib/wes/data/api/pagination.rb +27 -0
- data/lib/wes/data/api/response.rb +2 -1
- data/lib/wes/data/api/results.rb +51 -0
- data/lib/wes/data/api/video.rb +6 -2
- data/lib/wes/data/api.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1f5e364b9fe620bc778aa13c14472e2280dfc0
|
4
|
+
data.tar.gz: 502fc025a866651ee909d6b4dab9db9fcaf16480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7591edd66a1ceb587e5d1f5ed40e5c87a80bb155397afcd8064993ae5748f2db91aef4561d13c066a5a05b4ea57a544650f9131b22fc916dc839ceaf43ecb4c9
|
7
|
+
data.tar.gz: fe2ab64aed4472a8053a45002489f909dde8f478f3977c688195ddfeae668a64e273dd46e985c4133d789fe504353596a4619dbfb56bd8b5ea8d63d6333c19a8
|
data/lib/wes/data/api/base.rb
CHANGED
@@ -25,6 +25,14 @@ module Wes
|
|
25
25
|
def routes
|
26
26
|
configuration.routes
|
27
27
|
end
|
28
|
+
|
29
|
+
def apply_pagination(route, limit, offset)
|
30
|
+
delimiter = route.include?("?") ? '&' : '?'
|
31
|
+
format(
|
32
|
+
'%s%slimit=%s&offset=%s',
|
33
|
+
route, delimiter, limit, offset
|
34
|
+
)
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Wes
|
2
|
+
module Data
|
3
|
+
module API
|
4
|
+
class Pagination
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def next
|
10
|
+
@data.fetch('next', false)
|
11
|
+
end
|
12
|
+
|
13
|
+
def previous
|
14
|
+
@data.fetch('previous', false)
|
15
|
+
end
|
16
|
+
|
17
|
+
def next_offset
|
18
|
+
@data.dig('offsets', 'next') || -1
|
19
|
+
end
|
20
|
+
|
21
|
+
def previous_offset
|
22
|
+
@data.dig('offsets', 'previous') || -1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'wes/data/api/error/unexpected'
|
2
2
|
require 'wes/data/api/error/response'
|
3
|
+
require 'wes/data/api/results'
|
3
4
|
|
4
5
|
module Wes
|
5
6
|
module Data
|
@@ -13,7 +14,7 @@ module Wes
|
|
13
14
|
raise unexpected_error unless valid_response(response)
|
14
15
|
raise api_error unless VALID_RESPONSE_CODES.include?(response.status)
|
15
16
|
data = response.body || {}
|
16
|
-
data
|
17
|
+
data = Results.new(data)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'wes/data/api/pagination'
|
2
|
+
|
3
|
+
module Wes
|
4
|
+
module Data
|
5
|
+
module API
|
6
|
+
class Results
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(response)
|
10
|
+
parse_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def <<(val)
|
14
|
+
@data << val
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](val)
|
18
|
+
@data[val]
|
19
|
+
end
|
20
|
+
|
21
|
+
def each(&block)
|
22
|
+
@data.each(&block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_pair(&block)
|
26
|
+
@data.each_pair(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def last
|
30
|
+
@data.last
|
31
|
+
end
|
32
|
+
|
33
|
+
def pagination
|
34
|
+
@pagination ||= Pagination.new(@pagination_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def parse_response(response)
|
40
|
+
@pagination_data = response.kind_of?(Array) ? {} : response["pagination"]
|
41
|
+
@data = parse_data(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_data(response)
|
45
|
+
data = response.kind_of?(Array) ? response : response.fetch("data", [])
|
46
|
+
data.map { |item| OpenStruct.new(item) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/wes/data/api/video.rb
CHANGED
@@ -19,8 +19,12 @@ module Wes
|
|
19
19
|
attributes.nil? ? nil : model_klass.new(attributes)
|
20
20
|
end
|
21
21
|
|
22
|
-
def feed
|
23
|
-
route =
|
22
|
+
def feed(limit, offset)
|
23
|
+
route = apply_pagination(
|
24
|
+
[routes.videos, routes.feed].join('/'),
|
25
|
+
limit,
|
26
|
+
offset
|
27
|
+
)
|
24
28
|
attributes = client.get(route)
|
25
29
|
attributes.map { |a| model_klass.new(a) }
|
26
30
|
end
|
data/lib/wes/data/api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wes-data-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 11.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,8 +143,10 @@ files:
|
|
143
143
|
- lib/wes/data/api/model/video.rb
|
144
144
|
- lib/wes/data/api/model/video_transcoding_state.rb
|
145
145
|
- lib/wes/data/api/model/video_version.rb
|
146
|
+
- lib/wes/data/api/pagination.rb
|
146
147
|
- lib/wes/data/api/request.rb
|
147
148
|
- lib/wes/data/api/response.rb
|
149
|
+
- lib/wes/data/api/results.rb
|
148
150
|
- lib/wes/data/api/reward.rb
|
149
151
|
- lib/wes/data/api/routes.rb
|
150
152
|
- lib/wes/data/api/showcase.rb
|