filbunke 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Wouter de Bie
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = filbunke
2
+
3
+ Filbunke client
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Wouter de Bie. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "filbunke"
8
+ gem.summary = %Q{Filbunke client}
9
+ gem.description = %Q{Filbunke client and library}
10
+ gem.email = "wouter@deltaprojects.se"
11
+ gem.homepage = "http://github.com/deltaprojects/filbunke"
12
+ gem.authors = ["Wouter de Bie"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.files.exclude 'pkg'
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "filbunke #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
data/bin/.gitignore ADDED
File without changes
data/filbunke.gemspec ADDED
@@ -0,0 +1,48 @@
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{filbunke}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Wouter de Bie"]
12
+ s.date = %q{2010-11-03}
13
+ s.description = %q{Filbunke client and library}
14
+ s.email = %q{wouter@deltaprojects.se}
15
+ s.files = [
16
+ "LICENSE",
17
+ "README.rdoc",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "bin/.gitignore",
21
+ "filbunke.gemspec",
22
+ "lib/filbunke.rb",
23
+ "lib/filbunke/client.rb",
24
+ "lib/filbunke/file.rb",
25
+ "lib/filbunke/repository.rb",
26
+ "test/helper.rb",
27
+ "test/test_filbunke.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/deltaprojects/filbunke}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.6}
33
+ s.summary = %q{Filbunke client}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
46
+ end
47
+ end
48
+
@@ -0,0 +1,102 @@
1
+ module Filbunke
2
+ class Client
3
+
4
+ UPDATES_ACTION = 'updates'
5
+ FILES_ACTION = 'files'
6
+ URL_KEY = 'url'
7
+ FROM_CHECKPOINT_KEY = 'from_checkpoint'
8
+ HASH_KEY = 'hash'
9
+
10
+ def initialize(repository)
11
+ @repository = repository
12
+ end
13
+
14
+ def with_updated_files(last_checkpoint, local_path)
15
+ updates = get_updated_file_list(last_checkpoint)
16
+ updated_files = updates["files"] || []
17
+ updated_files.each do |raw_file|
18
+ file = File.new(raw_file)
19
+ if file.url.start_with?("http://")
20
+ local_file_path = File.join(local_path, file.path)
21
+ update_http_file!(file, local_file_path)
22
+ yield file
23
+ else
24
+ raise "Unsupported protocol for file: #{file.inspect}"
25
+ end
26
+ end
27
+ updates["checkpoint"] || last_checkpoint
28
+ end
29
+
30
+ def register_updated_file!(path, url, hash = nil)
31
+ register_http = Net::HTTP.new(@repository.host, @repository.port)
32
+ register_http.start do |http|
33
+ register_path = "/#{FILES_ACTION}/#{@repository.name}/#{path}?#{URL_KEY}=#{url}"
34
+ register_path += "&#{HASH_KEY}=#{hash}" if hash
35
+ request = Net::HTTP::Put.new(register_path)
36
+ response = http.request(request)
37
+ if response.code.to_i != 204
38
+ raise "Failed to register updated file: #{path}"
39
+ end
40
+ end
41
+ end
42
+
43
+ def register_deleted_file!(path)
44
+ register_http = Net::HTTP.new(@repository.host, @repository.port)
45
+ register_http.start do |http|
46
+ register_path = "/#{FILES_ACTION}/#{@repository.name}/#{path}"
47
+ request = Net::HTTP::Delete.new(register_path)
48
+ response = http.request(request)
49
+ if response.code.to_i != 204
50
+ raise "Failed to register deleted file: #{path}"
51
+ end
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def get_updated_file_list(last_checkpoint)
58
+ updates_http = Net::HTTP.new(@repository.host, @repository.port)
59
+ updates_http.start do |http|
60
+ updates_path = "/#{UPDATES_ACTION}/#{@repository.name}?#{FROM_CHECKPOINT_KEY}=#{last_checkpoint}"
61
+ request = Net::HTTP::Get.new(updates_path)
62
+ response = http.request(request)
63
+ if response.code.to_i == 200
64
+ JSON.parse(response.body)
65
+ else
66
+ raise "Failed to download updates for #{@repository.name}, error code = #{response.code}"
67
+ end
68
+ end
69
+ end
70
+
71
+ def update_http_file!(file, local_file_path)
72
+ uri = URI.parse(file.url)
73
+ file_http=Net::HTTP.new(uri.host, uri.port)
74
+ file_http.start do |http|
75
+ request = Net::HTTP::Get.new(uri.path)
76
+ request.basic_auth @repository.user, @repository.pass if @repository.user
77
+ response = http.request(request)
78
+ if response.code.to_i == 200
79
+ write_file!(local_file_path, response.body)
80
+ elsif response.code.to_i == 404
81
+ delete_file!(local_file_path)
82
+ else
83
+ raise "Failed to update file #{uri}, error code = #{response.code}"
84
+ end
85
+ end
86
+ end
87
+
88
+ def write_file!(file_path, contents)
89
+ FileUtils.mkdir_p(File.dirname(file_path))
90
+ File.open(file_path, 'w') do |file|
91
+ file.write(contents);
92
+ file.close
93
+ end
94
+ end
95
+
96
+ def delete_file!(file_path)
97
+ File.delete(file_path)
98
+ end
99
+
100
+ end
101
+ end
102
+
@@ -0,0 +1,31 @@
1
+ module Filbunke
2
+ class File
3
+
4
+ PATH_KEY = 'path'
5
+ URL_KEY = 'url'
6
+ HASH_KEY = 'hash'
7
+ STATE_KEY = 'state'
8
+
9
+ def initialize(json)
10
+ @json = json
11
+ end
12
+
13
+ def path
14
+ @json[PATH_KEY]
15
+ end
16
+
17
+ def url
18
+ @json[URL_KEY]
19
+ end
20
+
21
+ def hash
22
+ @json[HASH_KEY]
23
+ end
24
+
25
+ def state
26
+ @json[STATE_KEY]
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,15 @@
1
+ module Filbunke
2
+ class Repository
3
+
4
+ attr_accessor :host, :port, :name, :user, :pass
5
+
6
+ def initialize(name, host, port, user = nil, pass = nil)
7
+ @name = name
8
+ @host = host
9
+ @port = port
10
+ @user = user
11
+ @pass = pass
12
+ end
13
+
14
+ end
15
+ end
data/lib/filbunke.rb ADDED
@@ -0,0 +1,4 @@
1
+ puts "Loading filbunke"
2
+ require 'filbunke/client.rb'
3
+ require 'filbunke/file.rb'
4
+ require 'filbunke/repository.rb'
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'filbunke'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFilbunke < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filbunke
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Wouter de Bie
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-03 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: Filbunke client and library
33
+ email: wouter@deltaprojects.se
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files: []
39
+
40
+ files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ - Rakefile
44
+ - VERSION
45
+ - bin/.gitignore
46
+ - filbunke.gemspec
47
+ - lib/filbunke.rb
48
+ - lib/filbunke/client.rb
49
+ - lib/filbunke/file.rb
50
+ - lib/filbunke/repository.rb
51
+ - test/helper.rb
52
+ - test/test_filbunke.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/deltaprojects/filbunke
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Filbunke client
83
+ test_files: []
84
+