Class: Menu::Releases

Inherits:
Array
  • Object
show all
Defined in:
lib/menu/releases.rb

Constant Summary collapse

@@con =
Faraday.new(:url => ENV['MENU_URL']) do |faraday|
  faraday.request  :url_encoded             # form-encode POST params
  faraday.response :json, :content_type => /\bjson$/
  faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.do(component) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/menu/releases.rb', line 5

def self.do component
  raise "Missing component" unless component
  response = @@con.get("/#{component}.json")
  if response.success?
    Releases.from_array response.body['releases']
  else
    puts "New component, creating empty list"
    Releases.new
  end
end

.from_array(arr) ⇒ Object



16
17
18
19
20
# File 'lib/menu/releases.rb', line 16

def self.from_array arr
  r = Releases.new
  arr.each {|i| r << Release.new(i)}
  r
end

Instance Method Details

#to_jsonObject



22
23
24
25
26
# File 'lib/menu/releases.rb', line 22

def to_json
  {
    releases: sort_by {|o| o.version}
  }.to_json
end