Class: Craigslist::API::Resources::Account
- 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
-
#acknowledge(message_id) ⇒ true
Acknowledges an account message so it stops appearing on subsequent responses.
-
#posting_stats(posting_id, start: nil, stop: nil) ⇒ PostingStats
Engagement statistics for one posting.
-
#stats(start: nil, stop: nil) ⇒ Array<PostingStats>
Engagement statistics for every posting on the account.
Methods inherited from Base
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.
16 17 18 19 |
# File 'lib/craigslist/api/resources/account.rb', line 16 def acknowledge() transport.put(path("account", "message", , "ack")) true end |
#posting_stats(posting_id, start: nil, stop: nil) ⇒ PostingStats
Engagement statistics for one posting.
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.
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 |