Class: Convertible::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/convertible/client.rb

Constant Summary collapse

CONVERT =
'/convert'

Instance Method Summary collapse

Instance Method Details

#convert(data, content_type, output_content_type, options = {}) ⇒ Object

content_type and output_content_type must be valid mime types like ‘application/pdf’ or ‘text/plain’ if an URI instance is passed as data, the content will be fetched server side from said uri. content_type is ignored an should be nil in this case (convertible.io will use the content type from the remote resource).



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/convertible/client.rb', line 16

def convert(data, content_type, output_content_type, options = {})
  response = if URI === data
    self.class.get CONVERT, :headers => { 'Accept' => output_content_type,
                                          'X-Convert-Options' => option_string(options),
                                          'X-Source' => data.to_s }
  else
    self.class.post CONVERT, :body => data, :headers => { 'Content-Type' => content_type, 'Accept' => output_content_type, 'X-Convert-Options' => option_string(options) }
  end
  if response.code == 200
    return response
  else
    false
  end
end

#supported?(input_type, output_type) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/convertible/client.rb', line 41

def supported?(input_type, output_type)
  response = self.class.get '/supported', :query => { :in => input_type, :out => output_type }, :format => :json
  response['supported']
end

#supported_conversions(input_type = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/convertible/client.rb', line 31

def supported_conversions(input_type = nil)
  if input_type
    response = self.class.get '/supported', :query => { :in => input_type }, :format => :json
    response['out']
  else
    response = self.class.get '/supported', :format => :json
    response['supported']
  end
end