octokit 1.6.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # CHANGELOG
2
2
 
3
+ * [1.7.0 - June 18, 2012](https://github.com/pengwynn/octokit/compare/v1.6.1...v1.7.0)
3
4
  * [1.6.1 - June 14, 2012](https://github.com/pengwynn/octokit/compare/v1.6.0...v1.6.1)
4
5
  * [1.6.0 - June 14, 2012](https://github.com/pengwynn/octokit/compare/v1.5.0...v1.6.0)
5
6
  * [1.5.0 - June 14, 2012](https://github.com/pengwynn/octokit/compare/v1.4.0...v1.5.0)
@@ -1,6 +1,6 @@
1
1
  module Octokit
2
2
  class Client
3
- module Downloads
3
+ module Downloads
4
4
 
5
5
  # List available downloads for a repository
6
6
  #
@@ -12,18 +12,63 @@ module Octokit
12
12
  def downloads(repo, options={})
13
13
  get("repos/#{Repository.new(repo)}/downloads", options, 3)
14
14
  end
15
+ alias :list_downloads :downloads
15
16
 
16
17
  # Get single download for a repository
17
18
  #
18
19
  # @param repo [String, Repository, Hash] A GitHub repository
19
- # @param id [Integer] ID of the download
20
+ # @param id [Integer] ID of the download
20
21
  # @return [Download] A single download from the repository
21
22
  # @see http://developer.github.com/v3/repos/downloads/#get-a-single-download
22
- # @example Get the "Robawt" download from Github/Hubot
23
+ # @example Get the "Robawt" download from Github/Hubot
23
24
  # Octokit.download("github/hubot")
24
25
  def download(repo, id, options={})
25
26
  get("repos/#{Repository.new(repo)}/downloads/#{id}", options, 3)
26
27
  end
28
+
29
+
30
+ def create_download(repo, name, options={})
31
+ options[:content_type] ||= 'text/plain'
32
+ file = Faraday::UploadIO.new(name, options[:content_type])
33
+ resource = create_download_resource(repo, file.original_filename, File.size(name), options)
34
+
35
+ resource_hash = {
36
+ 'key' => resource.path,
37
+ 'acl' => resource.acl,
38
+ 'success_action_status' => 201,
39
+ 'Filename' => resource.name,
40
+ 'AWSAccessKeyId' => resource.accesskeyid,
41
+ 'Policy' => resource.policy,
42
+ 'Signature' => resource.signature,
43
+ 'Content-Type' => resource.mime_type,
44
+ 'file' => file
45
+ }
46
+
47
+ conn = Faraday.new(resource.s3_url) do |builder|
48
+ builder.request :multipart
49
+ builder.request :url_encoded
50
+ builder.adapter :net_http
51
+ end
52
+
53
+ response = conn.post '/', resource_hash
54
+ response.status == 201
55
+ end
56
+
57
+ # Delete a single download for a repository
58
+ #
59
+ # @param repo [String, Repository, Hash] A GitHub repository
60
+ # @param id [Integer] ID of the download
61
+ # @see http://developer.github.com/v3/repos/downloads/#delete-a-single-download
62
+ # @example Get the "Robawt" download from Github/Hubot
63
+ # Octokit.delete_download("github/hubot", 1234)
64
+ def delete_download(repo, id)
65
+ delete("repos/#{Repository.new(repo)}/downloads/#{id}", {}, 3, true, true, true)
66
+ end
67
+
68
+ private
69
+ def create_download_resource(repo, name, size, options={})
70
+ post("/repos/#{Repository.new(repo)}/downloads", options.merge({:name => name, :size => size}))
71
+ end
27
72
  end
28
73
  end
29
74
  end
@@ -1,3 +1,3 @@
1
1
  module Octokit
2
- VERSION = "1.6.1" unless defined?(Octokit::VERSION)
2
+ VERSION = "1.7.0" unless defined?(Octokit::VERSION)
3
3
  end
@@ -0,0 +1,21 @@
1
+ {
2
+ "url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
3
+ "html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
4
+ "id": 1,
5
+ "name": "new_file.jpg",
6
+ "description": "Description of your download",
7
+ "size": 1024,
8
+ "download_count": 40,
9
+ "content_type": ".jpg",
10
+ "policy": "ewogICAg...",
11
+ "signature": "mwnFDC...",
12
+ "bucket": "github",
13
+ "accesskeyid": "1ABCDEFG...",
14
+ "path": "downloads/ocotocat/Hello-World/new_file.jpg",
15
+ "acl": "public-read",
16
+ "expirationdate": "2011-04-14T16:00:49Z",
17
+ "prefix": "downloads/octocat/Hello-World/",
18
+ "mime_type": "image/jpeg",
19
+ "redirect": false,
20
+ "s3_url": "https://github.s3.amazonaws.com/"
21
+ }
@@ -18,7 +18,7 @@ describe Octokit::Client::Downloads do
18
18
 
19
19
  end
20
20
 
21
- describe ".download" do
21
+ describe ".download" do
22
22
 
23
23
  it "should get a single download" do
24
24
  stub_get("/repos/github/hubot/downloads/165347").
@@ -30,4 +30,35 @@ describe Octokit::Client::Downloads do
30
30
 
31
31
  end
32
32
 
33
+ describe ".create_download" do
34
+ before(:each) do
35
+ stub_post("/repos/octocat/Hello-World/downloads").
36
+ with(:body => {:name => "download_create.json", :size => 690,
37
+ :description => "Description of your download",
38
+ :content_type => "text/plain" }).
39
+ to_return(:body => fixture("v3/download_create.json"))
40
+ end
41
+ it "should create a download resource" do
42
+ resource = @client.send(:create_download_resource, "octocat/Hello-World", "download_create.json", 690, {:description => "Description of your download", :content_type => "text/plain"})
43
+ resource.s3_url.should == "https://github.s3.amazonaws.com/"
44
+ end
45
+
46
+ it "should post to a S3 url" do
47
+ stub_post("https://github.s3.amazonaws.com/").
48
+ to_return(:status => 201)
49
+ file_path = File.expand_path 'spec/fixtures/v3/download_create.json'
50
+ @client.create_download("octocat/Hello-World", file_path, {:description => "Description of your download", :content_type => "text/plain"}).should == true
51
+ end
52
+ end
53
+
54
+ describe ".delete_download" do
55
+
56
+ it "should delete a download" do
57
+ stub_request(:delete, "https://api.github.com/repos/octocat/Hellow-World/downloads/165347").
58
+ with(:headers => {'Accept'=>'*/*'}).
59
+ to_return(:status => 204, :body => "", :headers => {})
60
+ @client.delete_download('octocat/Hellow-World', 165347).status.should == 204
61
+ end
62
+ end
63
+
33
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-06-16 00:00:00.000000000 Z
14
+ date: 2012-06-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: addressable
18
- requirement: &70243204801800 !ruby/object:Gem::Requirement
18
+ requirement: &70266235724000 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '2.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70243204801800
26
+ version_requirements: *70266235724000
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
- requirement: &70243204801240 !ruby/object:Gem::Requirement
29
+ requirement: &70266235739020 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0.8'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70243204801240
37
+ version_requirements: *70266235739020
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: faraday_middleware
40
- requirement: &70243204800560 !ruby/object:Gem::Requirement
40
+ requirement: &70266235738180 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0.8'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70243204800560
48
+ version_requirements: *70266235738180
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: hashie
51
- requirement: &70243204816140 !ruby/object:Gem::Requirement
51
+ requirement: &70266235737060 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '1.2'
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *70243204816140
59
+ version_requirements: *70266235737060
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: multi_json
62
- requirement: &70243204815420 !ruby/object:Gem::Requirement
62
+ requirement: &70266235735960 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '1.3'
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *70243204815420
70
+ version_requirements: *70266235735960
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: json
73
- requirement: &70243204814180 !ruby/object:Gem::Requirement
73
+ requirement: &70266235735400 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70243204814180
81
+ version_requirements: *70266235735400
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: maruku
84
- requirement: &70243204812800 !ruby/object:Gem::Requirement
84
+ requirement: &70266235734700 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *70243204812800
92
+ version_requirements: *70266235734700
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rake
95
- requirement: &70243204811300 !ruby/object:Gem::Requirement
95
+ requirement: &70266235733720 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *70243204811300
103
+ version_requirements: *70266235733720
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rspec
106
- requirement: &70243204824720 !ruby/object:Gem::Requirement
106
+ requirement: &70266235732800 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,10 +111,10 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *70243204824720
114
+ version_requirements: *70266235732800
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: simplecov
117
- requirement: &70243204824280 !ruby/object:Gem::Requirement
117
+ requirement: &70266235748160 !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements:
120
120
  - - ! '>='
@@ -122,10 +122,10 @@ dependencies:
122
122
  version: '0'
123
123
  type: :development
124
124
  prerelease: false
125
- version_requirements: *70243204824280
125
+ version_requirements: *70266235748160
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: webmock
128
- requirement: &70243204823420 !ruby/object:Gem::Requirement
128
+ requirement: &70266235746260 !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
131
  - - ! '>='
@@ -133,10 +133,10 @@ dependencies:
133
133
  version: '0'
134
134
  type: :development
135
135
  prerelease: false
136
- version_requirements: *70243204823420
136
+ version_requirements: *70266235746260
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: yard
139
- requirement: &70243204821760 !ruby/object:Gem::Requirement
139
+ requirement: &70266235745600 !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
142
142
  - - ! '>='
@@ -144,7 +144,7 @@ dependencies:
144
144
  version: '0'
145
145
  type: :development
146
146
  prerelease: false
147
- version_requirements: *70243204821760
147
+ version_requirements: *70266235745600
148
148
  description: Simple wrapper for the GitHub v3 API
149
149
  email:
150
150
  - wynn.netherland@gmail.com
@@ -211,6 +211,7 @@ files:
211
211
  - spec/fixtures/v3/commits.json
212
212
  - spec/fixtures/v3/contributors.json
213
213
  - spec/fixtures/v3/download.json
214
+ - spec/fixtures/v3/download_create.json
214
215
  - spec/fixtures/v3/downloads.json
215
216
  - spec/fixtures/v3/emails.json
216
217
  - spec/fixtures/v3/followers.json
@@ -331,6 +332,7 @@ test_files:
331
332
  - spec/fixtures/v3/commits.json
332
333
  - spec/fixtures/v3/contributors.json
333
334
  - spec/fixtures/v3/download.json
335
+ - spec/fixtures/v3/download_create.json
334
336
  - spec/fixtures/v3/downloads.json
335
337
  - spec/fixtures/v3/emails.json
336
338
  - spec/fixtures/v3/followers.json