zencoder-fetcher 0.1.7 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -14
- data/bin/zencoder_fetcher +23 -23
- data/lib/zencoder_fetcher.rb +40 -35
- metadata +22 -43
- data/.document +0 -5
- data/.gitignore +0 -21
- data/Rakefile +0 -57
- data/VERSION +0 -1
- data/test/helper.rb +0 -10
- data/test/test_zencoder-fetcher.rb +0 -7
- data/zencoder-fetcher.gemspec +0 -66
data/README.rdoc
CHANGED
@@ -10,22 +10,12 @@ Run with the
|
|
10
10
|
|
11
11
|
Options:
|
12
12
|
* --url, -u: URL to post the Zencoder notification (default: http://localhost:3000)
|
13
|
-
* --loop, -l: Run the notifier in a loop
|
14
|
-
* --
|
13
|
+
* --loop, -l: Run the notifier in a loop.
|
14
|
+
* --interval, -n <i>: Check every n seconds. (Default: 60)
|
15
15
|
* --count, -c <i>: Number of notifications to retrieve per page. (Default: 50)
|
16
16
|
* --page, -p <i>: The page to load. (Default: 1)
|
17
|
-
* --
|
18
|
-
|
19
|
-
== Note on Patches/Pull Requests
|
20
|
-
|
21
|
-
* Fork the project.
|
22
|
-
* Make your feature addition or bug fix.
|
23
|
-
* Add tests for it. This is important so I don't break it in a
|
24
|
-
future version unintentionally.
|
25
|
-
* Commit, do not mess with rakefile, version, or history.
|
26
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
27
|
-
* Send me a pull request. Bonus points for topic branches.
|
17
|
+
* --since, -m <i>: Load notifications starting since n minutes ago.
|
28
18
|
|
29
19
|
== Copyright
|
30
20
|
|
31
|
-
Copyright (c) 2010 Zencoder. See LICENSE for details.
|
21
|
+
Copyright (c) 2010 Zencoder Inc. See LICENSE for details.
|
data/bin/zencoder_fetcher
CHANGED
@@ -18,13 +18,14 @@ where [options] are:
|
|
18
18
|
EOS
|
19
19
|
opt :url, "URL to post the Zencoder notification", :short => 'u', :type => String, :default => "http://localhost:3000"
|
20
20
|
opt :loop, "Run the notifier in a loop.", :short => 'l', :default => false
|
21
|
-
opt :
|
21
|
+
opt :interval, "Check every x seconds.", :short => 'n', :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 :
|
25
|
-
opt :
|
24
|
+
opt :since, "Load notifications starting since _n_ minutes ago.", :short => 'm', :type => Integer, :default => nil
|
25
|
+
opt :endpoint, "Zencoder endpoint to use. Defaults to https://app.zencoder.com/.", :short => 'e', :type => String
|
26
26
|
end
|
27
27
|
|
28
|
+
|
28
29
|
#
|
29
30
|
# Validate input
|
30
31
|
#
|
@@ -38,43 +39,42 @@ Usage:
|
|
38
39
|
zencoder_fetcher [options] <api_key>
|
39
40
|
|
40
41
|
EOS
|
41
|
-
exit
|
42
|
+
exit 1
|
42
43
|
end
|
43
44
|
|
45
|
+
|
44
46
|
#
|
45
47
|
# Run Zencoder Notifier
|
46
48
|
#
|
47
49
|
|
48
|
-
options
|
49
|
-
options[:api_key]
|
50
|
-
options[:url]
|
51
|
-
options[:count]
|
52
|
-
options[:page]
|
53
|
-
options[:
|
54
|
-
options[:
|
50
|
+
options = {}
|
51
|
+
options[:api_key] = ARGV[0]
|
52
|
+
options[:url] = opts[:url]
|
53
|
+
options[:count] = opts[:count]
|
54
|
+
options[:page] = opts[:page]
|
55
|
+
options[:since] = (opts[:since] && (Time.now.utc - (opts[:since].to_i * 60))) || nil
|
56
|
+
options[:endpoint] = opts[:endpoint]
|
55
57
|
|
56
58
|
begin
|
57
59
|
if opts[:loop]
|
58
|
-
@
|
60
|
+
@since = options[:since]
|
59
61
|
loop do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
@since_job_id = last_job if last_job > @since_job_id
|
65
|
-
sleep [10,opts[:seconds]].max
|
66
|
-
rescue Exception => e
|
67
|
-
raise e
|
68
|
-
end
|
62
|
+
puts "Checking Zencoder for Notifications" << (@since ? " since #{@since.utc.strftime('%b %e, %Y @ %H:%M:%S %Z')}" : "")
|
63
|
+
options.merge!(:since => @since)
|
64
|
+
@since = ZencoderFetcher.request(options)
|
65
|
+
sleep [10, opts[:interval]].max
|
69
66
|
end
|
70
67
|
else
|
71
68
|
ZencoderFetcher.request(options)
|
72
69
|
end
|
73
70
|
rescue SystemExit, Interrupt
|
74
|
-
|
71
|
+
puts "Quitting..."
|
72
|
+
exit 0
|
73
|
+
rescue FetcherError
|
74
|
+
exit 1
|
75
75
|
rescue Exception => e
|
76
76
|
puts e.class
|
77
77
|
puts e.message
|
78
78
|
puts e.backtrace
|
79
|
-
|
79
|
+
exit 1
|
80
80
|
end
|
data/lib/zencoder_fetcher.rb
CHANGED
@@ -1,48 +1,53 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'httparty'
|
3
3
|
require 'json'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module ZencoderFetcher
|
6
|
-
FETCHER_VERSION = [0,
|
7
|
-
|
7
|
+
FETCHER_VERSION = [0,2] unless defined?(FETCHER_VERSION)
|
8
|
+
|
8
9
|
def self.version
|
9
10
|
FETCHER_VERSION.join(".")
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
def self.request(options={})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
return latest_job_id
|
14
|
+
query = {
|
15
|
+
"api_key" => options[:api_key],
|
16
|
+
"per_page" => options[:count] || 50,
|
17
|
+
"page" => options[:page] || 1
|
18
|
+
}
|
19
|
+
query["since"] = options[:since].iso8601 if options[:since]
|
20
|
+
query = query.map{|k,v| "#{k}=#{v}" }.join("&")
|
21
|
+
|
22
|
+
local_url = options[:url] || "http://localhost:3000/"
|
23
|
+
|
24
|
+
response = HTTParty.get("https://#{options[:endpoint] || 'app'}.zencoder.com/api/notifications.json?#{query}",
|
25
|
+
:headers => { "HTTP_X_FETCHER_VERSION" => version })
|
26
|
+
|
27
|
+
if response["errors"]
|
28
|
+
puts "There was an error fetching notifications:"
|
29
|
+
puts response.body.to_s
|
30
|
+
raise
|
31
|
+
else
|
32
|
+
response["notifications"].each do |notification|
|
33
|
+
begin
|
34
|
+
HTTParty.post(local_url,
|
35
|
+
:body => notification.to_json,
|
36
|
+
:headers => { "Content-type" => "application/json" })
|
37
|
+
rescue Errno::ECONNREFUSED => e
|
38
|
+
puts "Unable to connect to your local server at #{local_url}. Is it running?"
|
39
|
+
raise FetcherLocalConnectionError
|
40
40
|
end
|
41
|
-
else
|
42
|
-
puts "No notifications found."
|
43
41
|
end
|
44
|
-
|
45
|
-
|
42
|
+
puts "Notifications retrieved: #{response["notifications"].size}"
|
43
|
+
puts "Posted to: #{local_url}" if response["notifications"].size > 0
|
44
|
+
puts
|
45
|
+
|
46
|
+
Time.parse(response["sent_at"])
|
46
47
|
end
|
47
48
|
end
|
48
|
-
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class FetcherError < StandardError; end
|
53
|
+
class FetcherLocalConnectionError < FetcherError; end
|
metadata
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zencoder-fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.1.7
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
|
-
-
|
12
|
+
- Chris Warren
|
13
|
+
- Brandon Arbini
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2011-07-14 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: trollop
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
version: "0"
|
33
|
-
type: :
|
33
|
+
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: httparty
|
@@ -60,48 +60,28 @@ dependencies:
|
|
60
60
|
version: "0"
|
61
61
|
type: :runtime
|
62
62
|
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: trollop
|
65
|
-
prerelease: false
|
66
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
|
-
requirements:
|
69
|
-
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
version: "0"
|
75
|
-
type: :runtime
|
76
|
-
version_requirements: *id004
|
77
63
|
description: Fetches notifications from Zencoder for local development where Zencoder is unable to communicate to the server, usually because it's localhost.
|
78
|
-
email:
|
64
|
+
email:
|
65
|
+
- chris@zencoder.com
|
66
|
+
- b@zencoder.com
|
79
67
|
executables:
|
80
68
|
- zencoder_fetcher
|
81
69
|
extensions: []
|
82
70
|
|
83
|
-
extra_rdoc_files:
|
84
|
-
|
85
|
-
- README.rdoc
|
71
|
+
extra_rdoc_files: []
|
72
|
+
|
86
73
|
files:
|
87
|
-
- .document
|
88
|
-
- .gitignore
|
89
|
-
- LICENSE
|
90
|
-
- README.rdoc
|
91
|
-
- Rakefile
|
92
|
-
- VERSION
|
93
74
|
- bin/zencoder_fetcher
|
94
75
|
- lib/zencoder_fetcher.rb
|
95
|
-
-
|
96
|
-
-
|
97
|
-
- zencoder-fetcher.gemspec
|
76
|
+
- LICENSE
|
77
|
+
- README.rdoc
|
98
78
|
has_rdoc: true
|
99
79
|
homepage: http://github.com/zencoder/zencoder-fetcher
|
100
80
|
licenses: []
|
101
81
|
|
102
82
|
post_install_message:
|
103
|
-
rdoc_options:
|
104
|
-
|
83
|
+
rdoc_options: []
|
84
|
+
|
105
85
|
require_paths:
|
106
86
|
- lib
|
107
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -125,10 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
105
|
requirements: []
|
126
106
|
|
127
107
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.5.0
|
129
109
|
signing_key:
|
130
110
|
specification_version: 3
|
131
111
|
summary: Fetches notifications from Zencoder for local development.
|
132
|
-
test_files:
|
133
|
-
|
134
|
-
- test/test_zencoder-fetcher.rb
|
112
|
+
test_files: []
|
113
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "zencoder-fetcher"
|
8
|
-
gem.summary = %Q{Fetches notifications from Zencoder for local development.}
|
9
|
-
gem.description = %Q{Fetches notifications from Zencoder for local development where Zencoder is unable to communicate to the server, usually because it's localhost.}
|
10
|
-
gem.email = "chris@zencoder.com"
|
11
|
-
gem.homepage = "http://github.com/zencoder/zencoder-fetcher"
|
12
|
-
gem.authors = ["chriswarren"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
-
gem.add_dependency 'httparty'
|
15
|
-
gem.add_dependency 'json'
|
16
|
-
gem.add_dependency 'trollop'
|
17
|
-
gem.executables = %w( zencoder_fetcher)
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
-
end
|
20
|
-
Jeweler::GemcutterTasks.new
|
21
|
-
rescue LoadError
|
22
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'rake/testtask'
|
26
|
-
Rake::TestTask.new(:test) do |test|
|
27
|
-
test.libs << 'lib' << 'test'
|
28
|
-
test.pattern = 'test/**/test_*.rb'
|
29
|
-
test.verbose = true
|
30
|
-
end
|
31
|
-
|
32
|
-
begin
|
33
|
-
require 'rcov/rcovtask'
|
34
|
-
Rcov::RcovTask.new do |test|
|
35
|
-
test.libs << 'test'
|
36
|
-
test.pattern = 'test/**/test_*.rb'
|
37
|
-
test.verbose = true
|
38
|
-
end
|
39
|
-
rescue LoadError
|
40
|
-
task :rcov do
|
41
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
task :test => :check_dependencies
|
46
|
-
|
47
|
-
task :default => :test
|
48
|
-
|
49
|
-
require 'rake/rdoctask'
|
50
|
-
Rake::RDocTask.new do |rdoc|
|
51
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
-
|
53
|
-
rdoc.rdoc_dir = 'rdoc'
|
54
|
-
rdoc.title = "zencoder-notifier #{version}"
|
55
|
-
rdoc.rdoc_files.include('README*')
|
56
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.7
|
data/test/helper.rb
DELETED
data/zencoder-fetcher.gemspec
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{zencoder-fetcher}
|
8
|
-
s.version = "0.1.7"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["chriswarren"]
|
12
|
-
s.date = %q{2010-06-28}
|
13
|
-
s.default_executable = %q{zencoder_fetcher}
|
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
|
-
s.email = %q{chris@zencoder.com}
|
16
|
-
s.executables = ["zencoder_fetcher"]
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE",
|
19
|
-
"README.rdoc"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
".gitignore",
|
24
|
-
"LICENSE",
|
25
|
-
"README.rdoc",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"bin/zencoder_fetcher",
|
29
|
-
"lib/zencoder_fetcher.rb",
|
30
|
-
"test/helper.rb",
|
31
|
-
"test/test_zencoder-fetcher.rb",
|
32
|
-
"zencoder-fetcher.gemspec"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/zencoder/zencoder-fetcher}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.7}
|
38
|
-
s.summary = %q{Fetches notifications from Zencoder for local development.}
|
39
|
-
s.test_files = [
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_zencoder-fetcher.rb"
|
42
|
-
]
|
43
|
-
|
44
|
-
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
-
s.specification_version = 3
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
51
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
52
|
-
s.add_runtime_dependency(%q<trollop>, [">= 0"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
|
-
s.add_dependency(%q<httparty>, [">= 0"])
|
56
|
-
s.add_dependency(%q<json>, [">= 0"])
|
57
|
-
s.add_dependency(%q<trollop>, [">= 0"])
|
58
|
-
end
|
59
|
-
else
|
60
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
61
|
-
s.add_dependency(%q<httparty>, [">= 0"])
|
62
|
-
s.add_dependency(%q<json>, [">= 0"])
|
63
|
-
s.add_dependency(%q<trollop>, [">= 0"])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|