class DBots::Service
Represents a basic service.
Constants
- AUTH_HEADER
- BASE_URL
Attributes
api_key[RW]
@return [String, nil] the token that will be used for the service
key[RW]
@return [String, nil] the token that will be used for the service
token[RW]
@return [String, nil] the token that will be used for the service
Public Class Methods
new(token = nil)
click to toggle source
@param token [String] the token/key for the service.
# File lib/dbots/data.rb, line 18 def initialize(token = nil) @token = token end
Public Instance Methods
get(path, query = {}, headers = {})
click to toggle source
@!visibility private
# File lib/dbots/data.rb, line 27 def get(path, query = {}, headers = {}) DBots::API.get("#{self.class::BASE_URL}#{path}?#{URI.encode_www_form(query)}", headers) end
get_authed(path, query = {}, headers = {})
click to toggle source
@!visibility private
# File lib/dbots/data.rb, line 32 def get_authed(path, query = {}, headers = {}) raise DBots::Err::RequiresToken unless token? headers[self.class::AUTH_HEADER] = @token DBots::API.get("#{self.class::BASE_URL}#{path}?#{URI.encode_www_form(query)}", headers) end
inspect()
click to toggle source
@!visibility private
# File lib/dbots/data.rb, line 48 def inspect "<#{self.class.name} @token?=#{token?}>" end
post_authed(path, body, query = {}, headers = {})
click to toggle source
@!visibility private
# File lib/dbots/data.rb, line 40 def post_authed(path, body, query = {}, headers = {}) raise DBots::Err::RequiresToken unless token? headers[self.class::AUTH_HEADER] = @token DBots::API.post("#{self.class::BASE_URL}#{path}?#{URI.encode_www_form(query)}", body, headers) end
token?()
click to toggle source
# File lib/dbots/data.rb, line 22 def token? @token != nil end