Module: TinyThomas

Defined in:
lib/tiny_thomas.rb,
lib/tiny_thomas/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tiny_thomas.rb', line 6

def self.permalink(url)
  @host = "tinythom.as"
  @tt_url = '/api/links'
  @payload = Hash["website_url", url].to_json 
  if url.include?('thomas.loc.gov')
    req = Net::HTTP::Post.new(@tt_url)
    req["content-type"] = "application/json"
    req.body = @payload
    response = Net::HTTP.new(@host).start {|http| http.request(req) }
    if response.code == "200"
      resp = CobraVsMongoose.xml_to_json(response.body)
      tt = JSON.parse(resp)
      return tt["link"]["thomas_permalink"]["$"] if tt["link"]
    end
  end
end