zencoder-fetcher 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/zencoder_fetcher +9 -7
- data/lib/zencoder_fetcher.rb +17 -9
- metadata +4 -4
data/bin/zencoder_fetcher
CHANGED
@@ -23,6 +23,7 @@ EOS
|
|
23
23
|
opt :page, "The page to load.", :short => 'p', :type => Integer, :default => 1
|
24
24
|
opt :since, "Load notifications starting since _n_ minutes ago.", :short => 'm', :type => Integer, :default => nil
|
25
25
|
opt :endpoint, "Zencoder endpoint to use. Defaults to https://app.zencoder.com/.", :short => 'e', :type => String
|
26
|
+
opt :api_version, "API version to use.", :short => 'v', :type => String, :default => 'v1'
|
26
27
|
end
|
27
28
|
|
28
29
|
|
@@ -47,13 +48,14 @@ end
|
|
47
48
|
# Run Zencoder Notifier
|
48
49
|
#
|
49
50
|
|
50
|
-
options
|
51
|
-
options[:api_key]
|
52
|
-
options[:url]
|
53
|
-
options[:count]
|
54
|
-
options[:page]
|
55
|
-
options[:since]
|
56
|
-
options[:endpoint]
|
51
|
+
options = {}
|
52
|
+
options[:api_key] = ARGV[0]
|
53
|
+
options[:url] = opts[:url]
|
54
|
+
options[:count] = opts[:count]
|
55
|
+
options[:page] = opts[:page]
|
56
|
+
options[:since] = (opts[:since] && (Time.now.utc - (opts[:since].to_i * 60))) || nil
|
57
|
+
options[:endpoint] = opts[:endpoint]
|
58
|
+
options[:api_version] = opts[:api_version]
|
57
59
|
|
58
60
|
begin
|
59
61
|
if opts[:loop]
|
data/lib/zencoder_fetcher.rb
CHANGED
@@ -9,7 +9,7 @@ rescue
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ZencoderFetcher
|
12
|
-
FETCHER_VERSION = [0,2,
|
12
|
+
FETCHER_VERSION = [0,2,7] unless defined?(FETCHER_VERSION)
|
13
13
|
|
14
14
|
def self.version
|
15
15
|
FETCHER_VERSION.join(".")
|
@@ -28,26 +28,34 @@ module ZencoderFetcher
|
|
28
28
|
local_url = options[:url] || "http://localhost:3000/"
|
29
29
|
auth = local_url.match(/^https?:\/\/([^\/]+):([^\/]+)@/) ? {:username=>$1, :password=>$2} : {}
|
30
30
|
|
31
|
-
response = HTTParty.get("https://#{options[:endpoint] || 'app'}.zencoder.com/api
|
31
|
+
response = HTTParty.get("https://#{options[:endpoint] || 'app'}.zencoder.com/api/#{options[:api_version] || 'v1'}/notifications.json?#{query}",
|
32
32
|
:headers => { "HTTP_X_FETCHER_VERSION" => version })
|
33
33
|
|
34
34
|
if response["errors"]
|
35
35
|
puts "There was an error fetching notifications:"
|
36
36
|
puts response.body.to_s
|
37
|
-
raise
|
37
|
+
raise FetcherError
|
38
38
|
else
|
39
39
|
puts "Notifications retrieved: #{response["notifications"].size}"
|
40
40
|
puts "Posting to #{local_url}" if response["notifications"].size > 0
|
41
41
|
response["notifications"].each do |notification|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
format = notification.delete("format")
|
43
|
+
if format == "xml"
|
44
|
+
begin
|
45
45
|
options = {:body => notification.to_xml}
|
46
|
-
|
46
|
+
rescue
|
47
|
+
puts "Unable to build notification."
|
48
|
+
end
|
49
|
+
else
|
50
|
+
begin
|
47
51
|
options = {:body => notification.to_json}
|
52
|
+
rescue
|
53
|
+
puts "Unable to build notification."
|
48
54
|
end
|
49
|
-
|
50
|
-
|
55
|
+
end
|
56
|
+
options = options.merge({:headers => {"Content-Type" => "application/#{format}"}}) if format
|
57
|
+
options = options.merge({:basic_auth => auth}) if !auth.empty?
|
58
|
+
begin
|
51
59
|
HTTParty.post(local_url, options)
|
52
60
|
rescue Errno::ECONNREFUSED => e
|
53
61
|
puts "Unable to connect to your local server at #{local_url}. Is it running?"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zencoder-fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Warren
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-10-
|
19
|
+
date: 2011-10-12 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: trollop
|