Created
May 18, 2017 14:57
-
-
Save mikejakobsen/b961278a63108a8a170a3203ee71767f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
class MercuryParser | |
attr_reader :url | |
def initialize(url) | |
@url = url | |
end | |
def parse | |
req = Net::HTTP::Get.new(uri) | |
req['x-api-key'] = ENV.fetch('MERCURY_TOKEN') | |
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| | |
http.request(req) | |
end | |
JSON.parse res.body | |
end | |
def self.parse(url) | |
new(url).parse | |
end | |
private | |
def uri | |
URI(base + api_url(url)) | |
end | |
def base | |
"https://mercury.postlight.com" | |
end | |
def api_url(url) | |
"/parser?url=#{url}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment