Class: Craigslist::API::Category

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

Overview

A craigslist posting category, as published by the public reference service.

Constant Summary collapse

UNSUPPORTED =

Categories the bulk posting interface explicitly does not support. Submitting to one of these is documented as something not to do.

%w[sbw rew swp sub reo prk hou sha].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abbreviation:, description: nil, type: nil, id: nil) ⇒ Category

Returns a new instance of Category.



14
15
16
17
18
19
20
# File 'lib/craigslist/api/category.rb', line 14

def initialize(abbreviation:, description: nil, type: nil, id: nil)
  @abbreviation = abbreviation
  @description = description
  @type = type
  @id = id
  freeze
end

Instance Attribute Details

#abbreviationObject (readonly)

Returns the value of attribute abbreviation.



12
13
14
# File 'lib/craigslist/api/category.rb', line 12

def abbreviation
  @abbreviation
end

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/craigslist/api/category.rb', line 12

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/craigslist/api/category.rb', line 12

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/craigslist/api/category.rb', line 12

def type
  @type
end

Class Method Details

.from(hash) ⇒ Category

Parameters:

  • hash (Hash)

    raw payload

Returns:



24
25
26
27
28
29
30
31
# File 'lib/craigslist/api/category.rb', line 24

def self.from(hash)
  new(
    abbreviation: hash["Abbreviation"],
    description: hash["Description"],
    type: hash["Type"],
    id: hash["CategoryID"]
  )
end

Instance Method Details

#inspectObject



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

def inspect
  "#<#{self.class.name} #{abbreviation.inspect} #{description.inspect} type=#{type.inspect}>"
end

#to_sObject



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

def to_s
  abbreviation.to_s
end

#unsupported?Boolean

Returns whether bulk posting to this category is disallowed.

Returns:

  • (Boolean)

    whether bulk posting to this category is disallowed



34
35
36
# File 'lib/craigslist/api/category.rb', line 34

def unsupported?
  UNSUPPORTED.include?(abbreviation)
end