class ArkEcosystem::Client::HTTP::Client

The HTTP client used for sending requests.

Attributes

http_client[RW]

Public Class Methods

new(config) click to toggle source

Create a new resource instance.

@param config [Hash]

@return [ArkEcosystem::Client::API::Two::Wallets]

# File lib/arkecosystem/client/http/client.rb, line 16
def initialize(config)
  @host = config[:host]
  @http_client = nil
end

Public Instance Methods

delete(url, query = {}) click to toggle source

Create and send a HTTP “DELETE” request.

@param url [String] @param query [Hash]

@return [Faraday::Response]

# File lib/arkecosystem/client/http/client.rb, line 57
def delete(url, query = {})
  send_request(:delete, url, query)
end
get(url, query = {}) click to toggle source

Create and send a HTTP “GET” request.

@param url [String] @param query [Hash]

@return [Faraday::Response]

# File lib/arkecosystem/client/http/client.rb, line 27
def get(url, query = {})
  send_request(:get, url, query)
end
post(url, payload = {}) click to toggle source

Create and send a HTTP “POST” request.

@param url [String] @param payload [Hash]

@return [Faraday::Response]

# File lib/arkecosystem/client/http/client.rb, line 37
def post(url, payload = {})
  send_request(:post, url, payload)
end
put(url, payload = {}) click to toggle source

Create and send a HTTP “PUT” request.

@param url [String] @param payload [Hash]

@return [Faraday::Response]

# File lib/arkecosystem/client/http/client.rb, line 47
def put(url, payload = {})
  send_request(:put, url, payload)
end

Private Instance Methods

faraday() click to toggle source

Create a new Faraday instance.

@return [Faraday]

# File lib/arkecosystem/client/http/client.rb, line 79
def faraday # rubocop:disable Metrics/MethodLength
  if @http_client.nil?
    Faraday.new @host.to_s do |faraday|
      faraday.headers['Content-Type'] = 'application/json'
      faraday.headers['API-Version'] = 2

      faraday.request :json

      faraday.adapter Faraday.default_adapter
    end
  else
    @http_client
  end
end
send_request(method, path, data) click to toggle source

Create and send a HTTP request.

@param method [String] @param path [String] @param data [String]

@return [Faraday::Response]

# File lib/arkecosystem/client/http/client.rb, line 70
def send_request(method, path, data)
  response = faraday.send(method, path, data)

  ArkEcosystem::Client::HTTP::Response.new(response)
end