crocodoc 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2013, Crocodoc
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ 3. Neither the name of Crocodoc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -8,7 +8,16 @@ Our API is based on REST principles and generally returns JSON encoded responses
8
8
  and in Ruby are converted to hashes unless otherwise noted.
9
9
 
10
10
  ## Installation
11
- You can get the library by cloning or downloading the repo.
11
+
12
+ We suggest installing the library as a gem.
13
+
14
+ gem install crocodoc
15
+
16
+ You can also add the library as a submodule in your git project.
17
+
18
+ git submodule add git@github.com:crocodoc/crocodoc-ruby.git
19
+
20
+ You can also get the library by cloning or downloading.
12
21
 
13
22
  To clone:
14
23
 
@@ -95,7 +104,7 @@ Pass in the UUID of the file or an array of UUIDS you want to check the status o
95
104
  This function returns a hash containing a "status" string" and a "viewable" boolean.
96
105
  If you passed in an array instead of a string, this function returns an array of hashes containing the status for each file.
97
106
 
98
- // $status contains status['status'] and status['viewable']
107
+ // status contains status['status'] and status['viewable']
99
108
  status = Crocodoc::Document.status(uuid)
100
109
 
101
110
  // statuses contains an array of status hashes
@@ -188,7 +197,7 @@ This function returns a session key.
188
197
  'is_copyprotected' => false,
189
198
  'is_demo' => false,
190
199
  'sidebar' => 'visible'
191
- ))
200
+ })
192
201
 
193
202
  ## Support
194
203
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
data/crocodoc.gemspec CHANGED
@@ -1,8 +1,10 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
2
 
3
+ require 'crocodoc/version'
4
+
3
5
  spec = Gem::Specification.new do |s|
4
6
  s.name = 'crocodoc'
5
- s.version = '1.0.0'
7
+ s.version = Crocodoc::VERSION
6
8
  s.summary = 'Ruby wrapper for the Crocodoc API'
7
9
  s.description = 'The Crocodoc API lets you upload documents and then generate secure and customized viewing sessions for them. See https://crocodoc.com for details.'
8
10
  s.authors = ['Brandon Goldman']
@@ -15,4 +17,4 @@ spec = Gem::Specification.new do |s|
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.require_paths = ['lib']
18
- end
20
+ end
data/examples.rb CHANGED
@@ -324,7 +324,7 @@ session_key = nil
324
324
  begin
325
325
  user = {'id' => 1,
326
326
  'name' => 'John Crocodoc'}
