gemfury 0.2.0.beta1 → 0.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,9 @@ require 'gemfury/version'
6
6
  require 'gemfury/const'
7
7
  require 'gemfury/error'
8
8
  require 'gemfury/platform'
9
- require 'gemfury/auth'
10
9
  require 'gemfury/configuration'
10
+
11
+ require 'gemfury/client/filters'
11
12
  require 'gemfury/client'
12
13
 
13
14
  module Gemfury
@@ -30,4 +31,13 @@ module Gemfury
30
31
  new.respond_to?(method, include_private) || super(method, include_private)
31
32
  end
32
33
  end
34
+ end
35
+
36
+ class Hash
37
+ # Access nested hashes as a period-separated path
38
+ def path(path, separator = '.')
39
+ path.split(separator).inject(self) do |hash, part|
40
+ hash.is_a?(Hash) ? hash[part] : nil
41
+ end
42
+ end
33
43
  end
@@ -1,6 +1,6 @@
1
1
  module Gemfury
2
2
  class Client
3
- include Gemfury::Auth
3
+ include Gemfury::Client::Filters
4
4
  attr_accessor *Configuration::VALID_OPTIONS_KEYS
5
5
 
6
6
  # Creates a new API
@@ -26,7 +26,7 @@ module Gemfury
26
26
 
27
27
  # Uploading a gem file
28
28
  def push_gem(gem_file, options = {})
29
- ensure_authorization!
29
+ ensure_ready!(:authorization)
30
30
  response = connection.post('gems', options.merge(
31
31
  :gem_file => gem_file
32
32
  ))
@@ -34,8 +34,25 @@ module Gemfury
34
34
  ensure_successful_response!(response)
35
35
  end
36
36
 
37
+ # List available gems
38
+ def list(options = {})
39
+ ensure_ready!(:authorization)
40
+ response = connection.get('gems', options)
41
+ ensure_successful_response!(response)
42
+ response.body
43
+ end
44
+
45
+ # List versions for a gem
46
+ def versions(name, options = {})
47
+ ensure_ready!(:authorization)
48
+ response = connection.get("gems/#{name}/versions", options)
49
+ ensure_successful_response!(response)
50
+ response.body
51
+ end
52
+
37
53
  # Get Authentication token via email/password
38
54
  def get_access_token(email, password, options = {})
55
+ ensure_ready!
39
56
  response = connection.post('access_token', options.merge(
40
57
  :email => email, :password => password
41
58
  ))
@@ -0,0 +1,33 @@
1
+ module Gemfury
2
+ class Client
3
+ module Filters
4
+
5
+ private
6
+ def ensure_ready!(*args)
7
+ # Ensure authorization
8
+ if args.include?(:authorization)
9
+ raise Unauthorized unless authenticated?
10
+ end
11
+
12
+ # Check version requirement
13
+ ensure_gem_compatibility! if self.check_gem_version
14
+ end
15
+
16
+ def authenticated?
17
+ self.user_api_key && !self.user_api_key.empty?
18
+ end
19
+
20
+ def ensure_gem_compatibility!
21
+ response = connection.get('status/version')
22
+ ensure_successful_response!(response)
23
+
24
+ current = Gem::Version.new(Gemfury::VERSION)
25
+ version = Gem::Requirement.new(response.body['version'])
26
+
27
+ unless version.satisfied_by?(current)
28
+ raise InvalidGemVersion.new('Please update your gem')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,14 +1,15 @@
1
1
  class Gemfury::Command::App < Thor
2
2
  include Gemfury::Command::Authorization
3
3
 
4
- desc "version" ,"Check whether the gem is up-to-date"
4
+ map "-v" => :version
5
+ desc "version" ,"Show Gemfury version", :hide => true
5
6
  def version
6
- client.check_version
7
+ shell.say Gemfury::VERSION
7
8
  end
8
9
 
9
- desc "push GEM" ,"upload a new version of a gem"
10
+ desc "push GEM" ,"Upload a new version of a gem"
10
11
  def push(*gems)
11
- with_authorization do
12
+ with_checks_and_rescues do
12
13
  gem_files = gems.map do |g|
13
14
  File.exists?(g) ? File.new(g) : nil
14
15
  end.compact
@@ -27,10 +28,45 @@ class Gemfury::Command::App < Thor
27
28
  end
28
29
  end
29
30
 
31
+ desc "list" ,"List your gems on Gemfury"
32
+ def list
33
+ with_checks_and_rescues do
34
+ gems = client.list
35
+ shell.say "\n*** GEMFURY GEMS ***\n\n"
36
+ gems.each do |g|
37
+ desc, version = g['name'], g.path('latest_version.version')
38
+ desc << " (#{version})" if version
39
+ shell.say desc
40
+ end
41
+ end
42
+ end
43
+
44
+ desc "versions GEM" ,"List all the available gem versions"
45
+ def versions(gem_name)
46
+ with_checks_and_rescues do
47
+ versions = client.versions(gem_name)
48
+ shell.say "\n*** #{gem_name.capitalize} Versions ***\n\n"
49
+ versions.each do |v|
50
+ shell.say v['version']
51
+ end
52
+ end
53
+ end
54
+
30
55
  private
