Class: Craigslist::API::Result
- Inherits:
-
Object
- Object
- Craigslist::API::Result
- Defined in:
- lib/craigslist/api/result.rb
Overview
The outcome of a single posting within a bulk submission.
Bulk submissions succeed and fail per item, and the HTTP status says nothing about it — a 200 can carry a document in which every posting failed. So submissions return results rather than raising: a batch with a few rejections is ordinary, not exceptional.
Constant Summary collapse
- VALID =
Returned by validate when the posting looks acceptable.
"VALID"- NOT_VALID =
Validation failed. #explanation says why.
"NOT_VALID"- POSTED =
The posting was accepted.
"POSTED"- FAILED =
Unexpected error at post time.
"FAILED"- INSUFFICIENT_BLOCKS =
The account has no remaining blocks for this area/category and is not invoiced. More must be purchased before the posting is processed.
"INSUFFICIENT_BLOCKS"- CREDIT_LIMIT_REACHED =
The invoiced account hit its credit limit.
"CREDIT_LIMIT_REACHED"- CREDIT_CARD_ERROR =
Billing the card named by
cl:purchaseWithCreditCardIDfailed. "CREDIT_CARD_ERROR"
Instance Attribute Summary collapse
-
#explanation ⇒ String?
readonly
Human-readable detail, populated on failure.
-
#key ⇒ String
readonly
The key you supplied for this posting.
-
#manage_url ⇒ String?
readonly
URL for editing or deleting the posting.
-
#posting_id ⇒ String?
readonly
Craigslist's id for the new posting, on success.
-
#preview_html ⇒ String?
readonly
HTML preview of the posting as submitted.
-
#status ⇒ String?
readonly
One of the status constants above.
-
#view_url ⇒ String?
readonly
Public URL of the posting.
-
#warnings ⇒ Array<String>
readonly
Non-fatal warnings, typically XML parsing complaints.
Instance Method Summary collapse
-
#credit_card_error? ⇒ Boolean
The credit card could not be billed.
-
#credit_limit_reached? ⇒ Boolean
The invoiced account hit its credit limit.
- #failure? ⇒ Boolean
-
#initialize(key:, status: nil, explanation: nil, posting_id: nil, manage_url: nil, view_url: nil, preview_html: nil, warnings: []) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
-
#insufficient_blocks? ⇒ Boolean
The account is out of posting blocks.
-
#not_valid? ⇒ Boolean
Rejected during validation.
-
#posted? ⇒ Boolean
Accepted for posting (post mode only).
-
#success? ⇒ Boolean
Either valid or posted.
-
#valid? ⇒ Boolean
Validated successfully (validate mode only).
-
#warnings? ⇒ Boolean
Whether any non-fatal warnings came back.
Constructor Details
#initialize(key:, status: nil, explanation: nil, posting_id: nil, manage_url: nil, view_url: nil, preview_html: nil, warnings: []) ⇒ Result
Returns a new instance of Result.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/craigslist/api/result.rb', line 59 def initialize(key:, status: nil, explanation: nil, posting_id: nil, manage_url: nil, view_url: nil, preview_html: nil, warnings: []) @key = key @status = status @explanation = explanation @posting_id = posting_id @manage_url = manage_url @view_url = view_url @preview_html = preview_html @warnings = Array(warnings).freeze freeze end |
Instance Attribute Details
#explanation ⇒ String? (readonly)
Returns human-readable detail, populated on failure.
41 42 43 |
# File 'lib/craigslist/api/result.rb', line 41 def explanation @explanation end |
#key ⇒ String (readonly)
Returns the key you supplied for this posting.
35 36 37 |
# File 'lib/craigslist/api/result.rb', line 35 def key @key end |
#manage_url ⇒ String? (readonly)
Returns URL for editing or deleting the posting.
47 48 49 |
# File 'lib/craigslist/api/result.rb', line 47 def manage_url @manage_url end |
#posting_id ⇒ String? (readonly)
Returns craigslist's id for the new posting, on success.
44 45 46 |
# File 'lib/craigslist/api/result.rb', line 44 def posting_id @posting_id end |
#preview_html ⇒ String? (readonly)
Returns HTML preview of the posting as submitted.
53 54 55 |
# File 'lib/craigslist/api/result.rb', line 53 def preview_html @preview_html end |
#status ⇒ String? (readonly)
Returns one of the status constants above.
38 39 40 |
# File 'lib/craigslist/api/result.rb', line 38 def status @status end |
#view_url ⇒ String? (readonly)
Returns public URL of the posting.
50 51 52 |
# File 'lib/craigslist/api/result.rb', line 50 def view_url @view_url end |
#warnings ⇒ Array<String> (readonly)
Returns non-fatal warnings, typically XML parsing complaints. Worth logging even when the posting succeeded.
57 58 59 |
# File 'lib/craigslist/api/result.rb', line 57 def warnings @warnings end |
Instance Method Details
#credit_card_error? ⇒ Boolean
Returns the credit card could not be billed.
108 109 110 |
# File 'lib/craigslist/api/result.rb', line 108 def credit_card_error? status == CREDIT_CARD_ERROR end |
#credit_limit_reached? ⇒ Boolean
Returns the invoiced account hit its credit limit.
103 104 105 |
# File 'lib/craigslist/api/result.rb', line 103 def credit_limit_reached? status == CREDIT_LIMIT_REACHED end |
#failure? ⇒ Boolean
88 89 90 |
# File 'lib/craigslist/api/result.rb', line 88 def failure? !success? end |
#inspect ⇒ Object
117 118 119 120 |
# File 'lib/craigslist/api/result.rb', line 117 def inspect "#<#{self.class.name} key=#{key.inspect} status=#{status.inspect} " \ "posting_id=#{posting_id.inspect}>" end |
#insufficient_blocks? ⇒ Boolean
Returns the account is out of posting blocks.
98 99 100 |
# File 'lib/craigslist/api/result.rb', line 98 def insufficient_blocks? status == INSUFFICIENT_BLOCKS end |
#not_valid? ⇒ Boolean
Returns rejected during validation.
93 94 95 |
# File 'lib/craigslist/api/result.rb', line 93 def not_valid? status == NOT_VALID end |
#posted? ⇒ Boolean
Returns accepted for posting (post mode only).
78 79 80 |
# File 'lib/craigslist/api/result.rb', line 78 def posted? status == POSTED end |
#success? ⇒ Boolean
Returns either valid or posted.
83 84 85 |
# File 'lib/craigslist/api/result.rb', line 83 def success? valid? || posted? end |
#valid? ⇒ Boolean
Returns validated successfully (validate mode only).
73 74 75 |
# File 'lib/craigslist/api/result.rb', line 73 def valid? status == VALID end |
#warnings? ⇒ Boolean
Returns whether any non-fatal warnings came back.
113 114 115 |
# File 'lib/craigslist/api/result.rb', line 113 def warnings? !warnings.empty? end |