Class: Craigslist::API::Resources::Postings

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#initialize

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.

Parameters:

  • zip (String)

Returns:



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.

Parameters:

  • posting_id (String, Integer)

Returns:

  • (String)

    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

Parameters:

  • posting_id (String, Integer)

Returns:

  • (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.

Parameters:

  • posting_id (String, Integer)

Returns:

  • (Integer, nil)

    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.

Parameters:

  • posting_id (String, Integer)

Returns:

  • (String, nil)

    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.

Parameters:

  • posting_id (String, Integer)

Returns:



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

Parameters:

  • posting_id (String, Integer)

Returns:

  • (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.

Parameters:

  • posting_id (String, Integer)
  • body (String)

Returns:

  • (String)

    the updated body as the API echoes it back



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.

Parameters:

  • posting_id (String, Integer)
  • price (Integer)

    in the currency of the posting's location

Returns:

  • (Integer)

    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.

Parameters:

  • posting_id (String, Integer)
  • remuneration (String)

    free text, e.g. "$19.95/hr plus tips"

Returns:

  • (String)

    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