gemfury 0.12.1 → 0.13.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '085b1527c75280eea2af851ba682cf633ad4c7254519e352ecaedce754067a4a'
4
- data.tar.gz: 044cb832c6707879b7117e65895b1908f09e98b55a4641bb5c98504c264c52b5
3
+ metadata.gz: 228c435c571bdaf3167db63c72c433b29619f31ecd0ffcb8ac4b1d3494996751
4
+ data.tar.gz: f9c4a05c60ff574af54d73cb80c0a501978b1a708b77daee1ad6eca2de126dbc
5
5
  SHA512:
6
- metadata.gz: cd3c775925ff9095bbc708945dede4c78082f5e24920e141b5089181fec866551a7f9e1fc7895b137f39c8e38f97252491b5fe15c9e932c52b5ed36c81bc4911
7
- data.tar.gz: d2c1fda36dbe5183821d728ac2982900f1b7f0c9730d8aade63255f9b1f248018d5b6519a68367e8b4f9a7cd24dde79986f472b6f0db2546e07eee0c1d48547b
6
+ metadata.gz: 588d530bbf6410a607916d3a2f20c2474ae6f91a0c4135f2ab78cd6cfffd164a26e59ce712f960890f76eeb465beeb7cdaf87e184532026bf479e9ab34d4828a
7
+ data.tar.gz: 4dc1bdaa0ddbe30cc4e96f2dca7a00bfbf55a4c580f6d4616b58b79c1c5170f615f92741ce5d5ac0b40f573dabf925ab6a48fd9f8983e82574c6aa41574c8b10
data/bin/fury CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- lib = File.expand_path('../../lib', __FILE__)
4
+ lib = File.expand_path('../lib', __dir__)
4
5
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
6
 
6
7
  require 'rubygems'
7
8
  require 'gemfury'
8
9
  require 'gemfury/command'
9
10
 
10
- if defined?(Warning) && Warning.respond_to?('[]')
11
- Warning[:deprecated] = !!ENV['DEBUG']
12
- end
11
+ Warning[:deprecated] = !!ENV['DEBUG'] if defined?(Warning) && Warning.respond_to?('[]')
13
12
 
14
13
  Gemfury::Command::App.start
data/bin/gemfury CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- exec(File.expand_path('../fury', __FILE__), *ARGV)
2
+ # frozen_string_literal: true
3
+
4
+ exec(File.expand_path('fury', __dir__), *ARGV)
@@ -1,32 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is a Faraday adapter that bypasses Faraday's response body
2
4
  # processing and streams body to STDOUT for text requests
3
5
 
4
6
  class Faraday::Adapter
5
7
  class FuryHttp < NetHttp
6
- def perform_request(http, env)
7
- accept = env.request_headers['Accept']
8
- return super if accept !~ /text\z/
9
-
10
- # Stream response body to STDOUT on success
11
- http.request(create_request(env)) do |resp|
12
- unless resp.is_a?(Net::HTTPSuccess)
13
- resp.body # Cache error body
14
- else
15
- resp.read_body do |chunk|
16
- $stdout.print(chunk)
17
- $stdout.flush
18
- end
8
+ def request_with_wrapped_block(http, env, &block)
9
+ is_text = env.request_headers['Accept'] =~ /text\z/
10
+ return super if !block.nil? || !is_text
19
11
 
20
- # Prevent #body from calling #read_body again
21
- klass = (class << resp; self; end)
22
- klass.send(:define_method, :body) { nil }
23
- end
24
-
25
- # Return response to NetHttp adapter
26
- return resp
12
+ # Stream chunks directly to STDOUT
13
+ resp = super(http, env) do |chunk|
14
+ $stdout.print(chunk)
15
+ $stdout.flush
27
16
  end
17
+
18
+ # Client sees nil body
19
+ resp.body = nil
20
+ resp
28
21
  end
29
22
  end
30
23
 
31
- register_middleware(:fury_http => FuryHttp)
24
+ register_middleware(fury_http: FuryHttp)
32
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
 
3
5
  # @private
@@ -5,13 +7,11 @@ module Faraday
5
7
  # @private
6
8
  class Request::MultipartWithFile < Faraday::Middleware
7
9
  def call(env)
8
-
9
10
  if env[:body].is_a?(Hash)
10
11
 
11
12
  # Check for IO (and IO-like objects, like Zip::InputStream) in the request,
