Class: Forem::Services::SegmentService

Inherits:
BaseService show all
Defined in:
lib/forem/services/segment_service.rb

Overview

Service for interacting with the Forem Segments API.

Segments are user-defined audience groups used for targeted content and billboard campaigns. Access via Client#segments. All methods inject the client's requestor automatically so no additional configuration is required.

Examples:

client = Forem::Client.new("your-api-key")
segments = client.segments.list
segment  = client.segments.retrieve(5)

See Also:

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Forem::Services::BaseService

Instance Method Details

#create(params = {}, opts = {}) ⇒ Forem::Segment

Create a new audience segment.

The Forem API does not accept any parameters on this endpoint — newly-created segments are always type_of: "manual" and do not carry a name. Manage membership separately via Forem::Segment#add_users and Forem::Segment#remove_users.

Examples:

segment = client.segments.create
segment.add_users(user_ids: [101, 102])

Parameters:

  • params (Hash) (defaults to: {})

    ignored by the API, kept for forward-compat

  • opts (Hash) (defaults to: {})

    per-request options

Returns:

See Also:



50
51
52
# File 'lib/forem/services/segment_service.rb', line 50

def create(params = {}, opts = {})
  Segment.create(params, opts_with_requestor(opts))
end

#delete(id, opts = {}) ⇒ nil

Delete an audience segment.

Examples:

client.segments.delete(5)

Parameters:

  • id (Integer, String)

    the segment ID to delete

  • opts (Hash) (defaults to: {})

    per-request options

Returns:

  • (nil)

    returns nil on success

See Also:



78
79
80
# File 'lib/forem/services/segment_service.rb', line 78

def delete(id, opts = {})
  Segment.delete(id, opts_with_requestor(opts))
end

#list(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Segment>

List all audience segments.

Examples:

client.segments.list

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :page (Integer)

    page number (default: 1)

  • :per_page (Integer)

    number of results per page

Returns:

See Also:



30
31
32
# File 'lib/forem/services/segment_service.rb', line 30

def list(params = {}, opts = {})
  Segment.list(params, opts_with_requestor(opts))
end

#retrieve(id, opts = {}) ⇒ Segment

Retrieve a single audience segment by its numeric ID.

Examples:

client.segments.retrieve(5)

Parameters:

  • id (Integer, String)

    the segment ID

  • opts (Hash) (defaults to: {})

    per-request options

Returns:

  • (Segment)

    the segment with the given ID

See Also:



64
65
66
# File 'lib/forem/services/segment_service.rb', line 64

def retrieve(id, opts = {})
  Segment.retrieve(id, opts_with_requestor(opts))
end