Class: Inkdit::Contract

Inherits:
Resource show all
Defined in:
lib/inkdit/contract.rb

Overview

Represents an Inkdit Contract.

Instance Attribute Summary

Attributes inherited from Resource

#url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #fetch!, #initialize, #inspect

Constructor Details

This class inherits a constructor from Inkdit::Resource

Class Method Details

.create(client, owner, params) ⇒ Contract

create a new contract.

Parameters:

  • client (Client)

    the client to create this contract with

  • owner (Entity)

    the entity that will own this contract

  • params (Hash)

    the details of the new contract. this should include the basic details required in a Contract Description.

Returns:

  • (Contract)

    contract the newly created contract

Raises:



13
14
15
16
17
18
# File 'lib/inkdit/contract.rb', line 13

def self.create(client, owner, params)
  response = client.post owner.contracts_link, { :body => params.to_json, :headers => { 'Content-Type' => 'application/json' } }
  raise Inkdit::Error.new(response) unless response.status == 201

  self.new(client, response.parsed)
end

Instance Method Details

#contentString

Returns the contract’s content.

Returns:

  • (String)

    the contract’s content



26
27
28
# File 'lib/inkdit/contract.rb', line 26

def content
  @params['content']
end

#content_updated_atObject

an opaque string indicating the version of the contract’s content



45
46
47
# File 'lib/inkdit/contract.rb', line 45

def content_updated_at
  @params['content_updated_at']
end

the URL of this contract’s HTML representation.



36
37
38
# File 'lib/inkdit/contract.rb', line 36

def html_link
  @params['links']['html']
end

#nameString

Returns a human-readable name for the contract.

Returns:

  • (String)

    a human-readable name for the contract



21
22
23
# File 'lib/inkdit/contract.rb', line 21

def name
  @params['name']
end

#share_with(individual, entity) ⇒ Object

Parameters:

  • individual (String)

    the url of an individual who should be connected to the contract

  • entity (String)

    the url of an entity that the individual should be connected to the contract through



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/inkdit/contract.rb', line 62

def share_with(individual, entity)
  params = {
    :individual => {
      :url => individual
    },
    :entity => {
      :url => entity
    }
  }
  @client.post self.sharing_link, { :body => params.to_json, :headers => { 'Content-Type' => 'application/json' } }
end


40
41
42
# File 'lib/inkdit/contract.rb', line 40

def sharing_link
  @params['links']['shared-with']
end

#signaturesArray<Signature,SignatureField>

Returns this contract’s signatures and unsigned signature fields.

Returns:



50
51
52
53
54
55
56
57
58
# File 'lib/inkdit/contract.rb', line 50

def signatures
  @params['signatures'].map do |s|
    if s['signed_by']
      Inkdit::Signature.new(@client, s)
    else
      Inkdit::SignatureField.new(@client, self, s)
    end
  end
end

#test?Boolean

whether the cantract is a test contract or not

Returns:

  • (Boolean)


31
32
33
# File 'lib/inkdit/contract.rb', line 31

def test?
  @params['test']
end