wcc-media-client 0.2.4 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab09c5594cc3c465e250a8aff766c6af21055316
4
- data.tar.gz: dd66f0f3e46cb41368e96bb0bbe1758844604681
3
+ metadata.gz: 5d99e5accc0f31100188ebd4828c70e4c6a01587
4
+ data.tar.gz: c8e7a0440d77d584d0d6fd5c31a7f8b4653b586b
5
5
  SHA512:
6
- metadata.gz: f80dd6f5ee11263e496ebc5341b3cba37d065b56a80ef3a8a658e24d37ac394122cd26d7eabe27433cbbe949de2063448dca95096841240bf39637f0b92127fd
7
- data.tar.gz: 0a6dc9994037e417f35449971716db01f596d05843105d9dca75bc8dc9cce9681babe8c4418d6f3c8a9384170e25587a6bdafe94678b1b50879c5ceb98e1db07
6
+ metadata.gz: 27cd7495cd94f831ffe43e6f3ace6eb361fd1692610c2292a5d97ddf913246d5f30c5095ca939cbb32d6db2682a4203bc307b317f024140fd2cfa263f902481f
7
+ data.tar.gz: f27fdaa1c3e889d8905c3fea8af49aceff523fcb9edfb82b424280463c4d78b48a071999dc2e4d7899ed749f5808313a4613f50385a517f01d2ce12816ca28aa
@@ -1,7 +1,7 @@
1
1
  module WCC
2
2
  module Media
3
- class Client < RestClient
4
- class Response < RestClient::AbstractResponse
3
+ class Client < ::WCC::API::RestClient
4
+ class Response < AbstractResponse
5
5
  def skip
6
6
  body.dig('pagination', 'offset')
7
7
  end
@@ -26,4 +26,4 @@ module WCC
26
26
  end
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../../rest_client'
1
+ require 'wcc/api/rest_client'
2
2
  require_relative 'message'
3
3
  require_relative 'series'
4
4
  require_relative 'speaker'
@@ -7,7 +7,7 @@ require_relative 'client/response'
7
7
 
8
8
  module WCC
9
9
  module Media
10
- class Client < RestClient
10
+ class Client < ::WCC::API::RestClient
11
11
  class << self
12
12
  attr_writer :default
13
13
  # The default client. Set this in an initializer to change the client used
@@ -91,4 +91,4 @@ module WCC
91
91
  end
92
92
  end
93
93
  end
94
- end
94
+ end
@@ -0,0 +1,5 @@
1
+ module WCC
2
+ module Media
3
+ VERSION = '0.3.0'.freeze
4
+ end
5
+ end
@@ -2,11 +2,11 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'wcc/media/client/version'
5
+ require 'wcc/media/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'wcc-media-client'
9
- spec.version = WCC::Media::Client::VERSION
9
+ spec.version = WCC::Media::VERSION
10
10
  spec.authors = ['Watermark Dev']
11
11
  spec.email = ['dev@watermark.org']
12
12
 
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.require_paths = ['lib']
26
26
 
27
+ spec.add_runtime_dependency 'wcc-api', '>= 0.3.0'
28
+
27
29
  spec.add_development_dependency 'byebug'
28
30
  spec.add_development_dependency 'http', '> 1.0', '< 3.0'
29
31
  spec.add_development_dependency 'httplog', '~> 1.0'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-media-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wcc-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: byebug
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,21 +153,16 @@ files:
139
153
  - ".rubocop.yml"
140
154
  - Gemfile
141
155
  - README.md
142
- - lib/rest_client.rb
143
- - lib/rest_client/api_error.rb
144
- - lib/rest_client/http_adapter.rb
145
- - lib/rest_client/response.rb
146
- - lib/rest_client/typhoeus_adapter.rb
147
156
  - lib/wcc/media/active_record_shim.rb
148
157
  - lib/wcc/media/base.rb
149
158
  - lib/wcc/media/cacheable.rb
150
159
  - lib/wcc/media/client.rb
151
160
  - lib/wcc/media/client/response.rb
152
- - lib/wcc/media/client/version.rb
153
161
  - lib/wcc/media/message.rb
