proteus_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,104 @@
1
+ module Proteus
2
+ class Client
3
+
4
+ def initialize(options = {})
5
+ options = merge_with_default_options(options)
6
+ @api_key = options[:api_key]
7
+ @domain = RestClient::Resource.new(options[:domain])
8
+ end
9
+
10
+ def self.config
11
+ @config ||= Proteus::Config.new
12
+ end
13
+
14
+ def test_api
15
+ response = submit_request(:get,'/',{})
16
+
17
+ {message: response.body}
18
+ end
19
+
20
+ def create_video_allocation(count=0,params={})
21
+ params = {count: count} if count > 0
22
+
23
+ body = submit_request_and_parse_json(:post,'/video_allocations',params)
24
+
25
+ return parse_video_allocation(body) if count==0
26
+ body.map { |e| parse_video_allocation(e) }
27
+ end
28
+
29
+ def create_video(video_allocation_id,type)
30
+ body = submit_request_and_parse_json(:post, '/videos',
31
+ {video_allocation_id: video_allocation_id,
32
+ type: type})
33
+
34
+ {video_id: body['_id'],url: body['allocation_url'] }
35
+ end
36
+
37
+ def create_video_versions(video_id,settings=nil)
38
+ params = {}
39
+ params = {version_settings: settings} unless settings.nil?
40
+
41
+ submit_request(:post, "/videos/#{video_id}/versions",params)
42
+
43
+ {message: 'success'}
44
+ end
45
+
46
+ def get_video(video_id)
47
+ submit_request_and_parse_json(:get,"/videos/#{video_id}",{})
48
+ end
49
+
50
+ def get_videos(*ids)
51
+ submit_request_and_parse_json(:get_raw,"/videos",{ids: ids})
52
+ end
53
+
54
+ def get_video_allocation(video_allocation_id)
55
+ submit_request_and_parse_json(:get,"/video_allocations/#{video_allocation_id}",{})
56
+ end
57
+
58
+ private
59
+
60
+ def merge_with_default_options(options)
61
+ opts = {
62
+ api_key: Client.config.api_key,
63
+ domain: Client.config.domain
64
+ }.merge(options)
65
+
66
+ raise "An API key has not been defined" unless opts[:api_key]
67
+ raise "A domain has not been defined" unless opts[:domain]
68
+
69
+ opts
70
+ end
71
+
72
+ def submit_request_and_parse_json(method,route,params)
73
+ response = submit_request(method,route,params)
74
+ JSON.parse(response)
75
+ end
76
+
77
+ def submit_request(method,route,params)
78
+ params = {:api_key => @api_key}.merge(params)
79
+
80
+ case method
81
+ when :get
82
+ @domain[route].get({params: params})
83
+ when :get_raw
84
+ params_str = RestClient::Payload::UrlEncoded.new(params).to_s
85
+ @domain["#{route}?#{params_str}"].get({})
86
+ when :post
87
+ @domain[route].post(params, :content_type => :json)
88
+ else
89
+ raise 'Undefined method'
90
+ end
91
+ end
92
+
93
+ def parse_video_allocation(video_allocation)
94
+ urls = [{type: 'direct', url: video_allocation['url_direct']}]
95
+ urls << {type: 'stream', url: video_allocation['url_stream']}
96
+
97
+ urls << {type: 'upload', url: video_allocation['url_upload']}
98
+
99
+ {video_allocation_id: video_allocation['_id'],urls: urls }
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,5 @@
1
+ module Proteus
2
+ class Config
3
+ attr_accessor :domain, :api_key
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ require_relative 'proteus/config'
5
+ require_relative 'proteus/client'
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proteus_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - solojavier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: It provides an interface to use proteus features
15
+ email: 1.27201@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/proteus_client.rb
21
+ - lib/proteus/config.rb
22
+ - lib/proteus/client.rb
23
+ homepage: https://github.com/solojavier/proteus_client
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.21
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Ruby client to use proteus rest service
47
+ test_files: []
48
+ has_rdoc: