Sha256: 4cdf0994b0dbf076396609828ae86bbd506e87afd5cc066ddc8a295fda42d87e

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require 'bulutfon_sdk/rest/base_request'

module BulutfonSDK
  module REST
    class Announcement < BaseRequest

      include BulutfonSDK::Util

      def initialize(*args)
        super(*args)
        @resource = 'announcements'
      end

      def all( params = {} )
        prepare_request( 'get', @resource,params)
      end

      def get( id )
        uri = prepare_uri("#{@resource}/#{id}")
        { download_path: uri.to_s }
      end

      def save( id, save_path)
        save_file( 'get', "#{@resource}/#{id}", save_path)
      end

      def create(params)
        prepare_atachment(params)
        prepare_request( 'post', @resource, params)
      end

      def delete(id)
        prepare_request( 'delete', "#{@resource}/#{id}")
      end

      private

      def prepare_atachment(params)
        file          = params[:announcement]
        basename      = File.basename file
        type          = file_content_type file
        content       = File.read(file)
        base_64_data  = Base64.strict_encode64(content)
        params[:announcement] = "data:#{type};name:#{basename};base64:#{base_64_data}"
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bulutfon_sdk-1.3.0 lib/bulutfon_sdk/rest/announcement.rb
bulutfon_sdk-1.2.1 lib/bulutfon_sdk/rest/announcement.rb
bulutfon_sdk-1.2.0 lib/bulutfon_sdk/rest/announcement.rb
bulutfon_sdk-1.1.3 lib/bulutfon_sdk/rest/announcement.rb
bulutfon_sdk-1.1.0 lib/bulutfon_sdk/rest/announcement.rb