Class: Craigslist::API::JsonTransport
- Inherits:
-
Object
- Object
- Craigslist::API::JsonTransport
- Defined in:
- lib/craigslist/api/json_transport.rb
Overview
Request plumbing for the JSON Bulkpost API.
Owns three concerns the resource classes should not repeat: attaching a bearer token (refreshing once on a 401), mapping HTTP status onto this library's error classes, and unwrapping the response envelope.
Constant Summary collapse
- FORM_CONTENT_TYPE =
Writes to the Bulkpost API are form-encoded, not JSON, even though the responses are JSON.
"application/x-www-form-urlencoded"
Instance Attribute Summary collapse
-
#account_messages ⇒ Array<Hash>
readonly
Account notices seen on the most recent response.
Instance Method Summary collapse
- #delete(path) ⇒ Envelope
- #get(path, params: {}) ⇒ Envelope
-
#initialize(config:, connection:, token_provider:) ⇒ JsonTransport
constructor
A new instance of JsonTransport.
- #post(path, form: nil) ⇒ Envelope
- #put(path, form: nil) ⇒ Envelope
-
#upload(path, part:, fields: {}) ⇒ Envelope
Uploads a file as
multipart/form-data.
Constructor Details
#initialize(config:, connection:, token_provider:) ⇒ JsonTransport
Returns a new instance of JsonTransport.
20 21 22 23 24 25 |
# File 'lib/craigslist/api/json_transport.rb', line 20 def initialize(config:, connection:, token_provider:) @config = config @connection = connection @token_provider = token_provider @account_messages = [] end |
Instance Attribute Details
#account_messages ⇒ Array<Hash> (readonly)
Returns account notices seen on the most recent response.
18 19 20 |
# File 'lib/craigslist/api/json_transport.rb', line 18 def @account_messages end |
Instance Method Details
#delete(path) ⇒ Envelope
43 44 45 |
# File 'lib/craigslist/api/json_transport.rb', line 43 def delete(path) run(:delete, path) end |
#get(path, params: {}) ⇒ Envelope
28 29 30 |
# File 'lib/craigslist/api/json_transport.rb', line 28 def get(path, params: {}) run(:get, path, params: params) end |
#post(path, form: nil) ⇒ Envelope
33 34 35 |
# File 'lib/craigslist/api/json_transport.rb', line 33 def post(path, form: nil) run(:post, path, form: form) end |
#put(path, form: nil) ⇒ Envelope
38 39 40 |
# File 'lib/craigslist/api/json_transport.rb', line 38 def put(path, form: nil) run(:put, path, form: form) end |
#upload(path, part:, fields: {}) ⇒ Envelope
Uploads a file as multipart/form-data.
53 54 55 |
# File 'lib/craigslist/api/json_transport.rb', line 53 def upload(path, part:, fields: {}) run(:put, path, body: fields.merge("file" => part), content_type: nil) end |