Class: Ipfs::Connection::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-ipfs-http-client/connection/base.rb

Direct Known Subclasses

Default, IpfsConfig, Unreachable

Constant Summary collapse

DEFAULT_BASE_PATH =
'/api/v0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/ruby-ipfs-http-client/connection/base.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/ruby-ipfs-http-client/connection/base.rb', line 8

def port
  @port
end

Instance Method Details

#build_uriObject



10
11
12
# File 'lib/ruby-ipfs-http-client/connection/base.rb', line 10

def build_uri
  URI::HTTP.build(host: @host, port: @port)
end

#make_persistentObject



23
24
25
# File 'lib/ruby-ipfs-http-client/connection/base.rb', line 23

def make_persistent
  HTTP.persistent build_uri
end

#up?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/ruby-ipfs-http-client/connection/base.rb', line 14

def up?
  begin
    HTTP.get("http://#{@host}:#{@port}#{DEFAULT_BASE_PATH}/id")
    true
  rescue HTTP::ConnectionError
    false
  end
end