Class: MVM::Client

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

Overview

HTTP client for MVM services.

Handles HTTP communication with MVM services including:

  • Bridge service

  • NFT service

  • Registry service

  • Scan service

Features

  • Automatic JSON encoding/decoding

  • Request retry on failures

  • Error handling with exceptions

  • Debug logging

Usage

client = MVM::Client.new('bridge.mvm.dev')
response = client.get('/info')
response = client.post('/users', public_key: '0x...')

Constant Summary collapse

SERVER_SCHEME =

The HTTPS scheme for all MVM requests.

'https'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Client

Initializes a new MVM Client.

Sets up HTTP connection with:

  • JSON request/response handling

  • Automatic retry on failures

  • Error raising on HTTP errors

  • Debug logging

Examples:

client = MVM::Client.new('bridge.mvm.dev')

Parameters:

  • host (String)

    the service hostname



49
50
51
52
53
54
55
56
57
58
# File 'lib/mvm/client.rb', line 49

def initialize(host)
  @host = host
  @conn = Faraday.new(url: "#{SERVER_SCHEME}://#{host}") do |f|
    f.request :json
    f.request :retry
    f.response :raise_error
    f.response :logger
    f.response :json
  end
end

Instance Attribute Details

#hostString (readonly)

Returns the service host.

Returns:

  • (String)

    the service host



33
34
35
# File 'lib/mvm/client.rb', line 33

def host
  @host
end

Instance Method Details

#get(path) ⇒ Hash

Performs a GET request.

Examples:

response = client.get('/info')

Parameters:

  • path (String)

    the request path

  • kwargs (Hash)

    query parameters

Returns:

  • (Hash)

    the parsed response body



70
71
72
# File 'lib/mvm/client.rb', line 70

def get(path, **)
  @conn.get(path, **).body
end

#post(path) ⇒ Hash

Performs a POST request.

Examples:

response = client.post('/users', public_key: '0x...')

Parameters:

  • path (String)

    the request path

  • kwargs (Hash)

    request body parameters

Returns:

  • (Hash)

    the parsed response body



84
85
86
# File 'lib/mvm/client.rb', line 84

def post(path, **)
  @conn.post(path, **).body
end