contemble 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b928df155d770843df5d221649b1b468dc3f051d3b236033d2cce64e3ad00b55
4
- data.tar.gz: 21e48f7a6381a182dd92db98694cd753695d31189187f9a3045411970fb83616
3
+ metadata.gz: d24648e5804b56f09d868bc242a5111a94e1d933105c358f3ed97663e1c1a954
4
+ data.tar.gz: 82a446c690a080657b2fb3c82e9bac37bb84aa1313c437eebb912bf7e82e3d61
5
5
  SHA512:
6
- metadata.gz: cefa4889c058afa05d6b44ea20952ad97471a9fc3dea7002ad800cb57dc53ba7a47dd3fb04b8ab1fd66b3d590470a3a1cd3862bb874c7b60f666d34cac0b5c61
7
- data.tar.gz: 98b09da9d6395c2f156bf49fa28046e74573e620fd0e4db94289b847046b586013c103224b0b0db555b9a73b29680d6541a16dd074a9e58386dd8143d7f3482f
6
+ metadata.gz: 1c4332db2ccc94acda3db69fcf3819db356639fa5e49217e396a952045ece72f00a40483c084c2b0bba022bedf2a88b4b32676c51c015c68b4dacea2bc8f5388
7
+ data.tar.gz: 325fdc43ec857e1f5778d4e3868e0f07a20d5f231b8c1d3e5bd2e2de9f38ab9828a1a8a2529c0acb54d79617dd46d47354f86fc5dadd1976c21e32d675c39c2c
data/README.md CHANGED
@@ -39,6 +39,12 @@ posts = client.collections.posts(collection_name: "blog")
39
39
 
40
40
  # Get individual post
41
41
  post = client.posts.show(slug: "post-slug")
42
+
43
+ # Get sitemap XML
44
+ sitemap_xml = client.sitemap.xml
45
+
46
+ # Get article schema
47
+ article_schema = client.schema.article(slug: "post-slug")
42
48
  ```
43
49
 
44
50
  ### Available Data
@@ -62,6 +68,46 @@ post = client.posts.show(slug: "post-slug")
62
68
 
63
69
  Each post includes a `url` field for easy linking based on your configured `post_path`.
64
70
 
71
+ **Sitemap XML** returns ready-to-use XML that can be saved to a file, proxied through your server, or included in your sitemap index.
72
+
73
+ ### Sitemap Usage
74
+
75
+ ```ruby
76
+ client = Contemble::Client.new(api_key: "your_api_key")
77
+
78
+ # Get complete sitemap as XML
79
+ sitemap_xml = client.sitemap.xml
80
+
81
+ # Save to file
82
+ File.write('public/contemble-sitemap.xml', sitemap_xml)
83
+
84
+ # Or proxy through your Rails app
85
+ def sitemap
86
+ client = Contemble::Client.new(api_key: ENV['CONTEMBLE_API_KEY'])
87
+ render xml: client.sitemap.xml
88
+ end
89
+ ```
90
+
91
+ The sitemap URLs will use your configured base URL from your Contemble team settings. For large teams with many posts, this will automatically return a sitemap index that references multiple sitemap files.
92
+
93
+ ### Schema Usage
94
+
95
+ ```ruby
96
+ client = Contemble::Client.new(api_key: "your_api_key")
97
+
98
+ # Get JSON-LD schema for a specific article
99
+ schema = client.schema.article(slug: "my-post")
100
+
101
+ # Use in your Rails template
102
+ content_for :head do
103
+ content_tag :script, type: "application/ld+json" do
104
+ raw schema.to_json
105
+ end
106
+ end
107
+ ```
108
+
109
+ **Article Schema** returns JSON-LD structured data including headline, description, dates, images, and publisher information for SEO rich snippets.
110
+
65
111
  ## License
66
112
 
67
113
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -21,6 +21,14 @@ module Contemble
21
21
  @posts ||= Resources::Posts.new(self)
22
22
  end
23
23
 
24
+ def sitemap
25
+ @sitemap ||= Resources::Sitemap.new(self)
26
+ end
27
+
28
+ def schema
29
+ @schema ||= Resources::Schema.new(self)
30
+ end
31
+
24
32
  def get(path, params = {})
25
33
  uri = URI("#{@base_url}#{path}")
26
34
  uri.query = URI.encode_www_form(params) unless params.empty?
@@ -32,6 +40,17 @@ module Contemble
32
40
  make_request(uri, request)
33
41
  end
34
42
 
43
+ def get_xml(path, params = {})
44
+ uri = URI("#{@base_url}#{path}")
45
+ uri.query = URI.encode_www_form(params) unless params.empty?
46
+
47
+ request = Net::HTTP::Get.new(uri)
48
+ request["Authorization"] = "Bearer #{@api_key}"
49
+ request["Accept"] = "application/xml"
50
+
51
+ make_request_xml(uri, request)
52
+ end
53
+
35
54
  def post(path, body = {})
36
55
  uri = URI("#{@base_url}#{path}")
37
56
 
@@ -52,6 +71,13 @@ module Contemble
52
71
  end
53
72
  end
54
73
 
74
+ def make_request_xml(uri, request)
75
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
76
+ response = http.request(request)
77
+ handle_response_xml(response)
78
+ end
79
+ end
80
+
55
81
  def handle_response(response)
56
82
  case response.code.to_i
57
83
  when 200..299
@@ -64,5 +90,18 @@ module Contemble
64
90
  raise Error, "Request failed with status #{response.code}: #{response.body}"
65
91
  end
66
92
  end
93
+
94
+ def handle_response_xml(response)
95
+ case response.code.to_i
96
+ when 200..299
97
+ response.body
98
+ when 404
99
+ raise Error, "Resource not found"
100
+ when 401
101
+ raise Error, "Unauthorized"
102
+ else
103
+ raise Error, "Request failed with status #{response.code}: #{response.body}"
104
+ end
105
+ end
67
106
  end
68
107
  end
@@ -43,5 +43,25 @@ module Contemble
43
43
  @client.get("/posts/#{slug}")
44
44
  end
45
45
  end
46
+
47
+ class Sitemap
48
+ def initialize(client)
49
+ @client = client
50
+ end
51
+
52
+ def xml
53
+ @client.get_xml("/sitemap.xml")
54
+ end
55
+ end
56
+
57
+ class Schema
58
+ def initialize(client)
59
+ @client = client
60
+ end
61
+
62
+ def article(slug:)
63
+ @client.get("/posts/#{slug}/schema")
64
+ end
65
+ end
46
66
  end
47
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Contemble
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contemble
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - contemble