proteus_client 0.0.1 → 0.0.2
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.
- data/lib/proteus_client/config.rb +12 -0
- data/lib/{proteus/client.rb → proteus_client/proxy.rb} +22 -10
- data/lib/proteus_client.rb +12 -2
- data/spec/proteus_client_spec.rb +217 -0
- metadata +6 -4
- data/lib/proteus/config.rb +0 -5
@@ -0,0 +1,12 @@
|
|
1
|
+
module ProteusClient
|
2
|
+
|
3
|
+
# Used to configure default values used for creating a ProteusClient::Proxy
|
4
|
+
# @example Configuring values
|
5
|
+
# ProteusClient.config.domain = "http://localhost:9292"
|
6
|
+
# ProteusClient.config.api_key= "api_key"
|
7
|
+
#
|
8
|
+
class Config
|
9
|
+
attr_accessor :domain, :api_key
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -1,5 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module ProteusClient
|
2
|
+
|
3
|
+
# Provides an interface for Proteus REST service to encode videos
|
4
|
+
# @example Creating a new proxy
|
5
|
+
# ProteusClient::Proxy.new
|
6
|
+
# ProteusClient::Proxy.new({api_key: "api_key", domain: "http://localhost:9292"})
|
7
|
+
#
|
8
|
+
# @example Testing service
|
9
|
+
# proteus_client.test_api #=> {message: 'Welcome to Proteus'}
|
10
|
+
#
|
11
|
+
# @example Calling a method
|
12
|
+
# proteus_client.create_video("video_id","type")
|
13
|
+
#
|
14
|
+
# @raise [APIKeyNotDefined] if api_key is not defined in ProteusClient.config or sent as param
|
15
|
+
# @raise [DomainNotDefined] if domain is not defined in ProteusClient.config or sent as param
|
16
|
+
# @raise [RestClient::Exception] if status code returned from services is not in 200..207
|
17
|
+
#
|
18
|
+
class Proxy
|
3
19
|
|
4
20
|
def initialize(options = {})
|
5
21
|
options = merge_with_default_options(options)
|
@@ -7,10 +23,6 @@ module Proteus
|
|
7
23
|
@domain = RestClient::Resource.new(options[:domain])
|
8
24
|
end
|
9
25
|
|
10
|
-
def self.config
|
11
|
-
@config ||= Proteus::Config.new
|
12
|
-
end
|
13
|
-
|
14
26
|
def test_api
|
15
27
|
response = submit_request(:get,'/',{})
|
16
28
|
|
@@ -59,12 +71,12 @@ module Proteus
|
|
59
71
|
|
60
72
|
def merge_with_default_options(options)
|
61
73
|
opts = {
|
62
|
-
api_key:
|
63
|
-
domain:
|
74
|
+
api_key: ProteusClient.config.api_key,
|
75
|
+
domain: ProteusClient.config.domain
|
64
76
|
}.merge(options)
|
65
77
|
|
66
|
-
raise "
|
67
|
-
raise "
|
78
|
+
raise "APIKeyNotDefined" unless opts[:api_key]
|
79
|
+
raise "DomainNotDefined" unless opts[:domain]
|
68
80
|
|
69
81
|
opts
|
70
82
|
end
|
data/lib/proteus_client.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest_client'
|
3
3
|
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
4
|
+
require_relative 'proteus_client/config'
|
5
|
+
require_relative 'proteus_client/proxy'
|
6
|
+
|
7
|
+
# Provides an interface to use Proteus rest services features
|
8
|
+
#
|
9
|
+
module ProteusClient
|
10
|
+
|
11
|
+
def self.config
|
12
|
+
@config ||= ProteusClient::Config.new
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stubs'
|
3
|
+
|
4
|
+
require_relative '../lib/proteus_client'
|
5
|
+
|
6
|
+
describe ProteusClient::Proxy do
|
7
|
+
|
8
|
+
let(:api_key) { "api_key" }
|
9
|
+
|
10
|
+
let(:proteus_client_wrong_api) do
|
11
|
+
described_class.new(domain: 'http://localhost:9292', api_key: 'wrong_api')
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:proteus_client) do
|
15
|
+
ProteusClient.config.domain = 'http://localhost:9292'
|
16
|
+
ProteusClient.config.api_key = 'api_key'
|
17
|
+
described_class.new()
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates a new instance of proteus with correct api_key" do
|
21
|
+
proteus_client
|
22
|
+
ProteusClient.config.api_key.should == api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'call to test_api' do
|
26
|
+
before(:all) do
|
27
|
+
stub_response(:get,'/',200,'Welcome to proteus',{})
|
28
|
+
@response = proteus_client.test_api
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns correct message" do
|
32
|
+
@response[:message].should == 'Welcome to proteus'
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'call to create_video_allocation'do
|
38
|
+
|
39
|
+
context 'with no count argument' do
|
40
|
+
|
41
|
+
before(:all) do
|
42
|
+
stub_create_video_allocation
|
43
|
+
@response = proteus_client.create_video_allocation()
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns a hash" do
|
47
|
+
@response.class.should == Hash
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns video_allocation_id" do
|
51
|
+
@response[:video_allocation_id].should == '4fe0f752831a9d08bb000010'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns urls" do
|
55
|
+
@response[:urls][0].should == {type: 'direct', url:'direct/4fe0f752831a9d08bb000010.flv'}
|
56
|
+
@response[:urls][1].should == {type: 'stream', url:'stream/4fe0f752831a9d08bb000010.flv'}
|
57
|
+
@response[:urls][2].should == {type: 'upload', url:'upload/4fe0f752831a9d08bb000010.flv'}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with count argument' do
|
63
|
+
|
64
|
+
before(:all) do
|
65
|
+
stub_create_video_allocations
|
66
|
+
@response = proteus_client.create_video_allocation(2)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns an array with two hashes" do
|
70
|
+
@response.class.should == Array
|
71
|
+
@response.size.should == 2
|
72
|
+
@response[0].class.should == Hash
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'call to create_video'do
|
80
|
+
|
81
|
+
before(:all) do
|
82
|
+
stub_create_video
|
83
|
+
@response = proteus_client.create_video('4fe0f752831a9d08bb000010','direct')
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns a hash" do
|
87
|
+
@response.class.should == Hash
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns video url" do
|
91
|
+
@response[:url].should == 'direct/4fe0f752831a9d08bb000010.flv'
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'call to create_video_versions'do
|
97
|
+
|
98
|
+
context 'with valid id' do
|
99
|
+
|
100
|
+
before(:all) do
|
101
|
+
stub_response(:post,'/videos/4fe0f752831a9d08bb000010/versions',
|
102
|
+
200,'',{})
|
103
|
+
@response = proteus_client.create_video_versions('4fe0f752831a9d08bb000010')
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns success message" do
|
107
|
+
@response[:message].should == 'success'
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with valid id and type' do
|
113
|
+
|
114
|
+
before(:all) do
|
115
|
+
stub_response(:post,'/videos/4fe0f752831a9d08bb000010/versions',
|
116
|
+
200,'',{version_settings: 'mobile'})
|
117
|
+
@response = proteus_client.create_video_versions('4fe0f752831a9d08bb000010','mobile')
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns true" do
|
121
|
+
@response[:message].should == 'success'
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'call to get_video'do
|
129
|
+
|
130
|
+
before(:all) do
|
131
|
+
stub_get_video
|
132
|
+
@response = proteus_client.get_video('4fe0f752831a9d08bb000010')
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns a hash" do
|
136
|
+
@response.class.should == Hash
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns video with correct format" do
|
140
|
+
@response['url'].class.should == String
|
141
|
+
@response['duration'].class.should == Fixnum
|
142
|
+
@response['versions'].class.should == Array
|
143
|
+
@response['versions'][0].class.should == Hash
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'call to get_videos' do
|
149
|
+
|
150
|
+
before(:all) do
|
151
|
+
stub_get_videos
|
152
|
+
@response = proteus_client.get_videos('4fe0f752831a9d08bb000010','4fe0f752831a9d08bb000010')
|
153
|
+
end
|
154
|
+
|
155
|
+
it "returns an array with hashes" do
|
156
|
+
@response.class.should == Array
|
157
|
+
@response.size.should == 2
|
158
|
+
@response.first.class.should == Hash
|
159
|
+
end
|
160
|
+
|
161
|
+
it "returns videos with correct format" do
|
162
|
+
video = @response.first
|
163
|
+
video['url'].class.should == String
|
164
|
+
video['duration'].class.should == Fixnum
|
165
|
+
video['versions'].class.should == Array
|
166
|
+
video['versions'][0].class.should == Hash
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'call to get_video_allocation' do
|
172
|
+
|
173
|
+
context 'with valid arguments' do
|
174
|
+
|
175
|
+
before(:all) do
|
176
|
+
stub_get_video_allocation
|
177
|
+
@response = proteus_client.get_video_allocation('4fe0f752831a9d08bb000010')
|
178
|
+
end
|
179
|
+
|
180
|
+
it "returns a hash" do
|
181
|
+
@response.class.should == Hash
|
182
|
+
end
|
183
|
+
|
184
|
+
it "returns video with correct format" do
|
185
|
+
@response['url_direct'].class.should == String
|
186
|
+
@response['url_stream'].class.should == String
|
187
|
+
@response['url_upload'].class.should == String
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'submit request' do
|
195
|
+
|
196
|
+
it 'call with :get works returns a correct response' do
|
197
|
+
stub_resource(:get)
|
198
|
+
proteus_client.send(:submit_request,:get,'/',{}).class.should == String
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'call with :post works returns a correct response' do
|
202
|
+
stub_resource(:post)
|
203
|
+
proteus_client.send(:submit_request,:post,'/',{}).class.should == String
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'call with :get works returns a correct response' do
|
207
|
+
stub_resource(:get)
|
208
|
+
proteus_client.send(:submit_request,:get_raw,'/',{}).class.should == String
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'call with not defined method works raises exception' do
|
212
|
+
lambda { proteus_client.send(:submit_request,:put,'/',{}) }.should raise_error
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proteus_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,8 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/proteus_client.rb
|
21
|
-
- lib/
|
22
|
-
- lib/
|
21
|
+
- lib/proteus_client/config.rb
|
22
|
+
- lib/proteus_client/proxy.rb
|
23
|
+
- spec/proteus_client_spec.rb
|
23
24
|
homepage: https://github.com/solojavier/proteus_client
|
24
25
|
licenses: []
|
25
26
|
post_install_message:
|
@@ -44,5 +45,6 @@ rubygems_version: 1.8.21
|
|
44
45
|
signing_key:
|
45
46
|
specification_version: 3
|
46
47
|
summary: Ruby client to use proteus rest service
|
47
|
-
test_files:
|
48
|
+
test_files:
|
49
|
+
- spec/proteus_client_spec.rb
|
48
50
|
has_rdoc:
|