contemble 0.1.2 → 0.1.3

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: 99fe1246d4eccb72cd14d795ff92c7fa39280a8f03f3c818c9365bf5813079b9
4
+ data.tar.gz: 16c7878a6a9e7539d92b8416183d8533cea6cace9d63e5e9822e8703e8e077ec
5
5
  SHA512:
6
- metadata.gz: cefa4889c058afa05d6b44ea20952ad97471a9fc3dea7002ad800cb57dc53ba7a47dd3fb04b8ab1fd66b3d590470a3a1cd3862bb874c7b60f666d34cac0b5c61
7
- data.tar.gz: 98b09da9d6395c2f156bf49fa28046e74573e620fd0e4db94289b847046b586013c103224b0b0db555b9a73b29680d6541a16dd074a9e58386dd8143d7f3482f
6
+ metadata.gz: e8d15a8ec3cd72266ac8b5e0092e404f865d4f91b0b4ec9d245f66bb51c94c7271448d7dd90ba2c7e7cc40f38d74a70ebd504cd369269c1ebdd76e00f3823ec9
7
+ data.tar.gz: 5f37a5a2585b0f7ef02fa6e0e593d18d58f36fd19f87952d36f278362e8958db0879eb33c94392896e462b2dc507024ec1ad25cfcc6cee561f3771ca68f1fa88
data/README.md CHANGED
@@ -39,6 +39,9 @@ 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
42
45
  ```
43
46
 
44
47
  ### Available Data
@@ -62,6 +65,28 @@ post = client.posts.show(slug: "post-slug")
62
65
 
63
66
  Each post includes a `url` field for easy linking based on your configured `post_path`.
64
67
 
68
+ **Sitemap XML** returns ready-to-use XML that can be saved to a file, proxied through your server, or included in your sitemap index.
69
+
70
+ ### Sitemap Usage
71
+
72
+ ```ruby
73
+ client = Contemble::Client.new(api_key: "your_api_key")
74
+
75
+ # Get complete sitemap as XML
76
+ sitemap_xml = client.sitemap.xml
77
+
78
+ # Save to file
79
+ File.write('public/contemble-sitemap.xml', sitemap_xml)
80
+
81
+ # Or proxy through your Rails app
82
+ def sitemap
83
+ client = Contemble::Client.new(api_key: ENV['CONTEMBLE_API_KEY'])
84
+ render xml: client.sitemap.xml
85
+ end
86
+ ```
87
+
88
+ 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.
89
+
65
90
  ## License
66
91
 
67
92
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -21,6 +21,10 @@ 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
+
24
28
  def get(path, params = {})
25
29
  uri = URI("#{@base_url}#{path}")
26
30
  uri.query = URI.encode_www_form(params) unless params.empty?
@@ -32,6 +36,17 @@ module Contemble
32
36
  make_request(uri, request)
33
37
  end
34
38
 
39
+ def get_xml(path, params = {})
40
+ uri = URI("#{@base_url}#{path}")
41
+ uri.query = URI.encode_www_form(params) unless params.empty?
42
+
43
+ request = Net::HTTP::Get.new(uri)
44
+ request["Authorization"] = "Bearer #{@api_key}"
45
+ request["Accept"] = "application/xml"
46
+
47
+ make_request_xml(uri, request)
48
+ end
49
+
35
50
  def post(path, body = {})
36
51
  uri = URI("#{@base_url}#{path}")
37
52
 
@@ -52,6 +67,13 @@ module Contemble
52
67
  end
53
68
  end
54
69
 
70
+ def make_request_xml(uri, request)
71
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
72
+ response = http.request(request)
73
+ handle_response_xml(response)
74
+ end
75
+ end
76
+
55
77
  def handle_response(response)
56
78
  case response.code.to_i
57
79
  when 200..299
@@ -64,5 +86,18 @@ module Contemble
64
86
  raise Error, "Request failed with status #{response.code}: #{response.body}"
65
87
  end
66
88
  end
89
+
90
+ def handle_response_xml(response)
91
+ case response.code.to_i
92
+ when 200..299
93
+ response.body
94
+ when 404
95
+ raise Error, "Resource not found"
96
+ when 401
97
+ raise Error, "Unauthorized"
98
+ else
99
+ raise Error, "Request failed with status #{response.code}: #{response.body}"
100
+ end
101
+ end
67
102
  end
68
103
  end
@@ -43,5 +43,15 @@ 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
46
56
  end
47
57
  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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - contemble