contemble 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e11de0b7a122b2a0e036240b764cda308ba26ce3a82b298d3e9a7333e70597e
4
+ data.tar.gz: 95b4039dd5515f0c07d8f305e4dd994a09492f96213e7656b6166c9a46e0a3d6
5
+ SHA512:
6
+ metadata.gz: 23c9a6586fc151ee597bc7ac1164310e5f78c9f12bff585dc3db49b806751f72eacb16bb5a44bfa85200116d77217c56347d28fdfb83873b7fc6164c960c8be2
7
+ data.tar.gz: 6d298dd5bbd779f9fbf176db84e31f745fd3fa75d073c1b2663649c89798ca5121e8cb3a154dbc1f6144150669cb564f56c627395bb14249a58cab0fb2008f96
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Contemble
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Contemble
2
+
3
+ A Ruby gem for interacting with the Contemble CMS API.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'contemble'
11
+ ```
12
+
13
+ ## Setup
14
+
15
+ Generate the initializer:
16
+
17
+ ```bash
18
+ rails generate contemble:install
19
+ ```
20
+
21
+ This creates `config/initializers/contemble.rb`:
22
+
23
+ ```ruby
24
+ Contemble.configure do |config|
25
+ config.post_path = "/blog"
26
+ end
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ client = Contemble::Client.new(api_key: "your_api_key")
33
+
34
+ # Get all posts
35
+ posts = client.collections.posts
36
+
37
+ # Get posts from specific collection
38
+ posts = client.collections.posts(collection_name: "blog")
39
+
40
+ # Get individual post
41
+ post = client.content.show(slug: "post-slug")
42
+ ```
43
+
44
+ Each post includes a `url` field for easy linking based on your configured `post_path`.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
6
+
7
+ module Contemble
8
+ class Client
9
+ attr_reader :base_url, :api_key
10
+
11
+ def initialize(api_key:)
12
+ @base_url = "https://api.contemble.com"
13
+ @api_key = api_key
14
+ end
15
+
16
+ def collections
17
+ @collections ||= Resources::Collections.new(self)
18
+ end
19
+
20
+ def content
21
+ @content ||= Resources::Content.new(self)
22
+ end
23
+
24
+ def get(path, params = {})
25
+ uri = URI("#{@base_url}#{path}")
26
+ uri.query = URI.encode_www_form(params) unless params.empty?
27
+
28
+ request = Net::HTTP::Get.new(uri)
29
+ request["Authorization"] = "Bearer #{@api_key}"
30
+ request["Content-Type"] = "application/json"
31
+
32
+ make_request(uri, request)
33
+ end
34
+
35
+ def post(path, body = {})
36
+ uri = URI("#{@base_url}#{path}")
37
+
38
+ request = Net::HTTP::Post.new(uri)
39
+ request["Authorization"] = "Bearer #{@api_key}"
40
+ request["Content-Type"] = "application/json"
41
+ request.body = body.to_json
42
+
43
+ make_request(uri, request)
44
+ end
45
+
46
+ private
47
+
48
+ def make_request(uri, request)
49
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
50
+ response = http.request(request)
51
+ handle_response(response)
52
+ end
53
+ end
54
+
55
+ def handle_response(response)
56
+ case response.code.to_i
57
+ when 200..299
58
+ JSON.parse(response.body) if response.body && !response.body.empty?
59
+ when 404
60
+ raise Error, "Resource not found"
61
+ when 401
62
+ raise Error, "Unauthorized"
63
+ else
64
+ raise Error, "Request failed with status #{response.code}: #{response.body}"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Contemble
4
+ class Configuration
5
+ attr_accessor :post_path
6
+
7
+ def initialize
8
+ @post_path = "/blog"
9
+ end
10
+ end
11
+
12
+ class << self
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+
21
+ delegate :post_path, to: :configuration
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Contemble
4
+ class Railtie < Rails::Railtie
5
+ generators do
6
+ require_relative "../generators/contemble/install_generator"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Contemble
4
+ module Resources
5
+ class Collections
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def list
11
+ @client.get("/collections")
12
+ end
13
+
14
+ def posts(collection_name: nil)
15
+ posts = if collection_name
16
+ @client.get("/collections/#{collection_name}")
17
+ else
18
+ collections = list
19
+ all_posts = []
20
+
21
+ collections.each do |collection|
22
+ posts = @client.get("/collections/#{collection["name"]}")
23
+ all_posts.concat(posts)
24
+ end
25
+
26
+ all_posts
27
+ end
28
+
29
+ posts.map do |post|
30
+ post.merge(
31
+ "url" => "#{Contemble.post_path}/#{post["slug"]}"
32
+ )
33
+ end
34
+ end
35
+ end
36
+
37
+ class Content
38
+ def initialize(client)
39
+ @client = client
40
+ end
41
+
42
+ def show(slug:)
43
+ @client.get("/content/#{slug}")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Contemble
4
+ VERSION = "0.1.1"
5
+ end
data/lib/contemble.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "contemble/version"
4
+ require_relative "contemble/configuration"
5
+ require_relative "contemble/resources"
6
+ require_relative "contemble/client"
7
+
8
+ if defined?(Rails::Railtie)
9
+ require_relative "contemble/railtie"
10
+ end
11
+
12
+ module Contemble
13
+ class Error < StandardError; end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/actions"
5
+
6
+ module Contemble
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Actions
10
+
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ desc "Creates a Contemble initializer file"
14
+
15
+ def create_initializer_file
16
+ template "contemble.rb", "config/initializers/contemble.rb"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ Contemble.configure do |config|
2
+ # Set the base path for post URLs
3
+ # Example: /articles, /blog, etc.
4
+ config.post_path = "/articles"
5
+ end
data/sig/contemble.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Contemble
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contemble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - contemble
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - development@contemble.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - LICENSE.txt
19
+ - README.md
20
+ - Rakefile
21
+ - lib/contemble.rb
22
+ - lib/contemble/client.rb
23
+ - lib/contemble/configuration.rb
24
+ - lib/contemble/railtie.rb
25
+ - lib/contemble/resources.rb
26
+ - lib/contemble/version.rb
27
+ - lib/generators/contemble/install_generator.rb
28
+ - lib/generators/contemble/templates/contemble.rb
29
+ - sig/contemble.rbs
30
+ homepage: https://contemble.com
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://contemble.com
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.7.2
50
+ specification_version: 4
51
+ summary: Ruby gem to connect to Contemble.com and serve content via our Headless API.
52
+ test_files: []