<commit_before>! Copyright (C) 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs base64 calendar checksums.hmac
checksums.sha combinators fry http http.client kernel locals
make math namespaces present random sequences sorting strings
urls urls.encoding urls.private checksums ;
IN: oauth

SYMBOL: consumer-token

TUPLE: token key secret user-data ;

: <token> ( key secret -- token )
    token new
        swap >>secret
        swap >>key ;

<PRIVATE

TUPLE: token-params
consumer-token
timestamp
nonce ;

: new-token-params ( class -- params )
    new
        consumer-token get >>consumer-token
        now timestamp>unix-time >integer >>timestamp
        16 random-bytes hex-string >>nonce ; inline

: present-base-url ( url -- string )
    [
        [ unparse-protocol ]
        [ path>> url-encode % ] bi
    ] "" make ;

:: signature-base-string ( url request-method params -- string )
    [
        request-method % "&" %
        url present-base-url url-encode-full % "&" %
        params assoc>query url-encode-full %
        url query>> [ assoc>query "&" prepend url-encode-full % ] when*
    ] "" make ;<commit_msg>Revert "oauth: Generate the oauth signature base string the way twitter does it."<commit_after>! Copyright (C) 2010 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs base64 calendar checksums.hmac
checksums.sha combinators fry http http.client kernel locals
make math namespaces present random sequences sorting strings
urls urls.encoding ;
IN: oauth

SYMBOL: consumer-token

TUPLE: token key secret user-data ;

: <token> ( key secret -- token )
    token new
        swap >>secret
        swap >>key ;

<PRIVATE

TUPLE: token-params
consumer-token
timestamp
nonce ;

: new-token-params ( class -- params )
    new
        consumer-token get >>consumer-token
        now timestamp>unix-time >integer >>timestamp
        random-32 >>nonce ; inline

:: signature-base-string ( url request-method params -- string )
    [
        request-method % "&" %
        url present url-encode-full % "&" %
        params assoc>query url-encode-full %
    ] "" make ;
{'fraction_non_alphanumeric': 0.10854503464203233, 'fraction_numerical': 0.007390300230946882, 'mean_word_length': 2.8404255319148937, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 38, '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': '2452999', 'n_tokens_mistral': 667, 'n_tokens_neox': 640, 'n_words': 200}