Class: Spade::Remote

Inherits:
Repository show all
Includes:
Gem::UserInteraction
Defined in:
lib/spade/remote.rb

Instance Attribute Summary

Attributes inherited from Repository

#creds, #env

Instance Method Summary collapse

Methods inherited from Repository

#dependency_for, #initialize, #logged_in?

Constructor Details

This class inherits a constructor from Spade::Repository

Instance Method Details

#add_owner(package, email) ⇒ Object



51
52
53
54
55
56
# File 'lib/spade/remote.rb', line 51

def add_owner(package, email)
  request :post, "api/v1/gems/#{package}/owners" do |req|
    req.set_form_data 'email' => email
    req.add_field "Authorization", creds.api_key
  end
end

#install(package, version, prerelease) ⇒ Object



76
77
78
79
80
# File 'lib/spade/remote.rb', line 76

def install(package, version, prerelease)
  inst = Spade::DependencyInstaller.new(:prerelease => prerelease)
  inst.install package, Gem::Requirement.new([version])
  inst.installed_gems
end

#list_owners(package) ⇒ Object



65
66
67
68
69
# File 'lib/spade/remote.rb', line 65

def list_owners(package)
  request :get, "api/v1/gems/#{package}/owners.yaml" do |req|
    req.add_field "Authorization", creds.api_key
  end
end

#list_packages(packages, all, prerelease) ⇒ Object



71
72
73
74
# File 'lib/spade/remote.rb', line 71

def list_packages(packages, all, prerelease)
  fetcher = Gem::SpecFetcher.fetcher
  fetcher.find_matching(dependency_for(packages), all, false, prerelease).map(&:first)
end

#login(email, password) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spade/remote.rb', line 7

def (email, password)
  response = raw_request :get, "api/v1/api_key" do |req|
    req.basic_auth email, password
  end

  case response
  when Net::HTTPSuccess
    creds.save(email, response.body)
    true
  else
    false
  end
end

#push(package) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spade/remote.rb', line 21

def push(package)
  begin
    body = Gem.read_binary package
    Gem::Format.from_file_by_path(package)
  rescue Exception => ex
    return "There was a problem opening your package.\n#{ex.class}: #{ex.to_s}"
  end

  request :post, "api/v1/gems" do |req|
    req.body = body
    req.add_field "Content-Length", body.size
    req.add_field "Content-Type",   "application/octet-stream"
    req.add_field "Authorization",  creds.api_key
  end
end

#remove_owner(package, email) ⇒ Object



58
59
60
61
62
63
# File 'lib/spade/remote.rb', line 58

def remove_owner(package, email)
  request :delete, "api/v1/gems/#{package}/owners" do |req|
    req.set_form_data 'email' => email
    req.add_field "Authorization", creds.api_key
  end
end

#unyank(package, version) ⇒ Object



44
45
46
47
48
49
# File 'lib/spade/remote.rb', line 44

def unyank(package, version)
  request :put, "api/v1/gems/unyank" do |req|
    req.set_form_data 'gem_name' => package, 'version' => version
    req.add_field "Authorization", creds.api_key
  end
end

#yank(package, version) ⇒ Object



37
38
39
40
41
42
# File 'lib/spade/remote.rb', line 37

def yank(package, version)
  request :delete, "api/v1/gems/yank" do |req|
    req.set_form_data 'gem_name' => package, 'version' => version
    req.add_field "Authorization", creds.api_key
  end
end