Class: BPM::Remote

Inherits:
Repository show all
Includes:
LibGems::UserInteraction
Defined in:
lib/bpm/remote.rb

Instance Attribute Summary

Attributes inherited from Repository

#creds

Instance Method Summary collapse

Methods inherited from Repository

#dependency_for, #initialize, #logged_in?

Constructor Details

This class inherits a constructor from BPM::Repository

Instance Method Details

#add_owner(package, email) ⇒ Object



49
50
51
52
53
54
# File 'lib/bpm/remote.rb', line 49

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

#find_package(package_name, package_version, prerelease) ⇒ Object



74
75
76
77
78
# File 'lib/bpm/remote.rb', line 74

def find_package(package_name, package_version, prerelease)
  fetcher = LibGems::SpecFetcher.fetcher
  dep = LibGems::Dependency.new(package_name, package_version)
  fetcher.find_matching(dep, true, false, prerelease).map(&:first)
end

#install(package, version, prerelease) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/bpm/remote.rb', line 80

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

#list_owners(package) ⇒ Object



63
64
65
66
67
# File 'lib/bpm/remote.rb', line 63

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



69
70
71
72
# File 'lib/bpm/remote.rb', line 69

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

#login(email, password) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bpm/remote.rb', line 5

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bpm/remote.rb', line 19

def push(package)
  begin
    body = LibGems.read_binary package
    LibGems::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



56
57
58
59
60
61
# File 'lib/bpm/remote.rb', line 56

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



42
43
44
45
46
47
# File 'lib/bpm/remote.rb', line 42

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



35
36
37
38
39
40
# File 'lib/bpm/remote.rb', line 35

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