net-github-upload 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +20 -3
  2. data/Rakefile +5 -62
  3. data/lib/net/github-upload.rb +52 -20
  4. metadata +17 -12
@@ -1,7 +1,7 @@
1
1
  = Ruby Net::GitHub::Upload
2
2
 
3
3
  * http://github.com/Constellation/ruby-net-github-upload
4
- * http://gemcutter.org/gems/net-github-upload
4
+ * http://rubygems.org/gems/net-github-upload
5
5
 
6
6
  == DESCRIPTION
7
7
 
@@ -27,7 +27,8 @@ respect to http://github.com/typester/net-github-upload-perl
27
27
  direct_link = gh.upload(
28
28
  :repos => repos,
29
29
  :file => 'test/test',
30
- :description => "test file"
30
+ :description => "test file",
31
+ :upload_timeout => 600 # Allow yourself time to upload larger files.
31
32
  )
32
33
  # direct link is link to Amazon S3.
33
34
  # Because GitHub refrection for file changing is async,
@@ -41,7 +42,7 @@ respect to http://github.com/typester/net-github-upload-perl
41
42
  :data => 'test',
42
43
  :name => "test_#{time}.txt",
43
44
  :content_type => 'text/plain',
44
- :description => "test file2"
45
+ :description => "test file2"
45
46
  )
46
47
 
47
48
  # replace file or data
@@ -58,6 +59,17 @@ respect to http://github.com/typester/net-github-upload-perl
58
59
  :content_type => 'text/plain',
59
60
  :description => "test file2"
60
61
  )
62
+
63
+ # Printing out progress (will yield to block once a second):
64
+ direct_link = gh.upload(
65
+ :repos => repos,
66
+ :file => 'test/test',
67
+ :description => "test file",
68
+ :upload_timeout => 600 # Allow yourself time to upload larger files.
69
+ ) do
70
+ print "."
71
+ end
72
+ puts "."
61
73
 
62
74
  == DEPENDENCY
63
75
 
@@ -71,6 +83,11 @@ respect to http://github.com/typester/net-github-upload-perl
71
83
  gem source -a http://gemcutter.org
72
84
  sudo gem install net-github-upload
73
85
 
86
+ == DEVELOPERS
87
+
88
+ id:Constellation
89
+ id:Spooner
90
+
74
91
  == LICENSE
75
92
 
76
93
  Ruby Net::Github::Upload
data/Rakefile CHANGED
@@ -1,87 +1,30 @@
1
1
  # vim: fileencoding=utf-8
2
2
  require 'rubygems'
3
+ require 'bundler/setup'
3
4
  require 'rake'
4
5
  require 'rake/clean'
5
6
  require 'rake/testtask'
