dm_cloud 0.0.4 → 0.0.5
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/dm_cloud.gemspec +1 -0
- data/lib/dm_cloud/builder/media.rb +9 -22
- data/lib/dm_cloud/media.rb +2 -2
- data/lib/dm_cloud/request.rb +8 -3
- data/lib/dm_cloud/signing.rb +28 -19
- data/lib/dm_cloud/streaming.rb +2 -0
- data/lib/dm_cloud/version.rb +1 -1
- data/lib/dm_cloud.rb +18 -36
- metadata +19 -3
data/dm_cloud.gemspec
CHANGED
@@ -26,16 +26,10 @@ module DMCloud
|
|
26
26
|
request['fields'] = []
|
27
27
|
|
28
28
|
# requested media meta datas
|
29
|
-
fields[:meta]
|
29
|
+
fields[:meta] = [ 'title'] unless fields[:meta]
|
30
|
+
fields[:meta].each { |value| request['fields'] << "meta.#{value.to_s}" }
|
31
|
+
request['fields'] += ['id', 'created', 'embed_url', 'frame_ratio']
|
30
32
|
|
31
|
-
#the creation date as a unix timestamp
|
32
|
-
request['fields'] << 'created' if fields[:created]
|
33
|
-
|
34
|
-
# the url of the embed player
|
35
|
-
request['fields'] << 'embed_url' if fields[:embed_url]
|
36
|
-
|
37
|
-
# the ratio of the video frame as a float (eg: 16/9, 4/3, etc).
|
38
|
-
request['fields'] << 'frame_ratio' if fields[:frame_ratio]
|
39
33
|
# the worldwide statistics on the number of views
|
40
34
|
# request['fields'] << 'stats.global.last_week' if fields[:stats][:global]
|
41
35
|
|
@@ -46,7 +40,7 @@ module DMCloud
|
|
46
40
|
|
47
41
|
assets_names = ['source'] if assets_names.nil?
|
48
42
|
if not fields[:assets]
|
49
|
-
request = all_assets_fields(request, assets_names)
|
43
|
+
# request = all_assets_fields(request, assets_names)
|
50
44
|
else
|
51
45
|
assets_names.each do |name|
|
52
46
|
fields[:assets].each { |value| request << "assets.#{name}.#{value.to_s}" }
|
@@ -62,16 +56,9 @@ module DMCloud
|
|
62
56
|
|
63
57
|
request['fields'] = []
|
64
58
|
# requested media meta datas
|
65
|
-
fields[:meta]
|
66
|
-
|
67
|
-
|
68
|
-
request['fields'] << 'created' if fields[:created]
|
69
|
-
|
70
|
-
# the url of the embed player
|
71
|
-
request['fields'] << 'embed_url' if fields[:embed_url]
|
72
|
-
|
73
|
-
# the ratio of the video frame as a float (eg: 16/9, 4/3, etc).
|
74
|
-
request['fields'] << 'frame_ratio' if fields[:frame_ratio]
|
59
|
+
fields[:meta] = [ 'title'] unless fields[:meta].present?
|
60
|
+
fields[:meta].each { |value| request['fields'] << "meta.#{value.to_s}" }
|
61
|
+
request['fields'] += ['id', 'created', 'embed_url', 'frame_ratio']
|
75
62
|
|
76
63
|
# TODO: handle global statistics request in another module
|
77
64
|
# the worldwide statistics on the number of views
|
@@ -84,10 +71,10 @@ module DMCloud
|
|
84
71
|
|
85
72
|
assets_names = ['source'] if assets_names.nil?
|
86
73
|
if not fields[:assets]
|
87
|
-
request = all_assets_fields(request, assets_names)
|
74
|
+
# request = all_assets_fields(request, assets_names)
|
88
75
|
else
|
89
76
|
assets_names.each do |name|
|
90
|
-
fields[:assets].each { |value| request << "assets.#{name}.#{value.to_s}" }
|
77
|
+
fields[:assets].each { |value| request['fields'] << "assets.#{name}.#{value.to_s}" }
|
91
78
|
end
|
92
79
|
end
|
93
80
|
|
data/lib/dm_cloud/media.rb
CHANGED
@@ -72,8 +72,8 @@ module DMCloud
|
|
72
72
|
def self.list(options = {})
|
73
73
|
call_type = "media.list"
|
74
74
|
|
75
|
-
page = options[:page]
|
76
|
-
per_page = options[:per_page]
|
75
|
+
page = options[:page] ? options[:page] : 1
|
76
|
+
per_page = options[:per_page] ? options[:per_page] : 10
|
77
77
|
|
78
78
|
params = {
|
79
79
|
:call => call_type,
|
data/lib/dm_cloud/request.rb
CHANGED
@@ -4,6 +4,8 @@ module DMCloud
|
|
4
4
|
class Request
|
5
5
|
|
6
6
|
DAILYMOTION_API = 'http://api.dmcloud.net/api'
|
7
|
+
DAILYMOTION_STATIC = 'http://api.dmcloud.net/api'
|
8
|
+
|
7
9
|
|
8
10
|
def self.send_request(params)
|
9
11
|
puts 'body request params : ' + params.to_json + "\n" + '-' * 80
|
@@ -23,8 +25,9 @@ module DMCloud
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def self.execute(call, params = {})
|
26
|
-
|
27
|
-
params['auth'] =
|
28
|
+
url = define(call)
|
29
|
+
params['auth'] = DMCloud::Signing.identify(params)
|
30
|
+
|
28
31
|
result = send_request(params)
|
29
32
|
parse_response(result)
|
30
33
|
end
|
@@ -33,6 +36,8 @@ module DMCloud
|
|
33
36
|
puts 'result : ' + result.to_yaml
|
34
37
|
end
|
35
38
|
|
36
|
-
|
39
|
+
def self.define(action)
|
40
|
+
DAILYMOTION_API
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
data/lib/dm_cloud/signing.rb
CHANGED
@@ -11,11 +11,11 @@ module DMCloud
|
|
11
11
|
api_key = DMCloud.config[:secret_key]
|
12
12
|
|
13
13
|
normalized_request = normalize(request).to_s
|
14
|
-
puts 'normalized_values : ' + normalized_request + "\n" + '-' * 80
|
14
|
+
puts 'identify:: normalized_values : ' + normalized_request + "\n" + '-' * 80
|
15
15
|
|
16
16
|
params = user_id + normalized_request + api_key
|
17
17
|
|
18
|
-
puts 'Values before MD5 encrypt : ' + params + "\n" + '-' * 80
|
18
|
+
puts 'identify:: Values before MD5 encrypt : ' + params + "\n" + '-' * 80
|
19
19
|
|
20
20
|
checksum = Digest::MD5.hexdigest(params)
|
21
21
|
auth_token = user_id + ':' + checksum
|
@@ -39,20 +39,21 @@ module DMCloud
|
|
39
39
|
# Result :
|
40
40
|
# return a string which contain the signed url like
|
41
41
|
# <url>?auth=<expires>-<sec>-<nonce>-<md5sum>[-<pub-sec-data>]
|
42
|
-
def self.sign(stream)
|
42
|
+
def self.sign(stream, security_datas = nil)
|
43
43
|
raise StandardError, "missing :stream in params" unless stream
|
44
|
-
|
45
|
-
sec_data = security_data(DMCloud.config[:security_level])
|
44
|
+
sec_level = security(DMCloud.config[:security_level])
|
45
|
+
sec_data = security_data(DMCloud.config[:security_level], security_datas) unless security_datas.nil?
|
46
46
|
|
47
47
|
base = {
|
48
|
-
:sec_level =>
|
48
|
+
:sec_level => sec_level,
|
49
49
|
:url_no_query => stream,
|
50
50
|
:expires => (Time.now + 1.hour).to_i,
|
51
51
|
:nonce => SecureRandom.hex(16)[0,8],
|
52
52
|
:secret => DMCloud.config[:secret_key]
|
53
53
|
}
|
54
|
+
|
54
55
|
base.merge!(:sec_data => sec_data, :pub_sec_data => sec_data) unless sec_data.nil?
|
55
|
-
|
56
|
+
|
56
57
|
digest_struct = build_digest_struct(base)
|
57
58
|
|
58
59
|
check_sum = Digest::MD5.hexdigest(digest_struct)
|
@@ -111,7 +112,7 @@ module DMCloud
|
|
111
112
|
type = :none unless type
|
112
113
|
type = type.to_sym if type.class == String
|
113
114
|
|
114
|
-
|
115
|
+
case type
|
115
116
|
when :none
|
116
117
|
0 # None
|
117
118
|
when :delegate
|
@@ -129,13 +130,12 @@ module DMCloud
|
|
129
130
|
when :referer
|
130
131
|
1 << 6 # A list of URL prefixes separated by spaces stored in the pub-sec-data component (ex: rf=http;//domain.com/a/+http:/domain.com/b/).
|
131
132
|
end
|
132
|
-
result
|
133
133
|
end
|
134
134
|
|
135
135
|
def self.security_data(type, value = nil)
|
136
136
|
type = type.to_sym if type.class == String
|
137
|
-
|
138
|
-
|
137
|
+
|
138
|
+
case type
|
139
139
|
when :asnum
|
140
140
|
"as=#{value}" # The number part of the end-user AS prefixed by the ‘AS’ string (ie: as=AS41690)
|
141
141
|
when :ip
|
@@ -149,13 +149,12 @@ module DMCloud
|
|
149
149
|
else
|
150
150
|
nil
|
151
151
|
end
|
152
|
-
result
|
153
152
|
end
|
154
153
|
|
155
154
|
def self.security_pub_sec_data(type, value)
|
156
155
|
type = type.to_sym if type.class == String
|
157
156
|
|
158
|
-
|
157
|
+
case type
|
159
158
|
when :country
|
160
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
|
161
160
|
when :referer
|
@@ -163,13 +162,23 @@ module DMCloud
|
|
163
162
|
else
|
164
163
|
nil
|
165
164
|
end
|
166
|
-
result
|
167
165
|
end
|
168
166
|
|
169
|
-
def self.normalize
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
167
|
+
def self.normalize params
|
168
|
+
case params
|
169
|
+
when Array
|
170
|
+
params.collect { |element| normalize(element) }.join('')
|
171
|
+
when Hash
|
172
|
+
params.to_a.sort_by {|a,b| a.to_s }.collect {|array| array.first.to_s + normalize(array.last)}.join('')
|
173
|
+
else
|
174
|
+
params.to_s
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# def self.normalize(params)
|
179
|
+
# str = params.to_json.to_s
|
180
|
+
# str.gsub!(/[^A-Za-z0-9]/, '')
|
181
|
+
# str
|
182
|
+
# end
|
174
183
|
end
|
175
184
|
end
|
data/lib/dm_cloud/streaming.rb
CHANGED
data/lib/dm_cloud/version.rb
CHANGED
data/lib/dm_cloud.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require "dm_cloud/version"
|
2
2
|
require 'yaml'
|
3
|
-
|
3
|
+
|
4
|
+
# This gem's comments come from DailyMotion Cloud API,
|
5
|
+
# that's the better way to see changes on new version and logic.
|
6
|
+
# For parts more generals and not representating DailyMotion Cloud API,
|
7
|
+
# I add some about my own opinion.
|
4
8
|
module DMCloud
|
5
9
|
|
6
10
|
# Configuration defaults
|
11
|
+
# I used this parts from Slainer68 paybox_system gem.
|
12
|
+
# I liked the concept and how he handle this part.
|
13
|
+
# Thx Slainer68, I created my first gem,
|
14
|
+
# and next one will be an update to your paybox_system gem.
|
7
15
|
@@config = {
|
8
16
|
:security_level => 'none',
|
9
17
|
:protocol => 'http'
|
@@ -18,6 +26,7 @@ module DMCloud
|
|
18
26
|
end
|
19
27
|
|
20
28
|
# Configure through yaml file
|
29
|
+
# for ruby scripting usage
|
21
30
|
def self.configure_with(yaml_file_path = nil)
|
22
31
|
yaml_file_path = YAML_INITIALIZER_PATH unless yaml_file_path
|
23
32
|
begin
|
@@ -31,46 +40,19 @@ module DMCloud
|
|
31
40
|
configure(config)
|
32
41
|
end
|
33
42
|
|
43
|
+
# Access to config variables (security level, user_id and api_key)
|
44
|
+
# NOTE: The unless @@config is not really interesting,
|
45
|
+
# this mean we should loose user credentials to API.
|
34
46
|
def self.config
|
35
47
|
@@config = configure unless @@config
|
36
48
|
@@config
|
37
49
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if !class_variable_defined? cv
|
43
|
-
begin
|
44
|
-
require library.to_s
|
45
|
-
class_variable_set(cv,true)
|
46
|
-
rescue LoadError
|
47
|
-
class_variable_set(cv,false)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
class_variable_get(cv)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
create_has_library :streaming
|
55
|
-
create_has_library :media
|
56
|
-
|
57
|
-
class << self
|
58
|
-
# Load a object saved on a file.
|
59
|
-
def load(filename)
|
60
|
-
if File.exists? filename
|
61
|
-
o=false
|
62
|
-
File.open(filename,"r") {|fp| o=Marshal.load(fp) }
|
63
|
-
o
|
64
|
-
else
|
65
|
-
false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
50
|
+
|
51
|
+
# Loading classes to easier access
|
52
|
+
# NOTE: I like this way to handle my classes,
|
53
|
+
# sexiest than using require 'my_class_file' everywhere
|
70
54
|
autoload(:Streaming, 'dm_cloud/streaming')
|
71
55
|
autoload(:Media, 'dm_cloud/media')
|
72
56
|
autoload(:Request, 'dm_cloud/request')
|
73
57
|
autoload(:Signing, 'dm_cloud/signing')
|
74
|
-
end
|
75
|
-
|
76
|
-
# Dir.glob('dm_cloud/**/*.rb').each{ |m| require File.dirname(__FILE__) + '/dm_cloud/' + m }
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: curb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.0
|
14
30
|
description: This gem will simplify usage of DailyMotion Cloud API, it represent api
|
15
31
|
in ruby style, with automated handler for search and upload files
|
16
32
|
email:
|