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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/lib/vhx.rb +4 -3
  4. data/lib/vhx/client.rb +6 -3
  5. data/lib/vhx/objects/analytics.rb +9 -0
  6. data/lib/vhx/utilities/vhx_object.rb +2 -2
  7. data/lib/vhx/version.rb +2 -2
  8. data/spec/client_spec.rb +44 -9
  9. data/spec/fixtures/sample_authorization_response.json +19 -0
  10. data/spec/fixtures/sample_collection_response.json +20 -0
  11. data/spec/fixtures/sample_collections_response.json +14 -0
  12. data/spec/fixtures/sample_create_video_response.json +33 -0
  13. data/spec/fixtures/sample_customer_response.json +16 -0
  14. data/spec/fixtures/sample_customers_response.json +28 -0
  15. data/spec/fixtures/sample_files_response.json +16 -0
  16. data/spec/fixtures/sample_product_response.json +30 -0
  17. data/spec/fixtures/sample_products_response.json +14 -0
  18. data/spec/fixtures/sample_video_response.json +47 -31
  19. data/spec/fixtures/sample_videos_response.json +14 -0
  20. data/spec/middleware/error_response_spec.rb +3 -7
  21. data/spec/middleware/oauth2_spec.rb +3 -7
  22. data/spec/objects/analytics_spec.rb +41 -0
  23. data/spec/objects/authorization_spec.rb +58 -0
  24. data/spec/objects/collection_item_spec.rb +53 -0
  25. data/spec/objects/collection_spec.rb +66 -0
  26. data/spec/objects/customer_spec.rb +82 -0
  27. data/spec/objects/product_spec.rb +65 -0
  28. data/spec/objects/site_spec.rb +36 -27
  29. data/spec/objects/user_spec.rb +40 -32
  30. data/spec/objects/video_file_spec.rb +52 -0
  31. data/spec/objects/video_spec.rb +67 -23
  32. data/spec/spec_helper.rb +2 -11
  33. data/spec/utilities/vhx_helper_spec.rb +11 -7
  34. data/spec/utilities/vhx_list_object_spec.rb +27 -0
  35. data/spec/utilities/vhx_object_spec.rb +69 -26
  36. data/vhx.gemspec +4 -4
  37. metadata +59 -66
  38. data/spec/fixtures/sample_package_response.json +0 -185
  39. data/spec/objects/file_spec.rb +0 -29
  40. data/spec/objects/package_spec.rb +0 -74
  41. data/spec/test_data.rb +0 -55
  42. data/spec/utilities/vhx_collection_spec.rb +0 -27
  43. data/spec/vcr/Vhx_Client/application_user/_refresh_access_token/access_token_changed.yml +0 -57
  44. data/spec/vcr/Vhx_Client/application_user/_refresh_access_token/oauth_token_refreshed.yml +0 -57
  45. data/spec/vcr/Vhx_File/associations/are_present.yml +0 -409
  46. data/spec/vcr/Vhx_Middleware_ErrorResponse/unauthorized_user_credentials.yml +0 -122
  47. data/spec/vcr/Vhx_Middleware_OAuth2/access_token_refresh.yml +0 -797
  48. data/spec/vcr/Vhx_Package/_add_video/with_hypermedia/returns_package_object.yml +0 -51
  49. data/spec/vcr/Vhx_Package/_add_video/with_id/returns_package_object.yml +0 -51
  50. data/spec/vcr/Vhx_Package/_create/returns_package_object.yml +0 -140
  51. data/spec/vcr/Vhx_Package/_find/with_hypermedia.yml +0 -243
  52. data/spec/vcr/Vhx_Package/_find/with_id.yml +0 -243
  53. data/spec/vcr/Vhx_Package/_remove_video/with_hypermedia/returns_success.yml +0 -51
  54. data/spec/vcr/Vhx_Package/_remove_video/with_id/returns_success.yml +0 -51
  55. data/spec/vcr/Vhx_Package/associations/are_present.yml +0 -195
  56. data/spec/vcr/Vhx_Site/_create/returns_site_object.yml +0 -91
  57. data/spec/vcr/Vhx_Site/_find/with_hypermedia.yml +0 -195
  58. data/spec/vcr/Vhx_Site/_find/with_id.yml +0 -195
  59. data/spec/vcr/Vhx_User/_find/with_hypermedia.yml +0 -81
  60. data/spec/vcr/Vhx_User/_find/with_id.yml +0 -81
  61. data/spec/vcr/Vhx_User/_me/returns_user_object.yml +0 -720
  62. data/spec/vcr/Vhx_User/_update/returns_user_object.yml +0 -212
  63. data/spec/vcr/Vhx_VhxObject/associations/cache/retreive_if_available.yml +0 -195
  64. data/spec/vcr/Vhx_VhxObject/associations/falls_back_to_links.yml +0 -310
  65. data/spec/vcr/Vhx_Video/_create/returns_video_object.yml +0 -125
  66. data/spec/vcr/Vhx_Video/associations/are_present.yml +0 -294
