Class: Gem::Commands::OwnerCommand
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Gem::Commands::OwnerCommand
- Defined in:
- lib/commands/owner.rb
Instance Method Summary collapse
- #add_owners(name, owners) ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ OwnerCommand
constructor
A new instance of OwnerCommand.
- #remove_owners(name, owners) ⇒ Object
- #show_owners(name) ⇒ Object
Constructor Details
#initialize ⇒ OwnerCommand
Returns a new instance of OwnerCommand.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/commands/owner.rb', line 6 def initialize super 'owner', description defaults.merge!(:add => [], :remove => []) add_option('-a', '--add EMAIL', 'Add an owner') do |value, | [:add] << value end add_option('-r', '--remove EMAIL', 'Remove an owner') do |value, | [:remove] << value end end |
Instance Method Details
#add_owners(name, owners) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/commands/owner.rb', line 28 def add_owners(name, owners) owners.each do |owner| response = make_request(:post, "gems/#{name}/owners.json") do |request| request.set_form_data("email" => owner) request.add_field("Authorization", api_key) end case response when Net::HTTPSuccess say "Added owner: #{owner}" else say "Error adding owner: #{owner}" end end end |
#description ⇒ Object
2 3 4 |
# File 'lib/commands/owner.rb', line 2 def description 'Manage gem owners on Gemcutter.' end |
#execute ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/commands/owner.rb', line 19 def execute setup name = get_one_gem_name add_owners name, [:add] remove_owners name, [:remove] show_owners name end |
#remove_owners(name, owners) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/commands/owner.rb', line 44 def remove_owners(name, owners) owners.each do |owner| response = make_request(:delete, "gems/#{name}/owners.json") do |request| request.set_form_data(:email => owner) request.add_field("Authorization", api_key) end case response when Net::HTTPSuccess say "Removed owner: #{owner}" else say "Error removing owner: #{owner}" end end end |
#show_owners(name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/commands/owner.rb', line 59 def show_owners(name) require 'json/pure' response = make_request(:get, "gems/#{name}/owners.json") do |request| request.add_field("Authorization", api_key) end case response when Net::HTTPSuccess begin owners = JSON.parse(response.body) say "Owners for gem: #{name}" owners.each do |owner| say "- #{owner['email']}" end rescue JSON::ParserError => json_error say "There was a problem parsing the data: #{json_error}" terminate_interaction end when Net::HTTPNotFound say "This gem is currently not hosted on Gemcutter." terminate_interaction when Net::HTTPUnauthorized say "You do not have permission to manage this gem." terminate_interaction else say "There was a problem processing your request." terminate_interaction end end |