contentzen 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +120 -0
- data/lib/contentzen/client.rb +183 -0
- data/lib/contentzen/version.rb +5 -0
- data/lib/contentzen.rb +8 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 861f6ced90b23184f35f33b8adb9e62c589c42c37ddeefe6b5956765eccba18d
|
4
|
+
data.tar.gz: 65db4772b48ff42ffb929079218ea8025e8d0ba88580fd2407ac958f080b074d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 299d2f7cfd12808e80e2904c3aa3d77590e1c1ac792c44b1a21542ec0e0cbfad98e93515462aba914c9d19195696e2781de2d8f47b7ee4d8b37b4cdf822b73fd
|
7
|
+
data.tar.gz: 1a91006e9d498bf6b6f4334d09250101020ca455b605611147d9f19a2b04ee6b256301c114535a50ccc8f653d4c9907c9ec1a1a9f7fe14744534b09b3a014d9c
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Your Name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# ContentZen Ruby SDK
|
2
|
+
|
3
|
+
Ruby SDK for ContentZen, designed for Rails and other Ruby-based stacks. Includes ActiveRecord-style queries for structured content.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'contentzen'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install contentzen
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'contentzen'
|
25
|
+
|
26
|
+
client = ContentZen::Client.new(api_token: 'your_api_token')
|
27
|
+
|
28
|
+
# Fetch public documents
|
29
|
+
client.public_documents(collection_uuid: 'your_collection_uuid')
|
30
|
+
|
31
|
+
# Fetch a specific document (public)
|
32
|
+
client.public_document(collection_uuid: 'your_collection_uuid', document_uuid: 'your_document_uuid')
|
33
|
+
|
34
|
+
# Fetch private documents (requires api_token)
|
35
|
+
client.documents(collection_uuid: 'your_collection_uuid')
|
36
|
+
|
37
|
+
# ... more usage examples ...
|
38
|
+
```
|
39
|
+
|
40
|
+
## Collections
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# Get all collections
|
44
|
+
client.collections
|
45
|
+
|
46
|
+
# Get a specific collection
|
47
|
+
client.collection(collection_uuid: 'your_collection_uuid')
|
48
|
+
|
49
|
+
# Create a collection
|
50
|
+
client.create_collection({
|
51
|
+
name: 'products',
|
52
|
+
display_name: 'Products',
|
53
|
+
description: 'Product catalog',
|
54
|
+
is_public: false,
|
55
|
+
fields: [
|
56
|
+
{ name: 'title', type: 'string', display_name: 'Product Title', required: true },
|
57
|
+
{ name: 'price', type: 'number', display_name: 'Price', required: true }
|
58
|
+
]
|
59
|
+
})
|
60
|
+
|
61
|
+
# Update a collection
|
62
|
+
client.update_collection(collection_uuid: 'your_collection_uuid', payload: { display_name: 'Updated Products' })
|
63
|
+
|
64
|
+
# Delete a collection
|
65
|
+
client.delete_collection(collection_uuid: 'your_collection_uuid')
|
66
|
+
|
67
|
+
# Get collection schema
|
68
|
+
client.collection_schema(collection_uuid: 'your_collection_uuid')
|
69
|
+
|
70
|
+
# Get collection fields
|
71
|
+
client.collection_fields(collection_uuid: 'your_collection_uuid')
|
72
|
+
|
73
|
+
# Get available field types
|
74
|
+
client.field_types
|
75
|
+
```
|
76
|
+
|
77
|
+
## Media
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# List all media files
|
81
|
+
client.list_media
|
82
|
+
|
83
|
+
# Upload a media file
|
84
|
+
client.upload_media('/path/to/file.jpg')
|
85
|
+
|
86
|
+
# Get media file details
|
87
|
+
client.media_file(media_uuid: 'your_media_uuid')
|
88
|
+
|
89
|
+
# Update media file metadata
|
90
|
+
client.update_media(media_uuid: 'your_media_uuid', payload: { alt_text: 'Updated alt text' })
|
91
|
+
|
92
|
+
# Delete a media file
|
93
|
+
client.delete_media(media_uuid: 'your_media_uuid')
|
94
|
+
|
95
|
+
# Download a media file (returns file data)
|
96
|
+
client.download_media(media_uuid: 'your_media_uuid')
|
97
|
+
```
|
98
|
+
|
99
|
+
## Webhooks
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
# List all webhooks
|
103
|
+
client.list_webhooks
|
104
|
+
|
105
|
+
# Create a webhook
|
106
|
+
client.create_webhook({
|
107
|
+
name: 'My Webhook',
|
108
|
+
url: 'https://example.com/webhook',
|
109
|
+
events: ['document.created', 'document.updated'],
|
110
|
+
method: 'POST'
|
111
|
+
})
|
112
|
+
|
113
|
+
# Update a webhook
|
114
|
+
client.update_webhook(webhook_uuid: 'your_webhook_uuid', payload: { name: 'Updated Webhook' })
|
115
|
+
|
116
|
+
# Delete a webhook
|
117
|
+
client.delete_webhook(webhook_uuid: 'your_webhook_uuid')
|
118
|
+
```
|
119
|
+
|
120
|
+
See [ContentZen API Docs](https://www.postman.com/winter-meteor-7066631/contentzen/collection/9m7enab/contentzen-api) for full API details.
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module ContentZen
|
8
|
+
class Client
|
9
|
+
API_BASE_URL = 'https://api.contentzen.io'.freeze
|
10
|
+
|
11
|
+
attr_reader :api_token
|
12
|
+
|
13
|
+
def initialize(api_token: nil)
|
14
|
+
@api_token = api_token
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public API: Get all published documents from a public collection
|
18
|
+
def public_documents(collection_uuid:, limit: 10, offset: 0, state: 'published')
|
19
|
+
get("/api/v1/documents/collection/#{collection_uuid}", params: { limit: limit, offset: offset, state: state })
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public API: Get a specific document from a public collection
|
23
|
+
def public_document(collection_uuid:, document_uuid:)
|
24
|
+
get("/api/v1/documents/collection/#{collection_uuid}/#{document_uuid}")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Private API: Get documents from a collection (requires API token)
|
28
|
+
def documents(collection_uuid:, limit: 10, offset: 0)
|
29
|
+
get("/api/v1/documents/#{collection_uuid}", auth: true, params: { limit: limit, offset: offset })
|
30
|
+
end
|
31
|
+
|
32
|
+
# Private API: Get a specific document (requires API token)
|
33
|
+
def document(collection_uuid:, document_uuid:)
|
34
|
+
get("/api/v1/documents/#{collection_uuid}/#{document_uuid}", auth: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
# --- Collections ---
|
38
|
+
|
39
|
+
# Get all collections (requires API token)
|
40
|
+
def collections
|
41
|
+
get("/api/v1/collections", auth: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get a specific collection (requires API token)
|
45
|
+
def collection(collection_uuid:)
|
46
|
+
get("/api/v1/collections/#{collection_uuid}", auth: true)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create a new collection (requires API token)
|
50
|
+
def create_collection(payload)
|
51
|
+
post("/api/v1/collections", payload, auth: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Update a collection (requires API token)
|
55
|
+
def update_collection(collection_uuid:, payload:)
|
56
|
+
put("/api/v1/collections/#{collection_uuid}", payload, auth: true)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete a collection (requires API token)
|
60
|
+
def delete_collection(collection_uuid:)
|
61
|
+
delete("/api/v1/collections/#{collection_uuid}", auth: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get collection schema (requires API token)
|
65
|
+
def collection_schema(collection_uuid:)
|
66
|
+
get("/api/v1/collections/#{collection_uuid}/schema", auth: true)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Get collection fields (requires API token)
|
70
|
+
def collection_fields(collection_uuid:)
|
71
|
+
get("/api/v1/collections/#{collection_uuid}/fields", auth: true)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get available field types (requires API token)
|
75
|
+
def field_types
|
76
|
+
get("/api/v1/collections/field-types", auth: true)
|
77
|
+
end
|
78
|
+
|
79
|
+
# --- Media ---
|
80
|
+
|
81
|
+
# List all media files (requires API token)
|
82
|
+
def list_media
|
83
|
+
get("/api/v1/media/ls", auth: true)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Upload a media file (requires API token)
|
87
|
+
def upload_media(file_path)
|
88
|
+
uri = URI.join(API_BASE_URL, "/api/v1/media/upload")
|
89
|
+
request = Net::HTTP::Post.new(uri)
|
90
|
+
request['Authorization'] = "Bearer #{@api_token}" if @api_token
|
91
|
+
form_data = [['file', File.open(file_path)]]
|
92
|
+
request.set_form(form_data, 'multipart/form-data')
|
93
|
+
perform_request(uri, request)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Get specific media file details (requires API token)
|
97
|
+
def media_file(media_uuid:)
|
98
|
+
get("/api/v1/media/#{media_uuid}", auth: true)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Update media file metadata (requires API token)
|
102
|
+
def update_media(media_uuid:, payload:)
|
103
|
+
put("/api/v1/media/#{media_uuid}", payload, auth: true)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Delete a media file (requires API token)
|
107
|
+
def delete_media(media_uuid:)
|
108
|
+
delete("/api/v1/media/#{media_uuid}", auth: true)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Download a media file (requires API token)
|
112
|
+
def download_media(media_uuid:)
|
113
|
+
get("/api/v1/media/#{media_uuid}/download", auth: true)
|
114
|
+
end
|
115
|
+
|
116
|
+
# --- Webhooks ---
|
117
|
+
|
118
|
+
# List all webhooks (requires API token)
|
119
|
+
def list_webhooks
|
120
|
+
get("/api/v1/webhooks", auth: true)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Create a new webhook (requires API token)
|
124
|
+
def create_webhook(payload)
|
125
|
+
post("/api/v1/webhooks", payload, auth: true)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Update a webhook (requires API token)
|
129
|
+
def update_webhook(webhook_uuid:, payload:)
|
130
|
+
put("/api/v1/webhooks/#{webhook_uuid}", payload, auth: true)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Delete a webhook (requires API token)
|
134
|
+
def delete_webhook(webhook_uuid:)
|
135
|
+
delete("/api/v1/webhooks/#{webhook_uuid}", auth: true)
|
136
|
+
end
|
137
|
+
|
138
|
+
# --- HTTP helpers ---
|
139
|
+
private
|
140
|
+
|
141
|
+
def get(path, auth: false, params: {})
|
142
|
+
uri = URI.join(API_BASE_URL, path)
|
143
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
144
|
+
request = Net::HTTP::Get.new(uri)
|
145
|
+
request['Authorization'] = "Bearer #{@api_token}" if auth && @api_token
|
146
|
+
perform_request(uri, request)
|
147
|
+
end
|
148
|
+
|
149
|
+
def post(path, payload, auth: false)
|
150
|
+
uri = URI.join(API_BASE_URL, path)
|
151
|
+
request = Net::HTTP::Post.new(uri)
|
152
|
+
request['Content-Type'] = 'application/json'
|
153
|
+
request['Authorization'] = "Bearer #{@api_token}" if auth && @api_token
|
154
|
+
request.body = payload.to_json
|
155
|
+
perform_request(uri, request)
|
156
|
+
end
|
157
|
+
|
158
|
+
def put(path, payload, auth: false)
|
159
|
+
uri = URI.join(API_BASE_URL, path)
|
160
|
+
request = Net::HTTP::Put.new(uri)
|
161
|
+
request['Content-Type'] = 'application/json'
|
162
|
+
request['Authorization'] = "Bearer #{@api_token}" if auth && @api_token
|
163
|
+
request.body = payload.to_json
|
164
|
+
perform_request(uri, request)
|
165
|
+
end
|
166
|
+
|
167
|
+
def delete(path, auth: false)
|
168
|
+
uri = URI.join(API_BASE_URL, path)
|
169
|
+
request = Net::HTTP::Delete.new(uri)
|
170
|
+
request['Authorization'] = "Bearer #{@api_token}" if auth && @api_token
|
171
|
+
perform_request(uri, request)
|
172
|
+
end
|
173
|
+
|
174
|
+
def perform_request(uri, request)
|
175
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
176
|
+
http.use_ssl = uri.scheme == 'https'
|
177
|
+
response = http.request(request)
|
178
|
+
JSON.parse(response.body)
|
179
|
+
rescue JSON::ParserError
|
180
|
+
response.body
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
data/lib/contentzen.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contentzen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Your Name
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Ruby SDK for ContentZen, designed for Rails and other Ruby-based stacks.
|
28
|
+
Includes ActiveRecord-style queries for structured content.
|
29
|
+
email:
|
30
|
+
- your@email.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- lib/contentzen.rb
|
38
|
+
- lib/contentzen/client.rb
|
39
|
+
- lib/contentzen/version.rb
|
40
|
+
homepage: https://contentzen.io
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://contentzen.io
|
45
|
+
source_code_uri: https://github.com/yourusername/contentzen-ruby
|
46
|
+
changelog_uri: https://github.com/yourusername/contentzen-ruby/CHANGELOG.md
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.0.3.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Ruby SDK for ContentZen headless CMS.
|
66
|
+
test_files: []
|