Sha256: 017f8df7646a3fb19b3d79aad1012be2ff7712e172e92eaa48b5ce16a16fbf52

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

class SmsAero
  HLR_STATUSES = {
    1 => :available,
    2 => :unavailable,
    3 => :nonexistent
  }.freeze

  operation :hlr do
    documentation "https://smsaero.ru/api/description/#hlr"

    path { "hlr" }

    query { attribute :phone, Types::Phone }

    response :success, 200, format: :json, model: Answer do
      attribute :id, proc(&:to_s)
      attribute :success, default: proc { id != "" }
    end

    response :failure, 200, format: :json, model: Answer do
      attribute :success, default: proc { false }
    end
  end

  operation :hlr_status do
    documentation "https://smsaero.ru/api/description/#hlr"

    path { "hlrStatus" }

    query { attribute :id, Types::Coercible::String.constrained(filled: true) }

    response :success, 200, format: :json, model: Answer do
      attribute :status, -> (s) { HLR_STATUSES[s.to_i] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sms_aero-0.0.11 lib/sms_aero/operations/hlr.rb