GithubHelp home page GithubHelp logo

kntyskw / box-view-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bgoldman/crocodoc-ruby

7.0 2.0 7.0 286 KB

Ruby wrapper for Crocodoc API

License: BSD 3-Clause "New" or "Revised" License

Shell 0.23% Ruby 99.77%

box-view-ruby's Introduction

box-view-ruby

Introduction

box-view-ruby is a Ruby wrapper for the Box View API (The new version of Crocodoc API). The Box View API lets you upload documents and then generate secure and customized viewing sessions for them. The API is based on REST principles and generally returns JSON encoded responses, and in Ruby are converted to hashes unless otherwise noted.

The gem is designed to keep the compatibility with the crocodoc gem so that it could work as a simple replacement for the gem. It is up to you to load this gem and do as follows to use it as the drop-in replacement and re-use your code that uses the Crocodoc API. The examples.rb works in that way. By the design, you may choose to use both versions at the same time.

Crocodoc = BoxView Crocodoc::Document.upload(...)

Installation

It has not been published as a gem since a more proper implementation may come from the Crocodoc team.

You can add it as a gem by using the bundler's git functionality.

gem "box-view-ruby", :git => "git://github.com/kntyskw/box-view-ruby"

You can also add the library as a submodule in your git project.

git submodule add [email protected]:kntyskw/box-view-ruby.git

You can also get the library by cloning or downloading.

To clone:

git clone [email protected]:kntyskw/box-view-ruby.git

To download:

wget https://github.com/kntyskw/box-view-ruby/zipball/master -O box-view-ruby.zip
unzip box-view-ruby.zip
mv kntyskw-box-view-ruby-* box-view-ruby

Require the library into any of your Ruby files.

If you have the files locally:

require_relative /path/to/box-view-ruby/crocodoc.rb

Please note that this library also requires that the 'rest-client' gem is installed, and a version of Ruby >= 1.9.

Getting Started

You can see a number of examples on how to use this library in examples.rb. These examples are interactive and you can run this file to see crocodoc-ruby in action.

To run these examples, open up examples.rb and change this line to show your API token:

BoxView.api_token = 'YOUR_API_TOKEN'

Save the file, make sure the example-files directory is writeable, and then run examples.rb:

ruby examples.rb

You should see 7 examples run with output in your terminal. You can inspect the examples.rb code to see each API call being used.

To start using box-view-ruby in your code, set your API token:

BoxView.api_token = 'YOUR_API_TOKEN'

And now you can start using the methods in BoxView::Document, BoxView::Download, and BoxView::Session.

Read on to find out more how to use crocodoc-ruby. You can also find more detailed information about our API here: https://crocodoc.com/docs/api/

Using the Crocodoc API Library

Errors

Errors are handled by throwing exceptions. We throw instances of CrocodocError.

Note that any Crocodoc API call can throw an exception. When making API calls, put them in a begin/rescue block. You can see examples.rb to see working code for each method using begin/rescue blocks.

Document

These methods allow you to upload, check the status of, and delete documents.

Upload

http://developers.box.com/view/ To upload a document, use BoxView::Document.upload(). Pass in a url (as a string). Note that passing a file resource object is NOT supported by Box API. This function returns a UUID of the file.

// with a url
uuid = BoxView::Document.upload(url)

Status

http://developers.box.com/view/ To check the status of a document, use BoxView::Document.status(). Pass in the UUID of the file you want to check the status of. This function returns a hash containing a "status" string" and a "viewable" boolean. Note that passing an array instead of a string is not supported at this time

// status contains status['status'] and status['viewable']
status = BoxView::Document.status(uuid)

// The foollowing is not supported right now .
//statuses = BoxView::Document.status([uuid, uuid2])

Delete

http://developers.box.com/view/ To delete a document, use BoxView::Document.delete(). Pass in the UUID of the file you want to delete. This function returns a boolean of whether the document was successfully deleted or not.

deleted  = BoxView::Document.delete(uuid)

Download

These methods allow you to download documents from Crocodoc in different ways. You can download PDF or ZIP archive of SVG files. Note that extracting text and thumbnails is not supported.

Document

http://developers.box.com/view/ To download a document, use BoxView::Download.document(). Pass in the uuid, an optional boolean of whether or not the file should be downloaded as a PDF. This function returns the file contents as a string, which you probably want to save to a file.

// with no optional arguments
file = BoxView::Download.document(uuid)
file_handle.write(file)

// with all optional arguments
file = BoxView::Download.document(uuid, true)
file_handle.write(file)

Thumbnail

Currently not supported because the Box API does not provide the equivalent functionality as of writing.

Text

Currently not supported because the Box API does not provide the equivalent functionality as of writing.

Session

The session method allows you to create a session for viewing documents in a secure manner.

Create

http://developers.box.com/view/ To get a session key, use BoxView::Session.create(). Pass in the uuid and optionally a params hash. This function returns a session key.

// without optional params
session_key = BoxView::Session.create(uuid)

Support

Please use github's issue tracker for API library support.

box-view-ruby's People

Contributors

bgoldman avatar kntyskw avatar bennettrogers avatar lassy avatar rlivsey avatar

Stargazers

 avatar Gerardo Ortega avatar Chirag Aggarwal avatar Andrew Gertig avatar Josh Powell avatar Malachai avatar sean rose avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.