net-github-upload 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -75,12 +75,12 @@ end
75
75
 
76
76
  desc "gem install"
77
77
  task :install => [:package] do
78
- sh "sudo gem install pkg/#{$name}-#{$version}.gem --local"
78
+ sh "gem install pkg/#{$name}-#{$version}.gem --local"
79
79
  end
80
80
 
81
81
  desc "gem uninstall"
82
82
  task :uninstall do
83
- sh "sudo gem uninstall #{$name}"
83
+ sh "gem uninstall #{$name}"
84
84
  end
85
85
 
86
86
  # vim: syntax=ruby
@@ -6,10 +6,14 @@ require 'faster_xml_simple'
6
6
  module Net
7
7
  module GitHub
8
8
  class Upload
9
- VERSION = '0.0.3'
9
+ VERSION = '0.0.4'
10
10
  def initialize params=nil
11
11
  @login = params[:login]
12
12
  @token = params[:token]
13
+
14
+ if @login.empty? or @token.empty?
15
+ raise "login or token is empty"
16
+ end
13
17
  end
14
18
 
15
19
  def upload info
@@ -46,9 +50,10 @@ module Net
46
50
  raise "file '#{info[:name]}' is already uploaded. please try different name"
47
51
  end
48
52
 
53
+ info[:content_type] ||= 'application/octet-stream'
49
54
  stat = HTTPClient.post("http://github.com/#{info[:repos]}/downloads", {
50
55
  "file_size" => info[:file] ? File.stat(info[:file]).size : info[:data].size,
51
- "content_type" => info[:content_type] || 'application/octet-stream',
56
+ "content_type" => info[:content_type],
52
57
  "file_name" => info[:name],
53
58
  "description" => info[:description] || '',
54
59
  "login" => @login,
@@ -68,7 +73,6 @@ module Net
68
73
  ['success_action_status', 201],
69
74
  ['key', upload_info['prefix'] + info[:name]],
70
75
  ['AWSAccessKeyId', upload_info['accesskeyid']],
71
- ['Content-Type', info[:content_type] || 'application/octet-stream'],
72
76
  ['signature', upload_info['signature']],
73
77
  ['acl', upload_info['acl']],
74
78
  ['file', f]
@@ -81,7 +85,6 @@ module Net
81
85
  ['success_action_status', 201],
82
86
  ['key', upload_info['prefix'] + info[:name]],
83
87
  ['AWSAccessKeyId', upload_info['accesskeyid']],
84
- ['Content-Type', info[:content_type] || 'application/octet-stream'],
85
88
  ['signature', upload_info['signature']],
86
89
  ['acl', upload_info['acl']],
87
90
  ['file', StringIO.new(info[:data])]
@@ -91,7 +94,7 @@ module Net
91
94
  if stat.code == 201
92
95
  return FasterXmlSimple.xml_in(stat.content)['PostResponse']['Location']
93
96
  else
94
- raise 'Failed to upload'
97
+ raise 'Failed to upload' + extract_error_message(stat)
95
98
  end
96
99
  end
97
100
 
@@ -100,6 +103,17 @@ module Net
100
103
  end
101
104
 
102
105
  private
106
+
107
+
108
+ def extract_error_message(stat)
109
+ # @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/ErrorResponses.html
110
+ error = FasterXmlSimple.xml_in(stat.content)['Error']
111
+ " due to #{error['Code']} (#{error['Message']})"
112
+ rescue
113
+ ''
114
+ end
115
+
116
+
103
117
  def list_files repos
104
118
  raise "required repository name" unless repos
105
119
  res = HTTPClient.get_content("http://github.com/#{repos}/downloads", {
data/test/github_test.rb CHANGED
@@ -9,7 +9,7 @@ class GitHubUploadTest < Test::Unit::TestCase
9
9
  :login => login,
10
10
  :token => token
11
11
  )
12
- @repos = 'taberareloo'
12
+ @repos = 'ruby-net-github-upload'
13
13
  end
14
14
 
15
15
  def test_file_upload
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-github-upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Constellation
@@ -9,39 +15,53 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-01-17 00:00:00 +09:00
18
+ date: 2010-08-12 00:00:00 +09:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: nokogiri
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 0
23
34
  version: 1.4.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: faster_xml_simple
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
33
48
  version: "0"
34
- version:
49
+ type: :runtime
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: httpclient
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
40
56
  requirements:
41
57
  - - ">="
42
58
  - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
43
62
  version: "0"
44
- version:
63
+ type: :runtime
64
+ version_requirements: *id003
45
65
  description: |
46
66
  Ruby Net::GitHub::Upload is upload user agent for GitHub Downloads
47
67
 
@@ -55,8 +75,8 @@ extra_rdoc_files:
55
75
  files:
56
76
  - README.rdoc
57
77
  - Rakefile
58
- - test/github_test.rb
59
78
  - test/test
79
+ - test/github_test.rb
60
80
  - lib/net/github-upload.rb
61
81
  has_rdoc: true
62
82
  homepage: http://github.com/Constellation/ruby-net-github-upload
@@ -73,21 +93,27 @@ rdoc_options:
73
93
  require_paths:
74
94
  - lib
75
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
76
97
  requirements:
77
98
  - - ">="
78
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
79
103
  version: "0"
80
- version:
81
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
82
106
  requirements:
83
107
  - - ">="
84
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
85
112
  version: "0"
86
- version:
87
113
  requirements: []
88
114
 
89
115
  rubyforge_project: ruby-net-github-upload
90
- rubygems_version: 1.3.5
116
+ rubygems_version: 1.3.7
91
117
  signing_key:
92
118
  specification_version: 3
93
119
  summary: ruby porting of Net::GitHub::Upload