Class: IPFS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ipfs/client.rb

Constant Summary collapse

DEFAULT_HOST =
'http://localhost'.freeze
DEFAULT_PORT =
5001
API_VERSION =
'v0'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:) ⇒ Client

Returns a new instance of Client.



18
19
20
21
# File 'lib/ipfs/client.rb', line 18

def initialize(host:, port:)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/ipfs/client.rb', line 12

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/ipfs/client.rb', line 12

def port
  @port
end

Class Method Details

.defaultObject



14
15
16
# File 'lib/ipfs/client.rb', line 14

def self.default
  new(host: DEFAULT_HOST, port: DEFAULT_PORT)
end

Instance Method Details

#add(file) ⇒ Object



35
36
37
# File 'lib/ipfs/client.rb', line 35

def add(file)
  Commands::Add.call self, file
end

#api_urlObject



23
24
25
# File 'lib/ipfs/client.rb', line 23

def api_url
  "#{host}:#{port}/api/#{API_VERSION}"
end

#cat(node) ⇒ Object



31
32
33
# File 'lib/ipfs/client.rb', line 31

def cat(node)
  Commands::Cat.call self, node
end

#ls(node) ⇒ Object



27
28
29
# File 'lib/ipfs/client.rb', line 27

def ls(node)
  Commands::LS.call self, node
end

#pin_rm(node, recursive: true) ⇒ Object



39
40
41
# File 'lib/ipfs/client.rb', line 39

def pin_rm(node, recursive: true)
  Commands::PinRm.call self, node, recursive: recursive
end