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.



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

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.defaultObject



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

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

Instance Method Details

#add(file) ⇒ Object



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

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

#api_urlObject



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

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

#cat(node) ⇒ Object



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

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

#ls(node) ⇒ Object



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

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