class EasyPdfCloud::Client
Attributes
access_token[RW]
The OAuth access token in use by the client
api_host[RW]
The host to use for API requests. Defaults to api.easypdfcloud.com
api_url[R]
The base URL to the Base API {api_host}/{version}
client_id[RW]
The client id (aka “Consumer Key”) to use for OAuth2 authentication
client_secret[RW]
The client secret (aka “Consumer Secret” to use for OAuth2 authentication)
host[RW]
The host to use for OAuth2 authentication. Defaults to www.easypdfcloud.com
refresh_token[RW]
The OAuth refresh token in use by the client
version[RW]
The API version the client is using. Defaults to v1
workflow_url[R]
The base URL to the workflow API
Public Class Methods
new(options)
click to toggle source
# File lib/easy_pdf_cloud.rb, line 27 def initialize(options) @options = options @host = options['host'] || 'https://www.easypdfcloud.com' @api_host = options['api_host'] || "https://api.easypdfcloud.com" @version = options['version'] || "v1" @api_url = "#{@api_host}/#{@version}" @workflow_url = "#{@api_url}/workflows" @client_id = options['client_id'] @client_secret = options['client_secret'] @access_token = options['access_token'] @refresh_token = options['refresh_token'] client_options = { :site => @host, :authorize_url => '/oauth2/authorize', :token_url => '/oauth2/token' } @client = OAuth2::Client.new(@client_id, @client_secret, client_options) #@client.auth_code.authorize_url(:redirect_uri => 'http://localhost', :scope => "epc.api", :state => "EasyPDFCloud") @access_token = OAuth2::AccessToken.from_hash(@client, {:access_token => @access_token, :refresh_token => @refresh_token}) end
Public Instance Methods
check_access_token()
click to toggle source
# File lib/easy_pdf_cloud.rb, line 60 def check_access_token if @access_token.expired? || @access_token.token.empty? puts "Refreshing EasyPdfCloud Access Token" # For older versions of oauth2 the refresh_token is not properly carried over after the call to refresh! @access_token = OAuth2::AccessToken.from_hash(@client, {:access_token => @options["access_token"], :refresh_token => @options["refresh_token"]}) @access_token = @access_token.refresh! verify_access_token end end
convert(filename, input_type, output_type, workflow_id=nil)
click to toggle source
# File lib/easy_pdf_cloud.rb, line 70 def convert(filename, input_type, output_type, workflow_id=nil) check_access_token out_filepath = nil wid = workflow_id || @options["workflow_id"] if wid out_filepath = workflow(wid).convert(filename, input_type, output_type) else raise "No workflow id was specified" end return out_filepath end
pdf2word(filename, pdf_data, workflow_id=nil)
click to toggle source
# File lib/easy_pdf_cloud.rb, line 82 def pdf2word(filename, pdf_data, workflow_id=nil) check_access_token word_data = "" if @options.has_key?("workflow_id") || workflow_id id = (workflow_id ? workflow_id : @options["workflow_id"]) word_data = workflow(id).convert_data(filename, pdf_data, 'pdf', 'docx') else raise "No workflow id was specified" end return word_data end
verify_access_token()
click to toggle source
# File lib/easy_pdf_cloud.rb, line 51 def verify_access_token begin workflows() rescue => e puts e.message raise "Access denied to easypdfcloud.com API. Verify your access and/or refresh token." end end
workflow(id)
click to toggle source
# File lib/easy_pdf_cloud.rb, line 107 def workflow(id) Workflow.new(self, id) end
workflow_details(id)
click to toggle source
# File lib/easy_pdf_cloud.rb, line 101 def workflow_details(id) response = @access_token.get("#{@workflow_url}/#{id}") workflow_id = response.parsed["workflowID"].to_i Workflow.new(self, workflow_id) end
workflows()
click to toggle source
# File lib/easy_pdf_cloud.rb, line 94 def workflows check_access_token response = @access_token.get(@workflow_url) hash = response.parsed hash["workflows"] end