Class: Craigslist::API::PostingHandle
- Inherits:
-
Object
- Object
- Craigslist::API::PostingHandle
- Defined in:
- lib/craigslist/api/posting_handle.rb
Overview
A live posting, addressed by id.
Returned by Client#posting. Holds no state of its own beyond the id — every reader hits the API — so it is safe to keep around, and it never goes stale.
Instance Attribute Summary collapse
- #id ⇒ String readonly
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add_image(source, **options) ⇒ ImageInfo
- #body ⇒ String
- #body=(value) ⇒ Object
- #delete ⇒ true
- #deleted? ⇒ Boolean
- #expired? ⇒ Boolean
- #images ⇒ Array<ImageInfo>
-
#initialize(client, id) ⇒ PostingHandle
constructor
A new instance of PostingHandle.
- #inspect ⇒ Object
- #price ⇒ Integer?
- #price=(value) ⇒ Object
- #remove_image(image_id) ⇒ true
- #remuneration ⇒ String?
- #remuneration=(value) ⇒ Object
- #reorder_images(image_ids) ⇒ true
- #stats(start: nil, stop: nil) ⇒ PostingStats
-
#status ⇒ String
One of Resources::Postings::STATUSES.
- #undelete ⇒ true
- #update_body(value) ⇒ String
- #update_price(value) ⇒ Integer
- #update_remuneration(value) ⇒ String
Constructor Details
#initialize(client, id) ⇒ PostingHandle
Returns a new instance of PostingHandle.
21 22 23 24 |
# File 'lib/craigslist/api/posting_handle.rb', line 21 def initialize(client, id) @client = client @id = id.to_s end |
Instance Attribute Details
#id ⇒ String (readonly)
19 20 21 |
# File 'lib/craigslist/api/posting_handle.rb', line 19 def id @id end |
Instance Method Details
#active? ⇒ Boolean
32 33 34 |
# File 'lib/craigslist/api/posting_handle.rb', line 32 def active? status == "active" end |
#add_image(source, **options) ⇒ ImageInfo
111 112 113 |
# File 'lib/craigslist/api/posting_handle.rb', line 111 def add_image(source, **) client.images.upload(id, source, **) end |
#body ⇒ String
47 48 49 |
# File 'lib/craigslist/api/posting_handle.rb', line 47 def body client.postings.body(id) end |
#body=(value) ⇒ Object
58 59 60 |
# File 'lib/craigslist/api/posting_handle.rb', line 58 def body=(value) update_body(value) end |
#delete ⇒ true
95 96 97 |
# File 'lib/craigslist/api/posting_handle.rb', line 95 def delete client.postings.delete(id) end |
#deleted? ⇒ Boolean
37 38 39 |
# File 'lib/craigslist/api/posting_handle.rb', line 37 def deleted? status == "deleted" end |
#expired? ⇒ Boolean
42 43 44 |
# File 'lib/craigslist/api/posting_handle.rb', line 42 def expired? status == "expired" end |
#images ⇒ Array<ImageInfo>
105 106 107 |
# File 'lib/craigslist/api/posting_handle.rb', line 105 def images client.images.list(id) end |
#inspect ⇒ Object
133 134 135 |
# File 'lib/craigslist/api/posting_handle.rb', line 133 def inspect "#<#{self.class.name} id=#{id.inspect}>" end |
#price ⇒ Integer?
63 64 65 |
# File 'lib/craigslist/api/posting_handle.rb', line 63 def price client.postings.price(id) end |
#price=(value) ⇒ Object
74 75 76 |
# File 'lib/craigslist/api/posting_handle.rb', line 74 def price=(value) update_price(value) end |
#remove_image(image_id) ⇒ true
117 118 119 |
# File 'lib/craigslist/api/posting_handle.rb', line 117 def remove_image(image_id) client.images.remove(id, image_id) end |
#remuneration ⇒ String?
79 80 81 |
# File 'lib/craigslist/api/posting_handle.rb', line 79 def remuneration client.postings.remuneration(id) end |
#remuneration=(value) ⇒ Object
90 91 92 |
# File 'lib/craigslist/api/posting_handle.rb', line 90 def remuneration=(value) update_remuneration(value) end |
#reorder_images(image_ids) ⇒ true
123 124 125 |
# File 'lib/craigslist/api/posting_handle.rb', line 123 def reorder_images(image_ids) client.images.reorder(id, image_ids) end |
#stats(start: nil, stop: nil) ⇒ PostingStats
129 130 131 |
# File 'lib/craigslist/api/posting_handle.rb', line 129 def stats(start: nil, stop: nil) client.account.posting_stats(id, start: start, stop: stop) end |
#status ⇒ String
Returns one of Resources::Postings::STATUSES.
27 28 29 |
# File 'lib/craigslist/api/posting_handle.rb', line 27 def status client.postings.status(id) end |
#undelete ⇒ true
100 101 102 |
# File 'lib/craigslist/api/posting_handle.rb', line 100 def undelete client.postings.undelete(id) end |
#update_body(value) ⇒ String
53 54 55 |
# File 'lib/craigslist/api/posting_handle.rb', line 53 def update_body(value) client.postings.update_body(id, value) end |
#update_price(value) ⇒ Integer
69 70 71 |
# File 'lib/craigslist/api/posting_handle.rb', line 69 def update_price(value) client.postings.update_price(id, value) end |
#update_remuneration(value) ⇒ String
85 86 87 |
# File 'lib/craigslist/api/posting_handle.rb', line 85 def update_remuneration(value) client.postings.update_remuneration(id, value) end |