12
13
  # which represent data to be uploaded. Replace these with Faraday
13
14
  env[:body].each do |key, value|
14
-
15
15
  # Faraday seems to expect a few IO methods to be available, but that's all:
16
16
  # https://github.com/lostisland/faraday/blob/master/lib/faraday/file_part.rb
17
17
  # :length seems to be an optional one
@@ -21,7 +21,7 @@ module Faraday
21
21
  #
22
22
  # We attempt to make our duck typing compatible with their duck typing
23
23
  if value.respond_to?(:read) && value.respond_to?(:rewind) && value.respond_to?(:close)
24
- env[:body][key] = Faraday::UploadIO.new(value, mime_type(value))
24
+ env[:body][key] = Faraday::Multipart::FilePart.new(value, mime_type(value))
25
25
  end
26
26
  end
27
27
  end
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gemfury
2
4
  class Client
3
5
  module Filters
6
+ private
4
7
 
5
- private
6
8
  def ensure_ready!(*args)
7
9
  # Ensure authorization
8
- if args.include?(:authorization)
9
- raise Unauthorized unless authenticated?
10
- end
10
+ return unless args.include?(:authorization)
11
+ raise Unauthorized unless authenticated?
11
12
  end
12
13
 
13
14
  def authenticated?
14
- self.user_api_key && !self.user_api_key.empty?
15
+ user_api_key && !user_api_key.empty?
15
16
  end
16
17
  end
17
18
  end
18
- end
19
+ end
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gemfury
2
4
  class Client
3
5
  class Handle503 < Faraday::Middleware
4
6
  def call(env)
5
- # This prevents errors in ParseJson
7
+ # This prevents errors in ParseJson
6
8
  @app.call(env).on_complete do |out|
7
9
  out[:body] = '' if out[:status] == 503
8
10
  end
9
11
  end
10
12
  end
11
13
 
12
- class ParseJson < Faraday::Response::Middleware
14
+ class ParseJson < Faraday::Middleware
13
15
  def parse(body)
14
16
  body =~ /\A\s*\z/ ? nil : MultiJson.decode(body)
15
17
  end
@@ -20,4 +22,4 @@ module Gemfury
20
22
  end
21
23
  end
22
24
  end
23
- end
25
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gemfury
2
4
  class Client
3
5
  include Gemfury::Client::Filters
@@ -5,7 +7,7 @@ module Gemfury
5
7
 
6
8
  # Creates a new API
7
9
  # @param options [Hash] values for attributes described in {Gemfury::Configuration}
8
- def initialize(options={})
10
+ def initialize(options = {})
9
11
  options = Gemfury.options.merge(options)
10
12
  Gemfury::VALID_OPTIONS_KEYS.each do |key|
11
13
  send("#{key}=", options[key])
@@ -34,8 +36,8 @@ module Gemfury
34
36
  # @return [Hash]
35
37
  def push_gem(file, options = {})
36
38
  ensure_ready!(:authorization)
37
- push_api = connection(:url => self.pushpoint)
38
- response = push_api.post('uploads', options.merge(:file => file))
39
+ push_api = connection(url: pushpoint)
40
+ response = push_api.post('uploads', options.merge(file: file))
39
41
  checked_response_body(response)
40
42
  end
41
43
 
@@ -83,7 +85,7 @@ module Gemfury
83
85
  # @return [Hash]
84
86
  def login(email, password, opts = {})
85
87
  ensure_ready!
86
- opts = opts.merge(:email => email, :password => password)
88
+ opts = opts.merge(email: email, password: password)
87
89
  checked_response_body(connection.post('login', opts))
88
90
  end
89
91
 
@@ -161,7 +163,7 @@ module Gemfury
161
163
  def git_rebuild(repo, options = {})
162
164
  ensure_ready!(:authorization)
163
165
  url = "#{git_repo_path(repo)}/builds"
164
- api = connection(:api_format => :text)
166
+ api = connection(api_format: :text)
165
167
  checked_response_body(api.post(url, options))
166
168
  end
167
169
 
@@ -184,51 +186,48 @@ module Gemfury
184
186
  def git_config_update(repo, updates, options = {})
185
187
  ensure_ready!(:authorization)
186
188
  path = "#{git_repo_path(repo)}/config-vars"
187
- opts = options.merge(:config_vars => updates)
189
+ opts = options.merge(config_vars: updates)
188
190
  response = connection.patch(path, opts)
