Class: Craigslist::API::Resources::Postings
- Defined in:
- lib/craigslist/api/resources/postings.rb
Overview
Reading and editing postings that already exist.
Postings are created through the RSS interface (Client#post); this covers everything afterwards.
Constant Summary collapse
- STATUSES =
Statuses a posting can report.
%w[active deleted expired pending removed].freeze
Constants inherited from Base
Base::BASE_PATH, Base::RESERVED
Instance Method Summary collapse
-
#area_for_zip(zip) ⇒ ZipLocation
Maps a US ZIP code onto the craigslist area that covers it, and the subarea within it when there is one.
-
#body(posting_id) ⇒ String
The posting body.
- #delete(posting_id) ⇒ true
-
#price(posting_id) ⇒ Integer?
For categories that carry a price.
-
#remuneration(posting_id) ⇒ String?
For jobs and gigs postings.
-
#status(posting_id) ⇒ String
One of STATUSES.
- #undelete(posting_id) ⇒ true
-
#update_body(posting_id, body) ⇒ String
Replaces the posting body.
-
#update_price(posting_id, price) ⇒ Integer
The updated price.
-
#update_remuneration(posting_id, remuneration) ⇒ String
The updated value.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Craigslist::API::Resources::Base
Instance Method Details
#area_for_zip(zip) ⇒ ZipLocation
Maps a US ZIP code onto the craigslist area that covers it, and the subarea within it when there is one.
89 90 91 |
# File 'lib/craigslist/api/resources/postings.rb', line 89 def area_for_zip(zip) ZipLocation.from(transport.get(path("posting", "zip", zip, "area")).data) end |
#body(posting_id) ⇒ String
Returns the posting body.
22 23 24 |
# File 'lib/craigslist/api/resources/postings.rb', line 22 def body(posting_id) fetch(transport.get(path("postings", posting_id, "body")), "body") end |
#delete(posting_id) ⇒ true
72 73 74 75 |
# File 'lib/craigslist/api/resources/postings.rb', line 72 def delete(posting_id) transport.delete(path("postings", posting_id)) true end |
#price(posting_id) ⇒ Integer?
Returns for categories that carry a price.
41 42 43 |
# File 'lib/craigslist/api/resources/postings.rb', line 41 def price(posting_id) fetch(transport.get(path("postings", posting_id, "price")), "price") end |
#remuneration(posting_id) ⇒ String?
Returns for jobs and gigs postings.
55 56 57 |
# File 'lib/craigslist/api/resources/postings.rb', line 55 def remuneration(posting_id) fetch(transport.get(path("postings", posting_id, "remuneration")), "remuneration") end |
#status(posting_id) ⇒ String
Returns one of STATUSES.
16 17 18 |
# File 'lib/craigslist/api/resources/postings.rb', line 16 def status(posting_id) fetch(transport.get(path("postings", posting_id, "status")), "status") end |
#undelete(posting_id) ⇒ true
79 80 81 82 |
# File 'lib/craigslist/api/resources/postings.rb', line 79 def undelete(posting_id) transport.put(path("postings", posting_id, "undelete")) true end |
#update_body(posting_id, body) ⇒ String
Replaces the posting body.
Postings in "ctd" (cars & trucks by dealer) must keep the VIN they were created with; the API rejects a body that changes it.
34 35 36 37 |
# File 'lib/craigslist/api/resources/postings.rb', line 34 def update_body(posting_id, body) envelope = transport.put(path("postings", posting_id, "body"), form: {"body" => body}) fetch(envelope, "body") end |
#update_price(posting_id, price) ⇒ Integer
Returns the updated price.
48 49 50 51 |
# File 'lib/craigslist/api/resources/postings.rb', line 48 def update_price(posting_id, price) envelope = transport.put(path("postings", posting_id, "price"), form: {"price" => price.to_i}) fetch(envelope, "price") end |
#update_remuneration(posting_id, remuneration) ⇒ String
Returns the updated value.
62 63 64 65 66 67 68 |
# File 'lib/craigslist/api/resources/postings.rb', line 62 def update_remuneration(posting_id, remuneration) envelope = transport.put( path("postings", posting_id, "remuneration"), form: {"remuneration" => remuneration} ) fetch(envelope, "remuneration") end |