documentcloud 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +41 -17
- data/lib/document_cloud.rb +1 -0
- data/lib/document_cloud/api/create_project.rb +21 -0
- data/lib/document_cloud/api/entities.rb +24 -0
- data/lib/document_cloud/api/projects.rb +15 -0
- data/lib/document_cloud/api/update_project.rb +28 -0
- data/lib/document_cloud/api/utils.rb +10 -0
- data/lib/document_cloud/client.rb +8 -0
- data/lib/document_cloud/configurable.rb +6 -1
- data/lib/document_cloud/document.rb +5 -0
- data/lib/document_cloud/project.rb +18 -0
- data/lib/document_cloud/version.rb +3 -4
- metadata +23 -11
- checksums.yaml +0 -15
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
DocumentCloud RubyGem
|
2
2
|
=====================
|
3
3
|
|
4
|
-
|
4
|
+
[](http://badge.fury.io/rb/documentcloud)
|
5
|
+
|
6
|
+
Rubygem for interacting with the DocumentCloud API
|
7
|
+
|
5
8
|
|
6
9
|
|
7
10
|
## Usage
|
@@ -9,11 +12,10 @@ Rubygem for interacting with the DocumentCloud API.
|
|
9
12
|
```gem install documentcloud``` or put in your gemfile and ```bundle install```
|
10
13
|
|
11
14
|
then
|
12
|
-
|
13
|
-
```ruby
|
15
|
+
``` ruby
|
14
16
|
require 'documentcloud'
|
15
17
|
```
|
16
|
-
|
18
|
+
if not in Rails
|
17
19
|
|
18
20
|
To authenticate, initialize the configuration and pass in a block:
|
19
21
|
|
@@ -51,31 +53,53 @@ remote_doc = DocumentCloud.upload('http://somesite.com/file.pdf', 'Document Titl
|
|
51
53
|
Both return a document object which can then be used.
|
52
54
|
|
53
55
|
|
56
|
+
## Objects
|
57
|
+
|
58
|
+
This gem creates several objects built from the JSON response in order to provide convenience methods and accessors.
|
59
|
+
|
54
60
|
### Document
|
55
61
|
|
56
|
-
|
62
|
+
Document objects wrap any document JSON. They are returned in search results, upload, and document methods.
|
57
63
|
|
58
64
|
``` ruby
|
59
65
|
doc = DocumentCloud.document('1234-document-id')
|
60
|
-
```
|
61
|
-
|
62
66
|
|
67
|
+
# Accessors
|
68
|
+
doc.id
|
69
|
+
doc.title
|
70
|
+
doc.access
|
71
|
+
doc.pages
|
72
|
+
doc.description
|
73
|
+
doc.source
|
74
|
+
doc.canonical_url
|
75
|
+
doc.language
|
76
|
+
doc.display_langauge
|
77
|
+
|
78
|
+
# Methods
|
79
|
+
doc.pdf # Full URL to pdf
|
80
|
+
doc.print_annotations
|
81
|
+
doc.related_article
|
82
|
+
doc.text # Raw parsed text from document
|
83
|
+
doc.thumbnail # Primary thumbnail of document
|
84
|
+
|
85
|
+
# Images
|
86
|
+
doc.image(page, size) # Returns the image of a page at the specified size
|
87
|
+
```
|
63
88
|
|
64
|
-
###
|
65
|
-
|
66
|
-
Update a document by providing the file id, and any parameters you want to change.
|
89
|
+
### Search Results
|
90
|
+
SearchResults objects return information about the search, and an array of Document objects
|
67
91
|
|
68
92
|
``` ruby
|
69
|
-
|
70
|
-
```
|
71
|
-
|
93
|
+
results = DocumentCloud.search('my query')
|
72
94
|
|
73
|
-
|
95
|
+
results.total # Total number of results
|
96
|
+
results.page # The current results page. Used by specifying page param: DocumentCloud.search('my query', page: 2)
|
97
|
+
results.per_page # Number of results per page
|
98
|
+
results.query # Query string
|
74
99
|
|
75
|
-
|
100
|
+
results.documents # Array of documents of results:
|
76
101
|
|
77
|
-
|
78
|
-
DocumentCloud.destroy('1234-file-name')
|
102
|
+
results.documents[0].title # First result title
|
79
103
|
```
|
80
104
|
|
81
105
|
|
data/lib/document_cloud.rb
CHANGED
@@ -3,6 +3,7 @@ require 'multi_json'
|
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
require_relative 'document_cloud/document'
|
6
|
+
require_relative 'document_cloud/project'
|
6
7
|
require_relative 'document_cloud/search_results'
|
7
8
|
require_relative 'document_cloud/default'
|
8
9
|
require_relative 'document_cloud/configurable'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DocumentCloud
|
2
|
+
module API
|
3
|
+
module CreateProject
|
4
|
+
include DocumentCloud::API::Utils
|
5
|
+
PROJECTS_PATH = "/projects.json"
|
6
|
+
|
7
|
+
# Create new project
|
8
|
+
#
|
9
|
+
# @see http://www.documentcloud.org/help/api
|
10
|
+
# @param title [String] The document's canonical title
|
11
|
+
# @param options [Hash] Customizable set of options
|
12
|
+
# @param options [String] :description A paragraph of detailed description
|
13
|
+
# @param options [Array] :document_ids A list of documents that the project contains, by id
|
14
|
+
# @returns [DocumentCloud::Project] The project created
|
15
|
+
def create_project(title, options={})
|
16
|
+
build_object DocumentCloud::Project, post(PROJECTS_PATH, options.merge(title: title))
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DocumentCloud
|
2
|
+
module API
|
3
|
+
module Entities
|
4
|
+
include DocumentCloud::API::Utils
|
5
|
+
DOCUMENT_PATH = "/documents"
|
6
|
+
ENTITIES_PATH = "/entities.json"
|
7
|
+
|
8
|
+
# Fetch document entities
|
9
|
+
#
|
10
|
+
# @param id [String] The document id
|
11
|
+
# @returns [Hash] The fetched document entities
|
12
|
+
def entities(id)
|
13
|
+
parse_json(get(entities_path(id)))[:entities]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def entities_path(document_id)
|
19
|
+
"#{DOCUMENT_PATH}/#{document_id.to_s}/#{ENTITIES_PATH}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DocumentCloud
|
2
|
+
module API
|
3
|
+
module Projects
|
4
|
+
include DocumentCloud::API::Utils
|
5
|
+
PROJECTS_PATH = "/projects.json"
|
6
|
+
|
7
|
+
# List projects
|
8
|
+
#
|
9
|
+
# @returns [Hash] The fetched document entities
|
10
|
+
def projects
|
11
|
+
build_objects DocumentCloud::Project, get(PROJECTS_PATH)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DocumentCloud
|
2
|
+
module API
|
3
|
+
module UpdateProject
|
4
|
+
include DocumentCloud::API::Utils
|
5
|
+
PROJECT_PATH = "/projects"
|
6
|
+
|
7
|
+
# update a project
|
8
|
+
#
|
9
|
+
# @see http://www.documentcloud.org/help/api
|
10
|
+
# @param id [String] The project id
|
11
|
+
# @param options [Hash] Customizable set of options
|
12
|
+
# @param options [String] :title The document's canonical title
|
13
|
+
# @param options [String] :description A paragraph of detailed description
|
14
|
+
# @param options [Array] :document_ids A list of documents that the project contains, by id
|
15
|
+
# @returns [DocumentCloud::Project] The project created
|
16
|
+
def update_project(id, options={})
|
17
|
+
build_object(DocumentCloud::Project, put(project_path(id), options))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def project_path(project_id)
|
23
|
+
"#{PROJECT_PATH}/#{project_id.to_s}.json"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -9,9 +9,19 @@ module DocumentCloud
|
|
9
9
|
def build_object(object, json)
|
10
10
|
parsed = parse_json json
|
11
11
|
parsed = parsed[:document] if parsed[:document]
|
12
|
+
parsed = parsed[:project] if parsed[:project]
|
13
|
+
parsed = parsed[:projects] if parsed[:projects]
|
12
14
|
object.new(parsed)
|
13
15
|
end
|
14
16
|
|
17
|
+
def build_objects(object, json)
|
18
|
+
parsed = parse_json json
|
19
|
+
parsed = parsed[:document] if parsed[:document]
|
20
|
+
parsed = parsed[:project] if parsed[:project]
|
21
|
+
parsed = parsed[:projects] if parsed[:projects]
|
22
|
+
return parsed.map{|o| object.new(o) }
|
23
|
+
end
|
24
|
+
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
@@ -5,6 +5,10 @@ require_relative 'api/upload'
|
|
5
5
|
require_relative 'api/document'
|
6
6
|
require_relative 'api/update'
|
7
7
|
require_relative 'api/destroy'
|
8
|
+
require_relative 'api/entities'
|
9
|
+
require_relative 'api/projects'
|
10
|
+
require_relative 'api/create_project'
|
11
|
+
require_relative 'api/update_project'
|
8
12
|
|
9
13
|
module DocumentCloud
|
10
14
|
class Client
|
@@ -14,6 +18,10 @@ module DocumentCloud
|
|
14
18
|
include DocumentCloud::API::Document
|
15
19
|
include DocumentCloud::API::Update
|
16
20
|
include DocumentCloud::API::Destroy
|
21
|
+
include DocumentCloud::API::Entities
|
22
|
+
include DocumentCloud::API::Projects
|
23
|
+
include DocumentCloud::API::CreateProject
|
24
|
+
include DocumentCloud::API::UpdateProject
|
17
25
|
include DocumentCloud::Configurable
|
18
26
|
|
19
27
|
def initialize(options={})
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
module DocumentCloud
|
2
3
|
module Configurable
|
3
4
|
attr_writer :email, :password
|
@@ -12,6 +13,7 @@ module DocumentCloud
|
|
12
13
|
def configure
|
13
14
|
yield self
|
14
15
|
format_email!
|
16
|
+
format_password!
|
15
17
|
self
|
16
18
|
end
|
17
19
|
|
@@ -27,7 +29,10 @@ module DocumentCloud
|
|
27
29
|
|
28
30
|
# Ensure email is correct format for RestClient posts
|
29
31
|
def format_email!
|
30
|
-
@email.
|
32
|
+
@email = CGI.escape @email
|
33
|
+
end
|
34
|
+
def format_password!
|
35
|
+
@password = CGI.escape @password
|
31
36
|
end
|
32
37
|
|
33
38
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DocumentCloud
|
2
|
+
class Project
|
3
|
+
attr_reader :id, :title, :description
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
@id = attrs[:id]
|
7
|
+
@title = attrs[:title]
|
8
|
+
@description = attrs[:description]
|
9
|
+
@document_ids = attrs[:document_ids]
|
10
|
+
end
|
11
|
+
|
12
|
+
def documents
|
13
|
+
@documents ||= @document_ids.map {|id| DocumentCloud.document(id) }
|
14
|
+
@documents
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module DocumentCloud
|
2
2
|
class Version
|
3
3
|
MAJOR = 0 unless defined? DocumentCloud::Version::MAJOR
|
4
|
-
MINOR =
|
5
|
-
PATCH =
|
4
|
+
MINOR = 3 unless defined? DocumentCloud::Version::MINOR
|
5
|
+
PATCH = 1 unless defined? DocumentCloud::Version::PATCH
|
6
6
|
PRE = nil unless defined? DocumentCloud::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
@@ -13,7 +13,6 @@ module DocumentCloud
|
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
metadata
CHANGED
@@ -1,41 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: documentcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Miles Zimmerman
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-11-07 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest-client
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - ~>
|
19
|
+
- - "~>"
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 1.6.7
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - ~>
|
27
|
+
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 1.6.7
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: multi_json
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - ~>
|
35
|
+
- - "~>"
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '1.8'
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - ~>
|
43
|
+
- - "~>"
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '1.8'
|
41
46
|
description: Rubygem for interacting with the DocumentCloud API
|
@@ -48,16 +53,21 @@ files:
|
|
48
53
|
- LICENSE
|
49
54
|
- README.md
|
50
55
|
- documentcloud.gemspec
|
56
|
+
- lib/document_cloud/api/create_project.rb
|
51
57
|
- lib/document_cloud/api/destroy.rb
|
52
58
|
- lib/document_cloud/api/document.rb
|
59
|
+
- lib/document_cloud/api/entities.rb
|
60
|
+
- lib/document_cloud/api/projects.rb
|
53
61
|
- lib/document_cloud/api/search.rb
|
54
62
|
- lib/document_cloud/api/update.rb
|
63
|
+
- lib/document_cloud/api/update_project.rb
|
55
64
|
- lib/document_cloud/api/upload.rb
|
56
65
|
- lib/document_cloud/api/utils.rb
|
57
66
|
- lib/document_cloud/client.rb
|
58
67
|
- lib/document_cloud/configurable.rb
|
59
68
|
- lib/document_cloud/default.rb
|
60
69
|
- lib/document_cloud/document.rb
|
70
|
+
- lib/document_cloud/project.rb
|
61
71
|
- lib/document_cloud/search_results.rb
|
62
72
|
- lib/document_cloud/version.rb
|
63
73
|
- lib/document_cloud.rb
|
@@ -65,25 +75,27 @@ files:
|
|
65
75
|
homepage: https://github.com/mileszim/documentcloud
|
66
76
|
licenses:
|
67
77
|
- MIT
|
68
|
-
metadata: {}
|
69
78
|
post_install_message:
|
70
79
|
rdoc_options: []
|
71
80
|
require_paths:
|
72
81
|
- lib
|
73
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
74
84
|
requirements:
|
75
|
-
- -
|
85
|
+
- - ">="
|
76
86
|
- !ruby/object:Gem::Version
|
77
87
|
version: '0'
|
78
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- -
|
91
|
+
- - ">="
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '0'
|
83
94
|
requirements: []
|
84
95
|
rubyforge_project:
|
85
|
-
rubygems_version:
|
96
|
+
rubygems_version: 1.8.25
|
86
97
|
signing_key:
|
87
|
-
specification_version:
|
98
|
+
specification_version: 3
|
88
99
|
summary: Rubygem for interacting with the DocumentCloud API
|
89
100
|
test_files: []
|
101
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
MjI1MGE0NTU0MTRiMDk3ZmE4ODQ0NjAwNmNlODc3YWM4YTZiZWZmYQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MDkwYjFlNDRkZmRlZjRmMGNiNjVkNzE1OTEwNGNiZWMxZTE5ZDQ3NQ==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
OWIzMDcxMDk1ZWE1M2Q0NjNiNTVlZTc1MjUxNWFkOTE3NTQ5M2ViYzhhNjkz
|
10
|
-
MTIyNTYwMThmODBkOGUzMTc2YmU5NzE4MjE5NDg4ZDliMzhjN2NiYzg1YzU5
|
11
|
-
NTkxNzIyNWIzZTkyN2MyYmYwZDQ1YmQyYmE3MGM4YjM0MTQ0ZWY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzdkMTk5MDk1ODFjNTEyYjAzNWJjMDVkYWZmYjJhMWFjNDVlZjAzOWIxMzZk
|
14
|
-
ZDVjNDE5ZDRlYjBhZGQwZWIyZTk2ZTc1ZWIzNjEyMjhkMDJhYzNhODc5MzAx
|
15
|
-
Zjc1MGY3M2IyODQ3NWE1YTYzYjJiMWIxY2U4NzAzNWE0ZDFjNTI=
|