Class: Repositories::Packagist

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

Constant Summary collapse

HAS_VERSIONS =
true
HAS_DEPENDENCIES =
true
LIBRARIAN_SUPPORT =
true
SECURITY_PLANNED =
true
URL =
'https://packagist.org'
COLOR =
'#4F5D95'

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

.acceptable_versions(project) ⇒ Object


48
49
50
51
52
# File 'app/models/repositories/packagist.rb', line 48

def self.acceptable_versions(project)
  project['versions'].select do |k, v|
    (k =~ /^dev-.*/i).nil?
  end
end

.dependencies(name, version) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/repositories/packagist.rb', line 54

def self.dependencies(name, version)
  vers = project(name)['versions'][version]
  return [] if vers.nil?
  vers.fetch('require', {}).reject{|k,v| k == 'php' }.map do |k,v|
    {
      project_name: k,
      requirements: v,
      kind: 'normal',
      optional: false,
      platform: self.name.demodulize
    }
  end + vers.fetch('require-dev', {}).reject{|k,v| k == 'php' }.map do |k,v|
    {
      project_name: k,
      requirements: v,
      kind: 'Development',
      optional: false,
      platform: self.name.demodulize
    }
  end
end

.mapping(project) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/repositories/packagist.rb', line 26

def self.mapping(project)
  return false unless project["versions"].any?
  latest_version = project["versions"].to_a.last[1]
  {
    :name =>  latest_version['name'],
    :description => latest_version['description'],
    :homepage => latest_version['home_page'],
    :keywords_array => Array.wrap(latest_version['keywords']),
    :licenses => latest_version['license'].join(','),
    :repository_url => repo_fallback(project['repository'],latest_version['home_page'])
  }
end

.project(name) ⇒ Object


22
23
24
# File 'app/models/repositories/packagist.rb', line 22

def self.project(name)
  get("https://packagist.org/packages/#{name}.json")['package']
end

.project_namesObject


10
11
12
# File 'app/models/repositories/packagist.rb', line 10

def self.project_names
  get("https://packagist.org/packages/list.json")['packageNames']
end

.recent_namesObject


14
15
16
17
18
19
20
# File 'app/models/repositories/packagist.rb', line 14

def self.recent_names
  u = 'https://packagist.org/feeds/releases.rss'
  updated = SimpleRSS.parse(Typhoeus.get(u).body).items.map(&:title)
  u = 'https://packagist.org/feeds/packages.rss'
  new_packages = SimpleRSS.parse(Typhoeus.get(u).body).items.map(&:title)
  (updated.map { |t| t.split(' ').first } + new_packages).uniq
end

.versions(project) ⇒ Object


39
40
41
42
43
44
45
46
# File 'app/models/repositories/packagist.rb', line 39

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