Module: DBC

Defined in:
lib/dbc-ruby.rb,
lib/dbc/user.rb,
lib/dbc/cohort.rb,
lib/dbc/api_key.rb,
lib/dbc/exercise.rb,
lib/dbc/challenge.rb,
lib/dbc/dbc_object.rb,
lib/dbc-ruby/version.rb,
lib/dbc/exercise_attempt.rb,
lib/dbc/challenge_attempt.rb

Defined Under Namespace

Classes: ApiKey, Challenge, ChallengeAttempt, Cohort, DbcObject, Exercise, ExerciseAttempt, User

Constant Summary collapse

VERSION =
'1.0.3'

Class Method Summary collapse

Class Method Details

.endpointObject



34
35
36
# File 'lib/dbc-ruby.rb', line 34

def self.endpoint
  @api_url
end

.request(path, options = {}) ⇒ Object



38
39
40
41
42
# File 'lib/dbc-ruby.rb', line 38

def self.request(path, options = {})
  raise ArgumentError.new "You must set ENV['DBC_API'] to your api token" unless self.token
  response = RestClient.get(@api_url + path, {accept: :json, authorization: 'DBC-API' + ' ' + @token, params: options})
  JSON.parse(response.body, symbolize_names: true)
end

.request_with_shared_token(path, options = {}) ⇒ Object



44
45
46
47
48
# File 'lib/dbc-ruby.rb', line 44

def self.request_with_shared_token(path, options = {})
  raise ArgumentError.new "You must set ENV['DBC_SHARED'] to your shared token" unless self.shared_token
  response = RestClient.get(@api_url + path, {accept: :json, authorization: 'DBC-SHARED' + ' ' + @shared_token , params: options})
  JSON.parse(response.body, symbolize_names: true)
end

.shared_tokenObject



30
31
32
# File 'lib/dbc-ruby.rb', line 30

def self.shared_token
  @shared_token ||= ENV['DBC_SHARED']
end

.shared_token=(token) ⇒ Object



26
27
28
# File 'lib/dbc-ruby.rb', line 26

def self.shared_token=(token)
  @shared_token = token
end

.tokenObject



22
23
24
# File 'lib/dbc-ruby.rb', line 22

def self.token
  @token ||= ENV['DBC_API']
end

.token=(token) ⇒ Object



18
19
20
# File 'lib/dbc-ruby.rb', line 18

def self.token=(token)
  @token = token
end