@@ -1,51 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vhx::User do
4
- let(:sample_user_response){ JSON.parse(File.read("spec/fixtures/sample_user_response.json")) }
5
- let(:vhx_user){Vhx::User.new(sample_user_response)}
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(test_credentials)
9
+ before{
10
+ Vhx.setup({api_key: 'testapikey'})
9
11
  }
10
12
 
11
- describe '::find', :vcr do
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
- it 'with hypermedia' do
17
- expect(Vhx::User.find('http://api.crystal.dev/users/1560703')).to be_instance_of(Vhx::User)
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
- describe '::me', :vcr do
22
- it 'returns user object' do
23
- expect(Vhx::User.me).to be_instance_of(Vhx::User)
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
- describe '#update', :vcr do
28
- it 'returns user object' do
29
- vhx_user.update(name: 'Test Name')
30
- expect(vhx_user.name).to eq 'Test Name'
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
- describe 'attributes' do
35
- it 'are present' do
36
- expect(vhx_user.id).to_not be_nil
37
- expect(vhx_user.name).to_not be_nil
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
- describe 'associations' do
42
- it 'are present' do
43
- expect{vhx_user.packages}.to_not raise_error(NoMethodError)
44
- expect{vhx_user.sites}.to_not raise_error(NoMethodError)
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
- it 'errors if not present' do
48
- expect{vhx_user.users}.to raise_error(NoMethodError)
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
@@ -1,36 +1,80 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vhx::Video, :vcr do
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
- before {
8
- Vhx.setup(test_credentials)
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
- describe '::create' do
12
- it 'returns video object' do
13
- attributes = {title: 'gem test video', description: 'this video is for gem testing', site: 'http://api.crystal.dev/sites/1900'}
14
- expect(Vhx::Video.create(attributes)).to be_instance_of(Vhx::Video)
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
- describe 'attributes' do
19
- it 'are present' do
20
- expect(vhx_video.id).to_not be_nil
21
- expect(vhx_video.title).to_not be_nil
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
- describe 'associations' do
26
- it 'are present' do
27
- expect{vhx_video.files}.to_not raise_error(NoMethodError)
28
- expect{vhx_video.site}.to_not raise_error(NoMethodError)
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
- it 'errors if not present' do
32
- expect{vhx_video.videos}.to raise_error(NoMethodError)
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
- end
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 'test_data'
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(:sample_user_response){ JSON.parse(File.read("spec/fixtures/sample_user_response.json")) }
5
- let(:vhx_object){Vhx::User.new(sample_user_response)}
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
- expect(Vhx::User.get_hypermedia('http://api.crystal.dev/users/1560703')).to eq 'http://api.crystal.dev/users/1560703'
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, :vcr do
4
- let(:sample_package_response){ JSON.parse(File.read("spec/fixtures/sample_package_response.json")) }
5
- let(:vhx_object_with_embedded){Vhx::Package.new(sample_package_response)}
6
- let(:vhx_object_without_embedded){sample_package_response['_embedded'] = {}; Vhx::Package.new(sample_package_response);}
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(sample_package_response)}.to raise_error(Vhx::InvalidResourceError)
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::Package.new(sample_package_response)).to be_instance_of(Vhx::Package)
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(test_credentials)
65
+ Vhx.setup({api_key: 'testapikey'})
21
66
  }
22
67
 
23
68
  it 'default to embedded' do
24
- Faraday::Connection.any_instance.should_not_receive(:get)
25
- expect(vhx_object_with_embedded.site).to be_instance_of Vhx::Site
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
- Faraday::Connection.any_instance.should_receive(:get).and_call_original
30
- expect(vhx_object_without_embedded.site).to be_instance_of Vhx::Site
31
- end
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
- describe 'cache' do
34
- it 'retreive if available' do
35
- vhx_object_without_embedded.site
36
- Faraday::Connection.any_instance.should_not_receive(:get)
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
- expect(vhx_object_with_embedded.videos).to be_instance_of Vhx::VhxListObject
44
- end
45
- end
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