Skip to content

Instantly share code, notes, and snippets.

@iintothewind
Last active March 27, 2018 04:23
Show Gist options
  • Save iintothewind/c845ac6fbf40becaf4e3e577fb4d8150 to your computer and use it in GitHub Desktop.
Save iintothewind/c845ac6fbf40becaf4e3e577fb4d8150 to your computer and use it in GitHub Desktop.

Revisions

  1. Ivar Chen revised this gist Mar 27, 2018. 1 changed file with 16 additions and 27 deletions.
    43 changes: 16 additions & 27 deletions curl_bash_wrapper.bash
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/usr/bin/env bash
    export REQ_BASE="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    export REQ_PWD="admin"
    export REQ_METHOD="POST"
    export REQ_BASE=""
    export REQ_USER=""
    export REQ_PWD=""
    export REQ_METHOD=""

    function cf_lower() {
    echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]'
    @@ -12,23 +12,23 @@ function cf_upper() {
    echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]'
    }

    function cf_startsWith() {
    function cf_starts_with() {
    local str=$1
    local pre=$2
    [[ "$str" == ${pre}* ]]
    }

    function cf_composeUrl() {
    function cf_compose_url() {
    local inputUrl=$1
    local baseUrl=$2
    if test $inputUrl && (cf_startsWith $inputUrl $baseUrl || cf_startsWith $inputUrl "http://"); then
    if test $inputUrl && (cf_starts_with $inputUrl $baseUrl || [[ $inputUrl =~ http.?://.+ ]]); then
    echo $inputUrl
    else
    echo "$baseUrl$inputUrl"
    fi
    }

    # used after a pipe, cat '{ "k": "v"}' | jsonfmt
    # used after a pipe, for example: echo '{ "k": "v"}' | cf_jsonfmt
    function cf_jsonfmt() {
    if type python > /dev/null 2>&1; then
    python -mjson.tool
    @@ -48,36 +48,26 @@ function cf_req() {
    local u;local p;local l;local m;local d;
    while getopts ":u:p:l:m:d:" o; do
    case "${o}" in
    u)
    u=${OPTARG}
    ;;
    p)
    p=${OPTARG}
    ;;
    l)
    l=${OPTARG}
    ;;
    m)
    m=${OPTARG}
    ;;
    d)
    d=${OPTARG}
    ;;
    u) u=${OPTARG} ;;
    p) p=${OPTARG} ;;
    l) l=${OPTARG} ;;
    m) m=${OPTARG} ;;
    d) d=${OPTARG} ;;
    esac
    done
    if type curl > /dev/null 2>&1; then
    if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -u ${u:-$REQ_USER}:${p:-$REQ_PWD} -X `cf_upper ${m:-$REQ_METHOD}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_compose_url $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$REQ_METHOD}` || test "DELETE" = `cf_upper ${m:-$REQ_METHOD}`; then echo ""; else echo ${d:-`cat`}; fi))
    else
    echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -X `cf_upper ${m:-$REQ_METHOD}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_compose_url $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$REQ_METHOD}` || test "DELETE" = `cf_upper ${m:-$REQ_METHOD}`; then echo ""; else echo ${d:-`cat`}; fi))
    fi
    else
    echo "curl is not found in PATH"
    return 1
    fi
    }

    # req -d '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]'
    # cf_req -d '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| cf_parse '["data"][0][0]["all_relationships"]'
    # $1 the key
    # $2 json string or read stdin from cat
    function cf_parse() {
    @@ -94,4 +84,3 @@ EOF
    return 1
    fi
    }

  2. Ivar Chen revised this gist Mar 24, 2018. No changes.
  3. Ivar Chen renamed this gist Mar 24, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions curl_query.bash → curl_bash_wrapper.bash
    Original file line number Diff line number Diff line change
    @@ -67,9 +67,9 @@ function cf_req() {
    done
    if type curl > /dev/null 2>&1; then
    if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    else
    echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    fi
    else
    echo "curl is not found in PATH"
  4. Ivar Chen revised this gist Mar 24, 2018. No changes.
  5. Ivar Chen revised this gist Mar 24, 2018. 1 changed file with 21 additions and 15 deletions.
    36 changes: 21 additions & 15 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -4,40 +4,46 @@ export REQ_USER="neo4j"
    export REQ_PWD="admin"
    export REQ_METHOD="POST"

    function lower() {
    function cf_lower() {
    echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]'
    }

    function upper() {
    function cf_upper() {
    echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]'
    }

    function startsWith() {
    function cf_startsWith() {
    local str=$1
    local pre=$2
    [[ "$str" == ${pre}* ]]
    }

    function composeUrl() {
    function cf_composeUrl() {
    local inputUrl=$1
    local baseUrl=$2
    if test $inputUrl && startsWith $inputUrl $baseUrl; then
    if test $inputUrl && (cf_startsWith $inputUrl $baseUrl || cf_startsWith $inputUrl "http://"); then
    echo $inputUrl
    else
    echo "$baseUrl$inputUrl"
    fi
    }

    function jsonfmt() {
    # used after a pipe, cat '{ "k": "v"}' | jsonfmt
    function cf_jsonfmt() {
    if type python > /dev/null 2>&1; then
    python -mjson.tool
    else
    echo "python is nof found in PATH"
    echo "python is not found in PATH"
    return 1
    fi
    }

    function req() {
    # -u : user name, default value: $REQ_USER
    # -p : password, default value: $REQ_PWD
    # -l : request url, it can be full url (startsWith http://baseurl.com) or sub-path (/data/resource), default value: $REQ_BASE
    # -m : request method, default value: $REQ_METHOD
    # -d : request body, defaut read from stdin by cat
    function cf_req() {
    local OPTIND=1
    local u;local p;local l;local m;local d;
    while getopts ":u:p:l:m:d:" o; do
    @@ -61,20 +67,20 @@ function req() {
    done
    if type curl > /dev/null 2>&1; then
    if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    else
    echo $(curl -k -s -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    fi
    else
    echo "curl is nof found in PATH"
    echo "curl is not found in PATH"
    return 1
    fi
    }

    # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]'
    # req -d '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]'
    # $1 the key
    # $2 json string or cat
    function parse() {
    # $2 json string or read stdin from cat
    function cf_parse() {
    if type python > /dev/null 2>&1; then
    python <<EOF
    import json
    @@ -84,7 +90,7 @@ except Exception as e:
    print("error: {}".format(e))
    EOF
    else
    echo "python is nof found in PATH"
    echo "python is not found in PATH"
    return 1
    fi
    }
  6. Ivar Chen revised this gist Mar 24, 2018. 1 changed file with 26 additions and 11 deletions.
    37 changes: 26 additions & 11 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    export REQ_BASE="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    export REQ_PWD="admin"
    export REQ_METHOD="POST"

    function lower() {
    echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]'
    @@ -36,18 +37,33 @@ function jsonfmt() {
    fi
    }


    # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    #$1 body, json string
    #$2 REQ_URL
    #$3 REQ_USER
    #$4 REQ_PWD
    function post() {
    function req() {
    local OPTIND=1
    local u;local p;local l;local m;local d;
    while getopts ":u:p:l:m:d:" o; do
    case "${o}" in
    u)
    u=${OPTARG}
    ;;
    p)
    p=${OPTARG}
    ;;
    l)
    l=${OPTARG}
    ;;
    m)
    m=${OPTARG}
    ;;
    d)
    d=${OPTARG}
    ;;
    esac
    done
    if type curl > /dev/null 2>&1; then
    if (test $3 || test $REQ_USER) && (test $4 || test $REQ_PWD); then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(composeUrl $2 $REQ_BASE)} -d @<(echo ${1:-`cat`}))
    if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then
    echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    else
    echo $(curl -s -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`}))
    echo $(curl -k -s -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi))
    fi
    else
    echo "curl is nof found in PATH"
    @@ -73,4 +89,3 @@ EOF
    fi
    }


  7. Ivar Chen revised this gist Mar 23, 2018. 1 changed file with 22 additions and 2 deletions.
    24 changes: 22 additions & 2 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/env bash
    export REQ_URL="http://localhost:7474/db/data/cypher"
    export REQ_BASE="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    export REQ_PWD="admin"

    @@ -11,6 +11,22 @@ function upper() {
    echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]'
    }

    function startsWith() {
    local str=$1
    local pre=$2
    [[ "$str" == ${pre}* ]]
    }

    function composeUrl() {
    local inputUrl=$1
    local baseUrl=$2
    if test $inputUrl && startsWith $inputUrl $baseUrl; then
    echo $inputUrl
    else
    echo "$baseUrl$inputUrl"
    fi
    }

    function jsonfmt() {
    if type python > /dev/null 2>&1; then
    python -mjson.tool
    @@ -28,7 +44,11 @@ function jsonfmt() {
    #$4 REQ_PWD
    function post() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`}))
    if (test $3 || test $REQ_USER) && (test $4 || test $REQ_PWD); then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(composeUrl $2 $REQ_BASE)} -d @<(echo ${1:-`cat`}))
    else
    echo $(curl -s -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`}))
    fi
    else
    echo "curl is nof found in PATH"
    return 1
  8. Ivar Chen revised this gist Mar 22, 2018. No changes.
  9. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ function jsonfmt() {
    #$4 REQ_PWD
    function post() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`}))
    else
    echo "curl is nof found in PATH"
    return 1
  10. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,12 @@ function upper() {
    }

    function jsonfmt() {
    python -mjson.tool
    if type python > /dev/null 2>&1; then
    python -mjson.tool
    else
    echo "python is nof found in PATH"
    return 1
    fi
    }


    @@ -25,6 +30,7 @@ function post() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    else
    echo "curl is nof found in PATH"
    return 1
    fi
    }
    @@ -33,7 +39,7 @@ function post() {
    # $1 the key
    # $2 json string or cat
    function parse() {
    if type curl > /dev/null 2>&1; then
    if type python > /dev/null 2>&1; then
    python <<EOF
    import json
    try:
    @@ -42,6 +48,7 @@ except Exception as e:
    print("error: {}".format(e))
    EOF
    else
    echo "python is nof found in PATH"
    return 1
    fi
    }
  11. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,11 @@ export REQ_USER="neo4j"
    export REQ_PWD="admin"

    function lower() {
    echo "$1" | tr '[:upper:]' '[:lower:]'
    echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]'
    }

    function upper() {
    echo "$1" | tr '[:lower:]' '[:upper:]'
    echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]'
    }

    function jsonfmt() {
  12. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,8 @@ function jsonfmt() {
    }


    #$1 json body
    # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    #$1 body, json string
    #$2 REQ_URL
    #$3 REQ_USER
    #$4 REQ_PWD
  13. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 4 additions and 7 deletions.
    11 changes: 4 additions & 7 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,7 @@
    #!/usr/bin/env bash
    export REQ_ERR_MSG=""
    export REQ_URL="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    export REQ_PWD="admin"
    export REQ_DEFAULT_METHOD="POST"

    function lower() {
    echo "$1" | tr '[:upper:]' '[:lower:]'
    @@ -22,19 +20,18 @@ function jsonfmt() {
    #$2 REQ_URL
    #$3 REQ_USER
    #$4 REQ_PWD
    #$5 REQ_METHOD
    function req() {
    function post() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    else
    return 1
    fi
    }

    # req '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| get '["data"][0][0]["all_relationships"]'
    # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]'
    # $1 the key
    # $2 json string or cat
    function get() {
    function parse() {
    if type curl > /dev/null 2>&1; then
    python <<EOF
    import json
  14. Ivar Chen revised this gist Mar 22, 2018. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,7 @@ function jsonfmt() {
    python -mjson.tool
    }


    #$1 json body
    #$2 REQ_URL
    #$3 REQ_USER
    @@ -25,12 +26,26 @@ function jsonfmt() {
    function req() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    return 0
    else
    return 1
    fi
    }


    # req '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| get '["data"][0][0]["all_relationships"]'
    # $1 the key
    # $2 json string or cat
    function get() {
    if type curl > /dev/null 2>&1; then
    python <<EOF
    import json
    try:
    print(json.loads('''${2:-`cat`}''')${1:-""})
    except Exception as e:
    print("error: {}".format(e))
    EOF
    else
    return 1
    fi
    }


  15. Ivar Chen revised this gist Mar 21, 2018. 1 changed file with 5 additions and 11 deletions.
    16 changes: 5 additions & 11 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,4 @@
    #!/usr/bin/env bash

    ERROR_MSG=""
    export NEO4J_URL="http://localhost:7474/db/data/cypher"
    export NEO4J_USER="neo4j"
    export NEO4J_PWD="admin"

    function body() {
    echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    }

    export REQ_ERR_MSG=""
    export REQ_URL="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    @@ -36,7 +26,11 @@ function req() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    return 0
    else
    return 1
    fi
    return 1
    }




  16. Ivar Chen revised this gist Mar 21, 2018. 1 changed file with 21 additions and 9 deletions.
    30 changes: 21 additions & 9 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -9,22 +9,34 @@ function body() {
    echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    }

    function jsonfmt() {
    python -mjson.tool
    export REQ_ERR_MSG=""
    export REQ_URL="http://localhost:7474/db/data/cypher"
    export REQ_USER="neo4j"
    export REQ_PWD="admin"
    export REQ_DEFAULT_METHOD="POST"

    function lower() {
    echo "$1" | tr '[:upper:]' '[:lower:]'
    }

    function upper() {
    echo "$1" | tr '[:lower:]' '[:upper:]'
    }

    quote () {
    local quoted=${1//\"/\"\\\"\"};
    printf "'%s'" "$quoted"
    function jsonfmt() {
    python -mjson.tool
    }

    function query() {
    #$1 json body
    #$2 REQ_URL
    #$3 REQ_USER
    #$4 REQ_PWD
    #$5 REQ_METHOD
    function req() {
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $NEO4J_USER)}:${4:-$(echo $NEO4J_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $NEO4J_URL)} -d @<(echo $1))
    echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1))
    return 0
    fi
    return 1
    }



  17. Ivar Chen revised this gist Mar 20, 2018. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    ERROR_MSG=""
    export NEO4J_URL="http://localhost:7474/db/data/cypher"
    export NEO4J_USER="neo4j"
    export NEO4J_PASSWD="admin"
    export NEO4J_PWD="admin"

    function body() {
    echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    @@ -19,13 +19,12 @@ quote () {
    }

    function query() {
    if type curl > /dev/null 2>&1 && $# == 4; then
    echo $(curl -s -u $2:$3 -X POST -H Accept:application/json -H Content-Type: application/json $1 -d @<(echo $4))
    if type curl > /dev/null 2>&1; then
    echo $(curl -s -u ${3:-$(echo $NEO4J_USER)}:${4:-$(echo $NEO4J_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $NEO4J_URL)} -d @<(echo $1))
    return 0
    fi
    return 1
    }




  18. Ivar Chen created this gist Mar 20, 2018.
    31 changes: 31 additions & 0 deletions curl_query.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env bash

    ERROR_MSG=""
    export NEO4J_URL="http://localhost:7474/db/data/cypher"
    export NEO4J_USER="neo4j"
    export NEO4J_PASSWD="admin"

    function body() {
    echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'
    }

    function jsonfmt() {
    python -mjson.tool
    }

    quote () {
    local quoted=${1//\"/\"\\\"\"};
    printf "'%s'" "$quoted"
    }

    function query() {
    if type curl > /dev/null 2>&1 && $# == 4; then
    echo $(curl -s -u $2:$3 -X POST -H Accept:application/json -H Content-Type: application/json $1 -d @<(echo $4))
    return 0
    fi
    return 1
    }