Sha256: 201e234de872704ccae884d6a3fdd22626ea497b377d173b725121ffa2ef9fd5
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true module WCC::Blogs class Post extend WCC::Blogs::Utils require 'time' def self.find(slug) new(WCC::Blogs.client.blog_show(slug).raw, client: WCC::Blogs.client) end def self.find_all PostSummary.find_all.map(&:full_post) end attr_reader :raw def initialize(raw, client: WCC::Blogs.client) @raw = raw @client = client end def author_full_name author&.fullName end def html @html ||= @client.get(_links.fragment) .body .force_encoding('UTF-8') end def metadata WCC::Blogs::Metadata.new(raw['metadata']) if raw['metadata'] end def published? true end def time_to_read # TODO nil end def to_param slug.sub(%r{^/}, '') end define_camelcase_alias( 'id', 'title', 'subtitle', 'summary', 'slug', 'host', 'path', 'digest', 'fragment_path' ) do |camelcase| raw[camelcase] end define_camelcase_alias( 'date', 'updated_at' ) do |camelcase| value = raw[camelcase] Time.parse(value) if value&.length end define_camelcase_alias( 'author', 'hero_image', 'thumbnail_image', 'flags' ) do |camelcase| OpenStruct.new(raw[camelcase]) if raw[camelcase] end def _links OpenStruct.new(raw['_links'] || {}) end define_camelcase_alias( 'published_properties', 'categories', 'tags' ) do |camelcase| targets = raw[camelcase] || [] targets.map { |val| OpenStruct.new(val) if val } end def collection CollectionSummary.new(raw['collection'], client: @client) if raw['collection'] end alias cache_key digest end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wcc-blogs-client-0.5.2 | lib/wcc/blogs/post.rb |