Class: MisarBlog::ArticlesResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/misarblog/client.rb

Overview

── Resource: Articles ───────────────────────────────────────────────────────

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from MisarBlog::Resource

Instance Method Details

#create_draft(title:, body_markdown:, tags: nil) ⇒ Object

POST /drafts — create an unpublished draft.



84
85
86
87
# File 'lib/misarblog/client.rb', line 84

def create_draft(title:, body_markdown:, tags: nil)
  body = compact(title: title, body_markdown: body_markdown, tags: tags)
  Models::Article.new(@client.request(:post, "/drafts", body))
end

#get(slug) ⇒ Object

GET /articles/slug



63
64
65
# File 'lib/misarblog/client.rb', line 63

def get(slug)
  Models::Article.new(@client.request(:get, "/articles/#{escape(slug)}"))
end

#list(status: nil, visibility: nil, webhook_only: nil, sort: nil, limit: nil) ⇒ Object

GET /articles



56
57
58
59
60
# File 'lib/misarblog/client.rb', line 56

def list(status: nil, visibility: nil, webhook_only: nil, sort: nil, limit: nil)
  qs = query(status: status, visibility: visibility,
             webhook_only: webhook_only, sort: sort, limit: limit)
  Models::ArticleList.new(@client.request(:get, "/articles#{qs}"))
end

#publish(title:, body_markdown:, tags: nil, cover_image_url: nil, schedule_at: nil, visibility: nil) ⇒ Object

POST /articles — publish (or schedule) a new article.



68
69
70
71
72
73
74
# File 'lib/misarblog/client.rb', line 68

def publish(title:, body_markdown:, tags: nil, cover_image_url: nil,
            schedule_at: nil, visibility: nil)
  body = compact(title: title, body_markdown: body_markdown, tags: tags,
                 cover_image_url: cover_image_url, schedule_at: schedule_at,
                 visibility: visibility)
  Models::Article.new(@client.request(:post, "/articles", body))
end

#recommendations(article_id:, limit: nil) ⇒ Object

GET /recommendations — related articles for a given article.



98
99
100
101
# File 'lib/misarblog/client.rb', line 98

def recommendations(article_id:, limit: nil)
  qs = query(article_id: article_id, limit: limit)
  @client.request(:get, "/recommendations#{qs}")
end

#search(q: nil, type: nil, tag: nil, author: nil, sort: nil, from: nil, to: nil, limit: nil) ⇒ Object

GET /search — full-text search across articles/profiles/tags.



90
91
92
93
94
95
# File 'lib/misarblog/client.rb', line 90

def search(q: nil, type: nil, tag: nil, author: nil, sort: nil,
           from: nil, to: nil, limit: nil)
  qs = query(q: q, type: type, tag: tag, author: author, sort: sort,
             from: from, to: to, limit: limit)
  @client.request(:get, "/search#{qs}")
end

#update(slug, title: nil, body_markdown: nil, tags: nil, publish: nil) ⇒ Object

PATCH /articles/slug — update an existing article.



77
78
79
80
81
# File 'lib/misarblog/client.rb', line 77

def update(slug, title: nil, body_markdown: nil, tags: nil, publish: nil)
  body = compact(title: title, body_markdown: body_markdown,
                 tags: tags, publish: publish)
  Models::Article.new(@client.request(:patch, "/articles/#{escape(slug)}", body))
end