Ruby wrapper for Commentatr API
This gem supports ruby version 1.9+ only.
Installation
Add this line to your application's Gemfile:
gem 'commentatr'
And then execute:
$ bundle
Or install it yourself as:
$ gem install commentatr
Usage
Initialize client
# Without params
Commentatr::Client.new()
# With blog credentials
Commentatr::Client.new(partner_host: "example.com", token: "...your secret token...")
# With client credentials
Commentatr::Client.new(client_id: 42, token: "...your secret token...")
Fetch comments for blog
# All entry comments
cttr.comments(page_id: "blog-1")
# Last 5 entry comments
cttr.comments(page_id: "blog-1", order: "desc", limit: 5)
# All comments since last time you checked
cttr.comments(page_id: "blog-1", after: Time.now.to_i - 3600)
Fetch comments for all client blogs
cttr.client_comments(order: "asc", offset: 100, limit: 10)
Fetch counters of comments for each entry of each client blog
cttr.counters
Moderator actions
cttr.approve(comment_id: 1)
cttr.reject(comment_id: 2)
cttr.delete(comment_id: 3)
cttr.junk(comment_id: 4)
# Mass management
cttr.approve(comment_id: [1, 2, 3, 4])
Admin actions
# Change comments approval setting
cttr = Commentatr::Client.new(partner_host: "example.com", token: "...your secret token...")
cttr.update_config(approval: false, readonly: true)
# Regenerate blog token
commentatr_config[:token] = cttr.regenerate_blog_token(partner_host: "example.com")
# Regenerate client token
commentatr_config[:token] = cttr.regenerate_client_token
You can perform all these actions passing all needed authentication params for each query
cttr = Commentatr::Client.new
cttr.comments(
partner_host: "example.com",
token: "...your secret token...",
page_id: "blog-1",
order: "asc",
offset: 50,
limit: 10
)
Working with responses
All responses are stored in Commentatr::Response
objects
response = cttr.comments(page_id: "blog-1")
response.code
# => 200
response.body.success
# => true
response.body.data
# => [ ...comments here... ]
response.body.errors
# => []