31
56
  def client
32
- options = {}
57
+ options = { :check_gem_version => true }
33
58
  options[:user_api_key] = @user_api_key if @user_api_key
34
59
  Gemfury::Client.new(options)
35
60
  end
61
+
62
+ def with_checks_and_rescues(&block)
63
+ with_authorization(&block)
64
+ rescue Gemfury::InvalidGemVersion => e
65
+ shell.say "You have a deprecated Gemfury gem", :red
66
+ if shell.yes? "Would you like to update this gem now? [yN]"
67
+ exec("gem update gemfury")
68
+ else
69
+ shell.say %q(No problem. You can also run "gem update gemfury")
70
+ end
71
+ end
36
72
  end
@@ -6,7 +6,8 @@ module Gemfury
6
6
  :user_api_key,
7
7
  :adapter,
8
8
  :endpoint,
9
- :user_agent].freeze
9
+ :user_agent,
10
+ :check_gem_version].freeze
10
11
 
11
12
  # The adapter that will be used to connect if none is set
12
13
  DEFAULT_ADAPTER = :net_http
@@ -21,6 +22,9 @@ module Gemfury
21
22
  # Default user API key
22
23
  DEFAULT_API_KEY = nil
23
24
 
25
+ # Default to skip the gem version check on API calls
26
+ DEFAULT_VERSION_CHECK = false
27
+
24
28
  # @private
25
29
  attr_accessor *VALID_OPTIONS_KEYS
26
30
 
@@ -47,6 +51,7 @@ module Gemfury
47
51
  self.adapter = DEFAULT_ADAPTER
48
52
  self.endpoint = DEFAULT_ENDPOINT
49
53
  self.user_agent = DEFAULT_USER_AGENT
54
+ self.check_gem_version = DEFAULT_VERSION_CHECK
50
55
  self
51
56
  end
52
57
  end
@@ -1,3 +1,3 @@
1
1
  module Gemfury
2
- VERSION = '0.2.0.beta1'
2
+ VERSION = '0.2.0.beta2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.beta1
4
+ version: 0.2.0.beta2
5
5
  prerelease: 6
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-08-26 00:00:00.000000000Z
12
+ date: 2011-08-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &70289577678140 !ruby/object:Gem::Requirement
16
+ requirement: &70150918484520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 1.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70289577678140
24
+ version_requirements: *70150918484520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &70289577677540 !ruby/object:Gem::Requirement
27
+ requirement: &70150918483840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 0.14.5
32
+ version: 0.14.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70289577677540
35
+ version_requirements: *70150918483840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: launchy
38
- requirement: &70289577677000 !ruby/object:Gem::Requirement
38
+ requirement: &70150918483340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.4.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70289577677000
46
+ version_requirements: *70150918483340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: multi_json
49
- requirement: &70289577676460 !ruby/object:Gem::Requirement
49
+ requirement: &70150918482760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,29 +54,29 @@ dependencies:
54
54
  version: 1.0.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70289577676460
57
+ version_requirements: *70150918482760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: faraday
60
- requirement: &70289577675960 !ruby/object:Gem::Requirement
60
+ requirement: &70150918482180 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
64
64
  - !ruby/object:Gem::Version
65
- version: 0.6.1
65
+ version: 0.7.4
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70289577675960
68
+ version_requirements: *70150918482180
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday_middleware
71
- requirement: &70289577675360 !ruby/object:Gem::Requirement
71
+ requirement: &70150918481600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 0.6.3
76
+ version: 0.7.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70289577675360
79
+ version_requirements: *70150918481600
80
80
  description: ! 'Client library and command-line tool to manage your gems on http://gemfury.com
81
81
 
82
82
  '
@@ -91,7 +91,7 @@ files:
91
91
  - bin/fury
92
92
  - bin/gemfury
93
93
  - lib/faraday/request/multipart_with_file.rb
94
- - lib/gemfury/auth.rb
94
+ - lib/gemfury/client/filters.rb
95
95
  - lib/gemfury/client.rb
96
96
  - lib/gemfury/command/app.rb
97
97
  - lib/gemfury/command/authorization.rb
@@ -106,7 +106,8 @@ homepage: http://gemfury.com
106
106
  licenses: []
107
107
  post_install_message: ! "************************************************************************\n\n
108
108
  \ Upload your first gem to start using Gemfury:\n fury push my-gem-1.0.gem\n\n
109
- \ Follow @gemfury on Twitter for announcements, updates, and news.\n https://twitter.com/gemfury\n\n************************************************************************\n"
109
+ \ Find out what else you can do:\n fury help\n\n Follow @gemfury on Twitter for
110
+ announcements, updates, and news.\n https://twitter.com/gemfury\n\n************************************************************************\n"
110
111
  rdoc_options: []
111
112
  require_paths:
112
113
  - lib
@@ -1,13 +0,0 @@
1
- module Gemfury
2
- module Auth
3
-
4
- private
5
- def authenticated?
6
- self.user_api_key && !self.user_api_key.empty?
7
- end
8
-
9
- def ensure_authorization!
10
- raise Unauthorized unless authenticated?
11
- end
12
- end
13
- end