Class: Basecamp3::Request
- Inherits:
-
Object
- Object
- Basecamp3::Request
- Defined in:
- lib/basecamp3/request.rb
Overview
A class for handling requests
Instance Method Summary collapse
-
#delete(path, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the delete request.
-
#get(path, params = {}, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the get request.
-
#initialize(access_token, uri) ⇒ Request
constructor
Initializes the request object.
-
#post(path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the post request.
-
#put(path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the put request.
-
#request(method, path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the request.
Constructor Details
#initialize(access_token, uri) ⇒ Request
Initializes the request object.
8 9 10 11 |
# File 'lib/basecamp3/request.rb', line 8 def initialize(access_token, uri) @access_token = access_token @uri = uri end |
Instance Method Details
#delete(path, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the delete request.
70 71 72 |
# File 'lib/basecamp3/request.rb', line 70 def delete(path, model = 'raw') request(:delete, path, nil, model) end |
#get(path, params = {}, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the get request.
38 39 40 |
# File 'lib/basecamp3/request.rb', line 38 def get(path, params = {}, model = 'raw') request(:get, "#{path}#{hash_to_get_query(params)}", nil, model) end |
#post(path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the post request.
49 50 51 |
# File 'lib/basecamp3/request.rb', line 49 def post(path, data = nil, model = 'raw') request(:post, path, data, model) end |
#put(path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the put request.
60 61 62 |
# File 'lib/basecamp3/request.rb', line 60 def put(path, data = nil, model = 'raw') request(:put, path, data, model) end |
#request(method, path, data = nil, model = 'raw') ⇒ Basecamp3::Model, OpenStruct
Sends the request.
21 22 23 24 25 26 27 28 29 |
# File 'lib/basecamp3/request.rb', line 21 def request(method, path, data = nil, model = 'raw') uri = build_request_uri(path) https = build_https_object(uri) request = build_request_object(method, uri) request.body = data.to_json unless data.nil? get_response(https, request, model) end |