Class: ProteusClient::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proteus_client/proxy.rb

Overview

Provides an interface for Proteus REST service to encode videos

Examples:

Creating a new proxy

ProteusClient::Proxy.new
ProteusClient::Proxy.new({account: "", api_key: "", root: "http://localhost:9292"})

Calling a method

proteus_client.create_video("video_id","type")

Raises:

  • (APIKeyNotDefined)

    if api_key is not defined in ProteusClient.config or sent as param

  • (RootNotDefined)

    if root is not defined in ProteusClient.config or sent as param

  • (RestClient::Exception)

    if status code returned from services is not in 200..207

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Proxy

Returns a new instance of Proxy.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/proteus_client/proxy.rb', line 17

def initialize(options = {})
  options = {
    account: ProteusClient.config.,
    api_key: ProteusClient.config.api_key,
    root:    ProteusClient.config.root
  }.merge(options)

  raise "AccountNotDefined" unless options[:account]
  raise "APIKeyNotDefined"  unless options[:api_key]
  raise "RootNotDefined"    unless options[:root]

  @user     = options[:account]
  @password = options[:api_key]
  @root     = resource(options[:root]) 
end

Instance Method Details

#create_recordingsObject



33
34
35
36
37
38
39
40
# File 'lib/proteus_client/proxy.rb', line 33

def create_recordings
  recordings = link(@root, 'proteus:recordings') 

  response   = resource(recordings).post({})
  properties = Representers::Recording.new(response).to_hash

  ProteusClient::Recording.new(properties)
end

#create_version(video_id, version_name, solution) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/proteus_client/proxy.rb', line 72

def create_version(video_id, version_name, solution)
  url      = link(@root, 'proteus:video')
  video    = expand_templated_route(url, 'id', video_id)
  versions = link(resource(video), 'proteus:video:versions')
  
  params   = { version_name: version_name, solution: solution }
  response = resource(versions).post(params)
  
  {message: 'success'}
end

#create_video(url, solution, version_name) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/proteus_client/proxy.rb', line 52

def create_video(url, solution, version_name)
  videos   = link(@root, 'proteus:videos')

  params     = { url: url, solution: solution, version_name: version_name }
  response   = resource(videos).post(params)
  properties = Representers::Video.new(response).to_hash

  ProteusClient::Video.new(properties)
end

#get_recording(id) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/proteus_client/proxy.rb', line 42

def get_recording(id)
  url       = link(@root, 'proteus:recording')
  recording = expand_templated_route(url, 'id', id)

  response   = resource(recording).get
  properties = Representers::Recording.new(response).to_hash

  ProteusClient::Recording.new(properties)
end

#get_video(id) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/proteus_client/proxy.rb', line 62

def get_video(id)
  url   = link(@root, 'proteus:video')
  video = expand_templated_route(url, 'id', id)

  response   = resource(video).get
  properties = Representers::Video.new(response).to_hash

  ProteusClient::Video.new(properties)
end