Class: Craigslist::API::Resources::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/craigslist/api/resources/account.rb

Overview

Account notices and posting statistics.

Constant Summary

Constants inherited from Base

Base::BASE_PATH, Base::RESERVED

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Craigslist::API::Resources::Base

Instance Method Details

#acknowledge(message_id) ⇒ true

Acknowledges an account message so it stops appearing on subsequent responses.

Craigslist attaches these notices to every response until they are acknowledged, which is why Client#account_messages exists.

Parameters:

  • message_id (String)

Returns:

  • (true)


16
17
18
19
# File 'lib/craigslist/api/resources/account.rb', line 16

def acknowledge(message_id)
  transport.put(path("account", "message", message_id, "ack"))
  true
end

#posting_stats(posting_id, start: nil, stop: nil) ⇒ PostingStats

Engagement statistics for one posting.

Parameters:

  • posting_id (String, Integer)
  • start (String, Date, Time, nil) (defaults to: nil)

    see #stats

  • stop (String, Date, Time, nil) (defaults to: nil)

    see #stats

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/craigslist/api/resources/account.rb', line 43

def posting_stats(posting_id, start: nil, stop: nil)
  envelope = transport.get(
    path("account", "stats", "posting", posting_id),
    params: window(start, stop)
  )

  # This endpoint returns a single-element array rather than an object.
  payload = envelope.data.is_a?(Array) ? envelope.data.first : envelope.data
  stats = PostingStats.from(payload || {})

  return stats unless stats.posting_id.nil?

  PostingStats.new(posting_id: posting_id.to_s, series: stats.series)
end

#stats(start: nil, stop: nil) ⇒ Array<PostingStats>

Engagement statistics for every posting on the account.

Parameters:

  • start (String, Date, Time, nil) (defaults to: nil)

    window start, "yyyy-mm-dd". Defaults server-side to 31 days ago.

  • stop (String, Date, Time, nil) (defaults to: nil)

    window end, "yyyy-mm-dd". Defaults server-side to yesterday.

Returns:



28
29
30
31
32
33
34
35
# File 'lib/craigslist/api/resources/account.rb', line 28

def stats(start: nil, stop: nil)
  envelope = transport.get(
    path("account", "stats", "all-postings"),
    params: window(start, stop)
  )

  Array(envelope.data).map { |entry| PostingStats.from(entry) }
end