Class: Ipfs::HttpApi

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

Constant Summary collapse

DEFAULT_HOST =
'localhost'
DEFAULT_PORT =
5001
DEFAULT_BASE_PATH =
'/api/v0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**api_server) ⇒ HttpApi

Returns a new instance of HttpApi.



12
13
14
15
16
# File 'lib/http_api.rb', line 12

def initialize(**api_server)
  @host = api_server[:host] || DEFAULT_HOST
  @port = api_server[:port] || DEFAULT_PORT
  @base_path = api_server[:base_path] || DEFAULT_BASE_PATH
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



6
7
8
# File 'lib/http_api.rb', line 6

def base_path
  @base_path
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/http_api.rb', line 6

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/http_api.rb', line 6

def port
  @port
end

Instance Method Details

#call(command) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/http_api.rb', line 18

def call(command)
  HTTP.request(
    command[:verb],
    url(command[:path]),
    command[:options] ? command[:options] : {}
  )
end