Class: Redd::Client
- Inherits:
-
Object
- Object
- Redd::Client
- Defined in:
- lib/redd/client.rb
Overview
The base class for JSON-based HTTP clients. Generic enough to be used for basically anything.
Direct Known Subclasses
Defined Under Namespace
Classes: Response
Constant Summary collapse
- USER_AGENT =
The default User-Agent to use if none was provided.
"Ruby:Redd:v#{Redd::VERSION} (by unknown)"
Instance Method Summary collapse
-
#delete(path, options = {}) ⇒ Response
Make a DELETE request.
-
#get(path, options = {}) ⇒ Response
Make a GET request.
-
#initialize(endpoint:, user_agent: USER_AGENT) ⇒ Client
constructor
Create a new client.
-
#patch(path, options = {}) ⇒ Response
Make a PATCH request.
-
#post(path, options = {}) ⇒ Response
Make a POST request.
-
#put(path, options = {}) ⇒ Response
Make a PUT request.
-
#request(verb, path, options = {}) ⇒ Response
Make an HTTP request.
Constructor Details
#initialize(endpoint:, user_agent: USER_AGENT) ⇒ Client
Create a new client.
22 23 24 25 |
# File 'lib/redd/client.rb', line 22 def initialize(endpoint:, user_agent: USER_AGENT) @endpoint = endpoint @user_agent = user_agent end |
Instance Method Details
#delete(path, options = {}) ⇒ Response
Make a DELETE request.
79 80 81 |
# File 'lib/redd/client.rb', line 79 def delete(path, = {}) request(:delete, path, form: ) end |
#get(path, options = {}) ⇒ Response
Make a GET request.
47 48 49 |
# File 'lib/redd/client.rb', line 47 def get(path, = {}) request(:get, path, params: ) end |
#patch(path, options = {}) ⇒ Response
Make a PATCH request.
71 72 73 |
# File 'lib/redd/client.rb', line 71 def patch(path, = {}) request(:patch, path, form: ) end |
#post(path, options = {}) ⇒ Response
Make a POST request.
55 56 57 |
# File 'lib/redd/client.rb', line 55 def post(path, = {}) request(:post, path, form: ) end |
#put(path, options = {}) ⇒ Response
Make a PUT request.
63 64 65 |
# File 'lib/redd/client.rb', line 63 def put(path, = {}) request(:put, path, form: ) end |
#request(verb, path, options = {}) ⇒ Response
Make an HTTP request.
35 36 37 38 39 40 41 |
# File 'lib/redd/client.rb', line 35 def request(verb, path, = {}) # Uncomment if desperate # puts "#{verb} #{path}: #{options}" response = connection.request(verb, path, **) Response.new(response.status.code, response.headers, response.body.to_s) end |