Sha256: 75c8d8e73ebfd33af02510f49dd67f5cc8ff2f94821dfde6c53cca46e1c0e2cd

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

# Copyright (C) 2017  Stratumn SAS
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

module AgentClient
  ##
  # Represents a Stratumn application
  class Application
    include Request
    extend Request

    attr_accessor :url, :id, :name, :agent_info

    def self.load(application_name, application_location = nil)
      url = application_location ||
            AgentClient.config[:application_url].gsub('%s', application_name)
      attributes = get(url)

      new(url,
          attributes['id'],
          attributes['name'],
          attributes['agentInfo'])
    end

    def initialize(url, id, name, agent_info)
      self.url = url
      self.id = id
      self.name = name
      self.agent_info = agent_info
    end

    def create_map(*args)
      result = post(url + '/maps', json: args)

      Link.new(self, result)
    end

    def get_link(link_hash)
      result = get(url + '/links/' + link_hash)

      Link.new(self, result)
    end

    def get_map(map_id, tags = [])
      query = tags.empty? ? '' : "?tags=#{tags.join('&tags=')}"

      result = get(url + '/maps/' + map_id + query)

      result.map do |link|
        Link.new(self, link)
      end
    end

    def get_branches(link_hash, tags = [])
      query = tags.empty? ? '' : "?tags=#{tags.join('&tags=')}"

      result = get(url + '/branches/' + link_hash + query)

      result.map do |link|
        Link.new(self, link)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stratumn_agent_client-0.2.0 lib/agent_client/application.rb