class Hubspot::Blog

HubSpot Contacts API

Constants

BLOG_LIST_PATH
BLOG_POSTS_PATH
GET_BLOG_BY_ID_PATH

Attributes

properties[R]

Public Class Methods

find_by_id(id) click to toggle source

Finds a specific blog by its ID {developers.hubspot.com/docs/methods/blogv2/get_blogs_blog_id} @return Hubspot::Blog

# File lib/hubspot/blog.rb, line 23
def find_by_id(id)
  response = Hubspot::Connection.get_json(GET_BLOG_BY_ID_PATH, { blog_id: id })
  new(response)
end
list() click to toggle source

Lists the blogs {developers.hubspot.com/docs/methods/blogv2/get_blogs} No param filtering is currently implemented @return [Hubspot::Blog] the first 20 blogs or empty_array

# File lib/hubspot/blog.rb, line 15
def list
  response = Hubspot::Connection.get_json(BLOG_LIST_PATH, {})
  response['objects'].map { |b| new(b) }
end
new(response_hash) click to toggle source
# File lib/hubspot/blog.rb, line 31
def initialize(response_hash)
  @properties = response_hash #no need to parse anything, we have properties
end

Public Instance Methods

[](property) click to toggle source
# File lib/hubspot/blog.rb, line 35
def [](property)
  @properties[property]
end
posts(params = {}) click to toggle source

Returns the posts for this blog instance.

defaults to returning the last 2 months worth of published blog posts
in date descending order (i.e. most recent first)

{developers.hubspot.com/docs/methods/blogv2/get_blog_posts} @return [Hubspot::BlogPost]

# File lib/hubspot/blog.rb, line 45
def posts(params = {})
  default_params = {
    content_group_id: self["id"],
    order_by: '-created',
    created__gt: Time.now - 2.month,
    state: 'PUBLISHED'
  }
  raise Hubspot::InvalidParams.new('params must be passed as a hash') unless params.is_a?(Hash)
  params = default_params.merge(params)

  raise Hubspot::InvalidParams.new('State parameter was invalid') unless [false, 'PUBLISHED', 'DRAFT'].include?(params[:state])
  params.each { |k, v| params.delete(k) if v == false }

  response = Hubspot::Connection.get_json(BLOG_POSTS_PATH, params)
  response['objects'].map { |p| BlogPost.new(p) }
end