boxview.rb 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b44aa6beac971dcb737e5768add6befed15c954b
4
+ data.tar.gz: 633b1da4ac6018885ae47560953cca745dd731e4
5
+ SHA512:
6
+ metadata.gz: 39007b6bc039d226e1949cecd361c45241db863ae775318c4adf3018a4d1b92436cff4104d6763bb36c92310ceda4274346864ce966adcd680c36a63f9310352
7
+ data.tar.gz: fcc92cca72d8a7e916e10d217b5b904e4560c15d7d70ebd25b6634ba5dc10a73b46a4d98c9d297e87a6b87bd811f9a19c95cba6c547d086e424e37e5332a21fd
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ boxviewrb
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p451
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ env:
3
+ global:
4
+ # BoxView API Key
5
+ secure: "G+bXUR1HcHzq6YoJwX34jh2LYCuIr/6N7nm2jQxfcUTo9LHpO+8xrCLWPGMiEPp1DOIHYbxL5Me6IJHZeQh2Z4Oh0EtyCN+3knXmEb6OZkR1UGKCi6MhROFn/TSqm768JchDGfVo8Z5FhVKzrGPgVmJTKqv7VqGT0coJ8emAyy8="
6
+ rvm:
7
+ - 2.0.0
8
+ - 2.1.0
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - vinny@getlua.com
13
+ on_success: change
14
+ on_failure: always
15
+ branches:
16
+ only:
17
+ - master
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Vincent Taverna
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # boxviewrb
2
+
3
+ [![Build Status](https://magnum.travis-ci.com/getlua/boxviewrb.svg?token=Huix46oxRzp8K3EvAxpb&branch=master)](https://magnum.travis-ci.com/getlua/boxviewrb)
4
+
5
+ A BoxView API wrapper. Built using the power of HTTParty to communicate with the BoxView API. The BoxView API has added some new features and improved documentation, this lib takes care of all of those new additions for you. You can learn more at the [developer page](http://developers.box.com/view/). Note this product and API are still in beta, and likely to change in the future. Boxviewrb works with all available requests that are documented by BoxView at the time of writing.
6
+
7
+ ##### Table of Contents
8
+ * [Installation](#installation)
9
+ * [Usage](#usage)
10
+ * [Configuration](#configuration)
11
+ * [Document](#document)
12
+ * [Create](#create_document)
13
+ * [MultiPart](#multipart)
14
+ * [List](#list)
15
+ * [Show](#show)
16
+ * [Update](#update)
17
+ * [Delete](#delete)
18
+ * [Thumbnail](#thumbnail)
19
+ * [Assets](#assets)
20
+ * [Session](#session)
21
+ * [Create](#create_session)
22
+ * [Convenience Methods](#convenience_methods)
23
+ * [Never Expire](#never_expire)
24
+ * [View](#create_session)
25
+ * [ViewerJS URL](#viewerjs_url)
26
+ * [Viewer URL](#viewer_url)
27
+ * [Supported MIMETypes](#supported_mimetypes)
28
+ * [Supported File Extensions](#supported_file_extensions)
29
+ * [Contributing](#contributing)
30
+ * [Author](#author)
31
+ * [License](#license)
32
+
33
+ <a name="installation"/>
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ gem 'boxviewrb'
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install boxviewrb
47
+
48
+ <a name="usage"/>
49
+ ## Usage
50
+
51
+ <a name="configuration"/>
52
+ ### Configuration
53
+
54
+ Defining an api key is the only required configuration. To get your own API Key, visit [Box and get a developer account](https://app.box.com/developers/services). Then create a new Box View application. Scroll to the bottom of the application settings page to find your api key.
55
+
56
+ ```ruby
57
+ BoxView.api_key = "#{BOXVIEW_APIKEY}" # Example: 'gyheecmm6ckk8jutlowlzfh2tbg72kck'
58
+ ```
59
+
60
+ <a name="document"/>
61
+ ### Document
62
+
63
+ <a name="create_document"/>
64
+ #### Create
65
+
66
+ See below for how to create a document using boxviewrb. Not all the paramaters used are required. The url is the only parameter that will be necessary in order to make a successful call with the BoxView API. Name refers to the name of the document. Non_SVG refers to whether you want to support browsers that cannot support svg. The Height and Width parameters refer to the size of a thumbnail that will give Box an early start to generating your thumbnail for you. You must still make a second request for a thumbnail, but it will be made available sooner upon request.
67
+
68
+ After this call is made, the BoxView API will return with a response. Boxviewrb will automatically have the document id available when the response is returned, call `BoxView.document_id` to retrieve it. If the call to BoxView fails, a specific error will be raised depending on what went wrong.
69
+
70
+ Required: `url`
71
+
72
+ Optional: `name`, `non_svg`, `width and height`
73
+
74
+ ```ruby
75
+ BoxView::Document.create
76
+ url: 'http://seriousmonkeybusiness.com/chimpanzee.docx',
77
+ name: 'chimpanzee',
78
+ non_svg: true,
79
+ width: 100,
80
+ height: 100
81
+ ```
82
+
83
+ <a name="multipart"/>
84
+ #### MultiPart
85
+
86
+ If you have access to the actual file you want to upload to box, you can directly upload it via a multipart upload. This method requires the path to the file to be specified in order for it to send the file to box. If the filepath does not exist, an error will be thrown. The other params (name, thumbnail and non_svg) are the same as the create request params.
87
+
88
+ Required: `filepath`
89
+
90
+ Optional: `name`, `non_svg`, `width and height`
91
+
92
+ ```ruby
93
+ BoxView::Document.multipart
94
+ filepath: '/Documents/sample.docx',
95
+ name: 'sample',
96
+ non_svg: true,
97
+ width: 100,
98
+ height: 100
99
+ ```
100
+
101
+ <a name="list"/>
102
+ #### List
103
+
104
+ This request will respond with a list of all the documents that are currently tied to the api key that has been supplied. Delete requests will remove documents from this list. This method returns the response untouched.
105
+
106
+ ```ruby
107
+ BoxView::Document.list
108
+ ```
109
+
110
+ <a name="show"/>
111
+ #### Show
112
+
113
+ Returns the metadata for a single document based on a specified document id. If the document has successfully been generated by box, the status of the document will be 'done'. If not the status will be 'error'. The status is returned in the response when calling show.
114
+
115
+ Required: `document_id`
116
+
117
+ ```ruby
118
+ BoxView::Document.show document_id: '937778a1a54b4337a5351a78f7188a24'
119
+ ```
120
+
121
+ <a name="update"/>
122
+ #### Update
123
+
124
+ Update the metadata of a single document based on a specified document id. Only the name can be updated at this time.
125
+
126
+ Required: `document_id`, `name`
127
+
128
+ ```ruby
129
+ BoxView::Document.update
130
+ document_id: '937778a1a54b4337a5351a78f7188a24',
131
+ name: 'recipes'
132
+ ```
133
+
134
+ <a name="delete"/>
135
+ #### Delete
136
+
137
+ Removes a previously created document from the Box View servers. This request is destructive.
138
+
139
+ Required: `document_id`
140
+
141
+ ```ruby
142
+ BoxView::Document.delete document_id: '937778a1a54b4337a5351a78f7188a24'
143
+ ```
144
+
145
+ <a name="thumbnail"/>
146
+ #### Thumbnail
147
+
148
+ A request to retrieve a thumbnail representation of a document. A document id must be specified in order to make the request. If the server response contains the response code `202` then the retry after attribute will be available when calling `BoxView::Document.retry_after`. This can be useful if Box is rate limiting.
149
+
150
+ Required: `document_id`, `width and height`
151
+
152
+ ```ruby
153
+ BoxView::Document.thumbnail
154
+ document_id: '937778a1a54b4337a5351a78f7188a24',
155
+ width: 100,
156
+ height: 100
157
+ ```
158
+
159
+ <a name="assets"/>
160
+ #### Assets
161
+
162
+ A request to retrieve a pdf or zip of the asset that was uploaded. The document will be retrieved as a pdf or zip. The zip contains compressed css/js/html that make up the converted document. This can be used in junction with viewerjs. This request defaults to zip if no type is specified.
163
+
164
+ Required: `document_id`, `type`
165
+
166
+ ```ruby
167
+ BoxView::Document.assets
168
+ document_id: '937778a1a54b4337a5351a78f7188a24',
169
+ type: 'pdf'
170
+ ```
171
+
172
+ <a name="session"/>
173
+ ### Session
174
+
175
+ <a name="create_session"/>
176
+ #### Create
177
+
178
+ Generating a document will give you a document id. Next you can create a session using this id. The session will begin the conversion process of the document. When Box is done converting your document it will be available to download through the assets method or the viewer url convenience method. A session expires after a set amount of time. You can set a duration or an expiration date for the session. If left blank, the session is set by box by default to expire in 60 minutes. Duration is marked in minutes. Expiration date is a timestamp. The variable is_downloadable refers to whether or not the box viewer will display a download button or not. If the server response contains the response code `202` then the retry after attribute will be available when calling `BoxView::Session.retry_after`.
179
+
180
+ After successfully generating a session, the session id will be available. You can either parse it out of the response that is returned, or just call `BoxView.session_id`.
181
+
182
+ Required: `document_id`
183
+
184
+ Optional: `duration`, `expiration_date`, `is_downloadable`
185
+
186
+ ```ruby
187
+ BoxView::Session.create
188
+ document_id: '937778a1a54b4337a5351a78f7188a24',
189
+ duration: 100,
190
+ expiration_date: (Time.now + 100.minutes),
191
+ is_downloadable: true
192
+ ```
193
+
194
+ <a name="convenience_methods"/>
195
+ ### Convenience Methods
196
+
197
+ <a name="never_expire"/>
198
+ #### Never Expire
199
+
200
+ When generating a session if you want your session to last for a very long time (a thousand years) call this method.
201
+
202
+ ```ruby
203
+ BoxView::Session.never_expire
204
+ ```
205
+
206
+ <a name="view"/>
207
+ #### View
208
+
209
+ Opens a default browser using the viewer url to view a BoxView converted document. Requires a `session_id`.
210
+
211
+ ```ruby
212
+ BoxView::Session.view
213
+ ```
214
+
215
+ <a name="viewerjs_url"/>
216
+ #### ViewerJS URL
217
+
218
+ This url can be used with viewerjs to display the assets without using the Box iframe or downloading the assets yourself. Requires a `session_id`.
219
+
220
+ ```ruby
221
+ BoxView::Session.viewerjs_url
222
+ ```
223
+
224
+ <a name="viewer_url"/>
225
+ #### Viewer URL
226
+
227
+ The url used in the view method. Can be used in an iframe to display the converted document. Requires a `session_id`.
228
+
229
+ ```ruby
230
+ BoxView::Session.viewer_url
231
+ ```
232
+
233
+ <a name="supported_mimetypes"/>
234
+ #### Supported MIMETypes
235
+
236
+ Returns an array containing all the mimetypes that BoxView is known to support.
237
+
238
+ ```ruby
239
+ BoxView::Document.supported_mimetypes
240
+ ```
241
+
242
+ <a name="supported_file_extensions"/>
243
+ #### Supported File Extensions
244
+
245
+ Returns an array containing all the extensions of filetypes that BoxView is known to support.
246
+
247
+ ```ruby
248
+ BoxView::Document.supported_file_extensions
249
+ ```
250
+
251
+ <a name="contributing"/>
252
+ ## Contributing
253
+
254
+ 1. Fork it ( https://github.com/[my-github-username]/boxviewrb/fork )
255
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
256
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
257
+ 4. Push to the branch (`git push origin my-new-feature`)
258
+ 5. Create a new Pull Request
259
+
260
+ <a name="author"/>
261
+ ## Author
262
+
263
+ Vincent Taverna, vinny@getlua.com, [vinnymac.github.io](http://vinnymac.github.io)
264
+
265
+ <a name="license"/>
266
+ ## License
267
+
268
+ boxviewrb is available under the MIT license. See the [LICENSE](LICENSE.txt) file for more information.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'boxview/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "boxview.rb"
9
+ spec.version = BoxView::VERSION
10
+ spec.authors = ["Vincent Taverna"]
11
+ spec.email = ["vinnymac@gmail.com"]
12
+ spec.summary = "Wrapper for the BoxView API"
13
+ spec.description = "Box View converts PDF and Office documents to HTML thus enabling these files to be easily embedded into web and mobile applications."
14
+ spec.homepage = "http://developers.box.com/view/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_runtime_dependency 'httmultiparty', '~> 0.3.14'
26
+ end
data/lib/boxview.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'httmultiparty'
2
+
3
+ require_relative 'boxview/document'
4
+ require_relative 'boxview/session'
5
+ require_relative 'boxview/errors'
6
+
7
+ module BoxView
8
+ include HTTMultiParty
9
+
10
+ BASE_URI = 'https://view-api.box.com'
11
+
12
+ MULTIPART_URI = 'https://upload.view-api.box.com'
13
+
14
+ BASE_PATH = '/1'
15
+
16
+ base_uri BASE_URI
17
+
18
+ class << self
19
+
20
+ attr_accessor :api_key, :document_id, :session_id
21
+
22
+ # Description:
23
+ # =>
24
+ # No Params!
25
+ def headers
26
+ {
27
+ 'Authorization' => "Token #{api_key}",
28
+ 'Content-type' => 'application/json'
29
+ }
30
+ end
31
+
32
+ # Description:
33
+ # =>
34
+ # No Params!
35
+ def api_key
36
+ raise BoxView::Errors::ApiKeyNotFound if @api_key.nil?
37
+ @api_key
38
+ end
39
+
40
+ # Description:
41
+ # =>
42
+ # No Params!
43
+ def document_id
44
+ raise BoxView::Errors::DocumentIdNotFound if @document_id.nil?
45
+ @document_id
46
+ end
47
+
48
+ # Description:
49
+ # =>
50
+ # No Params!
51
+ def session_id
52
+ raise BoxView::Errors::SessionIdNotFound if @session_id.nil?
53
+ @session_id
54
+ end
55
+ end
56
+ end