Sha256: 2de0c4804370c92d88f1c7d6ee88079365f191cd6bda0eca475700d43922afb5

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

module Nwsdk
  class Content
    include Helpers
    include Constants

    attr_accessor :output_dir, :include_types, :exclude_types,
      :condition, :endpoint

    def initialize(*args)
      Hash[*args].each {|k,v| self.send('%s='%k, v)}
      @include_types ||= []
      @exclude_types ||= []
      @output_dir    ||= 'tmp'
    end

    def build_request(session)
      endpoint.get_request(
        path: 'sdk/content',
        params: build_params(session)
      )
    end

    def each_session
      sessions=get_sessionids(self)
      sessions.each do |sessionid|
        begin
          response=build_request(sessionid).execute
        rescue RestClient::Gone
          next
        end
        next unless response.code==200
        yield response
      end
    end

    def each_session_file
      each_session do |response|
        content=response.body.encode('BINARY')
        next unless response.headers.has_key? :content_type
        boundary=get_boundary(response.headers[:content_type])
        each_multipart_response_entity(content,boundary) do |file|
          yield file
        end
      end
    end

    def build_params(session)
      send_params={
        session: session,
        maxSize: 0,
        render:  NW_CONTENT_TYPE_FILE_EXTRACTOR
      }
      unless include_types.empty?
        send_params[:includeFileTypes]=include_types.join(';')
      end
      unless exclude_types.empty?
        send_params[:excludeFileTypes]=exclude_types.join(';')
      end
      send_params
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nwsdk-1.2.0 lib/nwsdk/content.rb
nwsdk-1.1.7 lib/nwsdk/content.rb
nwsdk-1.1.3 lib/nwsdk/content.rb