Module: BooticClient

Defined in:
lib/bootic_client.rb,
lib/bootic_client/client.rb,
lib/bootic_client/entity.rb,
lib/bootic_client/errors.rb,
lib/bootic_client/version.rb,
lib/bootic_client/relation.rb,
lib/bootic_client/whiny_uri.rb,
lib/bootic_client/stores/memcache.rb,
lib/bootic_client/strategies/bearer.rb,
lib/bootic_client/strategies/strategy.rb,
lib/bootic_client/strategies/authorized.rb,
lib/bootic_client/strategies/basic_auth.rb,
lib/bootic_client/strategies/oauth2_strategy.rb,
lib/bootic_client/strategies/client_credentials.rb

Defined Under Namespace

Modules: EnumerableEntity, Stores, Strategies Classes: AccessForbiddenError, AuthorizationError, Client, ClientError, Entity, InvalidURLError, NotFoundError, Relation, ServerError, TransportError, UnauthorizedError, WhinyURI

Constant Summary collapse

InvalidConfigurationError =
Class.new(StandardError)
VERY_BASIC_URL_CHECK =
/^(http|https):/.freeze
AUTH_HOST =
'https://auth.bootic.net'.freeze
API_ROOT =
'https://api.bootic.net/v1'.freeze
VERSION =
"0.0.21".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_storeObject

Returns the value of attribute cache_store.



16
17
18
# File 'lib/bootic_client.rb', line 16

def cache_store
  @cache_store
end

.client_idObject

Returns the value of attribute client_id.



16
17
18
# File 'lib/bootic_client.rb', line 16

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



16
17
18
# File 'lib/bootic_client.rb', line 16

def client_secret
  @client_secret
end

.loggingObject

Returns the value of attribute logging.



15
16
17
# File 'lib/bootic_client.rb', line 15

def logging
  @logging
end

.user_agentObject

Returns the value of attribute user_agent.



16
17
18
# File 'lib/bootic_client.rb', line 16

def user_agent
  @user_agent
end

Class Method Details

.api_rootObject



66
67
68
# File 'lib/bootic_client.rb', line 66

def api_root
  @api_root || API_ROOT
end

.api_root=(v) ⇒ Object



53
54
55
56
# File 'lib/bootic_client.rb', line 53

def api_root=(v)
  check_url! :api_root, v
  set_non_nil :api_root, v
end

.auth_hostObject



62
63
64
# File 'lib/bootic_client.rb', line 62

def auth_host
  @auth_host || AUTH_HOST
end

.auth_host=(v) ⇒ Object



48
49
50
51
# File 'lib/bootic_client.rb', line 48

def auth_host=(v)
  check_url! :auth_host, v
  set_non_nil :auth_host, v
end

.check_url!(name, v) ⇒ Object



83
84
85
# File 'lib/bootic_client.rb', line 83

def check_url!(name, v)
  raise InvalidConfigurationError, "#{name} must be a valid URL" unless v.to_s =~ VERY_BASIC_URL_CHECK
end

.client(strategy_name, client_opts = {}, &on_new_token) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/bootic_client.rb', line 22

def client(strategy_name, client_opts = {}, &on_new_token)
  opts = client_opts.dup
  opts[:logging] = logging
  opts[:logger] = logger if logging
  opts[:cache_store] = cache_store if cache_store
  opts[:user_agent] = user_agent if user_agent
  require "bootic_client/strategies/#{strategy_name}"
  strategies.fetch(strategy_name.to_sym).new self, opts, &on_new_token
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (BooticClient)

    the object that the method was called on



74
75
76
# File 'lib/bootic_client.rb', line 74

def configure(&block)
  yield self
end

.loggerObject



70
71
72
# File 'lib/bootic_client.rb', line 70

def logger
  @logger || ::Logger.new(STDOUT)
end

.logger=(v) ⇒ Object



58
59
60
# File 'lib/bootic_client.rb', line 58

def logger=(v)
  set_non_nil :logger, v
end

.set_non_nil(name, v) ⇒ Object



78
79
80
81
# File 'lib/bootic_client.rb', line 78

def set_non_nil(name, v)
  raise InvalidConfigurationError, "#{name} cannot be nil" if v.nil?
  instance_variable_set("@#{name}", v)
end

.strategiesObject



18
19
20
# File 'lib/bootic_client.rb', line 18

def strategies
  @strategies ||= {}
end