Class: Craigslist::API::PostingHandle

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

Examples:

posting = client.posting("7123456780")
posting.status          #=> "active"
posting.price = 4200
posting.add_image("photo.jpg")
posting.delete

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/craigslist/api/posting_handle.rb', line 19

def id
  @id
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/craigslist/api/posting_handle.rb', line 32

def active?
  status == "active"
end

#add_image(source, **options) ⇒ ImageInfo

Returns:

See Also:



111
112
113
# File 'lib/craigslist/api/posting_handle.rb', line 111

def add_image(source, **options)
  client.images.upload(id, source, **options)
end

#bodyString

Returns:

  • (String)


47
48
49
# File 'lib/craigslist/api/posting_handle.rb', line 47

def body
  client.postings.body(id)
end

#body=(value) ⇒ Object

Parameters:

  • value (String)


58
59
60
# File 'lib/craigslist/api/posting_handle.rb', line 58

def body=(value)
  update_body(value)
end

#deletetrue

Returns:

  • (true)


95
96
97
# File 'lib/craigslist/api/posting_handle.rb', line 95

def delete
  client.postings.delete(id)
end

#deleted?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/craigslist/api/posting_handle.rb', line 37

def deleted?
  status == "deleted"
end

#expired?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/craigslist/api/posting_handle.rb', line 42

def expired?
  status == "expired"
end

#imagesArray<ImageInfo>

Returns:



105
106
107
# File 'lib/craigslist/api/posting_handle.rb', line 105

def images
  client.images.list(id)
end

#inspectObject



133
134
135
# File 'lib/craigslist/api/posting_handle.rb', line 133

def inspect
  "#<#{self.class.name} id=#{id.inspect}>"
end

#priceInteger?

Returns:

  • (Integer, nil)


63
64
65
# File 'lib/craigslist/api/posting_handle.rb', line 63

def price
  client.postings.price(id)
end

#price=(value) ⇒ Object

Parameters:

  • value (Integer)


74
75
76
# File 'lib/craigslist/api/posting_handle.rb', line 74

def price=(value)
  update_price(value)
end

#remove_image(image_id) ⇒ true

Parameters:

  • image_id (String)

Returns:

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

#remunerationString?

Returns:

  • (String, nil)


79
80
81
# File 'lib/craigslist/api/posting_handle.rb', line 79

def remuneration
  client.postings.remuneration(id)
end

#remuneration=(value) ⇒ Object

Parameters:

  • value (String)


90
91
92
# File 'lib/craigslist/api/posting_handle.rb', line 90

def remuneration=(value)
  update_remuneration(value)
end

#reorder_images(image_ids) ⇒ true

Parameters:

  • image_ids (Array<String>)

Returns:

  • (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..posting_stats(id, start: start, stop: stop)
end

#statusString

Returns:



27
28
29
# File 'lib/craigslist/api/posting_handle.rb', line 27

def status
  client.postings.status(id)
end

#undeletetrue

Returns:

  • (true)


100
101
102
# File 'lib/craigslist/api/posting_handle.rb', line 100

def undelete
  client.postings.undelete(id)
end

#update_body(value) ⇒ String

Parameters:

  • value (String)

Returns:

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

Parameters:

  • value (Integer)

Returns:

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

Parameters:

  • value (String)

Returns:

  • (String)


85
86
87
# File 'lib/craigslist/api/posting_handle.rb', line 85

def update_remuneration(value)
  client.postings.update_remuneration(id, value)
end