lib/hubspot/topic.rb in hubspot-ruby-0.1.7 vs lib/hubspot/topic.rb in hubspot-ruby-0.1.8
- old
+ new
@@ -1,43 +1,27 @@
-require 'hubspot/utils'
-require 'httparty'
-
module Hubspot
#
# HubSpot Topics API
#
class Topic
- TOPIC_LIST_PATH = "/content/api/v2/topics"
- GET_TOPIC_BY_ID_PATH = "/content/api/v2/topics/:topic_id"
+ TOPICS_PATH = "/content/api/v2/topics"
+ TOPIC_PATH = "/content/api/v2/topics/:topic_id"
class << self
# Lists the topics
# {https://developers.hubspot.com/docs/methods/blogv2/get_topics)
- # @return [Hubspot::Topic, []] array of topics or empty_array
+ # @return [Hubspot::Topic] array of topics
def list
- url = Hubspot::Utils.generate_url(TOPIC_LIST_PATH)
- resp = HTTParty.get(url, format: :json)
- if resp.success?
- resp.parsed_response['objects'].map do |topic_hash|
- Topic.new(topic_hash)
- end
- else
- []
- end
+ response = Hubspot::Connection.get_json(TOPICS_PATH, {})
+ response['objects'].map { |t| new(t) }
end
# Finds the details for a specific topic_id
# {https://developers.hubspot.com/docs/methods/blogv2/get_topics_topic_id }
- # @return Hubspot::Topic or nil
-
+ # @return Hubspot::Topic
def find_by_topic_id(id)
- url = Hubspot::Utils.generate_url(GET_TOPIC_BY_ID_PATH, topic_id: id)
- resp = HTTParty.get(url, format: :json)
- if resp.success?
- Topic.new(resp.parsed_response)
- else
- nil
- end
+ response = Hubspot::Connection.get_json(TOPIC_PATH, { topic_id: id })
+ new(response)
end
end
attr_reader :properties