<commit_before>package http

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strings"

	ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"

	cmds "github.com/jbenet/go-ipfs/commands"
)

const ApiPath = "/api/v0" // TODO: make configurable

func Send(req cmds.Request) (cmds.Response, error) {
	addr, err := ma.NewMultiaddr(req.Context().Config.Addresses.API)
	if err != nil {
		return nil, err
	}

	_, host, err := manet.DialArgs(addr)
	if err != nil {
		return nil, err
	}

	url := "http://" + host + ApiPath
	url += "/" + strings.Join(req.Path(), "/")

	var userEncoding string
	if enc, found := req.Option(cmds.EncShort); found {
		userEncoding = enc.(string)
		req.SetOption(cmds.EncShort, cmds.JSON)
	} else {
		enc, _ := req.Option(cmds.EncLong)
		userEncoding = enc.(string)
		req.SetOption(cmds.EncLong, cmds.JSON)
	}

	// TODO: handle multiple files with multipart
	var in io.Reader

	query := "?"
	for k, v := range req.Options() {<commit_msg>commands/http: Refactored API to a Client object that takes a string address<commit_after>package http

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strings"

	cmds "github.com/jbenet/go-ipfs/commands"
)

const ApiPath = "/api/v0" // TODO: make configurable

// Client is the commands HTTP client interface.
type Client interface {
	Send(req cmds.Request) (cmds.Response, error)
}

type client struct {
	serverAddress string
}

func NewClient(address string) Client {
	return &client{address}
}

func (c *client) Send(req cmds.Request) (cmds.Response, error) {
	url := "http://" + c.serverAddress + ApiPath
	url += "/" + strings.Join(req.Path(), "/")

	var userEncoding string
	if enc, found := req.Option(cmds.EncShort); found {
		userEncoding = enc.(string)
		req.SetOption(cmds.EncShort, cmds.JSON)
	} else {
		enc, _ := req.Option(cmds.EncLong)
		userEncoding = enc.(string)
		req.SetOption(cmds.EncLong, cmds.JSON)
	}

	// TODO: handle multiple files with multipart
	var in io.Reader

	query := "?"
	for k, v := range req.Options() {
{'fraction_non_alphanumeric': 0.15323707498835584, 'fraction_numerical': 0.0009315323707498836, 'mean_word_length': 3.794642857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4856593', 'n_tokens_mistral': 826, 'n_tokens_neox': 804, 'n_words': 184}