154
162
  - lib/wcc/media/series.rb
155
163
  - lib/wcc/media/speaker.rb
156
164
  - lib/wcc/media/tag.rb
165
+ - lib/wcc/media/version.rb
157
166
  - rakefile
158
167
  - wcc-media-client.gemspec
159
168
  homepage: https://github.com/watermarkchurch/media/wcc-media-client
@@ -176,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
185
  version: '0'
177
186
  requirements: []
178
187
  rubyforge_project:
179
- rubygems_version: 2.5.2
188
+ rubygems_version: 2.6.11
180
189
  signing_key:
181
190
  specification_version: 4
182
191
  summary: ''
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class RestClient
4
- class ApiError < StandardError
5
- attr_reader :response
6
-
7
- def self.[](code)
8
- case code
9
- when 404
10
- NotFoundError
11
- else
12
- ApiError
13
- end
14
- end
15
-
16
- def initialize(response)
17
- @response = response
18
- super(response.error_message)
19
- end
20
- end
21
-
22
- class NotFoundError < ApiError
23
- end
24
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- gem 'http'
4
- require 'http'
5
-
6
- class HttpAdapter
7
- def call(url, query, headers = {}, proxy = {})
8
- if proxy[:host]
9
- HTTP[headers].via(proxy[:host], proxy[:port], proxy[:username], proxy[:password])
10
- .get(url, params: query)
11
- else
12
- HTTP[headers].get(url, params: query)
13
- end
14
- end
15
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
- require_relative 'api_error'
5
-
6
- class RestClient
7
- class AbstractResponse
8
- extend ::Forwardable
9
-
10
- attr_reader :raw_response
11
- attr_reader :raw_body
12
- attr_reader :client
13
- attr_reader :request
14
-
15
- def_delegators :raw_response, :code, :headers
16
-
17
- def body
18
- @body ||= JSON.parse(raw_body)
19
- end
20
- alias_method :to_json, :body
21
-
22
- def initialize(client, request, raw_response)
23
- @client = client
24
- @request = request
25
- @raw_response = raw_response
26
- @raw_body = raw_response.body.to_s
27
- end
28
-
29
- def skip
30
- throw new NotImplementedError, 'Please implement "skip" parsing in response class'
31
- end
32
-
33
- def count
34
- throw new NotImplementedError, 'Please implement "count" parsing in response class'
35
- end
36
-
37
- def collection_response?
38
- page_items.nil? ? false : true
39
- end
40
-
41
- def page_items
42
- throw new NotImplementedError, 'Please implement "page_items" parsing in response class'
43
- end
44
-
45
- def error_message
46
- parsed_message =
47
- begin
48
- body.dig('error', 'message') || body.dig('message')
49
- rescue JSON::ParserError
50
- nil
51
- end
52
- parsed_message || "#{code}: #{raw_response.body}"
53
- end
54
-
55
- def next_page?
56
- return false unless collection_response?
57
-
58
- page_items.length + skip < count
59
- end
60
-
61
- def next_page
62
- return unless next_page?
63
-
64
- @next_page ||= @client.get(
65
- @request[:url],
66
- (@request[:query] || {}).merge(next_page_query)
67
- )
68
- @next_page.assert_ok!
69
- end
70
-
71
- def assert_ok!
72
- return self if code >= 200 && code < 300
73
-
74
- raise ApiError[code], self
75
- end
76
-
77
- # This method has a bit of complexity that is better kept in one location
78
- def each_page(&block)
79
- raise ArgumentError, 'Not a collection response' unless collection_response?
80
-
81
- ret =
82
- Enumerator.new do |y|
83
- y << self
84
-
85
- if next_page?
86
- next_page.each_page.each do |page|
87
- y << page
88
- end
89
- end
90
- end
91
-
92
- if block_given?
93
- ret.map(&block)
94
- else
95
- ret.lazy
96
- end
97
- end
98
-
99
- def items
100
- return unless collection_response?
101
-
102
- each_page.flat_map(&:page_items)
103
- end
104
-
105
- def first
106
- raise ArgumentError, 'Not a collection response' unless collection_response?
107
-
108
- page_items.first
109
- end
110
-
111
- def next_page_query
112
- return unless collection_response?
113
-
114
- {
115
- skip: page_items.length + skip,
116
- }
117
- end
118
- end
119
-
120
- class DefaultResponse < AbstractResponse
121
- def skip
122
- body['skip']
123
- end
124
-
125
- def count
126
- body['total']
127
- end
128
-
129
- def page_items
130
- body['items']
131
- end
132
- end
133
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
- gem 'typhoeus'
5
- require 'typhoeus'
6
-
7
- class RestClient
8
- class TyphoeusAdapter
9
- def call(url, query, headers = {}, proxy = {})
10
- raise NotImplementedError, 'Proxying Not Yet Implemented' if proxy[:host]
11
-
12
- TyphoeusAdapter::Response.new(
13
- Typhoeus.get(
14
- url,
15
- params: query,
16
- headers: headers
17
- )
18
- )
19
- end
20
-
21
- Response =
22
- Struct.new(:raw) do
23
- extend Forwardable
24
-
25
- def_delegators :raw, :body, :to_s, :code, :headers
26
-
27
- def status
28
- raw.code
29
- end
30
- end
31
- end
32
- end
data/lib/rest_client.rb DELETED
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'rest_client/response'
4
-
5
- class RestClient
6
- attr_reader :api_url
7
-
8
- def initialize(api_url:, headers: nil, **options)
9
- # normalizes a URL to have a slash on the end
10
- @api_url = api_url.gsub(/\/+$/, '') + '/'
11
-
12
- @adapter = RestClient.load_adapter(options[:adapter])
13
-
14
- @options = options
15
- @query_defaults = {}
16
- @headers = {
17
- 'Accept' => 'application/json',
18
- }.merge(headers || {}).freeze
19
- @response_class = options[:response_class] || DefaultResponse
20
- end
21
-
22
- # performs an HTTP GET request to the specified path within the configured
23
- # space and environment. Query parameters are merged with the defaults and
24
- # appended to the request.
25
- def get(path, query = {})
26
- url = URI.join(@api_url, path)
27
-
28
- @response_class.new(self,
29
- { url: url, query: query },
30
- get_http(url, query))
31
- end
32
-
33
- ADAPTERS = {
34
- http: ['http', '> 1.0', '< 3.0'],
35
- typhoeus: ['typhoeus', '~> 1.0'],
36
- }.freeze
37
-
38
- # This method is long due to the case statement,
39
- # not really a better way to do it
40
- def self.load_adapter(adapter)
41
- case adapter
42
- when nil
43
- ADAPTERS.each do |a, spec|
44
- begin
45
- gem(*spec)
46
- return load_adapter(a)
47
- rescue Gem::LoadError
48
- next
49
- end
50
- end
51
- raise ArgumentError, 'Unable to load adapter! Please install one of '\
52
- "#{ADAPTERS.values.map(&:join).join(',')}"
53
- when :http
54
- require_relative 'rest_client/http_adapter'
55
- HttpAdapter.new
56
- when :typhoeus
57
- require_relative 'rest_client/typhoeus_adapter'
58
- TyphoeusAdapter.new
59
- else
60
- unless adapter.respond_to?(:call)
61
- raise ArgumentError, "Adapter #{adapter} is not invokeable! Please "\
62
- "pass a proc or use one of #{ADAPTERS.keys}"
63
- end
64
- adapter
65
- end
66
- end
67
-
68
- private
69
-
70
- def get_http(url, query, headers = {}, proxy = {})
71
- headers = @headers.merge(headers || {})
72
-
73
- q = @query_defaults.dup
74
- q = q.merge(query) if query
75
-
76
- resp = @adapter.call(url, q, headers, proxy)
77
-
78
- resp = get_http(resp.headers['location'], nil, headers, proxy) if [301, 302, 307].include?(resp.code) && !@options[:no_follow_redirects]
79
- resp
80
- end
81
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../../rest_client'
2
-
3
- module WCC
4
- module Media
5
- class Client < RestClient
6
- VERSION = '0.2.4'.freeze
7
- end
8
- end
9
- end