Module: Giftbit::Base

Included in:
Giftbit, Giftbit
Defined in:
lib/giftbit/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



7
8
9
10
# File 'lib/giftbit/base.rb', line 7

def self.extended(klass)
  klass.send :cattr_accessor, :endpoint, :auth, :auths
  klass.endpoint = 'https://testbedapp.giftbit.com/papi/v1/'
end

.included(klass) ⇒ Object



12
13
14
# File 'lib/giftbit/base.rb', line 12

def self.included(klass)
  klass.send :attr_accessor, :auth
end

Instance Method Details

#auths?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/giftbit/base.rb', line 36

def auths?
  auths = instance? ? self.class.auths : self.auths
  auths && auths.any?
end

#get_authObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/giftbit/base.rb', line 16

def get_auth
  fail "auth and auths can't both be set" if inherited_auth && auths?

  if auth = instance? ? self.auth : inherited_auth
    auth
  elsif auths?
    fail 'you must init a new API instance with the auth you want to use'
  else
    fail 'you must set an auth token at application boot'
  end
end

#inherited_authObject



28
29
30
# File 'lib/giftbit/base.rb', line 28

def inherited_auth
  instance? ? self.class.auth : auth
end

#inherited_endpointObject



32
33
34
# File 'lib/giftbit/base.rb', line 32

def inherited_endpoint
  instance? ? self.class.endpoint : endpoint
end

#instance?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/giftbit/base.rb', line 41

def instance?
  self.class == Giftbit
end