swftly 0.1.2
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/lib/swftly.rb +56 -0
- data/lib/swftly/runtime.rb +17 -0
- metadata +112 -0
data/lib/swftly.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
class Swftly
|
2
|
+
require 'curb'
|
3
|
+
attr_accessor :swf_path, :auto_process
|
4
|
+
attr_reader :runtime, :markup, :raw, :converted,
|
5
|
+
:converter_response_code, :fetcher_response_code
|
6
|
+
|
7
|
+
#init w/ a swf, through false for the second param if you don't wanna
|
8
|
+
#immediately trigger post-conversion processing
|
9
|
+
def initialize( swf_path = '', auto_process = true )
|
10
|
+
@swf_path = swf_path
|
11
|
+
@auto_process = auto_process
|
12
|
+
end
|
13
|
+
|
14
|
+
# post the swf to swiffy and parse/process the results
|
15
|
+
def swiff
|
16
|
+
return nil unless @swf_path.instance_of? String
|
17
|
+
|
18
|
+
file = Curl::PostField.file 'swfFile', @swf_path
|
19
|
+
converter = Curl::Easy.http_post("https://www.google.com/doubleclick/studio/swiffy/upload", file) do |curl|
|
20
|
+
curl.multipart_form_post = true
|
21
|
+
curl.headers["User-Agent"] = "Curl/Ruby"
|
22
|
+
curl.follow_location = true
|
23
|
+
curl.enable_cookies = true
|
24
|
+
end
|
25
|
+
|
26
|
+
@converter_response_code = converter.response_code
|
27
|
+
@raw = converter.body_str
|
28
|
+
|
29
|
+
process! if @auto_process
|
30
|
+
end
|
31
|
+
|
32
|
+
# perform and process the second fetching
|
33
|
+
def process!
|
34
|
+
return failed unless @converter_response_code == 200
|
35
|
+
|
36
|
+
path = URI::extract(@raw).detect { |d| d.match /\/o\// }
|
37
|
+
path += @raw.split('","').detect { |d| d.match '.html' }
|
38
|
+
|
39
|
+
fetcher = Curl.get(path)
|
40
|
+
|
41
|
+
@fetcher_response_code = fetcher.response_code
|
42
|
+
@markup = fetcher.body_str
|
43
|
+
|
44
|
+
@runtime = Runtime.new(@markup)
|
45
|
+
@converted = Converted.new(@markup)
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def failed
|
51
|
+
raise "File conversion failed with response code #{converted_response_code}."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
require 'swftly/runtime'
|
56
|
+
require 'swftly/converted'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Runtime
|
2
|
+
attr_reader :markup
|
3
|
+
|
4
|
+
def initialize(markup)
|
5
|
+
@markup = markup
|
6
|
+
@urls = URI::extract @markup
|
7
|
+
end
|
8
|
+
|
9
|
+
def version
|
10
|
+
url.split('/')[-2] #we'll strip out runtime version here
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
@urls.detect { |d| d.match /runtime\.js/} #typically the first js file in the set.
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swftly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jnf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.4
|
20
|
+
none: false
|
21
|
+
name: curb
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.8.4
|
29
|
+
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
none: false
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
none: false
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
none: false
|
53
|
+
name: vcr
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
none: false
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
none: false
|
69
|
+
name: webmock
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
none: false
|
78
|
+
description: swftly abstracts and automates interactions with Swiffy, Google's hosted
|
79
|
+
swf converter.
|
80
|
+
email: jeremy.flores@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- lib/swftly.rb
|
86
|
+
- lib/swftly/runtime.rb
|
87
|
+
homepage: https://github.com/jnf/swftly
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- .
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
none: false
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
none: false
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.23
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: swftly abstracts and automates interactions with Swiffy, Google's hosted
|
111
|
+
swf converter.
|
112
|
+
test_files: []
|