Sha256: 02b1bc844c1637e492b5106a7bcf1c942fdc0b69a5a3f034d36a49ea34e8c6f5

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# Copyright 2017 Stratumn SAS. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module AgentClient
  ##
  # Represents an Indigo agent
  class Agent
    include Request
    extend Request

    attr_reader :url

    def self.load(url)
      result = get(url)
      instance = new(url)

      process_list = result['processes']
      raise('Agent has not sent the processes') if process_list.nil?

      if process_list.respond_to?('each')
        process_list.each do |pname, pcontent|
          instance.add_new_process(pname, pcontent)
        end
      end
      instance
    end

    def list_processes
      @processes.values
    end

    def get(process_name)
      @processes[process_name]
    end

    def initialize(url)
      @url = url
      @processes = {}
    end

    def add_new_process(name, content)
      process = Process.new(url,
                            name,
                            content['processInfo'],
                            content['storeInfo'])
      @processes[name] = process
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
indigoframework_agent_client-0.2.0 lib/agent_client/agent.rb