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 +4 -4
- data/README.md +25 -0
- data/lib/contemble/client.rb +35 -0
- data/lib/contemble/resources.rb +10 -0
- data/lib/contemble/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99fe1246d4eccb72cd14d795ff92c7fa39280a8f03f3c818c9365bf5813079b9
|
|
4
|
+
data.tar.gz: 16c7878a6a9e7539d92b8416183d8533cea6cace9d63e5e9822e8703e8e077ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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).
|
data/lib/contemble/client.rb
CHANGED
|
@@ -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
|
data/lib/contemble/resources.rb
CHANGED
data/lib/contemble/version.rb
CHANGED