vhx-ruby 0.0.7 → 0.0.8
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/README.md +4 -1
- data/lib/vhx.rb +4 -3
- data/lib/vhx/client.rb +6 -3
- data/lib/vhx/objects/analytics.rb +9 -0
- data/lib/vhx/utilities/vhx_object.rb +2 -2
- data/lib/vhx/version.rb +2 -2
- data/spec/client_spec.rb +44 -9
- data/spec/fixtures/sample_authorization_response.json +19 -0
- data/spec/fixtures/sample_collection_response.json +20 -0
- data/spec/fixtures/sample_collections_response.json +14 -0
- data/spec/fixtures/sample_create_video_response.json +33 -0
- data/spec/fixtures/sample_customer_response.json +16 -0
- data/spec/fixtures/sample_customers_response.json +28 -0
- data/spec/fixtures/sample_files_response.json +16 -0
- data/spec/fixtures/sample_product_response.json +30 -0
- data/spec/fixtures/sample_products_response.json +14 -0
- data/spec/fixtures/sample_video_response.json +47 -31
- data/spec/fixtures/sample_videos_response.json +14 -0
- data/spec/middleware/error_response_spec.rb +3 -7
- data/spec/middleware/oauth2_spec.rb +3 -7
- data/spec/objects/analytics_spec.rb +41 -0
- data/spec/objects/authorization_spec.rb +58 -0
- data/spec/objects/collection_item_spec.rb +53 -0
- data/spec/objects/collection_spec.rb +66 -0
- data/spec/objects/customer_spec.rb +82 -0
- data/spec/objects/product_spec.rb +65 -0
- data/spec/objects/site_spec.rb +36 -27
- data/spec/objects/user_spec.rb +40 -32
- data/spec/objects/video_file_spec.rb +52 -0
- data/spec/objects/video_spec.rb +67 -23
- data/spec/spec_helper.rb +2 -11
- data/spec/utilities/vhx_helper_spec.rb +11 -7
- data/spec/utilities/vhx_list_object_spec.rb +27 -0
- data/spec/utilities/vhx_object_spec.rb +69 -26
- data/vhx.gemspec +4 -4
- metadata +59 -66
- data/spec/fixtures/sample_package_response.json +0 -185
- data/spec/objects/file_spec.rb +0 -29
- data/spec/objects/package_spec.rb +0 -74
- data/spec/test_data.rb +0 -55
- data/spec/utilities/vhx_collection_spec.rb +0 -27
- data/spec/vcr/Vhx_Client/application_user/_refresh_access_token/access_token_changed.yml +0 -57
- data/spec/vcr/Vhx_Client/application_user/_refresh_access_token/oauth_token_refreshed.yml +0 -57
- data/spec/vcr/Vhx_File/associations/are_present.yml +0 -409
- data/spec/vcr/Vhx_Middleware_ErrorResponse/unauthorized_user_credentials.yml +0 -122
- data/spec/vcr/Vhx_Middleware_OAuth2/access_token_refresh.yml +0 -797
- data/spec/vcr/Vhx_Package/_add_video/with_hypermedia/returns_package_object.yml +0 -51
- data/spec/vcr/Vhx_Package/_add_video/with_id/returns_package_object.yml +0 -51
- data/spec/vcr/Vhx_Package/_create/returns_package_object.yml +0 -140
- data/spec/vcr/Vhx_Package/_find/with_hypermedia.yml +0 -243
- data/spec/vcr/Vhx_Package/_find/with_id.yml +0 -243
- data/spec/vcr/Vhx_Package/_remove_video/with_hypermedia/returns_success.yml +0 -51
- data/spec/vcr/Vhx_Package/_remove_video/with_id/returns_success.yml +0 -51
- data/spec/vcr/Vhx_Package/associations/are_present.yml +0 -195
- data/spec/vcr/Vhx_Site/_create/returns_site_object.yml +0 -91
- data/spec/vcr/Vhx_Site/_find/with_hypermedia.yml +0 -195
- data/spec/vcr/Vhx_Site/_find/with_id.yml +0 -195
- data/spec/vcr/Vhx_User/_find/with_hypermedia.yml +0 -81
- data/spec/vcr/Vhx_User/_find/with_id.yml +0 -81
- data/spec/vcr/Vhx_User/_me/returns_user_object.yml +0 -720
- data/spec/vcr/Vhx_User/_update/returns_user_object.yml +0 -212
- data/spec/vcr/Vhx_VhxObject/associations/cache/retreive_if_available.yml +0 -195
- data/spec/vcr/Vhx_VhxObject/associations/falls_back_to_links.yml +0 -310
- data/spec/vcr/Vhx_Video/_create/returns_video_object.yml +0 -125
- data/spec/vcr/Vhx_Video/associations/are_present.yml +0 -294
data/spec/objects/user_spec.rb
CHANGED
@@ -1,51 +1,59 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vhx::User do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
def user_response
|
6
|
+
JSON.parse(File.read("spec/fixtures/sample_user_response.json"))
|
7
|
+
end
|
6
8
|
|
7
|
-
before
|
8
|
-
Vhx.setup(
|
9
|
+
before{
|
10
|
+
Vhx.setup({api_key: 'testapikey'})
|
9
11
|
}
|
10
12
|
|
11
|
-
describe '
|
12
|
-
it 'with id' do
|
13
|
-
expect(Vhx::User.find(1560703)).to be_instance_of(Vhx::User)
|
14
|
-
end
|
13
|
+
describe 'api operations' do
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
describe '::find' do
|
16
|
+
it 'raises error' do
|
17
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: user_response))
|
18
|
+
expect{Vhx::User.find(123)}.to_not raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '::retrieve' do
|
23
|
+
it 'raises error' do
|
24
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: user_response))
|
25
|
+
expect{Vhx::User.retrieve(123)}.to_not raise_error
|
26
|
+
end
|
18
27
|
end
|
19
|
-
end
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
describe '::list' do
|
30
|
+
it 'raises error' do
|
31
|
+
expect{Vhx::User.list()}.to raise_error(NoMethodError)
|
32
|
+
end
|
24
33
|
end
|
25
|
-
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
describe '::all' do
|
36
|
+
it 'raises errors' do
|
37
|
+
expect{Vhx::User.all()}.to raise_error(NoMethodError)
|
38
|
+
end
|
31
39
|
end
|
32
|
-
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
describe '::create' do
|
42
|
+
it 'raises error' do
|
43
|
+
expect{Vhx::User.create()}.to raise_error(NoMethodError)
|
44
|
+
end
|
38
45
|
end
|
39
|
-
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
describe '#udpate' do
|
48
|
+
it 'raises error' do
|
49
|
+
expect{Vhx::User.new({}).update}.to raise_error(NoMethodError)
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
|
-
|
48
|
-
|
53
|
+
describe '::delete' do
|
54
|
+
it 'raises error' do
|
55
|
+
expect{Vhx::User.delete(1)}.to raise_error(NoMethodError)
|
56
|
+
end
|
49
57
|
end
|
50
58
|
end
|
51
|
-
end
|
59
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vhx::Video::File do
|
4
|
+
before{
|
5
|
+
Vhx.setup({api_key: 'testapikey'})
|
6
|
+
}
|
7
|
+
|
8
|
+
describe 'api operations' do
|
9
|
+
|
10
|
+
describe '::find' do
|
11
|
+
it 'raises error' do
|
12
|
+
expect{Vhx::Video::File.find(123)}.to raise_error(NoMethodError)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '::retrieve' do
|
17
|
+
it 'raises error' do
|
18
|
+
expect{Vhx::Video::File.retrieve(123)}.to raise_error(NoMethodError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '::list' do
|
23
|
+
it 'raises error' do
|
24
|
+
expect{Vhx::Video::File.list()}.to raise_error(NoMethodError)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '::all' do
|
29
|
+
it 'raises errors' do
|
30
|
+
expect{Vhx::Video::File.all()}.to raise_error(NoMethodError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '::create' do
|
35
|
+
it 'raises error' do
|
36
|
+
expect{Vhx::Video::File.create()}.to raise_error(NoMethodError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#udpate' do
|
41
|
+
it 'raises error' do
|
42
|
+
expect{Vhx::Video::File.new({}).update}.to raise_error(NoMethodError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '::delete' do
|
47
|
+
it 'raises error' do
|
48
|
+
expect{Vhx::Video::File.delete(1)}.to raise_error(NoMethodError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/objects/video_spec.rb
CHANGED
@@ -1,36 +1,80 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Vhx::Video
|
4
|
-
let(:sample_video_response){ JSON.parse(File.read("spec/fixtures/sample_video_response.json")) }
|
5
|
-
let(:vhx_video){Vhx::Video.new(sample_video_response)}
|
3
|
+
describe Vhx::Video do
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
def video_response
|
6
|
+
JSON.parse(File.read("spec/fixtures/sample_video_response.json"))
|
7
|
+
end
|
8
|
+
|
9
|
+
def videos_response
|
10
|
+
JSON.parse(File.read("spec/fixtures/sample_videos_response.json"))
|
11
|
+
end
|
12
|
+
|
13
|
+
before{
|
14
|
+
Vhx.setup({api_key: 'testapikey'})
|
9
15
|
}
|
16
|
+
|
17
|
+
describe 'api operations' do
|
10
18
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
19
|
+
describe '::find' do
|
20
|
+
it 'does not error' do
|
21
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: video_response))
|
22
|
+
expect{Vhx::Video.find(123)}.to_not raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '::retrieve' do
|
27
|
+
it 'does not error' do
|
28
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: video_response))
|
29
|
+
expect{Vhx::Video.retrieve(123)}.to_not raise_error
|
30
|
+
end
|
15
31
|
end
|
16
|
-
end
|
17
32
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
33
|
+
describe '::list' do
|
34
|
+
it 'does not error' do
|
35
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: videos_response))
|
36
|
+
expect{Vhx::Video.list()}.to_not raise_error
|
37
|
+
end
|
22
38
|
end
|
23
|
-
end
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
40
|
+
describe '::all' do
|
41
|
+
it 'does not error' do
|
42
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: videos_response))
|
43
|
+
expect{Vhx::Video.all()}.to_not raise_error
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
|
-
|
32
|
-
|
47
|
+
describe '::create' do
|
48
|
+
it 'raises error' do
|
49
|
+
Vhx.connection.stub(:post).and_return(OpenStruct.new(body: videos_response))
|
50
|
+
expect{Vhx::Video.create({})}.to_not raise_error
|
51
|
+
end
|
33
52
|
end
|
34
|
-
end
|
35
53
|
|
36
|
-
|
54
|
+
describe '#udpate' do
|
55
|
+
it 'raises error' do
|
56
|
+
expect{Vhx::Video.new({}).update}.to raise_error(NoMethodError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '::delete' do
|
61
|
+
it 'raises error' do
|
62
|
+
expect{Vhx::Video.delete(1)}.to raise_error(NoMethodError)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#files' do
|
67
|
+
|
68
|
+
def files_response
|
69
|
+
JSON.parse(File.read("spec/fixtures/sample_files_response.json"))
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'fetches linked association' do
|
73
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: files_response))
|
74
|
+
files = Vhx::Video.new(video_response).files
|
75
|
+
expect(files.first.class).to eq(Vhx::Video::File)
|
76
|
+
expect(Vhx.connection).to have_received(:get)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'vhx'
|
2
|
-
require 'vcr'
|
3
2
|
require 'json'
|
4
|
-
require '
|
5
|
-
|
6
|
-
VCR.configure do |vcr_config|
|
7
|
-
vcr_config.cassette_library_dir = 'spec/vcr'
|
8
|
-
vcr_config.hook_into :webmock
|
9
|
-
vcr_config.configure_rspec_metadata!
|
10
|
-
end
|
3
|
+
require 'webmock/rspec'
|
11
4
|
|
12
5
|
RSpec.configure do |config|
|
13
|
-
config.include TestData
|
14
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
6
|
config.run_all_when_everything_filtered = true
|
16
7
|
config.filter_run :focus
|
17
8
|
config.order = 'random'
|
18
|
-
end
|
9
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vhx::HelperMethods do
|
4
|
-
let(:
|
5
|
-
let(:vhx_object){Vhx::User.new(
|
4
|
+
let(:user_response){ JSON.parse(File.read("spec/fixtures/sample_user_response.json")) }
|
5
|
+
let(:vhx_object){Vhx::User.new(user_response)}
|
6
|
+
|
7
|
+
before{
|
8
|
+
Vhx.setup({api_key: 'testapikey'})
|
9
|
+
}
|
6
10
|
|
7
11
|
describe '#get_klass' do
|
8
12
|
context 'class method' do
|
@@ -21,27 +25,27 @@ describe Vhx::HelperMethods do
|
|
21
25
|
describe '#get_hypermedia' do
|
22
26
|
context 'hypermedia parameter' do
|
23
27
|
it 'returns hypermedia parameter' do
|
24
|
-
|
28
|
+
resource_url = 'https://api.vhx.tv/users/1560703'
|
29
|
+
expect(Vhx::User.get_hypermedia(resource_url)).to eq(resource_url)
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
28
33
|
context 'id parameter' do
|
29
34
|
it 'converts to hypermedia path' do
|
30
|
-
expect(vhx_object.get_hypermedia(1560703)).to eq '/users/1560703'
|
35
|
+
expect(vhx_object.get_hypermedia(1560703)).to eq 'https://api.vhx.tv/users/1560703'
|
31
36
|
end
|
32
37
|
|
33
38
|
context 'klass specified' do
|
34
39
|
it 'applies klass parameter' do
|
35
|
-
expect(vhx_object.get_hypermedia(1560703, 'Video')).to eq '/videos/1560703'
|
40
|
+
expect(vhx_object.get_hypermedia(1560703, 'Video')).to eq 'https://api.vhx.tv/videos/1560703'
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
44
|
context 'klass not specified' do
|
40
45
|
it 'determines klass' do
|
41
|
-
expect(vhx_object.get_hypermedia(1560703)).to eq '/users/1560703'
|
46
|
+
expect(vhx_object.get_hypermedia(1560703)).to eq 'https://api.vhx.tv/users/1560703'
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
45
|
-
|
46
50
|
end
|
47
51
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vhx::VhxListObject do
|
4
|
+
let(:hash_list){ JSON.parse(File.read("spec/fixtures/sample_hash_list.json")) }
|
5
|
+
let(:array_list){ JSON.parse(File.read("spec/fixtures/sample_array_list.json")) }
|
6
|
+
|
7
|
+
context 'hash list' do
|
8
|
+
it 'has #previous, #next methods based on _links' do
|
9
|
+
expect(Vhx::VhxListObject.new(hash_list, 'files').next).to eq 'pending'
|
10
|
+
expect(Vhx::VhxListObject.new(hash_list, 'files').previous).to eq 'pending'
|
11
|
+
end
|
12
|
+
|
13
|
+
xit 'makes call to url in #previous, #next' do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'builds array from _embedded' do
|
18
|
+
expect(Vhx::VhxListObject.new(hash_list, 'files').kind_of?(Array)).to eq true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'array list' do
|
23
|
+
it 'builds array from parameter' do
|
24
|
+
expect(Vhx::VhxListObject.new(array_list, 'files').kind_of?(Array)).to eq true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,53 +1,96 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Vhx::VhxObject
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe Vhx::VhxObject do
|
4
|
+
|
5
|
+
def customer_response
|
6
|
+
JSON.parse(File.read("spec/fixtures/sample_customer_response.json"))
|
7
|
+
end
|
8
|
+
|
9
|
+
def products_response
|
10
|
+
JSON.parse(File.read("spec/fixtures/sample_products_response.json"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def customer
|
14
|
+
Vhx::Customer.new(customer_response)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#to_json' do
|
18
|
+
it 'returns json' do
|
19
|
+
expect(customer.to_json.class).to be(String)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#to_hash' do
|
24
|
+
it 'returns object as a hash' do
|
25
|
+
expect(customer.to_hash.class).to be(Hash)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#href' do
|
30
|
+
it 'returns the href of the object' do
|
31
|
+
expect(customer.href).to match("https://api.vhx.tv/customers")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#links' do
|
36
|
+
it 'returns links object' do
|
37
|
+
expect(customer.links.self).to match("https://api.vhx.tv/customers")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#_links' do
|
42
|
+
it 'returns raw _links hash' do
|
43
|
+
expect(customer._links['self']['href']).to match("https://api.vhx.tv/customers")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#_embedded' do
|
48
|
+
it 'returns raw _embedded hash' do
|
49
|
+
expect(customer._embedded.keys).to include('products')
|
50
|
+
end
|
51
|
+
end
|
7
52
|
|
8
53
|
describe '#validate_class' do
|
9
54
|
it 'raises error' do
|
10
|
-
expect{Vhx::VhxObject.new(
|
55
|
+
expect{Vhx::VhxObject.new(customer_response)}.to raise_error(Vhx::InvalidResourceError)
|
11
56
|
end
|
12
57
|
|
13
58
|
it 'succeeds' do
|
14
|
-
expect(Vhx::
|
59
|
+
expect(Vhx::Customer.new(customer_response)).to be_instance_of(Vhx::Customer)
|
15
60
|
end
|
16
61
|
end
|
17
62
|
|
18
63
|
describe 'associations' do
|
19
64
|
before {
|
20
|
-
Vhx.setup(
|
65
|
+
Vhx.setup({api_key: 'testapikey'})
|
21
66
|
}
|
22
67
|
|
23
68
|
it 'default to embedded' do
|
24
|
-
|
25
|
-
|
69
|
+
Vhx.connection.stub(:get)
|
70
|
+
customer = Vhx::Customer.new(customer_response)
|
71
|
+
products = customer.products
|
72
|
+
expect(products).to be_instance_of Vhx::VhxListObject
|
73
|
+
expect(Vhx.connection).to_not have_received(:get)
|
26
74
|
end
|
27
75
|
|
28
76
|
it 'falls back to links' do
|
29
|
-
|
30
|
-
|
31
|
-
|
77
|
+
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: products_response))
|
78
|
+
customer_no_embedded = customer_response
|
79
|
+
customer_no_embedded['_embedded'] = {}
|
80
|
+
customer = Vhx::Customer.new(customer_no_embedded)
|
32
81
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
expect(vhx_object_without_embedded.site).to be_instance_of Vhx::Site
|
38
|
-
end
|
82
|
+
products = customer.products
|
83
|
+
|
84
|
+
expect(products).to be_instance_of Vhx::VhxListObject
|
85
|
+
expect(Vhx.connection).to have_received(:get).exactly(1).times
|
39
86
|
end
|
40
87
|
|
41
88
|
describe 'has_many' do
|
42
89
|
it 'returns VhxListObject object' do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
describe 'has_one' do
|
48
|
-
it 'returns resource object' do
|
49
|
-
expect(vhx_object_with_embedded.site).to be_instance_of Vhx::Site
|
90
|
+
customer = Vhx::Customer.new(customer_response)
|
91
|
+
products = customer.products
|
92
|
+
expect(products).to be_instance_of Vhx::VhxListObject
|
50
93
|
end
|
51
94
|
end
|
52
95
|
end
|
53
|
-
end
|
96
|
+
end
|