Class: Craigslist::API::PostingBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/craigslist/api/posting_block.rb

Overview

Remaining prepaid posting blocks for one area/product combination.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(area:, product_class:, product_name:, remaining_posts:) ⇒ PostingBlock

Returns a new instance of PostingBlock.



19
20
21
22
23
24
25
# File 'lib/craigslist/api/posting_block.rb', line 19

def initialize(area:, product_class:, product_name:, remaining_posts:)
  @area = area
  @product_class = product_class
  @product_name = product_name
  @remaining_posts = remaining_posts.to_i
  freeze
end

Instance Attribute Details

#areaString (readonly)

Returns area abbreviation, e.g. "htf".

Returns:

  • (String)

    area abbreviation, e.g. "htf"



8
9
10
# File 'lib/craigslist/api/posting_block.rb', line 8

def area
  @area
end

#product_classString (readonly)

Returns e.g. "CAR", "JOB".

Returns:

  • (String)

    e.g. "CAR", "JOB"



11
12
13
# File 'lib/craigslist/api/posting_block.rb', line 11

def product_class
  @product_class
end

#product_nameString (readonly)

Returns e.g. "hartford cars & trucks - by dealer block".

Returns:

  • (String)

    e.g. "hartford cars & trucks - by dealer block"



14
15
16
# File 'lib/craigslist/api/posting_block.rb', line 14

def product_name
  @product_name
end

#remaining_postsInteger (readonly)

Returns postings still available against this block.

Returns:

  • (Integer)

    postings still available against this block



17
18
19
# File 'lib/craigslist/api/posting_block.rb', line 17

def remaining_posts
  @remaining_posts
end

Class Method Details

.from(hash) ⇒ PostingBlock

Parameters:

  • hash (Hash)

    raw payload

Returns:



29
30
31
32
33
34
35
36
# File 'lib/craigslist/api/posting_block.rb', line 29

def self.from(hash)
  new(
    area: hash["area"],
    product_class: hash["productClass"],
    product_name: hash["productName"],
    remaining_posts: hash["remainingPosts"]
  )
end

Instance Method Details

#inspectObject



38
39
40
41
# File 'lib/craigslist/api/posting_block.rb', line 38

def inspect
  "#<#{self.class.name} area=#{area.inspect} class=#{product_class.inspect} " \
    "remaining=#{remaining_posts}>"
end