Module: CodewarsApi::RequestHelper
- Defined in:
- lib/codewars_api/helpers/request_helper.rb
Class Method Summary collapse
- .add_api_key(request_options, api_key) ⇒ Object
- .add_body_options(request_options, body_options) ⇒ Object
- .get(url, options = nil) ⇒ Object
- .post(url, options = {}) ⇒ Object
Class Method Details
.add_api_key(request_options, api_key) ⇒ Object
8 9 10 11 12 |
# File 'lib/codewars_api/helpers/request_helper.rb', line 8 def self.add_api_key(, api_key) = .dup [:headers] = { 'Authorization' => api_key } end |
.add_body_options(request_options, body_options) ⇒ Object
14 15 16 17 18 |
# File 'lib/codewars_api/helpers/request_helper.rb', line 14 def self.(, ) = .dup [:body] = end |
.get(url, options = nil) ⇒ Object
29 30 31 32 33 |
# File 'lib/codewars_api/helpers/request_helper.rb', line 29 def self.get(url, = nil) uri = URI(CodewarsApi::BASE_URL + url) headers = [:headers] if https(uri).request_get uri, headers end |
.post(url, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/codewars_api/helpers/request_helper.rb', line 20 def self.post(url, = {}) uri = URI(CodewarsApi::BASE_URL + url) headers = { 'Content-Type' => 'application/json' } headers.merge! [:headers] if request = Net::HTTP::Post.new(uri.path, headers) request.body = [:body].to_json if https(uri).request(request) end |