dmcloud 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/dmcloud.gemspec +1 -1
- data/lib/dm_cloud/builder/media.rb +2 -1
- data/lib/dm_cloud/media.rb +18 -0
- data/lib/dm_cloud/request.rb +11 -11
- data/lib/dm_cloud/signing.rb +20 -20
- data/lib/dm_cloud/streaming.rb +0 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGJiOWVmMGRkMDMwMDIxYWQ5ZjA5NDQwN2E4NTM5YTFjOGRiM2IyYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTQzMzhmYjlmZmM4MTJlNzAxZDliODVmMmEzNzYyZDljY2ZhMDdjMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGY4ZjU4Y2ZjODVhMDZhODgxYzQzZmIyNTdkYmVjN2UwYzg2MmU0OWNjNGYy
|
10
|
+
ZDcxMmE4NzZmODJkYjdjYTc0MWMxYjg4NjI5ZDRlYjA0NzNhNGU4MWQ2ZDBl
|
11
|
+
OGUzYWUxNjFkYWI3YWZhZGM2NDJkMzIwMTBjNzNjMjMxNDdiYzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWI3ODk4YmNlMWIxZjJmNDRkZDRlZDFmYzc2Mjg1NGVlN2Q3ZThmNzEwMWZj
|
14
|
+
NmM0MjZjYzFmN2MwMzE0YTVjNmExMmIyYmYyMWNhZGFiODg4YmQwMzM1YTg1
|
15
|
+
ZGI2YWJlOTYyYzcyN2Q0ODQzZGZmZGRhYTZhNDAzODZlYWVjMDc=
|
data/dmcloud.gemspec
CHANGED
@@ -22,9 +22,10 @@ module DmCloud
|
|
22
22
|
request = Hash.new
|
23
23
|
|
24
24
|
# the media id
|
25
|
-
request[:
|
25
|
+
request[:id] = media_id
|
26
26
|
|
27
27
|
# requested media meta datas
|
28
|
+
request[:fields] = []
|
28
29
|
fields[:meta] = ['title'] unless fields[:meta]
|
29
30
|
fields[:meta].each { |value| request[:fields] << "meta.#{value.to_s}" }
|
30
31
|
request[:fields] += ['id', 'created', 'embed_url', 'frame_ratio']
|
data/lib/dm_cloud/media.rb
CHANGED
@@ -57,6 +57,7 @@ module DmCloud
|
|
57
57
|
:call => call_type,
|
58
58
|
args: DmCloud::Builder::Media.info(media_id, assets_names, fields)
|
59
59
|
}
|
60
|
+
|
60
61
|
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
61
62
|
end
|
62
63
|
|
@@ -81,5 +82,22 @@ module DmCloud
|
|
81
82
|
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
82
83
|
end
|
83
84
|
|
85
|
+
# Gets a URL pointer to the actual file...
|
86
|
+
def self.url(media_id, asset_name)
|
87
|
+
raise StandardError, "missing :media_id in params" unless media_id
|
88
|
+
raise StandardError, "missing :asset_name in params" unless asset_name
|
89
|
+
fields = { :assets => ["download_url"] }
|
90
|
+
|
91
|
+
self.info(media_id, [asset_name], fields)["result"]["assets"][asset_name]["download_url"]
|
92
|
+
end
|
93
|
+
|
94
|
+
# Gets the real URL that points to the download link on DMCloud's specific server
|
95
|
+
def self.download_url(media_id, asset_name)
|
96
|
+
download_url = self.url(media_id, asset_name)
|
97
|
+
response = Net::HTTP.get_response(URI.parse(download_url))
|
98
|
+
download_url = response.header["location"]
|
99
|
+
|
100
|
+
download_url
|
101
|
+
end
|
84
102
|
end
|
85
103
|
end
|
data/lib/dm_cloud/request.rb
CHANGED
@@ -3,10 +3,10 @@ require 'json'
|
|
3
3
|
|
4
4
|
module DmCloud
|
5
5
|
class Request
|
6
|
-
|
6
|
+
|
7
7
|
DAILYMOTION_API = 'http://api.DmCloud.net/api'
|
8
8
|
DAILYMOTION_STATIC = 'http://api.DmCloud.net/api'
|
9
|
-
|
9
|
+
|
10
10
|
# This method control signing for Media calls and handle request and response.
|
11
11
|
def self.execute(call, params = {})
|
12
12
|
url = define(call)
|
@@ -15,8 +15,8 @@ module DmCloud
|
|
15
15
|
result = send_request(params)
|
16
16
|
parse_response(result)
|
17
17
|
end
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
|
20
20
|
def self.send_request(params)
|
21
21
|
@uri = URI.parse(DAILYMOTION_API)
|
22
22
|
|
@@ -24,20 +24,20 @@ module DmCloud
|
|
24
24
|
request = Net::HTTP::Post.new(@uri.request_uri)
|
25
25
|
request.content_type = 'application/json'
|
26
26
|
request.body = params.to_json
|
27
|
-
|
27
|
+
|
28
28
|
# puts 'request (YAML format ): ' + request.to_yaml + "\n" + '-' * 80
|
29
|
-
|
29
|
+
|
30
30
|
http.request(request).body
|
31
31
|
end
|
32
|
-
|
33
32
|
|
34
|
-
|
33
|
+
|
34
|
+
|
35
35
|
def self.parse_response(result)
|
36
36
|
JSON.parse(result)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.define(action)
|
40
|
-
DAILYMOTION_API
|
40
|
+
DAILYMOTION_API
|
41
41
|
end
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
data/lib/dm_cloud/signing.rb
CHANGED
@@ -24,7 +24,7 @@ module DmCloud
|
|
24
24
|
|
25
25
|
auth_token
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# To sign a URL, the client needs a secret shared with Dailymotion Cloud.
|
29
29
|
# This secret is call client secret and is available in the back-office interface.
|
30
30
|
# Params:
|
@@ -34,22 +34,22 @@ module DmCloud
|
|
34
34
|
# nonce: A 8 characters-long random alphanumeric lowercase string to make the signature unique.
|
35
35
|
# secret: The client secret.
|
36
36
|
# sec-data: If sec-level doesn’t have the DELEGATED bit activated,
|
37
|
-
# this component contains concatenated informations
|
37
|
+
# this component contains concatenated informations
|
38
38
|
# for all activated sec levels.
|
39
39
|
# pub-sec-data: Some sec level data have to be passed in clear in the signature.
|
40
40
|
# To generate this component the parameters are serialized using x-www-form-urlencoded, compressed with gzip and encoded in base64.
|
41
41
|
# Result :
|
42
|
-
# return a string which contain the signed url like
|
42
|
+
# return a string which contain the signed url like
|
43
43
|
# <expires>-<sec>-<nonce>-<md5sum>[-<pub-sec-data>]
|
44
44
|
def self.sign(stream, security_datas = nil)
|
45
45
|
raise StandardError, "missing :stream in params" unless stream
|
46
46
|
sec_level = security(DmCloud.config[:security_level])
|
47
47
|
sec_data = security_data(DmCloud.config[:security_level], security_datas) unless security_datas.nil?
|
48
48
|
|
49
|
-
base = {
|
49
|
+
base = {
|
50
50
|
:sec_level => sec_level,
|
51
51
|
:url_no_query => stream,
|
52
|
-
:expires => 1
|
52
|
+
:expires => Time.now + 1*60*60, # 1 hour from now
|
53
53
|
:nonce => SecureRandom.hex(16)[0,16],
|
54
54
|
:secret => DmCloud.config[:secret_key]
|
55
55
|
}
|
@@ -60,13 +60,13 @@ module DmCloud
|
|
60
60
|
|
61
61
|
signed_url = [base[:expires], base[:sec_level], base[:nonce], check_sum].compact
|
62
62
|
signed_url.merge!(:pub_sec_data => sec_data) unless sec_data.nil?
|
63
|
-
|
63
|
+
|
64
64
|
# puts signed_url
|
65
|
-
|
65
|
+
|
66
66
|
signed_url = signed_url.join('-')
|
67
67
|
signed_url
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# Prepare datas for signing
|
71
71
|
# Params :
|
72
72
|
# base : contains media id and others for url signing
|
@@ -89,29 +89,29 @@ module DmCloud
|
|
89
89
|
# This security level may wrongly block some users
|
90
90
|
# which have their internet access load-balanced between several proxies.
|
91
91
|
# This is the case in some office network or some ISPs.
|
92
|
-
# User-Agent: Used in addition to one of the two former levels,
|
92
|
+
# User-Agent: Used in addition to one of the two former levels,
|
93
93
|
# this level a limit on the exact user-agent of the end-user.
|
94
94
|
# This is more secure but in some specific condition may lead to wrongly blocked users.
|
95
95
|
# Use Once: The signed URL will only be usable once.
|
96
96
|
# Note: should not be used with stream URLs.
|
97
97
|
# Country: The URL can only be queried from specified countrie(s).
|
98
98
|
# The rule can be reversed to allow all countries except some.
|
99
|
-
# Referer: The URL can only be queried
|
99
|
+
# Referer: The URL can only be queried
|
100
100
|
# if the Referer HTTP header contains a specified value.
|
101
101
|
# If the URL contains a Referer header with a different value,
|
102
102
|
# the request is refused. If the Referer header is missing,
|
103
|
-
# the request is accepted in order to prevent from false positives as some browsers,
|
103
|
+
# the request is accepted in order to prevent from false positives as some browsers,
|
104
104
|
# anti-virus or enterprise proxies may remove this header.
|
105
|
-
# Delegate: This option instructs the signing algorithm
|
105
|
+
# Delegate: This option instructs the signing algorithm
|
106
106
|
# that security level information won’t be embeded into the signature
|
107
107
|
# but gathered and lock at the first use.
|
108
108
|
# Result :
|
109
|
-
# Return a string which contain the signed url like
|
109
|
+
# Return a string which contain the signed url like
|
110
110
|
# http://cdn.DmCloud.net/route/<user_id>/<media_id>/<asset_name>.<asset_extension>?auth=<auth_token>
|
111
111
|
def self.security(type = nil)
|
112
112
|
type = :none unless type
|
113
113
|
type = type.to_sym if type.class == String
|
114
|
-
|
114
|
+
|
115
115
|
case type
|
116
116
|
when :none
|
117
117
|
0 # None
|
@@ -153,7 +153,7 @@ module DmCloud
|
|
153
153
|
|
154
154
|
def self.security_pub_sec_data(type, value)
|
155
155
|
type = type.to_sym if type.class == String
|
156
|
-
|
156
|
+
|
157
157
|
case type
|
158
158
|
when :country
|
159
159
|
"cc=#{value}" # A list of 2 characters long country codes in lowercase by comas. If the list starts with a dash, the rule is inverted (ie: cc=fr,gb,de or cc=-fr,it). This data have to be stored in pub-sec-data component
|
@@ -163,10 +163,10 @@ module DmCloud
|
|
163
163
|
nil
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
167
|
-
|
166
|
+
|
167
|
+
|
168
168
|
# This block comes from Cloudkey gem.
|
169
|
-
# I discovered this gem far after I start this one
|
169
|
+
# I discovered this gem far after I start this one
|
170
170
|
# and I will try to add file upload from http or ftp.
|
171
171
|
# (Missing in their gem)
|
172
172
|
def self.normalize params
|
@@ -179,11 +179,11 @@ module DmCloud
|
|
179
179
|
params.to_s
|
180
180
|
end
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
# def self.normalize(params)
|
184
184
|
# str = params.to_json.to_s
|
185
185
|
# str.gsub!(/[^A-Za-z0-9]/, '')
|
186
186
|
# str
|
187
187
|
# end
|
188
188
|
end
|
189
|
-
end
|
189
|
+
end
|
data/lib/dm_cloud/streaming.rb
CHANGED
@@ -67,14 +67,5 @@ module DmCloud
|
|
67
67
|
stream += '?auth=[AUTH_TOKEN]'.gsub!('[AUTH_TOKEN]', DmCloud::Signing.sign(stream, security))
|
68
68
|
stream
|
69
69
|
end
|
70
|
-
|
71
|
-
# Gets the real URL that points to the download link on DMCloud's specific server
|
72
|
-
def self.download_url(media_id, asset_name, asset_extension = nil, security = {})
|
73
|
-
download_url = self.url(media_id, asset_name, asset_extension, security)
|
74
|
-
response = Net::HTTP.get_response(URI.parse(download_url))
|
75
|
-
download_url = response.header["location"]
|
76
|
-
|
77
|
-
download_url
|
78
|
-
end
|
79
70
|
end
|
80
71
|
end
|