Sha256: 0ae8c199b08cb033e515305206aecde86adb8c00b68ca56af03b68466d5cd78c

Contents?: true

Size: 992 Bytes

Versions: 12

Compression:

Stored size: 992 Bytes

Contents

require 'vng/resource'

module Vng
  # Provides methods to interact with Vonigo service types.
  class ServiceType < Resource
    PATH = '/api/v1/resources/serviceTypes/'

    attr_reader :id, :type, :duration

    def initialize(id:, type:, duration:)
      @id = id
      @type = type
      @duration = duration
    end

    def self.all
      data = request path: PATH

      data['ServiceTypes'].map do |body|
        id = body['serviceTypeID']
        type = body['serviceType']
        duration = body['duration']

        new id: id, type: type, duration: duration
      end
    end

    def self.where(zip:)
      body = {
        zip: zip,
      }

      data = request path: PATH, body: body

      data.fetch('ServiceTypes', []).filter do |body|
        body['isActive']
      end.map do |body|
        id = body['serviceTypeID']
        type = body['serviceType']
        duration = body['duration']

        new id: id, type: type, duration: duration
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vng-1.7.0 lib/vng/service_type.rb
vng-1.6.0 lib/vng/service_type.rb
vng-1.5.0 lib/vng/service_type.rb
vng-1.4.4 lib/vng/service_type.rb
vng-1.4.3 lib/vng/service_type.rb
vng-1.4.2 lib/vng/service_type.rb
vng-1.4.1 lib/vng/service_type.rb
vng-1.4.0 lib/vng/service_type.rb
vng-1.3.0 lib/vng/service_type.rb
vng-1.2.0 lib/vng/service_type.rb
vng-1.1.0 lib/vng/service_type.rb
vng-1.0.0 lib/vng/service_type.rb