Class: EOL::Cycle

Inherits:
Object
  • Object
show all
Defined in:
lib/eol_rb/cycle.rb

Overview

Class for retrieving information about Cycles

Defined Under Namespace

Classes: NotFoundError

Class Method Summary collapse

Class Method Details

.get(client, product, cycle) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eol_rb/cycle.rb', line 11

def get(client, product, cycle)
  res = client.get("/#{product}/#{cycle}.json")

  if res.status == 404
    available_cycles = []
    Products.get(client, product).each do |p|
      available_cycles.push(p["cycle"])
    end

    raise NotFoundError,
          "Cycle #{cycle} could not be found under product #{product}. Try any of #{available_cycles.inspect}"
  end

  specs = JSON.parse(res.body).merge({ "cycle" => cycle })

  Models::Cycle.new(specs)
end