openstax_content 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +98 -0
- data/lib/openstax/content/version.rb +1 -1
- data/lib/{openstax/content.rb → openstax_content.rb} +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 578cf5b445c79d9e7dd1a904da90cb3daf527d2d8b7de128d07640e15d8bd066
|
4
|
+
data.tar.gz: b2bfe3524398a047b6722a047aa245de8ed52d02e4c9c37ca28f0b36840ba081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f7708cce0fb71727d985dcef91f6b0844f1b3ba2b134a55cc6f4eb3bddf0132c633cce04ed8221d16f8aac785a08f1ef16fe17e6f184c7f481c479054e496b
|
7
|
+
data.tar.gz: 07bd028f00e935ef240585da56b2fd88e82959da61213787f03421e1f07c0afecb8f3257b9b269ff1affea5483a227f70d299e1782a528e7ebb1c4d96dd2dd6b
|
data/README.md
CHANGED
@@ -1,2 +1,100 @@
|
|
1
|
+
[![Tests](https://github.com/openstax/content-ruby/workflows/Tests/badge.svg)](https://github.com/openstax/content-ruby/actions/workflows/tests.yml)
|
2
|
+
|
1
3
|
# content-ruby
|
2
4
|
Ruby bindings to read and parse the OpenStax ABL and the content archive
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Add this gem to your Gemfile and then add the following configuration to your boot
|
8
|
+
(for example, in a Rails initializer):
|
9
|
+
|
10
|
+
```rb
|
11
|
+
OpenStax::Content.configure do |config|
|
12
|
+
config.abl_url = ENV['OPENSTAX_CONTENT_ABL_URL']
|
13
|
+
config.archive_path = ENV['OPENSTAX_CONTENT_ARCHIVE_PATH']
|
14
|
+
config.bucket_name = ENV['OPENSTAX_CONTENT_BUCKET_NAME']
|
15
|
+
config.domain = ENV['OPENSTAX_CONTENT_DOMAIN']
|
16
|
+
config.exercises_search_api_url = ENV['OPENSTAX_CONTENT_EXERCISES_SEARCH_API_URL']
|
17
|
+
config.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
18
|
+
config.s3_region = ENV['OPENSTAX_CONTENT_S3_REGION']
|
19
|
+
config.s3_access_key_id = ENV['OPENSTAX_CONTENT_S3_ACCESS_KEY_ID']
|
20
|
+
config.s3_secret_access_key = ENV['OPENSTAX_CONTENT_S3_SECRET_ACCESS_KEY']
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
It's probably a good idea to read these values from environment variables
|
25
|
+
s3_access_key_id and s3_secret_access_key are optional (you can use AWS instance roles instead)
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Approved Book List (to get approved books and approved versions)
|
30
|
+
```rb
|
31
|
+
abl = OpenStax::Content::Abl.new
|
32
|
+
approved_books = abl.approved_books
|
33
|
+
approved_versions = abl.approved_versions
|
34
|
+
```
|
35
|
+
|
36
|
+
### S3 Bucket Listing (to get latest archive and book versions)
|
37
|
+
```rb
|
38
|
+
s3 = OpenStax::Content::S3.new
|
39
|
+
if s3.bucket_configured?
|
40
|
+
latest_archive_version = s3.ls.last
|
41
|
+
latest_book_ids = s3.ls latest_archive_version
|
42
|
+
chosen_book = latest_book_ids.sample
|
43
|
+
book_uuid, book_version = chosen_book.split('@', 2)
|
44
|
+
book = OpenStax::Content::Book.new(
|
45
|
+
archive_version: latest_archive_version, uuid: book_uuid, version: book_version
|
46
|
+
)
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
### Archive (to create archive links, load content and get book and page slugs)
|
51
|
+
```rb
|
52
|
+
archive = OpenStax::Content::Archive.new latest_archive_version
|
53
|
+
|
54
|
+
book_id = "#{book_uuid}@#{book_version}"
|
55
|
+
page_id = "#{book_id}:#{page_uuid}"
|
56
|
+
|
57
|
+
book_url = archive.url_for book_id
|
58
|
+
page_url = archive.url_for page_id
|
59
|
+
|
60
|
+
book_json = archive.fetch book_id
|
61
|
+
page_json = archive.fetch page_id
|
62
|
+
|
63
|
+
book_hash = archive.json book_id
|
64
|
+
page_hash = archive.json page_id
|
65
|
+
|
66
|
+
book_slug = archive.slug book_id # or book_uuid
|
67
|
+
page_slug = archive.slug page_id # or "#{book_uuid}:#{page_uuid}"
|
68
|
+
```
|
69
|
+
|
70
|
+
### Fragment Splitter (to split pages and create interactive readings)
|
71
|
+
```rb
|
72
|
+
fragment_splitter = OpenStax::Content::FragmentSplitter.new(
|
73
|
+
book.reading_processing_instructions, reference_view_url
|
74
|
+
)
|
75
|
+
fragment_splitter.split_into_fragments page.root
|
76
|
+
```
|
77
|
+
|
78
|
+
## Testing
|
79
|
+
|
80
|
+
To run all existing tests for this gem, simply execute the following from the main folder:
|
81
|
+
|
82
|
+
```sh
|
83
|
+
$ rake
|
84
|
+
```
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork the openstax/content-ruby repo on Github
|
89
|
+
2. Create a feature or bugfix branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Write tests for the feature/bugfix
|
91
|
+
4. Implement the new feature/bugfix
|
92
|
+
5. Make sure both new and old tests pass (`rake`)
|
93
|
+
6. Commit your changes (`git commit -am 'Added some feature'`)
|
94
|
+
7. Push the branch (`git push origin my-new-feature`)
|
95
|
+
8. Create a new Pull Request to openstax/content-ruby on Github
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
This gem is distributed under the terms of the AGPLv3 license.
|
100
|
+
See the LICENSE file for details.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dante Soares
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Ruby bindings to read and parse the OpenStax ABL and the content archive
|
112
140
|
email:
|
113
141
|
- dante.m.soares@rice.edu
|
@@ -117,7 +145,6 @@ extra_rdoc_files: []
|
|
117
145
|
files:
|
118
146
|
- LICENSE
|
119
147
|
- README.md
|
120
|
-
- lib/openstax/content.rb
|
121
148
|
- lib/openstax/content/abl.rb
|
122
149
|
- lib/openstax/content/archive.rb
|
123
150
|
- lib/openstax/content/book.rb
|
@@ -136,6 +163,7 @@ files:
|
|
136
163
|
- lib/openstax/content/s3.rb
|
137
164
|
- lib/openstax/content/title.rb
|
138
165
|
- lib/openstax/content/version.rb
|
166
|
+
- lib/openstax_content.rb
|
139
167
|
homepage: https://github.com/openstax/content-ruby
|
140
168
|
licenses:
|
141
169
|
- AGPL-3.0
|