601d64ee2635 — Eddie Barraco 5 years ago
Add article commands
2 files changed, 123 insertions(+), 0 deletions(-)

M script.sh
M src/Entity/Article.php
M script.sh +102 -0
@@ 205,14 205,116 @@ cmd_tag_put() {
 	echo $(send_rest_put_request "tags" "$id" "$put_data") | jq .
 }
 
+cmd_article_post_usage() {
+	echo "$0 article post article-title article-teasing article-content"
+}
+
+cmd_article_put_usage() {
+	echo "$0 article put article-title"
+}
+
+cmd_article_get_usage() {
+	echo "$0 article get article-id"
+}
+
+cmd_article_list_usage() {
+	echo "$0 article list"
+}
+
+cmd_article_find_usage() {
+	echo "$0 article find tags.label=toot"
+	echo "$0 article find \"tags.label[]=foo&tags.label[]=bar\""
+}
+
+cmd_article_usage() {
+	cmd_article_list_usage
+	cmd_article_find_usage
+	cmd_article_get_usage
+	cmd_article_post_usage
+	cmd_article_put_usage
+}
+
+cmd_article() {
+	ensure_token
+	case "$1" in
+		post) shift; cmd_article_post "$@";;
+		put) shift; cmd_article_put "$@";;
+		get) shift; cmd_article_get "$@";;
+		list) shift; cmd_article_list "$@";;
+		find) shift; cmd_article_find "$@";;
+		*) cmd_article_usage ;;
+	esac
+}
+
+cmd_article_list() {
+	echo $(send_rest_index_request "articles") | jq .
+}
+
+cmd_article_find() {
+	search="$1"
+
+	if [ -z "$search" ]
+	then
+		cmd_article_find_usage
+		exit 1
+	fi
+
+	echo $(send_rest_index_request "articles" "$search") | jq .
+}
+
+cmd_article_get() {
+	id="$1"
+
+	if [ -z "$id" ]
+	then
+		cmd_article_get_usage
+		exit 1
+	fi
+
+	echo $(send_rest_get_request "articles" "$id") | jq .
+}
+
+cmd_article_post() {
+	title="$1"
+	teasing="$2"
+	content="$3"
+
+	if [ -z "$title" ] || [ -z "$teasing" ] || [ -z "$content" ]
+	then
+		cmd_article_post_usage
+		exit 1
+	fi
+
+	post_data="{\"title\": \"$title\", \"teasing\": \"$teasing\", \"content\": \"$content\"}"
+
+	echo $(send_rest_post_request "articles" "$post_data") | jq .
+}
+
+cmd_article_put() {
+	id="$1"
+	title="$2"
+
+	if [ -z "$id" ] || [ -z "$title" ]
+	then
+		cmd_article_put_usage
+		exit 1
+	fi
+
+	put_data="{\"title\": \"$title\"}"
+
+	echo $(send_rest_put_request "articles" "$id" "$put_data") | jq .
+}
+
 cmd_global_usage() {
 	echo "Usage:"
 	cmd_tag_usage
+	cmd_article_usage
 	cmd_token_usage
 }
 
 case "$1" in
 	tag) shift; cmd_tag "$@";;
+	article) shift; cmd_article "$@";;
 	token) shift; cmd_token "$@";;
 	*) cmd_global_usage ;;
 esac

          
M src/Entity/Article.php +21 -0
@@ 43,16 43,37 @@ class Article
         return $this->title;
     }
 
+    public function setTitle(string $title): self
+    {
+        $this->title = $title;
+
+        return $this;
+    }
+
     public function getTeasing(): ?string
     {
         return $this->teasing;
     }
 
+    public function setTeasing(string $teasing): self
+    {
+        $this->teasing = $teasing;
+
+        return $this;
+    }
+
     public function getContent(): ?string
     {
         return $this->content;
     }
 
+    public function setContent(string $teasing): self
+    {
+        $this->content = $teasing;
+
+        return $this;
+    }
+
     public function getTags(): ?\Traversable
     {
         return $this->tags;