6
- require 'rake/packagetask'
7
- require 'rake/gempackagetask'
8
- require 'rake/rdoctask'
9
- require 'rake/contrib/sshpublisher'
10
- require './lib/net/github-upload'
11
-
12
- $version = Net::GitHub::Upload::VERSION
13
- $readme = 'README.rdoc'
14
- $rdoc_opts = %W(--main #{$readme} --charset utf-8 --line-numbers --inline-source)
15
- $name = 'net-github-upload'
16
- $github_name = 'ruby-net-github-upload'
17
- $summary = 'ruby porting of Net::GitHub::Upload'
18
- $description = <<-EOS
19
- Ruby Net::GitHub::Upload is upload user agent for GitHub Downloads
20
- EOS
21
- $author = 'Constellation'
22
- $email = 'utatane.tea@gmail.com'
23
- $page = 'http://github.com/Constellation/ruby-net-github-upload'
24
- $rubyforge_project = 'ruby-net-github-upload'
25
-
7
+ require 'rdoc/task'
26
8
 
27
9
  task :default => [:test]
28
10
  task :package => [:clean]
29
11
 
12
+ Bundler::GemHelper.install_tasks
13
+
30
14
  Rake::TestTask.new("test") do |t|
31
15
  t.libs << "test"
32
16
  t.pattern = "test/**/*_test.rb"
33
17
  t.verbose = true
34
18
  end
35
19
 
36
- spec = Gem::Specification.new do |s|
37
- s.name = $name
38
- s.version = $version
39
- s.platform = Gem::Platform::RUBY
40
- s.has_rdoc = true
41
- s.extra_rdoc_files = [$readme]
42
- s.rdoc_options += $rdoc_opts
43
- s.summary = $summary
44
- s.description = $description
45
- s.author = $author
46
- s.email = $email
47
- s.homepage = $page
48
- s.executables = $exec
49
- s.rubyforge_project = $rubyforge_project
50
- s.require_path = 'lib'
51
- s.test_files = Dir["test/*_test.rb"]
52
- s.add_dependency('nokogiri', '>=1.4.0')
53
- s.add_dependency('faster_xml_simple')
54
- s.add_dependency('json')
55
- s.add_dependency('httpclient')
56
- s.files = %w(README.rdoc Rakefile) + Dir["{bin,test,lib}/**/*"]
57
- end
58
-
59
- Rake::GemPackageTask.new(spec) do |p|
60
- p.need_tar = true
61
- p.gem_spec = spec
62
- end
63
-
64
20
  Rake::RDocTask.new do |rdoc|
65
21
  rdoc.rdoc_dir = 'doc'
66
- rdoc.options += $rdoc_opts
67
22
  rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/**/*.c")
68
23
  end
69
24
 
70
- desc "gem spec"
71
- task :gemspec do
72
- File.open("#{$github_name}.gemspec", "wb") do |f|
73
- f << spec.to_ruby
74
- end
75
- end
76
-
77
- desc "gem install"
78
- task :install => [:package] do
79
- sh "gem install pkg/#{$name}-#{$version}.gem --local"
80
- end
81
-
82
25
  desc "gem uninstall"
83
26
  task :uninstall do
84
- sh "gem uninstall #{$name}"
27
+ sh "gem uninstall net-github-upload"
85
28
  end
86
29
 
87
30
  # vim: syntax=ruby
@@ -8,7 +8,7 @@ require 'faster_xml_simple'
8
8
  module Net
9
9
  module GitHub
10
10
  class Upload
11
- VERSION = '0.0.7'
11
+ VERSION = '0.0.8'
12
12
  def initialize params=nil
13
13
  @login = params[:login]
14
14
  @token = params[:token]
@@ -18,6 +18,20 @@ module Net
18
18
  end
19
19
  end
20
20
 
21
+ # Upload a file to github. Will fail if the file already exists.
22
+ # To upload, either supply :data and :name or :file.
23
+ #
24
+ # @param [Hash] info
25
+ # @option info [String] :content_type ('application/octet-stream') Type of data to send
26
+ # @option info [String] :data Data to upload as a file. Requires that the :name option is set.
27
+ # @option info [String] :description ('') Description of file on Github download page.
28
+ # @option info [String] :file Path to file to upload.
29
+ # @option info [String] :name (filename of info[:file] if uploading a file) Name the file will have (not including path) when uploaded.
30
+ # @option info [Boolean] :replace (false) True to force overwriting of an existing file.
31
+ # @option info [String] :repos Name of Github project, such as "my_project", which is the repository.
32
+ # @option info [Float] :upload_timeout (120) Maximum time, in seconds, before abandoning a file upload.
33
+ # @option info [Float] :yield_interval (1) Interval, in seconds, between yields if block is given.
34
+ # @yield [] Optional block will yield every info[:yield_interval] seconds (This can be used, for example, to print "#" every second so users see that the upload is continuing).
21
35
  def upload info
22
36
  unless info[:repos]
23
37
  raise "required repository name"
@@ -70,30 +84,47 @@ module Net
70
84
  f << info[:data]
71
85
  f.flush
72
86
  end
73
- stat = HTTPClient.post("http://github.s3.amazonaws.com/", [
74
- ['Filename', info[:name]],
75
- ['policy', upload_info['policy']],
76
- ['success_action_status', 201],
77
- ['key', upload_info['path']],
78
- ['AWSAccessKeyId', upload_info['accesskeyid']],
79
- ['Content-Type', upload_info['content_type'] || 'application/octet-stream'],
80
- ['signature', upload_info['signature']],
81
- ['acl', upload_info['acl']],
82
- ['file', f]
83
- ])
84
- f.close
85
-
86
- if stat.code == 201
87
- return FasterXmlSimple.xml_in(stat.content)['PostResponse']['Location']
87
+ client = HTTPClient.new
88
+ client.send_timeout = info[:upload_timeout] if info[:upload_timeout]
89
+
90
+ res = begin
91
+ connection = client.post_async("http://github.s3.amazonaws.com/", [
92
+ ['Filename', info[:name]],
93
+ ['policy', upload_info['policy']],
94
+ ['success_action_status', 201],
95
+ ['key', upload_info['path']],
96
+ ['AWSAccessKeyId', upload_info['accesskeyid']],
97
+ ['Content-Type', upload_info['content_type'] || 'application/octet-stream'],
98
+ ['signature', upload_info['signature']],
99
+ ['acl', upload_info['acl']],
100
+ ['file', f]
101
+ ])
102
+
103
+ until connection.finished?
104
+ yield if block_given?
105
+ sleep info[:yield_interval] || 1
106
+ end
107
+
108
+ connection.pop
109
+ ensure
110
+ f.close
111
+ end
112
+
113
+ if res.status == 201
114
+ return FasterXmlSimple.xml_in(res.body.read)['PostResponse']['Location']
88
115
  else
89
- raise 'Failed to upload' + extract_error_message(stat)
116
+ raise 'Failed to upload' + extract_error_message(res.body)
90
117
  end
91
118
  end
92
119
 
93
- def replace info
94
- upload info.merge( :replace => true )
120
+ # Upload a file and replace it if it already exists on the server.
121
+ #
122
+ # @see #upload
123
+ def replace info = {}, &block
124
+ upload info.merge( :replace => true ), &block
95
125
  end
96
126
 
127
+ # Delete all uploaded files.
97
128
  def delete_all repos
98
129
  unless repos
99
130
  raise "required repository name"
@@ -104,6 +135,7 @@ module Net
104
135
  }
