somleng/somleng

View on GitHub
app/serializers/twilio_api/webhook/recording_status_callback_serializer.rb

Summary

Maintainability
A
15 mins
Test Coverage
module TwilioAPI
  module Webhook
    class RecordingStatusCallbackSerializer < TwilioAPISerializer
      # https://www.twilio.com/docs/voice/api/recording#recordingstatuscallback

      # | Parameter          | Description                                                                                                                             |
      # |--------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
      # | CallSid            | A unique identifier for this call, generated by Twilio.                                                                                 |
      # | AccountSid         | Your Twilio account ID.                                                                                                                 |
      # | RecordingSid       | The unique identifier for the recording.                                                                                                |
      # | RecordingUrl       | The URL of the recorded audio.                                                                                                          |
      # | RecordingStatus    | The status of the recording. Possible values are: `in-progress`, `completed`, `absent`.                                                 |
      # | RecordingDuration  | The length of the recording, in seconds. (only provided when RecordingStatus is `completed`)                                            |
      # | RecordingChannels  | The number of channels in the final recording file as an integer. Possible values are `1`, `2`.                                         |
      # | RecordingStartTime | The timestamp of when the recording started.                                                                                            |
      # | RecordingSource    | The initiation method used to create this recording. For recordings initiated with this API, the value will be `StartCallRecordingAPI`. |

      def attributes
        super.merge(
          "ApiVersion" => nil,
          "CallSid" => nil,
          "AccountSid" => nil,
          "RecordingSid" => nil,
          "RecordingUrl" => nil,
          "RecordingStatus" => nil,
          "RecordingDuration" => nil,
          "RecordingChannels" => nil,
          "RecordingStartTime" => nil,
          "RecordingSource" => nil
        )
      end

      def ApiVersion
        TwilioAPI::ResourceSerializer::API_VERSION
      end

      def CallSid
        object.phone_call_id
      end

      def AccountSid
        object.account_id
      end

      def RecordingSid
        object.id
      end

      def RecordingUrl
        url_helpers.api_twilio_account_phone_call_recording_url(
          object.account,
          object.phone_call,
          object,
          subdomain: AppSettings.config_for(:api_subdomain)
        )
      end

      def RecordingStatus
        object.status
      end

      def RecordingDuration
        object.duration
      end

      def RecordingChannels
        object.channels
      end

      def RecordingStartTime
        object.start_time.utc.rfc2822
      end

      def RecordingSource
        object.source
      end
    end
  end
end