Class: ButterCMS::Post
Defined Under Namespace
Classes: RecordNotFound
Class Method Summary collapse
-
.all ⇒ ButterCMS::Post
Returns post for given slug if available otherwise raises error RecordNotFound.
-
.find(slug) ⇒ ButterCMS::Post
Returns all available posts from the API.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from ButterCMS::Resource
Class Method Details
.all ⇒ ButterCMS::Post
Returns post for given slug if available otherwise raises error RecordNotFound
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/butter_cms/post.rb', line 7 def self.all posts = [] = { page_size: 10, page: 0 } more_posts = true while more_posts = .merge(page: [:page] + 1) fetch_service = ButterCMS::PostsFetchService.new() posts = posts | fetch_service.posts more_posts = fetch_service.more_posts? end posts end |
.find(slug) ⇒ ButterCMS::Post
Returns all available posts from the API
25 26 27 28 29 30 31 |
# File 'lib/butter_cms/post.rb', line 25 def self.find(slug) response = ::ButterCMS::Requests::Get.call("posts/#{slug}") post_attributes = ::ButterCMS::Parsers::Post.new(response).post ::ButterCMS::Parsers::PostObject.call(post_attributes) rescue RestClient::NotFound raise RecordNotFound end |