Class: Hubspot::BlogPost

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot/blog.rb

Constant Summary collapse

GET_BLOG_POST_BY_ID_PATH =
"/content/api/v2/blog-posts/:blog_post_id"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_hash) ⇒ BlogPost

Returns a new instance of BlogPost.



74
75
76
# File 'lib/hubspot/blog.rb', line 74

def initialize(response_hash)
  @properties = response_hash #no need to parse anything, we have properties
end

Class Method Details

.find_by_blog_post_id(id) ⇒ Object

Returns:

  • Hubspot::BlogPost



69
70
71
72
# File 'lib/hubspot/blog.rb', line 69

def self.find_by_blog_post_id(id)
  response = Hubspot::Connection.get_json(GET_BLOG_POST_BY_ID_PATH, { blog_post_id: id })
  new(response)
end

Instance Method Details

#[](property) ⇒ Object



78
79
80
# File 'lib/hubspot/blog.rb', line 78

def [](property)
  @properties[property]
end

#created_atObject



82
83
84
# File 'lib/hubspot/blog.rb', line 82

def created_at
  Time.at(@properties['created'] / 1000)
end

#topicsObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hubspot/blog.rb', line 86

def topics
  @topics ||= begin
    if @properties['topic_ids'].empty?
      []
    else
      @properties['topic_ids'].map do |topic_id|
        Hubspot::Topic.find_by_topic_id(topic_id)
      end
    end
  end
end