net-github-upload 0.0.2 → 0.0.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/README.rdoc CHANGED
@@ -35,10 +35,26 @@ respect to http://github.com/typester/net-github-upload-perl
35
35
 
36
36
  # data upload
37
37
  # you can define content_type => Amazon S3 Content-Type
38
+ time = Time.now.to_i
38
39
  direct_link = gh.upload(
39
40
  :repos => repos,
40
41
  :data => 'test',
41
- :name => "test_#{Time.now.to_i}.txt",
42
+ :name => "test_#{time}.txt",
43
+ :content_type => 'text/plain',
44
+ :description => "test file2"
45
+ )
46
+
47
+ # replace file or data
48
+ # thx id:rngtng !
49
+ direct_link = gh.replace(
50
+ :repos => repos,
51
+ :file => 'test/test',
52
+ :description => "test file"
53
+ )
54
+ direct_link = gh.replace(
55
+ :repos => repos,
56
+ :data => 'test',
57
+ :name => "test_#{time}.txt",
42
58
  :content_type => 'text/plain',
43
59
  :description => "test file2"
44
60
  )
@@ -6,7 +6,7 @@ require 'faster_xml_simple'
6
6
  module Net
7
7
  module GitHub
8
8
  class Upload
9
- VERSION = '0.0.2'
9
+ VERSION = '0.0.3'
10
10
  def initialize params=nil
11
11
  @login = params[:login]
12
12
  @token = params[:token]
@@ -33,7 +33,16 @@ module Net
33
33
  raise "required name parameter for filename with data parameter"
34
34
  end
35
35
 
36
- if list_files(info[:repos]).any?{|obj| obj[:name] == info[:name]}
36
+ if info[:replace]
37
+ list_files(info[:repos]).each { |obj|
38
+ next unless obj[:name] == info[:name]
39
+ HTTPClient.post("http://github.com/#{info[:repos]}/downloads/#{obj[:id].gsub( "download_", '')}", {
40
+ "_method" => "delete",
41
+ "login" => @login,
42
+ "token" => @token
43
+ })
44
+ }
45
+ elsif list_files(info[:repos]).any?{|obj| obj[:name] == info[:name]}
37
46
  raise "file '#{info[:name]}' is already uploaded. please try different name"
38
47
  end
39
48
 
@@ -86,6 +95,10 @@ module Net
86
95
  end
87
96
  end
88
97
 
98
+ def replace info
99
+ upload info.merge( :replace => true )
100
+ end
101
+
89
102
  private
90
103
  def list_files repos
91
104
  raise "required repository name" unless repos
data/test/github_test.rb CHANGED
@@ -22,15 +22,38 @@ class GitHubUploadTest < Test::Unit::TestCase
22
22
  )
23
23
  }
24
24
  assert_instance_of String, direct_link
25
+
26
+ # replace method : thx id:rngtng
27
+ assert_nothing_raised {
28
+ direct_link = @gh.replace(
29
+ :repos => @repos,
30
+ :file => 'test/test',
31
+ :description => "test file"
32
+ )
33
+ }
34
+ assert_instance_of String, direct_link
25
35
  end
26
36
 
27
37
  def test_content_upload
28
38
  direct_link = nil
39
+ time = Time.now.to_i
29
40
  assert_nothing_raised {
30
41
  direct_link = @gh.upload(
31
42
  :repos => @repos,
32
43
  :data => 'test',
33
- :name => "test_#{Time.now.to_i}.txt",
44
+ :name => "test_#{time}.txt",
45
+ :content_type => 'text/plain',
46
+ :description => "test file2"
47
+ )
48
+ }
49
+ assert_instance_of String, direct_link
50
+
51
+ # replace method : thx id:rngtng
52
+ assert_nothing_raised {
53
+ direct_link = @gh.replace(
54
+ :repos => @repos,
55
+ :data => 'test',
56
+ :name => "test_#{time}.txt",
34
57
  :content_type => 'text/plain',
35
58
  :description => "test file2"
36
59
  )
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Constellation
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-05 00:00:00 +09:00
12
+ date: 2010-01-17 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency