Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add snake_case #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions esy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fetch",
"name": "reason-fetch",
"version": "0.1.0",
"description": "Fetch libraries and interface for ReasonML/OCaml",
"license": "MIT",
Expand All @@ -12,15 +12,15 @@
]
},
"scripts": {
"example": "esy refmterr dune exec examples/fetch_native_lwt_get.exe",
"example:native-lwt": "esy refmterr dune exec examples/fetch-native-lwt/get.exe",
"format": "esy dune build @fmt --auto-promote",
"test": "esy dune runtest test",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate"
},
"dependencies": {
"fetch-native-lwt": "*",
"fetch-core": "*",
"fetch-native-lwt": "*",
"@opam/dune": "^1.11.1",
"@opam/opium_core": "rgrinberg/opium:opium_core.opam",
"@opam/reason": "^3.5.0",
Expand Down
50 changes: 25 additions & 25 deletions esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions examples/dune

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Fetch.(
| Ok({Response.body, status, url, _}) => {
Printf.printf(
"Status-Code: %d\nBody: %s\nUrl: %s",
Response.Status.toCode(status),
Response.Body.toString(body),
Response.Status.to_code(status),
Response.Body.to_string(body),
url,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
let handleResponse =
let map_successful =
Fetch.Response.(
fun
| Ok({status, _}) when Status.isSuccessful(status) => "Success!"
| Ok({status, _}) when Status.is_successful(status) => "Success!"
| _ => "That's anything but successful. :-("
);

Fetch.(
fetch("http://httpbin.org/get", ())
|> Lwt.map(handleResponse)
|> Lwt.map(map_successful)
|> Lwt.map(Console.log)
|> Lwt_main.run
);
3 changes: 3 additions & 0 deletions examples/fetch-native-lwt/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executables
(names Get GetIsSuccessful)
(libraries console.lib fetch-native-lwt))
1 change: 1 addition & 0 deletions fetch-native-lwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@opam/utop": "2.4.2"
},
"resolutions": {
"fetch-core": "link:./fetch-core.json",
"@opam/httpaf-lwt-unix": "anmonteiro/httpaf:httpaf-lwt-unix.opam#76b461bed081c64908fb1fdfa076ab2c936ca622",
"@opam/httpaf-lwt": "anmonteiro/httpaf:httpaf-lwt.opam#76b461bed081c64908fb1fdfa076ab2c936ca622",
"@opam/httpaf": "anmonteiro/httpaf:httpaf.opam#76b461bed081c64908fb1fdfa076ab2c936ca622"
Expand Down
3 changes: 3 additions & 0 deletions src/fetch-core/body.rei → src/fetch-core/Body.rei
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ type t;

let toString: t => string;
let ofString: string => t;

let to_string: t => string;
let of_string: string => t;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/fetch-core/method.re → src/fetch-core/Method.re
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ let toString =
| `PUT => "PUT"
| `TRACE => "TRACE"
| `Other(v) => v;

let of_string = ofString;
let to_string = toString;
3 changes: 3 additions & 0 deletions src/fetch-core/method.rei → src/fetch-core/Method.rei
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ type t = [ standard | `Other(string)];

let ofString: string => t;
let toString: t => string;

let of_string: string => t;
let to_string: t => string;
2 changes: 1 addition & 1 deletion src/fetch-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The goal is to be pluggable with any HTTP or Promise-implementation provided it
E.g.

```re
module Fetch = Fetch_core.Fetchify.Make({
module Fetch = Fetch_Core.Fetchify.Make({
module Response = {
/* your implementation */
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/fetch-core/s.re → src/fetch-core/S.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module type Body = {

let toString: t => string;
let ofString: string => t;

let to_string: t => string;
let of_string: string => t;
};

module type Response = {
Expand Down
10 changes: 10 additions & 0 deletions src/fetch-core/status.re → src/fetch-core/Status.re
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ let ofCode =
| 511 => `NetworkAuthenticationRequired
| c => `Other(c);

let to_code = toCode;
let of_code = ofCode;

let isSuccessful =
fun
| #success => true
Expand Down Expand Up @@ -248,4 +251,11 @@ let isError =
| #clientError => true
| _ => false;

let is_informational = isInformational;
let is_successful = isSuccessful;
let is_redirect = isRedirect;
let is_client_error = isClientError;
let is_server_error = isServerError;
let is_error = isError;

let make = ofCode;
10 changes: 10 additions & 0 deletions src/fetch-core/status.rei → src/fetch-core/Status.rei
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,21 @@ type t = [ standard | `Other(int)];
let toCode: t => int;
let ofCode: int => t;

let to_code: t => int;
let of_code: int => t;

let isInformational: t => bool;
let isSuccessful: t => bool;
let isRedirect: t => bool;
let isClientError: t => bool;
let isServerError: t => bool;
let isError: t => bool;

let is_informational: t => bool;
let is_successful: t => bool;
let is_redirect: t => bool;
let is_client_error: t => bool;
let is_server_error: t => bool;
let is_error: t => bool;

let make: int => t;
2 changes: 1 addition & 1 deletion src/fetch-core/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name fetch_core)
(name Fetch_Core)
(public_name fetch-core)
(modules_without_implementation body))
11 changes: 7 additions & 4 deletions src/fetch-native-lwt/fetch.re → src/fetch-native-lwt/Fetch.re
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module IO = {
module Response = {
module Status = {
include Fetch_core.Response.Status;
include Fetch_Core.Response.Status;
};

module Headers = {
include Fetch_core.Headers;
include Fetch_Core.Headers;
};

module Body = {
Expand All @@ -19,6 +19,9 @@ module IO = {
};

let ofString = body => `String(body);

let to_string = toString;
let of_string = ofString;
};

type t = {
Expand All @@ -38,7 +41,7 @@ module IO = {

type t = Lwt.t(result(Response.t, exn));

let make = ({headers, body, meth, url}: Fetch_core.Request.t) => {
let make = ({headers, body, meth, url}: Fetch_Core.Request.t) => {
Lwt.Infix.(
Morph.Request.make(
~meth,
Expand Down Expand Up @@ -74,4 +77,4 @@ module IO = {
};
};

include Fetch_core.Fetchify.Make(IO);
include Fetch_Core.Fetchify.Make(IO);
2 changes: 1 addition & 1 deletion src/fetch-native-lwt/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name fetch)
(name Fetch)
(public_name fetch-native-lwt)
(libraries fetch-core morph_client))
2 changes: 1 addition & 1 deletion test/method.re → test/Method.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Fetch_core.Method;
open Fetch_Core.Method;

module ToString = {
let toStringTest = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/status.re → test/Status.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Fetch_core.Status;
open Fetch_Core.Status;

module ToCode = {
let informationToCode = () => {
Expand Down
4 changes: 2 additions & 2 deletions test/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(tests
(names status method)
(libraries alcotest fetch_core))
(names Status Method)
(libraries alcotest fetch-core))