Module: DBots::API
- Defined in:
- lib/dbots/api.rb
Overview
Main API functions
Defined Under Namespace
Classes: Response
Class Method Summary collapse
- .get(url, headers = {}) ⇒ Object
- .post(url, body, headers = {}) ⇒ Object
-
.request(type, *attributes) ⇒ Object
Request an endpoint easily.
- .user_agent ⇒ Object
Class Method Details
.get(url, headers = {}) ⇒ Object
12 13 14 15 |
# File 'lib/dbots/api.rb', line 12 def get(url, headers = {}) headers['User-Agent'] = user_agent request(:get, url, headers) end |
.post(url, body, headers = {}) ⇒ Object
17 18 19 20 |
# File 'lib/dbots/api.rb', line 17 def post(url, body, headers = {}) headers['User-Agent'] = user_agent request(:post, url, body, headers) end |
.request(type, *attributes) ⇒ Object
Request an endpoint easily
27 28 29 30 31 32 33 34 |
# File 'lib/dbots/api.rb', line 27 def request(type, *attributes) response = RestClient.send(type, *attributes) Response.new(response, parse_json(response.body)) rescue RestClient:: raise DBots::Err:: rescue RestClient::InternalServerError raise DBots::Err::ServerFail end |
.user_agent ⇒ Object
22 23 24 |
# File 'lib/dbots/api.rb', line 22 def user_agent "dbots (https://github.com/dbots-pkg/dbots.rb #{DBots::VERSION}) rest-client/#{RestClient::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}" end |