gemfury 0.3.2 → 0.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,17 +11,12 @@ module Gemfury
11
11
  end
12
12
  end
13
13
 
14
- # Verify gem version
15
- def check_version
16
- response = connection.get('status/version')
14
+ # Get the information for the current account
15
+ def account_info
16
+ ensure_ready!(:authorization)
17
+ response = connection.get('users/me')
17
18
  ensure_successful_response!(response)
18
-
19
- current = Gem::Version.new(Gemfury::VERSION)
20
- latest = Gem::Version.new(response.body['version'])
21
-
22
- unless latest.eql?(current)
23
- raise InvalidGemVersion.new('Please update your gem')
24
- end
19
+ response.body
25
20
  end
26
21
 
27
22
  # Uploading a gem file
@@ -69,6 +64,28 @@ module Gemfury
69
64
  response.body['access_token']
70
65
  end
71
66
 
67
+ # List collaborators for this account
68
+ def list_collaborators(options = {})
69
+ ensure_ready!(:authorization)
70
+ response = connection.get('collaborators', options)
71
+ ensure_successful_response!(response)
72
+ response.body
73
+ end
74
+
75
+ # Add a collaborator to the account
76
+ def add_collaborator(login, options = {})
77
+ ensure_ready!(:authorization)
78
+ response = connection.put("collaborators/#{login}", options)
79
+ ensure_successful_response!(response)
80
+ end
81
+
82
+ # Remove a collaborator to the account
83
+ def remove_collaborator(login, options = {})
84
+ ensure_ready!(:authorization)
85
+ response = connection.delete("collaborators/#{login}", options)
86
+ ensure_successful_response!(response)
87
+ end
88
+
72
89
  private
73
90
  def connection(options = {})
74
91
  options = {
@@ -85,6 +102,10 @@ module Gemfury
85
102
  options[:headers][:authorization] = self.user_api_key
86
103
  end
87
104
 
105
+ if self.account
106
+ options[:params] = { :as => self.account }
107
+ end
108
+
88
109
  Faraday.new(options) do |builder|
89
110
  builder.use Faraday::Request::MultipartWithFile
90
111
  builder.use Faraday::Request::Multipart
@@ -103,6 +124,7 @@ module Gemfury
103
124
  when 404 then Gemfury::NotFound
104
125
  when 400
105
126
  case error['type']
127
+ when 'Forbidden' then Gemfury::Forbidden
106
128
  when 'GemVersionError' then Gemfury::InvalidGemVersion
107
129
  else Gemfury::Error
108
130
  end
@@ -1,6 +1,9 @@
1
1
  class Gemfury::Command::App < Thor
2
2
  include Gemfury::Command::Authorization
3
3
 
4
+ # Impersonation
5
+ class_option :as, :desc => 'Access an account other than your own'
6
+
4
7
  map "-v" => :version
5
8
  desc "version" ,"Show Gemfury version", :hide => true
6
9
  def version
@@ -35,7 +38,7 @@ class Gemfury::Command::App < Thor
35
38
  shell.say "\n*** GEMFURY GEMS ***\n\n"
36
39
  gems.each do |g|
37
40
  desc, version = g['name'], g.path('latest_version.version')
38
- desc << " (#{version})" if version
41
+ desc << " (#{version ? version : 'beta'})"
39
42
  shell.say desc
40
43
  end
41
44
  end
@@ -72,11 +75,48 @@ class Gemfury::Command::App < Thor
72
75
  end
73
76
  end
74
77
 
78
+ ### COLLABORATION MANAGEMENT ###
79
+ map "sharing:add" => 'sharing_add'
80
+ map "sharing:remove" => 'sharing_remove'
81
+
82
+ desc "sharing", "List collaborators"
83
+ def sharing
84
+ with_checks_and_rescues do
85
+ me = client.account_info['username']
86
+ collaborators = client.list_collaborators
87
+ if collaborators.empty?
88
+ shell.say "You (#{me}) are the only collaborator", :green
89
+ else
90
+ shell.say %Q(\n*** Collaborators for "#{me}" ***\n), :green
91
+ usernames = [me] + collaborators.map { |c| c['username'] }
92
+ shell.say usernames.join("\n")
93
+ end
94
+ shell.say "\n"
95
+ end
96
+ end
97
+
98
+ desc "sharing:add USERNAME", "Add a collaborator"
99
+ def sharing_add(username)
100
+ with_checks_and_rescues do
101
+ client.add_collaborator(username)
102
+ shell.say "Added #{username} as a collaborator"
103
+ end
104
+ end
105
+
106
+ desc "sharing:remove USERNAME", "Remove a collaborator"
107
+ def sharing_remove(username)
108
+ with_checks_and_rescues do
109
+ client.remove_collaborator(username)
110
+ shell.say "Removed #{username} as a collaborator"
111
+ end
112
+ end
113
+
75
114
  private
76
115
  def client
77
- options = {}
78
- options[:user_api_key] = @user_api_key if @user_api_key
79
- Gemfury::Client.new(options)
116
+ opts = {}
117
+ opts[:user_api_key] = @user_api_key if @user_api_key
118
+ opts[:account] = options[:as] if options[:as]
119
+ Gemfury::Client.new(opts)
80
120
  end
81
121
 
82
122
  def with_checks_and_rescues(&block)
@@ -88,6 +128,8 @@ private
88
128
  else
89
129
  shell.say %q(No problem. You can also run "gem update gemfury")
90
130
  end
131
+ rescue Gemfury::Forbidden => e
132
+ shell.say "Oops! You're not allowed to access this", :red
91
133
  rescue Gemfury::NotFound => e
92
134
  shell.say "Oops! Doesn't look like this exists", :red
93
135
  rescue Exception => e
@@ -20,9 +20,13 @@ private
20
20
  prompt_credentials! if @user_api_key.nil?
21
21
  block.call
22
22
  rescue Gemfury::Unauthorized
23
- shell.say "Oops! Authentication failure.", :red
24
- @user_api_key = nil
25
- retry
23
+ if acct = client.account
24
+ shell.say %Q(Oops! You don't have access to "#{acct}"), :red
25
+ else
26
+ shell.say "Oops! Authentication failure.", :red
27
+ @user_api_key = nil
28
+ retry
29
+ end
26
30
  end
27
31
  end
28
32
 
@@ -6,13 +6,13 @@ module Gemfury
6
6
  :user_api_key,
7
7
  :adapter,
8
8
  :endpoint,
9
- :user_agent].freeze
9
+ :user_agent,
10
+ :account].freeze
10
11
 
