Sha256: a9497ac2b01abcd25517a447e510790af1ead5818bfb8d4565e3e514b11b3bd3

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module StratumnSdk
  class Link
    include Request

    attr_accessor :application, :meta, :state, :link, :linkHash

    def initialize(application, obj)
      self.application = application

      self.link = obj['link']
      self.meta = link['meta']
      self.state = link['state']
      self.linkHash = obj['meta']['linkHash']

      application.agent_info['functions'].each do |(method, _)|
        define_singleton_method(method) do |*args|

          url = "#{application.url}/links/#{linkHash}/#{method}"

          result = post(url, json: args)

          Link.new(application, result)
        end
      end
    end

    def previous
      application.get_link(meta['prevLinkHash']) if meta['prevLinkHash']
    end

    def get_branches(tags)
      application.get_branches(linkHash, tags)
    end

    def load
      application.get_link(linkHash)
    end

    def self.load(segment)
      meta = segment['meta']

      application = Application.load(meta['application'], meta['applicationLocation'])

      application.get_link(meta['linkHash'])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stratumn_sdk-0.0.1 lib/stratumn_sdk/link.rb