vhx-ruby 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/lib/vhx.rb +10 -10
- data/lib/vhx/objects/video.rb +1 -0
- data/lib/vhx/utilities/api_operations/create.rb +9 -2
- data/lib/vhx/utilities/api_operations/delete.rb +7 -3
- data/lib/vhx/utilities/api_operations/list.rb +8 -4
- data/lib/vhx/utilities/api_operations/request.rb +8 -4
- data/lib/vhx/utilities/api_operations/update.rb +3 -3
- data/lib/vhx/version.rb +1 -1
- data/spec/objects/customer_spec.rb +24 -8
- data/spec/objects/video_spec.rb +59 -11
- data/vhx.gemspec +4 -4
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56058d63c232a5221d030477f8de29ebea8efd62
|
4
|
+
data.tar.gz: 807adb8c7fc959aaa2fe7749a9618aaa07d2d1c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 574e551381081eb677a163544611b61d1daec286b5441f3cd60328df803ab80d0356413afe850ac1ec27fe3f151bb35691d505c2e467742a4c6d660408112504
|
7
|
+
data.tar.gz: 9714c5b4e9e6a702afa07db4ca965d187afa1dbbc5efdc3c9287f8d52a422deb1d2da796bdc9402b7162df0ee3d2c6a6e8fe63b1fb0fbf194bd50f4e83c27048
|
data/README.md
CHANGED
@@ -6,6 +6,29 @@ The VHX API is currently Private Beta. You can request an API key by emailing ap
|
|
6
6
|
|
7
7
|
`gem install vhx-ruby`
|
8
8
|
|
9
|
+
#### Building Locally
|
10
|
+
|
11
|
+
```shell
|
12
|
+
$ gem build vhx.gemspec
|
13
|
+
Successfully built RubyGem
|
14
|
+
Name: vhx
|
15
|
+
Version: 0.0.0
|
16
|
+
File: vhx-0.0.0.gem
|
17
|
+
|
18
|
+
$ gem install vhx-0.0.0.gem
|
19
|
+
Successfully installed vhx-0.0.0
|
20
|
+
1 gem installed
|
21
|
+
|
22
|
+
$ irb
|
23
|
+
irb(main)> require 'vhx'
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Running Specs
|
27
|
+
|
28
|
+
```shell
|
29
|
+
rspec .
|
30
|
+
```
|
31
|
+
|
9
32
|
### Documentation
|
10
33
|
|
11
34
|
Documentation is available at http://dev.vhx.tv/docs/api/ruby.
|
@@ -16,7 +39,7 @@ Full API reference is available at http://dev.vhx.tv/docs/api?ruby.
|
|
16
39
|
Before requesting your first resource, you must setup an instance of the Vhx Client:
|
17
40
|
|
18
41
|
```ruby
|
19
|
-
vhx = Vhx.setup({ api_key: 'your VHX API key'}
|
42
|
+
vhx = Vhx.setup({ api_key: 'your VHX API key' })
|
20
43
|
```
|
21
44
|
|
22
45
|
Here's an example of creating a Vhx resource with payload options. You can handle errors by rescuing Vhx::VhxError.
|
data/lib/vhx.rb
CHANGED
@@ -36,20 +36,20 @@ module Vhx
|
|
36
36
|
|
37
37
|
class << self
|
38
38
|
def setup(options = {})
|
39
|
-
options[:client_id]
|
40
|
-
options[:client_secret]
|
41
|
-
options[:api_key]
|
42
|
-
options[:api_base]
|
43
|
-
options[:auto_refresh]
|
39
|
+
options[:client_id] ||= @client_id
|
40
|
+
options[:client_secret] ||= @client_secret
|
41
|
+
options[:api_key] ||= @api_key
|
42
|
+
options[:api_base] ||= @api_base_url
|
43
|
+
options[:auto_refresh] = @auto_refresh || false
|
44
44
|
Vhx.client = Vhx::Client.new(options)
|
45
45
|
end
|
46
46
|
|
47
47
|
def config(config = {})
|
48
|
-
@client_id
|
49
|
-
@client_secret
|
50
|
-
@api_key
|
51
|
-
@auto_refresh
|
52
|
-
@api_base_url
|
48
|
+
@client_id = config[:client_id]
|
49
|
+
@client_secret = config[:client_secret]
|
50
|
+
@api_key = config[:api_key]
|
51
|
+
@auto_refresh = config[:auto_refresh] || false
|
52
|
+
@api_base_url = config[:api_base]
|
53
53
|
end
|
54
54
|
|
55
55
|
def client
|
data/lib/vhx/objects/video.rb
CHANGED
@@ -2,10 +2,17 @@ module Vhx
|
|
2
2
|
module ApiOperations
|
3
3
|
module Create
|
4
4
|
module ClassMethods
|
5
|
-
def create(payload)
|
5
|
+
def create(payload, headers = {})
|
6
6
|
klass = get_klass
|
7
7
|
response = Vhx.connection.post do |req|
|
8
|
-
req.url('/' + klass.downcase + 's') #This url is based purely on VHX's API convention.
|
8
|
+
req.url('/' + klass.downcase + 's') # This url is based purely on VHX's API convention.
|
9
|
+
|
10
|
+
if headers.length > 0
|
11
|
+
headers.each do |key, value|
|
12
|
+
req.headers[key] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
9
16
|
req.body = payload
|
10
17
|
end
|
11
18
|
|
@@ -2,8 +2,12 @@ module Vhx
|
|
2
2
|
module ApiOperations
|
3
3
|
module Delete
|
4
4
|
module ClassMethods
|
5
|
-
def delete(identifier, payload = {})
|
6
|
-
Vhx.connection.delete(
|
5
|
+
def delete(identifier, payload = {}, headers = {})
|
6
|
+
Vhx.connection.delete(
|
7
|
+
get_hypermedia(identifier),
|
8
|
+
payload,
|
9
|
+
headers,
|
10
|
+
)
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -13,4 +17,4 @@ module Vhx
|
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
16
|
-
end
|
20
|
+
end
|
@@ -4,13 +4,17 @@ module Vhx
|
|
4
4
|
module ApiOperations
|
5
5
|
module List
|
6
6
|
module ClassMethods
|
7
|
-
def all(payload = {})
|
8
|
-
response = Vhx.connection.get(
|
7
|
+
def all(payload = {}, headers = {})
|
8
|
+
response = Vhx.connection.get(
|
9
|
+
'/' + get_klass.downcase + 's',
|
10
|
+
payload,
|
11
|
+
headers,
|
12
|
+
)
|
9
13
|
VhxListObject.new(response.body, get_klass.downcase + 's')
|
10
14
|
end
|
11
15
|
|
12
|
-
def list(payload = {})
|
13
|
-
self.all(payload)
|
16
|
+
def list(payload = {}, headers = {})
|
17
|
+
self.all(payload, headers)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -2,13 +2,17 @@ module Vhx
|
|
2
2
|
module ApiOperations
|
3
3
|
module Request
|
4
4
|
module ClassMethods
|
5
|
-
def find(identifier)
|
6
|
-
response = Vhx.connection.get(
|
5
|
+
def find(identifier, payload = {}, headers = {})
|
6
|
+
response = Vhx.connection.get(
|
7
|
+
get_hypermedia(identifier),
|
8
|
+
payload,
|
9
|
+
headers,
|
10
|
+
)
|
7
11
|
self.new(response.body)
|
8
12
|
end
|
9
13
|
|
10
|
-
def retrieve(identifier)
|
11
|
-
self.find(identifier)
|
14
|
+
def retrieve(identifier, payload = {}, headers = {})
|
15
|
+
self.find(identifier, payload, headers)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -2,8 +2,8 @@ module Vhx
|
|
2
2
|
module ApiOperations
|
3
3
|
module Update
|
4
4
|
module InstanceMethods
|
5
|
-
def update(payload)
|
6
|
-
Vhx.connection.put(self.href, payload)
|
5
|
+
def update(payload, headers = {})
|
6
|
+
Vhx.connection.put(self.href, payload, headers)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -12,4 +12,4 @@ module Vhx
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
data/lib/vhx/version.rb
CHANGED
@@ -12,34 +12,34 @@ describe Vhx::Customer do
|
|
12
12
|
before{
|
13
13
|
Vhx.setup({api_key: 'testapikey'})
|
14
14
|
}
|
15
|
-
|
15
|
+
|
16
16
|
describe 'api operations' do
|
17
17
|
|
18
18
|
describe '::find' do
|
19
19
|
it 'does not error' do
|
20
20
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: customer_response))
|
21
|
-
expect{Vhx::Customer.find(123)}.to_not raise_error
|
21
|
+
expect{Vhx::Customer.find(123)}.to_not raise_error
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
24
24
|
|
25
25
|
describe '::retrieve' do
|
26
26
|
it 'does not error' do
|
27
27
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: customer_response))
|
28
|
-
expect{Vhx::Customer.retrieve(123)}.to_not raise_error
|
28
|
+
expect{Vhx::Customer.retrieve(123)}.to_not raise_error
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '::list' do
|
33
33
|
it 'does not error' do
|
34
34
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: customers_response))
|
35
|
-
expect{Vhx::Customer.list()}.to_not raise_error
|
35
|
+
expect{Vhx::Customer.list()}.to_not raise_error
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '::all' do
|
40
40
|
it 'does not error' do
|
41
41
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: customers_response))
|
42
|
-
expect{Vhx::Customer.all()}.to_not raise_error
|
42
|
+
expect{Vhx::Customer.all()}.to_not raise_error
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -61,13 +61,29 @@ describe Vhx::Customer do
|
|
61
61
|
Vhx.connection.stub(:delete).and_return(OpenStruct.new(body: ""))
|
62
62
|
expect{Vhx::Customer.delete(1)}.to_not raise_error
|
63
63
|
end
|
64
|
+
|
65
|
+
it "supports headers" do
|
66
|
+
params = [
|
67
|
+
:delete,
|
68
|
+
"https://api.vhx.tv/customers/1",
|
69
|
+
nil,
|
70
|
+
{ "VHX-Client-IP" => "1.2.3.4" },
|
71
|
+
]
|
72
|
+
response = OpenStruct.new(body: "")
|
73
|
+
|
74
|
+
expect_any_instance_of(Faraday::Connection).to receive(:run_request).
|
75
|
+
with(*params).
|
76
|
+
and_return(response)
|
77
|
+
|
78
|
+
Vhx::Customer.delete(1, {}, { 'VHX-Client-IP' => '1.2.3.4' })
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
82
|
describe '#add_product' do
|
67
83
|
it 'returns customer' do
|
68
84
|
Vhx.connection.stub(:put).and_return(OpenStruct.new(body: customer_response))
|
69
85
|
customer = Vhx::Customer.new(customer_response).add_product(1)
|
70
|
-
expect(customer.class).to eq(Vhx::Customer)
|
86
|
+
expect(customer.class).to eq(Vhx::Customer)
|
71
87
|
end
|
72
88
|
end
|
73
89
|
|
@@ -75,7 +91,7 @@ describe Vhx::Customer do
|
|
75
91
|
it 'returns customer' do
|
76
92
|
Vhx.connection.stub(:delete).and_return(OpenStruct.new(body: customer_response))
|
77
93
|
customer = Vhx::Customer.new(customer_response).remove_product(1)
|
78
|
-
expect(customer.class).to eq(Vhx::Customer)
|
94
|
+
expect(customer.class).to eq(Vhx::Customer)
|
79
95
|
end
|
80
96
|
end
|
81
97
|
end
|
data/spec/objects/video_spec.rb
CHANGED
@@ -13,34 +13,66 @@ describe Vhx::Video do
|
|
13
13
|
before{
|
14
14
|
Vhx.setup({api_key: 'testapikey'})
|
15
15
|
}
|
16
|
-
|
16
|
+
|
17
17
|
describe 'api operations' do
|
18
18
|
|
19
19
|
describe '::find' do
|
20
20
|
it 'does not error' do
|
21
21
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: video_response))
|
22
|
-
expect{Vhx::Video.find(123)}.to_not raise_error
|
22
|
+
expect{Vhx::Video.find(123)}.to_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "supports headers" do
|
26
|
+
params = [
|
27
|
+
:get,
|
28
|
+
"https://api.vhx.tv/videos/123",
|
29
|
+
nil,
|
30
|
+
{ "VHX-Client-IP" => "1.2.3.4" },
|
31
|
+
]
|
32
|
+
response = OpenStruct.new(body: video_response)
|
33
|
+
|
34
|
+
expect_any_instance_of(Faraday::Connection).to receive(:run_request).
|
35
|
+
with(*params).
|
36
|
+
and_return(response)
|
37
|
+
|
38
|
+
Vhx::Video.find(123, {}, { 'VHX-Client-IP' => '1.2.3.4' })
|
23
39
|
end
|
24
|
-
end
|
40
|
+
end
|
25
41
|
|
26
42
|
describe '::retrieve' do
|
27
43
|
it 'does not error' do
|
28
44
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: video_response))
|
29
|
-
expect{Vhx::Video.retrieve(123)}.to_not raise_error
|
45
|
+
expect{Vhx::Video.retrieve(123)}.to_not raise_error
|
30
46
|
end
|
31
47
|
end
|
32
48
|
|
33
49
|
describe '::list' do
|
34
50
|
it 'does not error' do
|
35
51
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: videos_response))
|
36
|
-
expect{Vhx::Video.list()}.to_not raise_error
|
52
|
+
expect{Vhx::Video.list()}.to_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "supports headers" do
|
56
|
+
params = [
|
57
|
+
:get,
|
58
|
+
"/videos",
|
59
|
+
nil,
|
60
|
+
{ "VHX-Client-IP" => "1.2.3.4" },
|
61
|
+
]
|
62
|
+
response = OpenStruct.new(body: videos_response)
|
63
|
+
|
64
|
+
expect_any_instance_of(Faraday::Connection).to receive(:run_request).
|
65
|
+
with(*params).
|
66
|
+
and_return(response)
|
67
|
+
|
68
|
+
Vhx::Video.list({}, { 'VHX-Client-IP' => '1.2.3.4' })
|
37
69
|
end
|
38
70
|
end
|
39
71
|
|
40
72
|
describe '::all' do
|
41
73
|
it 'does not error' do
|
42
74
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: videos_response))
|
43
|
-
expect{Vhx::Video.all()}.to_not raise_error
|
75
|
+
expect{Vhx::Video.all()}.to_not raise_error
|
44
76
|
end
|
45
77
|
end
|
46
78
|
|
@@ -51,9 +83,26 @@ describe Vhx::Video do
|
|
51
83
|
end
|
52
84
|
end
|
53
85
|
|
54
|
-
describe '#
|
86
|
+
describe '#update' do
|
55
87
|
it 'raises error' do
|
56
|
-
|
88
|
+
Vhx.connection.stub(:put).and_return(OpenStruct.new(body: video_response))
|
89
|
+
expect{Vhx::Video.new(video_response).update({})}.to_not raise_error(NoMethodError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "supports headers" do
|
93
|
+
params = [
|
94
|
+
:put,
|
95
|
+
"https://api.vhx.tv/videos/1",
|
96
|
+
{ title: "Video" },
|
97
|
+
{ "VHX-Client-IP" => "1.2.3.4" },
|
98
|
+
]
|
99
|
+
response = OpenStruct.new(body: videos_response)
|
100
|
+
|
101
|
+
expect_any_instance_of(Faraday::Connection).to receive(:run_request).
|
102
|
+
with(*params).
|
103
|
+
and_return(response)
|
104
|
+
video = Vhx::Video.new(video_response)
|
105
|
+
video.update({ title: "Video" }, { 'VHX-Client-IP' => '1.2.3.4' })
|
57
106
|
end
|
58
107
|
end
|
59
108
|
|
@@ -64,15 +113,14 @@ describe Vhx::Video do
|
|
64
113
|
end
|
65
114
|
|
66
115
|
describe '#files' do
|
67
|
-
|
68
116
|
def files_response
|
69
117
|
JSON.parse(File.read("spec/fixtures/sample_files_response.json"))
|
70
118
|
end
|
71
|
-
|
119
|
+
|
72
120
|
it 'fetches linked association' do
|
73
121
|
Vhx.connection.stub(:get).and_return(OpenStruct.new(body: files_response))
|
74
122
|
files = Vhx::Video.new(video_response).files
|
75
|
-
expect(files.first.class).to eq(Vhx::Video::File)
|
123
|
+
expect(files.first.class).to eq(Vhx::Video::File)
|
76
124
|
expect(Vhx.connection).to have_received(:get)
|
77
125
|
end
|
78
126
|
end
|
data/vhx.gemspec
CHANGED
@@ -5,10 +5,10 @@ require 'vhx/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'vhx-ruby'
|
7
7
|
spec.version = Vhx::VERSION
|
8
|
-
spec.authors = ['Sagar Shah']
|
9
|
-
spec.date = '2017-
|
10
|
-
spec.description = 'A Ruby wrapper for the
|
11
|
-
spec.summary = 'A Ruby wrapper for the
|
8
|
+
spec.authors = ['Sagar Shah', 'Kevin Sheurs']
|
9
|
+
spec.date = '2017-02-03'
|
10
|
+
spec.description = 'A Ruby wrapper for the VHX developer API.'
|
11
|
+
spec.summary = 'A Ruby wrapper for the VHX developer API.'
|
12
12
|
spec.email = ['sagar@vhx.tv', 'dev@vhx.tv', 'wontae@vhx.tv', 'charlie@vhx.tv', 'kevin@vhx.tv', 'scott@vhx.tv']
|
13
13
|
spec.homepage = 'http://dev.vhx.tv/docs/api/'
|
14
14
|
spec.license = 'MIT'
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vhx-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sagar Shah
|
8
|
+
- Kevin Sheurs
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: faraday
|
@@ -66,7 +67,7 @@ dependencies:
|
|
66
67
|
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
69
|
-
description: A Ruby wrapper for the
|
70
|
+
description: A Ruby wrapper for the VHX developer API.
|
70
71
|
email:
|
71
72
|
- sagar@vhx.tv
|
72
73
|
- dev@vhx.tv
|
@@ -165,7 +166,7 @@ rubyforge_project:
|
|
165
166
|
rubygems_version: 2.5.1
|
166
167
|
signing_key:
|
167
168
|
specification_version: 4
|
168
|
-
summary: A Ruby wrapper for the
|
169
|
+
summary: A Ruby wrapper for the VHX developer API.
|
169
170
|
test_files:
|
170
171
|
- spec/client_spec.rb
|
171
172
|
- spec/fixtures/sample_array_list.json
|