Class: Forem::Segment
- Inherits:
-
APIResource
- Object
- ForemObject
- APIResource
- Forem::Segment
- Extended by:
- APIOperations::Create, APIOperations::List, APIOperations::Retrieve
- Includes:
- APIOperations::Delete
- Defined in:
- lib/forem/resources/segment.rb
Overview
Represents a user segment used for targeted content delivery on Forem.
Audience segments for billboard targeting. The API only permits managing segments you create yourself.
Segments are named groups of users that can be targeted with specific billboards or other content. Admins can create and delete segments, list their members, and add or remove users from them. Managing segments requires an admin API key.
Available operations (via mixins):
- +List+ — GET /api/segments (getSegments)
- +Create+ — POST /api/segments (createSegment)
- +Retrieve+ — GET /api/segments/:id
- +Delete+ — instance-level delete (DELETE /api/segments/:id)
Segment Fields
id(Integer) — The segment IDtype_of(String) — Marks segment as manually manageduser_count(Integer) — Current number of users in the segment
Constant Summary collapse
- OBJECT_NAME =
"segment"- RESOURCE_PATH =
"/api/segments"
Instance Attribute Summary
Attributes inherited from ForemObject
Instance Method Summary collapse
-
#add_users(params = {}, opts = {}) ⇒ ForemResponse
Add one or more users to this segment.
-
#remove_users(params = {}, opts = {}) ⇒ ForemResponse
Remove one or more users from this segment.
-
#users(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::User>
Return the users who belong to this segment.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Retrieve
Methods included from APIOperations::Delete
Methods inherited from APIResource
#refresh, resource_path, #resource_url
Methods inherited from ForemObject
#==, #[], #[]=, construct_from, cursor_list, #initialize, #inspect, #method_missing, paginated_list, #respond_to_missing?, #to_hash
Methods included from APIOperations::Request
Constructor Details
This class inherits a constructor from Forem::ForemObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Forem::ForemObject
Instance Method Details
#add_users(params = {}, opts = {}) ⇒ ForemResponse
Add one or more users to this segment.
Add users in bulk. The response distinguishes successes (added) from failures (couldn't add).
Sends a PUT request to /api/segments/:id/add_users (addUsersToSegment).
83 84 85 |
# File 'lib/forem/resources/segment.rb', line 83 def add_users(params = {}, opts = {}) request(:put, "#{resource_url}/add_users", params, opts) end |
#remove_users(params = {}, opts = {}) ⇒ ForemResponse
Remove one or more users from this segment.
Sends a PUT request to /api/segments/:id/remove_users.
99 100 101 |
# File 'lib/forem/resources/segment.rb', line 99 def remove_users(params = {}, opts = {}) request(:put, "#{resource_url}/remove_users", params, opts) end |
#users(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::User>
Return the users who belong to this segment.
Returns users in this segment. Default: 30 per page, max: 1000.
Sends a GET request to /api/segments/:id/users (getUsersInSegment).
62 63 64 65 66 |
# File 'lib/forem/resources/segment.rb', line 62 def users(params = {}, opts = {}) opts = opts.dup opts[:requestor] ||= @requestor Forem::User.paginated_list("#{resource_url}/users", params, opts) end |