Class: Repositories::Atom

Inherits:
Base
  • Object
show all
Defined in:
app/models/repositories/atom.rb

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
SECURITY_PLANNED =
true
URL =
'https://atom.io'
COLOR =
'#244776'

Constants inherited from Base

Base::HIDDEN, Base::LIBRARIAN_PLANNED

Class Method Summary collapse

Methods inherited from Base

color, download_dependencies, formatted_name, get, get_html, get_json, get_raw, import, import_async, import_new, import_new_async, import_recent, import_recent_async, new_names, package_link, repo_fallback, save, save_dependencies, update

Class Method Details

.dependencies(name, version) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/repositories/atom.rb', line 51

def self.dependencies(name, version)
  deps = get("https://atom.io/api/packages/#{name}/versions/#{version}")["dependencies"] || []
  deps.map do |name,req|
    {
      project_name: name,
      requirements: req,
      kind: 'normal',
      optional: false,
      platform: 'Npm' # woah!
    }
  end
end

.mapping(project) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'app/models/repositories/atom.rb', line 32

def self.mapping(project)
   = project['metadata']
  repo = ['repository'].is_a?(Hash) ? ['repository']['url'] : ['repository']
  {
    :name => project['name'],
    :description => ['description'],
    :repository_url => repo_fallback(repo, '')
  }
end

.project(name) ⇒ Object



28
29
30
# File 'app/models/repositories/atom.rb', line 28

def self.project(name)
  get("https://atom.io/api/packages/#{name}")
end

.project_namesObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/repositories/atom.rb', line 10

def self.project_names
  page = 1
  projects = []
  while true
    r = get("https://atom.io/api/packages?page=#{page}")
    break if  r == []
    projects += r
    page +=1
  end
  projects.map{|project| project['name'] }.sort.uniq
end

.recent_namesObject



22
23
24
25
26
# File 'app/models/repositories/atom.rb', line 22

def self.recent_names
  projects = get('https://atom.io/api/packages?page=1&sort=created_at&direction=desc') +
  get('https://atom.io/api/packages?page=1&sort=updated_at&direction=desc')
  projects.map{|project| project['name'] }.uniq
end

.versions(project) ⇒ Object



42
43
44
45
46
47
48
49
# File 'app/models/repositories/atom.rb', line 42

def self.versions(project)
  project['versions'].map do |k,v|
    {
      :number => k,
      :published_at => nil
    }
  end
end