Sha256: 17b02cd305aa93eaddd5808ea4eb3104bcc05a5421e34bf78e2838fc3773e871

Contents?: true

Size: 1.56 KB

Versions: 79

Compression:

Stored size: 1.56 KB

Contents

# ********** Copyright Viacom, Inc. Apache 2.0 **********
module RokuBuilder

  # Super class for modules
  # This class defines a common initializer and allows subclasses
  # to define their own secondary initializer
  class Util

    # Common initializer of device utils
    # @param config [Config] Configuration object for the app
    def initialize(config: )
      @logger = Logger.instance
      @config = config
      @roku_ip_address = @config.device_config[:ip]
      @dev_username = @config.device_config[:user]
      @dev_password = @config.device_config[:password]
      @url = "http://#{@roku_ip_address}"
      init
    end

    private

    # Second initializer to be overwriten
    def init
      #Override in subclass
    end

    # Generates a simpe Faraday connection with digest credentials
    # @return [Faraday] The faraday connection
    def simple_connection
      Faraday.new(url: @url) do |f|
        f.request :digest, @dev_username, @dev_password
        f.adapter Faraday.default_adapter
      end
    end

    # Generates a multipart Faraday connection with digest credentials
    # @param port [Integer] optional port to connect to
    # @return [Faraday] The faraday connection
    def multipart_connection(port: nil)
      url = @url
      url = "#{url}:#{port}" if port
      Faraday.new(url: url) do |f|
        f.headers['Content-Type'] = Faraday::Request::Multipart.mime_type
        f.request :digest, @dev_username, @dev_password
        f.request :multipart
        f.request :url_encoded
        f.adapter Faraday.default_adapter
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
roku_builder-4.25.5 lib/roku_builder/util.rb
roku_builder-4.25.4 lib/roku_builder/util.rb
roku_builder-4.25.3 lib/roku_builder/util.rb
roku_builder-4.25.1 lib/roku_builder/util.rb
roku_builder-4.25.0 lib/roku_builder/util.rb
roku_builder-4.24.3 lib/roku_builder/util.rb
roku_builder-4.24.1 lib/roku_builder/util.rb
roku_builder-4.24.0 lib/roku_builder/util.rb
roku_builder-4.23.2 lib/roku_builder/util.rb
roku_builder-4.23.1 lib/roku_builder/util.rb
roku_builder-4.23.0 lib/roku_builder/util.rb
roku_builder-4.22.9 lib/roku_builder/util.rb
roku_builder-4.22.8 lib/roku_builder/util.rb
roku_builder-4.22.7 lib/roku_builder/util.rb
roku_builder-4.22.6 lib/roku_builder/util.rb
roku_builder-4.22.5 lib/roku_builder/util.rb
roku_builder-4.22.4 lib/roku_builder/util.rb
roku_builder-4.22.3 lib/roku_builder/util.rb
roku_builder-4.22.2 lib/roku_builder/util.rb
roku_builder-4.22.1 lib/roku_builder/util.rb