105
136
  end
106
137
 
138
+ # Delete an individual file (used by #replace when replacing existing files).
107
139
  def delete repos, id
108
140
  HTTPClient.post("https://github.com/#{repos}/downloads/#{id.gsub( "download_", '')}", {
109
141
  "_method" => "delete",
@@ -112,6 +144,7 @@ module Net
112
144
  })
113
145
  end
114
146
 
147
+ # List all the files uploaded to a repository.
115
148
  def list_files repos
116
149
  raise "required repository name" unless repos
117
150
  res = HTTPClient.get_content("https://github.com/#{repos}/downloads", {
@@ -144,4 +177,3 @@ module Net
144
177
  end
145
178
  end
146
179
  end
147
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-github-upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-22 00:00:00.000000000Z
12
+ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70245485988420 !ruby/object:Gem::Requirement
16
+ requirement: &70186498494780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70245485988420
24
+ version_requirements: *70186498494780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faster_xml_simple
27
- requirement: &70245485988000 !ruby/object:Gem::Requirement
27
+ requirement: &70186498494180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70245485988000
35
+ version_requirements: *70186498494180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70245485987540 !ruby/object:Gem::Requirement
38
+ requirement: &70186498493420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70245485987540
46
+ version_requirements: *70186498493420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: httpclient
49
- requirement: &70245485987120 !ruby/object:Gem::Requirement
49
+ requirement: &70186498492880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70245485987120
57
+ version_requirements: *70186498492880
58
58
  description: ! 'Ruby Net::GitHub::Upload is upload user agent for GitHub Downloads
59
59
 
60
60
  '
@@ -78,7 +78,6 @@ rdoc_options:
78
78
  - --charset
79
79
  - utf-8
80
80
  - --line-numbers
81
- - --inline-source
82
81
  require_paths:
83
82
  - lib
84
83
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -87,15 +86,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
86
  - - ! '>='
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
89
+ segments:
90
+ - 0
91
+ hash: 651643364530444235
90
92
  required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  none: false
92
94
  requirements:
93
95
  - - ! '>='
94
96
  - !ruby/object:Gem::Version
95
97
  version: '0'
98
+ segments:
99
+ - 0
100
+ hash: 651643364530444235
96
101
  requirements: []
97
102
  rubyforge_project: ruby-net-github-upload
98
- rubygems_version: 1.8.6
103
+ rubygems_version: 1.8.15
99
104
  signing_key:
100
105
  specification_version: 3
101
106
  summary: ruby porting of Net::GitHub::Upload