11
12
  # The adapter that will be used to connect if none is set
12
13
  DEFAULT_ADAPTER = :net_http
13
14
 
14
15
  # The endpoint that will be used to connect if none is set
15
- #
16
16
  DEFAULT_ENDPOINT = 'https://www.gemfury.com/1/'.freeze
17
17
 
18
18
  # The value sent in the 'User-Agent' header if none is set
@@ -21,6 +21,9 @@ module Gemfury
21
21
  # Default user API key
22
22
  DEFAULT_API_KEY = nil
23
23
 
24
+ # Use the current account (no impersonation)
25
+ DEFAULT_ACCOUNT = nil
26
+
24
27
  # @private
25
28
  attr_accessor *VALID_OPTIONS_KEYS
26
29
 
@@ -47,6 +50,7 @@ module Gemfury
47
50
  self.adapter = DEFAULT_ADAPTER
48
51
  self.endpoint = DEFAULT_ENDPOINT
49
52
  self.user_agent = DEFAULT_USER_AGENT
53
+ self.account = DEFAULT_ACCOUNT
50
54
  self
51
55
  end
52
56
  end
data/lib/gemfury/error.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  module Gemfury
2
2
  # Base Error class
3
- class Error < StandardError; end
3
+ Error = Class.new(StandardError)
4
4
 
5
5
  # The Gemfury gem version doesn't match the one on the server
6
- class InvalidGemVersion < Error; end
6
+ InvalidGemVersion = Class.new(Error)
7
7
 
8
8
  # Client#user_api_key is not defined or Gemfury returns 401
9
- class Unauthorized < Error; end
9
+ Unauthorized = Class.new(Error)
10
+
11
+ # Client is not allowed to perform this operation
12
+ Forbidden = Class.new(Error)
10
13
 
11
14
  # Returned if something is not found
12
- class NotFound < Error; end
15
+ NotFound = Class.new(Error)
13
16
  end
@@ -1,3 +1,3 @@
1
1
  module Gemfury
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0.beta1'
3
3
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
5
- prerelease:
4
+ version: 0.4.0.beta1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Rykov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-29 00:00:00.000000000Z
12
+ date: 2011-10-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &70204899099800 !ruby/object:Gem::Requirement
16
+ requirement: &70192202900480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70204899099800
24
+ version_requirements: *70192202900480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &70204899099160 !ruby/object:Gem::Requirement
27
+ requirement: &70192202899980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.14.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70204899099160
35
+ version_requirements: *70192202899980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: launchy
38
- requirement: &70204899098700 !ruby/object:Gem::Requirement
38
+ requirement: &70192202899520 !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: *70204899098700
46
+ version_requirements: *70192202899520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: multi_json
49
- requirement: &70204899029120 !ruby/object:Gem::Requirement
49
+ requirement: &70192202899060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70204899029120
57
+ version_requirements: *70192202899060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: faraday
60
- requirement: &70204899028440 !ruby/object:Gem::Requirement
60
+ requirement: &70192202898600 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.7.4
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70204899028440
68
+ version_requirements: *70192202898600
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday_middleware
71
- requirement: &70204899027600 !ruby/object:Gem::Requirement
71
+ requirement: &70192202898140 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.7.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70204899027600
79
+ version_requirements: *70192202898140
80
80
  description: ! 'Client library and command-line tool to manage your gems on http://gemfury.com
81
81
 
82
82
  '
@@ -120,12 +120,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - ! '>'
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 1.3.1
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 1.8.10
128
+ rubygems_version: 1.8.11
129
129
  signing_key:
130
130
  specification_version: 3
131
131
  summary: Client library and command-line tool to manage your gems on Gemfury