zencoder-fetcher 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/bin/zencoder_fetcher +12 -3
- data/lib/zencoder_fetcher.rb +8 -3
- data/zencoder-fetcher.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/zencoder_fetcher
CHANGED
@@ -21,6 +21,7 @@ EOS
|
|
21
21
|
opt :seconds, "Check every x seconds.", :short => 's', :type => Integer, :default => 60
|
22
22
|
opt :count, "Number of notifications to retrieve per page.", :short => 'c', :type => Integer, :default => 50
|
23
23
|
opt :page, "The page to load.", :short => 'p', :type => Integer, :default => 1
|
24
|
+
opt :all, "Get all records on each request, rather than only new ones.", :short => 'a', :default => false
|
24
25
|
end
|
25
26
|
|
26
27
|
#
|
@@ -48,13 +49,21 @@ options[:api_key] = ARGV[0]
|
|
48
49
|
options[:url] = opts[:url]
|
49
50
|
options[:count] = opts[:count]
|
50
51
|
options[:page] = opts[:page]
|
52
|
+
options[:all] = opts[:all]
|
51
53
|
|
52
54
|
begin
|
53
55
|
if opts[:loop]
|
56
|
+
@since_job_id = 0
|
54
57
|
loop do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
begin
|
59
|
+
puts "Checking Zencoder for Notifications at #{Time.now}"
|
60
|
+
options.merge!({:since_job_id => @since_job_id})
|
61
|
+
last_job = ZencoderFetcher.request(options)
|
62
|
+
@since_job_id = last_job if last_job > @since_job_id
|
63
|
+
sleep [10,opts[:seconds]].max
|
64
|
+
rescue Exception => e
|
65
|
+
raise e
|
66
|
+
end
|
58
67
|
end
|
59
68
|
else
|
60
69
|
ZencoderFetcher.request(options)
|
data/lib/zencoder_fetcher.rb
CHANGED
@@ -14,20 +14,25 @@ module ZencoderFetcher
|
|
14
14
|
post_uri = options[:url] ? options[:url] : "http://localhost:3000/"
|
15
15
|
per_page = options[:count] ? options[:count] : 50
|
16
16
|
page = options[:page] ? options[:page] : 1
|
17
|
+
since_job_id = (options[:all] || options[:since_job_id].to_s == "") ? 0 : options[:since_job_id]
|
17
18
|
|
18
19
|
begin
|
19
|
-
response = HTTParty.get("http://app.zencoder.com/api/notifications.json?api_key=#{api_key}&per_page=#{per_page}&page=#{page}")
|
20
|
-
|
20
|
+
response = HTTParty.get("http://app.zencoder.com/api/notifications.json?api_key=#{api_key}&per_page=#{per_page}&page=#{page}&since_id=#{since_job_id}")
|
21
|
+
|
22
|
+
if response.body.is_a?(String)
|
21
23
|
if response.body =~ /\{"errors"/
|
22
24
|
puts JSON.parse(response.body)["errors"]
|
23
25
|
else
|
24
26
|
i = 0
|
25
|
-
|
27
|
+
latest_job_id = 0
|
28
|
+
JSON.parse(response.body).each do |job|
|
26
29
|
options = {:headers => {"Content-type" => "application/json"}, :body => job}
|
27
30
|
HTTParty.post(post_uri, options)
|
31
|
+
latest_job_id = JSON.parse(job)["job"]["id"].to_i if JSON.parse(job)["job"]["id"].to_i > latest_job_id
|
28
32
|
i += 1
|
29
33
|
end
|
30
34
|
puts "#{i} notifications retrieved and posted to #{post_uri}"
|
35
|
+
return latest_job_id
|
31
36
|
end
|
32
37
|
else
|
33
38
|
puts "No notifications found."
|
data/zencoder-fetcher.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zencoder-fetcher}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["chriswarren"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-07}
|
13
13
|
s.default_executable = %q{zencoder_fetcher}
|
14
14
|
s.description = %q{Fetches notifications from Zencoder for local development where Zencoder is unable to communicate to the server, usually because it's localhost.}
|
15
15
|
s.email = %q{chris@zencoder.com}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- chriswarren
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-07 00:00:00 -05:00
|
18
18
|
default_executable: zencoder_fetcher
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|