<commit_before>#|
 This file is a part of Chirp
 (c) 2014 TymoonNET/NexT http://tymoon.eu (<EMAIL>)
 Author: <NAME> <<EMAIL>>
|#

(in-package #:org.tymoonnext.chirp)

(defvar *direct-messages/* "https://api.twitter.com/1.1/direct_messages.json")
(defvar *direct-messages/sent* "https://api.twitter.com/1.1/direct_messages/sent.json")
(defvar *direct-messages/show* "https://api.twitter.com/1.1/direct_messages/show.json")
(defvar *direct-messages/destroy* "https://api.twitter.com/1.1/direct_messages/destroy.json")
(defvar *direct-messages/new* "https://api.twitter.com/1.1/direct_messages/new.json")

(defclass* direct-message ()
  (id text recipient sender created-at entities)
  (:documentation "Class representation of a twitter direct-message object."))

(defmethod print-object ((dm direct-message) stream)
  (print-unreadable-object (dm stream :type T)
    (format stream "~a -> ~a #~a" (screen-name (sender dm)) (screen-name (recipient dm)) (id dm)))
  dm)

(define-make-* (direct-message parameters)
  :id :text
  (:recipient (parse-when-param :recipient #'make-user))
  (:sender (parse-when-param :sender #'make-user))
  (:created-at (parse-when-param :created-at #'parse-twitter-time))
  (:entities (parse-when-param :entities #'make-entities)))

(defun direct-messages (&key since-id max-id (count 20) (include-entities T) skip-status)
  "Returns the 20 most recent direct messages sent to the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 incoming DMs.

According to spec https://dev.twitter.com/docs/api/1.1/get/direct_messages"
  (assert (<= count 200) () "COUNT has to be less than 200.")
  (unless include-entities (setf include-entities "false"))
  (mapcar #'make-direct-message (signed-request *direct-messages/* :parameters (prepare* since-id max-id count include-entities skip-status) :method :GET)))<commit_msg>Fixed text decoding<commit_after>#|
 This file is a part of Chirp
 (c) 2014 TymoonNET/NexT http://tymoon.eu (<EMAIL>)
 Author: <NAME> <<EMAIL>>
|#

(in-package #:org.tymoonnext.chirp)

(defvar *direct-messages/* "https://api.twitter.com/1.1/direct_messages.json")
(defvar *direct-messages/sent* "https://api.twitter.com/1.1/direct_messages/sent.json")
(defvar *direct-messages/show* "https://api.twitter.com/1.1/direct_messages/show.json")
(defvar *direct-messages/destroy* "https://api.twitter.com/1.1/direct_messages/destroy.json")
(defvar *direct-messages/new* "https://api.twitter.com/1.1/direct_messages/new.json")

(defclass* direct-message ()
  (id text recipient sender created-at entities)
  (:documentation "Class representation of a twitter direct-message object."))

(defmethod print-object ((dm direct-message) stream)
  (print-unreadable-object (dm stream :type T)
    (format stream "~a -> ~a #~a" (screen-name (sender dm)) (screen-name (recipient dm)) (id dm)))
  dm)

(define-make-* (direct-message parameters)
  :id
  (:text (xml-decode (cdr (assoc :text parameters))))
  (:recipient (parse-when-param :recipient #'make-user))
  (:sender (parse-when-param :sender #'make-user))
  (:created-at (parse-when-param :created-at #'parse-twitter-time))
  (:entities (parse-when-param :entities #'make-entities)))

(defun direct-messages (&key since-id max-id (count 20) (include-entities T) skip-status)
  "Returns the 20 most recent direct messages sent to the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 incoming DMs.

According to spec https://dev.twitter.com/docs/api/1.1/get/direct_messages"
  (assert (<= count 200) () "COUNT has to be less than 200.")
  (unless include-entities (setf include-entities "false"))
  (mapcar #'make-direct-message (signed-request *direct-messages/* :parameters (prepare* since-id max-id count include-entities skip-status) :method :GET)))
{'fraction_non_alphanumeric': 0.15621840242669363, 'fraction_numerical': 0.016177957532861477, 'mean_word_length': 4.743105950653121, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '7279044', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1282, 'n_words': 356}