streamio 0.9.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +13 -0
- data/lib/streamio/model.rb +20 -14
- data/lib/streamio/resource.rb +58 -0
- data/lib/streamio/version.rb +1 -1
- data/lib/streamio/video.rb +4 -8
- data/lib/streamio.rb +4 -1
- data/streamio.gemspec +5 -4
- metadata +30 -13
data/HISTORY.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# 1.0.2 2012-11-26
|
2
|
+
|
3
|
+
* Replaced httpclient with net/http + multipart-post to avoid timeouts on file posting.
|
4
|
+
|
5
|
+
# 1.0.1 2012-11-23
|
6
|
+
|
7
|
+
* Loosend multi_json dependency version to conform with other ruby gems.
|
8
|
+
* Updated some development dependencies.
|
9
|
+
|
10
|
+
# 1.0.0 2012-11-23
|
11
|
+
|
12
|
+
* Replaced rest-client dependency with httpclient to support large file uploads.
|
13
|
+
|
1
14
|
# 0.9.2 2012-11-06
|
2
15
|
|
3
16
|
* Video#original_video accessor
|
data/lib/streamio/model.rb
CHANGED
@@ -7,7 +7,7 @@ module Streamio
|
|
7
7
|
#
|
8
8
|
# @return [Model] The found model.
|
9
9
|
def find(id)
|
10
|
-
parse_response(resource
|
10
|
+
parse_response(resource.get(id))
|
11
11
|
end
|
12
12
|
|
13
13
|
# Querys for a list of models.
|
@@ -19,7 +19,8 @@ module Streamio
|
|
19
19
|
# @return [Array] Array of found models.
|
20
20
|
def all(parameters = {})
|
21
21
|
sanitize_parameters(parameters)
|
22
|
-
|
22
|
+
response = resource.get(nil, parameters)
|
23
|
+
parse_response(response)
|
23
24
|
end
|
24
25
|
|
25
26
|
# Deletes model with the given id. Raises exception if failing to do so.
|
@@ -28,7 +29,7 @@ module Streamio
|
|
28
29
|
#
|
29
30
|
# @return [Boolean] True if the delete request is successful.
|
30
31
|
def destroy(id)
|
31
|
-
resource
|
32
|
+
resource.delete(id)
|
32
33
|
true
|
33
34
|
end
|
34
35
|
|
@@ -53,12 +54,13 @@ module Streamio
|
|
53
54
|
# @return [Integer] The number of models found.
|
54
55
|
def count(parameters = {})
|
55
56
|
sanitize_parameters(parameters)
|
56
|
-
|
57
|
+
response = resource.get("count", parameters)
|
58
|
+
MultiJson.decode(response.body)["count"]
|
57
59
|
end
|
58
60
|
|
59
61
|
def resource_name(name)
|
60
62
|
define_singleton_method(:resource) do
|
61
|
-
|
63
|
+
Resource.new(name)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -152,9 +154,6 @@ module Streamio
|
|
152
154
|
else
|
153
155
|
persist
|
154
156
|
end
|
155
|
-
rescue RestClient::UnprocessableEntity => e
|
156
|
-
@errors = MultiJson.decode(e.response)
|
157
|
-
false
|
158
157
|
end
|
159
158
|
|
160
159
|
# Deletes the record and freezes this instance to reflect that no changes
|
@@ -162,7 +161,7 @@ module Streamio
|
|
162
161
|
#
|
163
162
|
# @return [Boolean] True if the record was deleted.
|
164
163
|
def destroy
|
165
|
-
self.class.resource
|
164
|
+
self.class.resource.delete(id)
|
166
165
|
@attributes.freeze
|
167
166
|
true
|
168
167
|
end
|
@@ -211,8 +210,11 @@ module Streamio
|
|
211
210
|
parameters[key] = @attributes[key] if @attributes.has_key?(key)
|
212
211
|
end
|
213
212
|
|
214
|
-
self.class.resource
|
215
|
-
|
213
|
+
response = self.class.resource.put(id, parameters)
|
214
|
+
|
215
|
+
@errors = MultiJson.decode(response.body) unless response.code.to_i == 204
|
216
|
+
|
217
|
+
response.code.to_i == 204
|
216
218
|
end
|
217
219
|
|
218
220
|
def persist
|
@@ -221,12 +223,16 @@ module Streamio
|
|
221
223
|
parameters[key] = @attributes[key] if @attributes.has_key?(key)
|
222
224
|
end
|
223
225
|
|
224
|
-
|
226
|
+
response = self.class.resource.post(nil, parameters)
|
227
|
+
json = MultiJson.decode(response.body)
|
225
228
|
|
226
229
|
(self.class.accessable_attributes + self.class.readable_attributes).each do |attribute|
|
227
|
-
@attributes[attribute] =
|
230
|
+
@attributes[attribute] = json[attribute]
|
228
231
|
end
|
229
|
-
|
232
|
+
|
233
|
+
@errors = json unless response.code.to_i == 201
|
234
|
+
|
235
|
+
response.code.to_i == 201
|
230
236
|
end
|
231
237
|
end
|
232
238
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Streamio
|
2
|
+
class Resource
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@resource_path = "/api/v1/#{@name}"
|
8
|
+
|
9
|
+
uri = URI.parse(Streamio.protocol+Streamio.host)
|
10
|
+
@net = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
@net.use_ssl = Streamio.use_ssl
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(path, parameters = {})
|
15
|
+
@net.request(net_request(Net::HTTP::Get, path, parameters))
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(path, parameters = {})
|
19
|
+
request_class = parameters.any? do |key, value|
|
20
|
+
value.is_a?(File)
|
21
|
+
end ? Net::HTTP::Post::Multipart : Net::HTTP::Post
|
22
|
+
|
23
|
+
@net.request(net_request(request_class, path, parameters))
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(path, parameters = {})
|
27
|
+
@net.request(net_request(Net::HTTP::Put, path, parameters))
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(path)
|
31
|
+
@net.request(net_request(Net::HTTP::Delete, path))
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def net_request(request_class, sub_path, parameters = {})
|
36
|
+
path = @resource_path
|
37
|
+
path << "/#{sub_path}" if sub_path
|
38
|
+
|
39
|
+
if request_class == Net::HTTP::Get
|
40
|
+
path << "?#{Rack::Utils.build_query(parameters)}" unless parameters.empty?
|
41
|
+
req = request_class.new(path)
|
42
|
+
elsif request_class == Net::HTTP::Post::Multipart
|
43
|
+
parameters.each do |key, value|
|
44
|
+
parameters[key] = UploadIO.new(value, "application/octet-stream", File.basename(value.path)) if value.is_a?(File)
|
45
|
+
parameters[key] = value.join(", ") if value.is_a?(Array)
|
46
|
+
end
|
47
|
+
req = request_class.new(path, parameters)
|
48
|
+
else
|
49
|
+
req = request_class.new(path)
|
50
|
+
req.body = Rack::Utils.build_query(parameters)
|
51
|
+
end
|
52
|
+
|
53
|
+
req.basic_auth(Streamio.username, Streamio.password)
|
54
|
+
req["Accept"] = "application/json"
|
55
|
+
req
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/streamio/version.rb
CHANGED
data/lib/streamio/video.rb
CHANGED
@@ -14,11 +14,9 @@ module Streamio
|
|
14
14
|
#
|
15
15
|
# @return [Boolean] Indicating wether the transcoding was successfully created.
|
16
16
|
def add_transcoding(parameters)
|
17
|
-
self.class.resource
|
17
|
+
response = self.class.resource.post("#{id}/transcodings", parameters)
|
18
18
|
reload
|
19
|
-
|
20
|
-
rescue RestClient::Exception
|
21
|
-
false
|
19
|
+
response.code.to_i == 201
|
22
20
|
end
|
23
21
|
|
24
22
|
# Deletes a transcoding from the video and reloads itself to
|
@@ -28,11 +26,9 @@ module Streamio
|
|
28
26
|
#
|
29
27
|
# @return [Boolean] Indicating wether the transcoding was successfully deleted.
|
30
28
|
def delete_transcoding(transcoding_id)
|
31
|
-
self.class.resource
|
29
|
+
response = self.class.resource.delete("#{id}/transcodings/#{transcoding_id}")
|
32
30
|
reload
|
33
|
-
|
34
|
-
rescue RestClient::Exception
|
35
|
-
false
|
31
|
+
response.code.to_i == 200
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
data/lib/streamio.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require "
|
1
|
+
require "rack"
|
2
|
+
require "net/https"
|
3
|
+
require "net/http/post/multipart"
|
2
4
|
require "multi_json"
|
3
5
|
require "time"
|
4
6
|
|
5
7
|
require "streamio/version"
|
8
|
+
require "streamio/resource"
|
6
9
|
require "streamio/model"
|
7
10
|
require "streamio/video"
|
8
11
|
require "streamio/image"
|
data/streamio.gemspec
CHANGED
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.files = Dir.glob("lib/**/*") + %w(Gemfile streamio.gemspec HISTORY.md README.md)
|
15
15
|
|
16
|
-
s.add_dependency("
|
17
|
-
s.add_dependency("
|
16
|
+
s.add_dependency("rack", "~> 1.0")
|
17
|
+
s.add_dependency("multipart-post", "~> 1.1")
|
18
|
+
s.add_dependency("multi_json", "~> 1.3")
|
18
19
|
|
19
20
|
s.add_development_dependency("rspec", "~> 2.7")
|
20
|
-
s.add_development_dependency("webmock", "~> 1.
|
21
|
-
s.add_development_dependency("rake", "~> 0
|
21
|
+
s.add_development_dependency("webmock", "~> 1.9")
|
22
|
+
s.add_development_dependency("rake", "~> 10.0")
|
22
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: rack
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,23 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multipart-post
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.1'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: multi_json
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +50,7 @@ dependencies:
|
|
34
50
|
requirements:
|
35
51
|
- - ~>
|
36
52
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.3
|
53
|
+
version: '1.3'
|
38
54
|
type: :runtime
|
39
55
|
prerelease: false
|
40
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +58,7 @@ dependencies:
|
|
42
58
|
requirements:
|
43
59
|
- - ~>
|
44
60
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.3
|
61
|
+
version: '1.3'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rspec
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
85
|
+
version: '1.9'
|
70
86
|
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.
|
93
|
+
version: '1.9'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: rake
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +98,7 @@ dependencies:
|
|
82
98
|
requirements:
|
83
99
|
- - ~>
|
84
100
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0
|
101
|
+
version: '10.0'
|
86
102
|
type: :development
|
87
103
|
prerelease: false
|
88
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +106,7 @@ dependencies:
|
|
90
106
|
requirements:
|
91
107
|
- - ~>
|
92
108
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0
|
109
|
+
version: '10.0'
|
94
110
|
description: Ruby wrapper for Streamios API.
|
95
111
|
email:
|
96
112
|
- david@streamio.com
|
@@ -104,6 +120,7 @@ files:
|
|
104
120
|
- lib/streamio/model.rb
|
105
121
|
- lib/streamio/player.rb
|
106
122
|
- lib/streamio/playlist.rb
|
123
|
+
- lib/streamio/resource.rb
|
107
124
|
- lib/streamio/upload.rb
|
108
125
|
- lib/streamio/version.rb
|
109
126
|
- lib/streamio/video.rb
|
@@ -126,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
143
|
version: '0'
|
127
144
|
segments:
|
128
145
|
- 0
|
129
|
-
hash: -
|
146
|
+
hash: -3529804903575399490
|
130
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
148
|
none: false
|
132
149
|
requirements:
|
@@ -135,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
152
|
version: '0'
|
136
153
|
segments:
|
137
154
|
- 0
|
138
|
-
hash: -
|
155
|
+
hash: -3529804903575399490
|
139
156
|
requirements: []
|
140
157
|
rubyforge_project:
|
141
158
|
rubygems_version: 1.8.24
|