Class: SyllabsApi::Modules::Extract::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/syllabs-api/modules/extract/base.rb

Constant Summary collapse

API_URL =
'http://api.syllabs.com/v0/extract?extract=body'
RESPONSE_FORMAT =
'json'

Class Method Summary collapse

Class Method Details

.fetch_response(body) ⇒ Object



19
20
21
22
23
24
# File 'lib/syllabs-api/modules/extract/base.rb', line 19

def self.fetch_response(body)
  json = JSON.parse(body)
  Extract::Response.new(json['response']['url'], json['response']['text'])
rescue Exception => e
  raise e
end

.process(api_key, url) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/syllabs-api/modules/extract/base.rb', line 10

def self.process(api_key, url)
  params = {url: url, format: RESPONSE_FORMAT}
  http_response = HttpProcessor.post(api_key, API_URL, params)
  fetch_response(http_response.body)
rescue Exception => e
  raise e
end