Sha256: ba2c823094261128290964923cf2cabaab044f437ce093d351819746785b97ed

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module SPACEX
  class Ships < Hashie::Trash
    include Hashie::Extensions::IgnoreUndeclared

    property 'ship_id', from: 'id'
    property 'ship_name'
    property 'ship_model'
    property 'ship_type'
    property 'roles'
    property 'active'
    property 'imo'
    property 'mmsi'
    property 'abs'
    property 'ship_class', from: 'class'
    property 'weight_lbs'
    property 'weight_kg'
    property 'year_built'
    property 'home_port'
    property 'status'
    property 'speed_kn'
    property 'course_deg'
    property 'position'
    property 'successful_landings'
    property 'attempted_landings'
    property 'missions'
    property 'url'
    property 'image'

    class << self
      def retrieve_all
        data = SPACEX::BaseRequest.call_api('ships')
        data.get.body.map { |k| SPACEX::Ships.new(k) }
      end

      def get(ship_id = nil)
        return retrieve_all if ship_id.nil?

        data = SPACEX::BaseRequest.get("ships/#{ship_id}")
        SPACEX::Ships.new(data)
      end

      def info(ship_id = nil)
        get(ship_id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spacex-0.0.7 lib/spacex/ships.rb