189
191
  checked_response_body(response)
190
192
  end
191
193
 
192
- private
194
+ private
195
+
193
196
  def escape(str)
194
197
  CGI.escape(str)
195
198
  end
196
199
 
197
200
  def git_repo_path(*args)
198
201
  rest = args.map { |a| escape(a) }
199
- ['git/repos', self.account || 'me'].concat(rest).join('/')
202
+ ['git/repos', account || 'me'].concat(rest).join('/')
200
203
  end
201
204
 
202
205
  def connection(options = {})
203
206
  # The 'Accept' HTTP header for API versioning
204
207
  http_accept = begin
205
- v = options.delete(:api_version) || self.api_version
208
+ v = options.delete(:api_version) || api_version
206
209
  f = options.delete(:api_format) || :json
207
210
  "application/vnd.fury.v#{v.to_i}+#{f}"
208
211
  end
209
212
 
210
213
  # Faraday client options
211
214
  options = {
212
- :url => self.endpoint,
213
- :params => {},
214
- :headers => {
215
- :accept => http_accept,
216
- :user_agent => self.user_agent,
217
- :x_gem_version => Gemfury::VERSION,
215
+ url: endpoint,
216
+ params: {},
217
+ headers: {
218
+ accept: http_accept,
219
+ user_agent: user_agent,
220
+ x_gem_version: Gemfury::VERSION
218
221
  }.merge(options.delete(:headers) || {})
219
222
  }.merge(options)
220
223
 
221
- if self.user_api_key
222
- options[:headers][:authorization] = self.user_api_key
223
- end
224
+ options[:headers][:authorization] = user_api_key if user_api_key
224
225
 
225
- if self.account
226
- options[:params][:as] = self.account
227
- end
226
+ options[:params][:as] = account if account
228
227
 
229
228
  Faraday.new(options) do |builder|
230
229
  builder.use Faraday::Request::MultipartWithFile
231
- builder.use Faraday::Request::Multipart
230
+ builder.use Faraday::Multipart::Middleware
232
231
  builder.use Faraday::Request::UrlEncoded
233
232
  builder.use ParseJson
234
233
  builder.use Handle503
@@ -237,37 +236,35 @@ module Gemfury
237
236
  end
238
237
 
239
238
  def checked_response_body(response)
240
- if response.success?
241
- return response.body
242
- else
243
- error = (response.body || {})['error'] || {}
244
- error_class = case error['type']
245
- when 'Forbidden' then Gemfury::Forbidden
246
- when 'GemVersionError' then Gemfury::InvalidGemVersion
247
- when 'InvalidGemFile' then Gemfury::CorruptGemFile
248
- when 'DupeVersion' then Gemfury::DupeVersion
249
- else
250
- case response.status
251
- when 401 then Gemfury::Unauthorized
252
- when 403 then Gemfury::Forbidden
253
- when 404 then Gemfury::NotFound
254
- when 409 then Gemfury::Conflict
255
- when 503 then Gemfury::TimeoutError
256
- else Gemfury::Error
257
- end
258
- end
259
-
260
- raise(error_class, error['message'])
261
- end
239
+ return response.body if response.success?
240
+
241
+ error = (response.body || {})['error'] || {}
242
+ error_class = case error['type']
243
+ when 'Forbidden' then Gemfury::Forbidden
244
+ when 'GemVersionError' then Gemfury::InvalidGemVersion
245
+ when 'InvalidGemFile' then Gemfury::CorruptGemFile
246
+ when 'DupeVersion' then Gemfury::DupeVersion
247
+ else
248
+ case response.status
249
+ when 401 then Gemfury::Unauthorized
250
+ when 403 then Gemfury::Forbidden
251
+ when 404 then Gemfury::NotFound
252
+ when 409 then Gemfury::Conflict
253
+ when 503 then Gemfury::TimeoutError
254
+ else Gemfury::Error
255
+ end
256
+ end
257
+
258
+ raise(error_class, error['message'])
262
259
  end
263
260
 
264
261
  def s3_put_file(uri, file)
265
262
  Faraday::Connection.new(uri) do |f|
266
263
  f.adapter :net_http
267
264
  end.put(uri, file, {
268
- :content_length => file.stat.size.to_s,
269
- :content_type => ''
270
- })
265
+ content_length: file.stat.size.to_s,
266
+ content_type: ''
267
+ })
271
268
  end
272
269
  end
273
270
  end