contemble 0.1.1 → 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 +44 -1
- data/lib/contemble/client.rb +37 -2
- data/lib/contemble/resources.rb +12 -2
- 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
|
@@ -38,11 +38,54 @@ posts = client.collections.posts
|
|
|
38
38
|
posts = client.collections.posts(collection_name: "blog")
|
|
39
39
|
|
|
40
40
|
# Get individual post
|
|
41
|
-
post = client.
|
|
41
|
+
post = client.posts.show(slug: "post-slug")
|
|
42
|
+
|
|
43
|
+
# Get sitemap XML
|
|
44
|
+
sitemap_xml = client.sitemap.xml
|
|
42
45
|
```
|
|
43
46
|
|
|
47
|
+
### Available Data
|
|
48
|
+
|
|
49
|
+
**Individual posts** include:
|
|
50
|
+
|
|
51
|
+
- `slug`, `title`, `sub_title`, `description`
|
|
52
|
+
- `meta_title`, `meta_description`
|
|
53
|
+
- `body` (HTML content)
|
|
54
|
+
- `published_at`
|
|
55
|
+
- `collection` (collection name)
|
|
56
|
+
- `featured_image`
|
|
57
|
+
- `url` (generated based on your configured `post_path`)
|
|
58
|
+
|
|
59
|
+
**Posts in collections** include:
|
|
60
|
+
|
|
61
|
+
- `slug`, `title`, `sub_title`, `description`
|
|
62
|
+
- `published_at`
|
|
63
|
+
- `featured_image`
|
|
64
|
+
- `url` (generated based on your configured `post_path`)
|
|
65
|
+
|
|
44
66
|
Each post includes a `url` field for easy linking based on your configured `post_path`.
|
|
45
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.
|
|
46
89
|
|
|
47
90
|
## License
|
|
48
91
|
|
data/lib/contemble/client.rb
CHANGED
|
@@ -17,8 +17,12 @@ module Contemble
|
|
|
17
17
|
@collections ||= Resources::Collections.new(self)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def
|
|
21
|
-
@
|
|
20
|
+
def posts
|
|
21
|
+
@posts ||= Resources::Posts.new(self)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def sitemap
|
|
25
|
+
@sitemap ||= Resources::Sitemap.new(self)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def get(path, params = {})
|
|
@@ -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
|
@@ -34,13 +34,23 @@ module Contemble
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
class
|
|
37
|
+
class Posts
|
|
38
38
|
def initialize(client)
|
|
39
39
|
@client = client
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def show(slug:)
|
|
43
|
-
@client.get("/
|
|
43
|
+
@client.get("/posts/#{slug}")
|
|
44
|
+
end
|
|
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")
|
|
44
54
|
end
|
|
45
55
|
end
|
|
46
56
|
end
|
data/lib/contemble/version.rb
CHANGED