stupeflix 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,17 +20,24 @@ Or install it yourself as:
20
20
 
21
21
  Retrieve your API keys from http://developer.stupeflix.com/keychain/ and then replace the placeholder variables below.
22
22
 
23
- s = Stupeflix.new YOUR_ACCESS_KEY, YOUR_SECRET_KEY, 'user/resource'
24
- id = 'some_unique_identifier'
23
+ ```ruby
24
+ # Set a unique identifier e.g. 'user/resource_id'
25
+ id = "user/resource_id#{Time.now.to_i}"
26
+
27
+ # Configure credentials
28
+ s = Stupeflix::Video.new id, YOUR_ACCESS_KEY, YOUR_SECRET_KEY
25
29
 
26
30
  # To PUT a video definition
27
- s.put_definition definition_xml, id
31
+ s.definition = definition_xml
28
32
 
29
33
  # POST profiles to request videos be generated accordingly
30
- s.post_profiles profiles_xml, id
34
+ s.profiles = profiles_xml
31
35
 
32
36
  # GET status of requested videos
33
- s.status id
37
+ s.status
38
+ ```
39
+
40
+ See the [examples directory](http://github.com/pgeraghty/stupeflix-api/tree/master/examples) for guidance.
34
41
 
35
42
  Follow [this link](http://stupeflix-api.readthedocs.org/en/latest/resources/04_video_description_langage.html) for more
36
43
  information about how to produce a definition. I recommend Nokogiri's XML builder.
@@ -0,0 +1,23 @@
1
+ # Set a unique identifier e.g. 'user/resource_id'
2
+ id = "user/resource_id#{Time.now.to_i}"
3
+
4
+ # Configure credentials
5
+ s = Stupeflix::Video.new id, YOUR_ACCESS_KEY, YOUR_SECRET_KEY
6
+
7
+ # To PUT a video definition
8
+ s.definition = Stupeflix::Definition.new do |xml|
9
+ images = %w(qiwD B0-X hXBA rEpt 9w95 ILMo mO6A oUay st5s wExP 01Wb IouW zlCm).map { |i| 'http://gdurl.com/' + i }.shuffle[0...8]
10
+ xml.stack(duration: 4) {
11
+ xml.add_image images.pop
12
+ xml.add_text 'Example', align: 'center,center'
13
+ }
14
+ images.each_with_index do |i,x|
15
+ xml.add_slide i, "Slide #{x}", duration: 4
16
+ end
17
+ end
18
+
19
+ # POST profiles to request videos be generated accordingly
20
+ s.profiles = '<profiles><profile name="720p"><stupeflixStore></stupeflixStore></profile></profiles>'
21
+
22
+ # GET status of requested videos
23
+ s.status
@@ -1,6 +1,3 @@
1
- class Stupeflix
2
- VERSION = '0.0.1'
3
- def self.version
4
- VERSION
5
- end
1
+ module Stupeflix
2
+ VERSION = '0.0.2'
6
3
  end
data/lib/stupeflix.rb CHANGED
@@ -1,50 +1,123 @@
1
1
  require 'stupeflix/version'
2
2
  require 'httparty'
3
+ require 'nokogiri'
3
4
 
4
- class Stupeflix
5
- include HTTParty
6
- base_uri 'services.stupeflix.com'
5
+ module Stupeflix
6
+ class Video
7
+ include HTTParty
8
+ base_uri 'services.stupeflix.com'
7
9
 
8
- def initialize key, secret, id_prefix
9
- @key, @secret, @prefix = key, secret, id_prefix
10
- self.class.default_params AccessKey: key
11
- end
10
+ def initialize id, key, secret
11
+ @id, @key, @secret = id, key, secret
12
+ self.class.default_params AccessKey: key
13
+ end
12
14
 
13
- def req method, body, mime, t, url
14
- md5hex, md5base64 = md5(body) rescue [nil, nil] # md5hex can be compared to etag in response for verification
15
- [{ Date: t, Signature: sign([method, md5base64, mime, t, url, nil]*"\n") },
16
- body ? { 'Content-MD5' => md5base64.to_s, 'Content-Length' => body.length.to_s, 'Content-Type' => mime } : nil]
17
- end
15
+ def req method, body, mime, t, url
16
+ md5hex, md5base64 = md5(body) rescue [nil, nil] # md5hex can be compared to etag in response for verification
17
+ [{ Date: t, Signature: sign([method, md5base64, mime, t, url, nil]*"\n") },
18
+ body ? { 'Content-MD5' => md5base64.to_s, 'Content-Length' => body.length.to_s, 'Content-Type' => mime } : nil]
19
+ end
18
20
 
19
- def put_definition d, id=Time.now.to_i
20
- params, headers = req('PUT', d, 'text/xml', Time.now.to_i, url = "#{url id}/definition/")
21
- self.class.put url, query: params, headers: headers, body: d
22
- end
21
+ def definition= d
22
+ params, headers = req('PUT', d, 'text/xml', Time.now.to_i, url = "#{self.url}/definition/")
23
+ self.class.put url, query: params, headers: headers, body: d
24
+ end
23
25
 
24
- def post_profiles profiles, id=Time.now.to_i
25
- params, headers = req('POST', body = "ProfilesXML=#{CGI::escape profiles}",
26
- 'application/x-www-form-urlencoded', Time.now.to_i, url = "#{url id}/")
27
- self.class.post url, query: params, headers: headers, body: body
28
- end
26
+ # TODO make this an array or..?
27
+ def profiles= profiles_xml
28
+ params, headers = req('POST', body = "ProfilesXML=#{CGI::escape profiles_xml}",
29
+ 'application/x-www-form-urlencoded', Time.now.to_i, url = "#{self.url}/")
30
+ self.class.post url, query: params, headers: headers, body: body
31
+ end
29
32
 
30
- def status id=Time.now.to_i
31
- params, headers = req('GET', nil, nil, Time.now.to_i, url = "#{url id}/status/")
32
- r = self.class.get url, query: params #, format: :json
33
- r.parsed_response rescue r
34
- end
33
+ def status
34
+ params, headers = req('GET', nil, nil, Time.now.to_i, url = "#{self.url}/status/")
35
+ r = self.class.get url, query: params #, format: :json
36
+ r.parsed_response rescue r
37
+ end
35
38
 
36
- def url id
37
- "/stupeflix-1.0/#{@prefix}#{id}"
38
- end
39
+ def url
40
+ "/stupeflix-1.0/#{@id}" # user/resource
41
+ end
42
+
43
+ protected
39
44
 
40
- protected
45
+ def sign str
46
+ OpenSSL::HMAC.hexdigest OpenSSL::Digest::Digest.new('sha1'), @secret, str
47
+ end
41
48
 
42
- def sign str
43
- OpenSSL::HMAC.hexdigest OpenSSL::Digest::Digest.new('sha1'), @secret, str
49
+ def md5 body
50
+ md5 = Digest::MD5.new().update body
51
+ [md5.hexdigest, Base64.encode64(md5.digest).strip]
52
+ end
44
53
  end
45
54
 
46
- def md5 body
47
- md5 = Digest::MD5.new().update body
48
- [md5.hexdigest, Base64.encode64(md5.digest).strip]
55
+ class Definition < Nokogiri::XML::Builder
56
+ EFFECTS = %w(kenburns flower rectangles none) # http://wiki.stupeflix.com/doku.php?id=effects
57
+ FONTS = %w(arial arialbold arialroundedmtbold comicsansms couriernew landspeedrecord saddlebag timesnewroman verdana)
58
+ DIRECTIONS = %w(left right up down)
59
+ TRANSITIONS = %w(circle crossfade cube move over radial scan scans spiral strip swirl under waterdrop)
60
+ TRANSITIONS_WITH_DIR = %w(cube move over scan spiral under)
61
+
62
+ def initialize &block
63
+ super({}, Nokogiri::XML::Document.new) do |x|
64
+ x.movie(service: 'craftsman-1.0') {
65
+ x.body {
66
+ yield x if block_given?
67
+ }
68
+ }
69
+ end.root
70
+ end
71
+
72
+ def add_slide url, caption, options={}
73
+ options = { duration: 1 }.merge options
74
+ add_transition
75
+ stack(duration: options[:duration]) {
76
+ add_image url
77
+ add_text_overlay caption unless caption.length > 0 rescue nil
78
+ }
79
+ end
80
+
81
+ def add_map map
82
+ overlay(right: '0.0', bottom: '0.0', width:'0.25') {
83
+ image filename: map
84
+ animator type: 'slide-in', direction: 'up', duration:'1.0'
85
+ animator type: 'slide-out', direction: 'down', 'margin-start' => '6.0'
86
+ }
87
+ end
88
+
89
+ def add_image url, options={}
90
+ effect({ type: EFFECTS.sample }.merge options) {
91
+ image filename: url
92
+ }
93
+ end
94
+
95
+ def add_text caption, options={}
96
+ return unless caption.length > 0 rescue nil
97
+ defaults = { type: 'zone', vector: 'true', align: 'left,bottom' }
98
+ long_caption = caption.length > 30
99
+ #defaults[:align] = 'center,top'
100
+ defaults[:fontsize] = 30 unless long_caption # prevent auto-scale from filling screen with huge text
101
+ text_(defaults.merge options) {
102
+ text caption
103
+ filter(type: 'distancemap', distanceWidth: 40.0)
104
+ filter type: 'distancecolor', distanceWidth: 40.0, color: '#de7316',
105
+ strokeColor: '#000000', strokeOpacity: 1.0, strokeWidth: 0.02,
106
+ dropShadowColor: '#00000044', dropShadowOpacity: 1.0, dropShadowBlurWidth: '0.9',
107
+ dropShadowPosition: '0.01,-0.01', outerGlowColor: '#ffffff44', outerGlowOpacity: 1.0, outerGlowBlurWidth: 0.7
108
+ }
109
+ end
110
+
111
+ def add_text_overlay caption, options={}
112
+ overlay {
113
+ add_text caption, options
114
+ }
115
+ end
116
+
117
+ def add_transition options={}
118
+ defaults = { type: TRANSITIONS.sample }
119
+ defaults[:direction] = DIRECTIONS.sample if TRANSITIONS_WITH_DIR.include? defaults[:type]
120
+ transition defaults.merge(options)
121
+ end
49
122
  end
50
123
  end
data/stupeflix.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'stupeflix/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = 'stupeflix'
8
- gem.version = Stupeflix.version
8
+ gem.version = Stupeflix::VERSION
9
9
  gem.platform = Gem::Platform::RUBY
10
10
  gem.authors = ['Paul Geraghty']
11
11
  gem.email = ['muse@appsthatcould.be']
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ['lib']
20
20
 
21
21
  gem.add_dependency 'httparty', '>= 0'
22
+ gem.add_dependency 'nokogiri', '>= 0'
22
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stupeflix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
30
46
  description: Stupeflix API wrapper using HTTParty
31
47
  email:
32
48
  - muse@appsthatcould.be
@@ -39,6 +55,7 @@ files:
39
55
  - LICENSE.txt
40
56
  - README.md
41
57
  - Rakefile
58
+ - examples/example.rb
42
59
  - lib/stupeflix.rb
43
60
  - lib/stupeflix/version.rb
44
61
  - stupeflix.gemspec