327
- session_key = Crocodoc::Session.create(uuid2, {'isEditable' => true,
327
+ session_key = Crocodoc::Session.create(uuid2, {'is_editable' => true,
328
328
  'user' => user,
329
329
  'filter' => 'all',
330
330
  'is_admin' => true,
@@ -360,4 +360,4 @@ rescue CrocodocError => e
360
360
  puts 'failed :('
361
361
  puts ' Error Code: ' + e.code
362
362
  puts ' Error Message: ' + e.message
363
- end
363
+ end
data/lib/crocodoc.rb CHANGED
@@ -76,7 +76,7 @@ module Crocodoc
76
76
  def self._error(error, client, method, response)
77
77
  message = self.name + ': [' + error + '] ' + client + '.' + String(method) + "\r\n\r\n"
78
78
  response = JSON.generate(response) if response.is_a? Hash
79
- message += response
79
+ message += response unless response.nil?
80
80
  raise CrocodocError.new(message, error)
81
81
  end
82
82
 
@@ -128,7 +128,7 @@ module Crocodoc
128
128
 
129
129
  if result == 'true'
130
130
  json_decoded = true
131
- elsif result == 'false'
131
+ elsif result == 'false' or result == ''
132
132
  json_decoded = false
133
133
  else
134
134
  json_decoded = JSON.parse(result)
@@ -136,42 +136,42 @@ module Crocodoc
136
136
 
137
137
  if json_decoded == false
138
138
  return self._error('server_response_not_valid_json', self.name, __method__, {
139
- response => result,
140
- get_params => get_params,
141
- post_params => post_params
139
+ response: result,
140
+ get_params: get_params,
141
+ post_params: post_params
142
142
  })
143
143
  end
144
144
 
145
145
  if json_decoded.is_a? Hash and json_decoded.has_key? 'error'
146
146
  return self._error(json_decoded['error'], self.name, __method__, {
147
- get_params => get_params,
148
- post_params => post_params
147
+ get_params: get_params,
148
+ post_params: post_params
149
149
  })
150
150
  end
151
151
 
152
152
  result = json_decoded
153
153
  end
154
154
 
155
- http_4xx_error_codes = {'400' => 'bad_request',
156
- '401' => 'unauthorized',
157
- '404' => 'not_found',
158
- '405' => 'method_not_allowed'}
155
+ http_4xx_error_codes = {400 => 'bad_request',
156
+ 401 => 'unauthorized',
157
+ 404 => 'not_found',
158
+ 405 => 'method_not_allowed'}
159
159
 
160
160
  if http_4xx_error_codes.has_key? http_code
161
- error = 'server_error_' + http_code + '_' + http_4xx_error_codes[http_code]
161
+ error = 'server_error_' + http_code.to_s + '_' + http_4xx_error_codes[http_code]
162
162
  return self._error(error, self.name, __method__, {
163
- url => url,
164
- get_params => get_params,
165
- postParams => post_params
163
+ url: url,
164
+ get_params: get_params,
165
+ post_params: post_params
166
166
  })
167
167
  end
168
168
 
169
169
  if http_code >= 500 and http_code < 600
170
- error = 'server_error_' + http_code + '_unknown'
170
+ error = 'server_error_' + http_code.to_s + '_unknown'
171
171
  return self._error(error, self.name, __method__, {
172
- url => url,
173
- get_params => get_params,
174
- post_params => post_params
172
+ url: url,
173
+ get_params: get_params,
174
+ post_params: post_params
175
175
  })
176
176
  end
177
177
 
@@ -22,7 +22,7 @@ module Crocodoc
22
22
  # @return [Boolean] Was the file deleted?
23
23
  # @raise [CrocodocError]
24
24
  def self.delete(uuid)
25
- post_params = {'uuid' => uuid}
25
+ post_params = {uuid: uuid}
26
26
  Crocodoc._request(self.path, 'delete', nil, post_params)
27
27
  end
28
28
 
@@ -39,9 +39,9 @@ module Crocodoc
39
39
  # bool, or an array of the uuid and an error
40
40
  # @raise [CrocodocError]
41
41
  def self.status(uuids)
42
- is_single_uuid = uuids.is_a? String
42
+ is_single_uuid = !(uuids.is_a? Array)
43
43
  uuids = [uuids] if is_single_uuid
44
- get_params = {'uuids' => uuids.join(',')}
44
+ get_params = {uuids: uuids.join(',')}
45
45
  response = Crocodoc._request(self.path, 'status', get_params, nil)
46
46
  is_single_uuid ? response[0] : response
47
47
  end
@@ -57,7 +57,7 @@ module Crocodoc
57
57
 
58
58
  if url_or_file.is_a? String
59
59
  post_params['url'] = url_or_file
60
- elsif url_or_file.is_a? File
60
+ elsif url_or_file.respond_to?(:read) && url_or_file.respond_to?(:path)
61
61
  post_params['file'] = url_or_file
62
62
  else
63
63
  return Crocodoc::_error('invalid_url_or_file_param', self.name, __method__, nil)
@@ -30,7 +30,7 @@ module Crocodoc
30
30
  # @return [String] The downloaded file contents as a string
31
31
  # @raise CrocodocError
32
32
  def self.document(uuid, is_pdf=false, is_annotated=false, filter=nil)
33
- get_params = {'uuid' => uuid}
33
+ get_params = {uuid: uuid}
34
34
  get_params['pdf'] = 'true' if is_pdf
35
35
  get_params['annotated'] = 'true' if is_annotated
36
36
 
@@ -49,7 +49,7 @@ module Crocodoc
49
49
  # @return [String] The file's extracted text
50
50
  # @raise CrocodocError
51
51
  def self.text(uuid)
52
- get_params = {'uuid' => uuid}
52
+ get_params = {uuid: uuid}
53
53
  Crocodoc._request(self.path, 'text', get_params, nil, false)
54
54
  end
55
55
 
@@ -62,7 +62,7 @@ module Crocodoc
62
62
  # @return [String] The downloaded thumbnail contents
63
63
  # @raise CrocodocError
64
64
  def self.thumbnail(uuid, width=nil, height=nil)
65
- get_params = {'uuid' => uuid}
65
+ get_params = {uuid: uuid}
66
66
 
67
67
  if width != nil and height != nil
68
68
  get_params['size'] = String(width) + 'x' + String(height)
@@ -43,7 +43,7 @@ module Crocodoc
43
43
  # @return [String] A unique session key for the document
44
44
  # @raise [CrocodocError]
45
45
  def self.create(uuid, params = {})
46
- post_params = {'uuid' => uuid}
46
+ post_params = {uuid: uuid}
47
47
 
48
48
  if params.has_key? 'is_editable'
49
49
  post_params['editable'] = params['is_editable'] ? 'true' : 'false'
@@ -0,0 +1,3 @@
1
+ module Crocodoc
2
+ VERSION = '1.0.1'
3
+ end
@@ -1,6 +1,6 @@
1
1
  # CrocodocError extends the default exception class.
2
2
  # It adds a code field.
3
- class CrocodocError < Exception
3
+ class CrocodocError < StandardError
4
4
  # An error code string
5
5
  @code = nil
6
6
 
@@ -10,7 +10,7 @@ class CrocodocError < Exception
10
10
  end
11
11
 
12
12
  def initialize(message, code)
13
- @message = message
13
+ super message
14
14
  @code = code
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,65 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: crocodoc
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Brandon Goldman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-19 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rest-client
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 1
31
- - 4
32
- version: "1.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: json
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.4'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
34
+ requirements:
41
35
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 13
44
- segments:
45
- - 1
46
- - 1
47
- version: "1.1"
36
+ - !ruby/object:Gem::Version
37
+ version: '1.1'
48
38
  type: :runtime
49
- version_requirements: *id002
50
- description: The Crocodoc API lets you upload documents and then generate secure and customized viewing sessions for them. See https://crocodoc.com for details.
51
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
46
+ description: The Crocodoc API lets you upload documents and then generate secure and
47
+ customized viewing sessions for them. See https://crocodoc.com for details.
48
+ email:
52
49
  - brandon.goldman@gmail.com
53
50
  executables: []
54
-
55
51
  extensions: []
56
-
57
52
  extra_rdoc_files: []
58
-
59
- files:
53
+ files:
60
54
  - .gitignore
61
55
  - Gemfile
56
+ - LICENSE
62
57
  - README.md
58
+ - VERSION
63
59
  - crocodoc.gemspec
64
60
  - example-files/form-w4.pdf
65
61
  - examples.rb
@@ -67,39 +63,30 @@ files:
67
63
  - lib/crocodoc/document.rb
68
64
  - lib/crocodoc/download.rb
69
65
  - lib/crocodoc/session.rb
66
+ - lib/crocodoc/version.rb
70
67
  - lib/crocodoc_error.rb
71
68
  homepage: https://crocodoc.com/docs/api/
72
69
  licenses: []
73
-
74
70
  post_install_message:
75
71
  rdoc_options: []
76
-
77
- require_paths:
72
+ require_paths:
78
73
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
80
75
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
81
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
97
86
  requirements: []
98
-
99
87
  rubyforge_project:
100
- rubygems_version: 1.7.2
88
+ rubygems_version: 1.8.24
101
89
  signing_key:
102
90
  specification_version: 3
103
91
  summary: Ruby wrapper for the Crocodoc API
104
92
  test_files: []
105
-