class Diffbot::Article
Class to parse a Diffbot
article from a given URL
Attributes
url[R]
@!attribute url
@return [String] Target URL for the given article
Public Class Methods
new(url)
click to toggle source
Instantiate an Article
from a URL
@param url [String] Specify the target article url @return [Article] @see www.diffbot.com/products/automatic/article/ @example Create an Article
article = Diffbot::Article.new("www.example.com/some-url")
# File lib/diffbot_api/article.rb, line 18 def initialize(url) validate_diffbot_token! @url = URI.parse(url) extract_article end
Public Instance Methods
[](key)
click to toggle source
Get article fields
@return [String]
# File lib/diffbot_api/article.rb, line 28 def [](key) @response[key] end
Private Instance Methods
article_endpoint()
click to toggle source
Builds the Diffbot
API url for article resources
@return [String]
# File lib/diffbot_api/article.rb, line 43 def article_endpoint File.join api_url, "article" end
extract_article()
click to toggle source
Extracts article data through Diffbot
API
# File lib/diffbot_api/article.rb, line 35 def extract_article api_response = request.get article_endpoint, token: Diffbot.token, url: @url @response = JSON.parse(api_response.body) end