Class: GameRocket::Configuration
- Inherits:
-
Object
- Object
- GameRocket::Configuration
- Defined in:
- lib/gamerocket/configuration.rb
Constant Summary collapse
- API_VERSION =
"1"
Class Attribute Summary collapse
-
.apiKey ⇒ Object
writeonly
Sets the attribute apiKey.
-
.custom_user_agent ⇒ Object
writeonly
Sets the attribute custom_user_agent.
- .logger ⇒ Object
-
.secretKey ⇒ Object
writeonly
Sets the attribute secretKey.
Instance Attribute Summary collapse
-
#apiKey ⇒ Object
readonly
Returns the value of attribute apiKey.
-
#secretKey ⇒ Object
readonly
Returns the value of attribute secretKey.
Class Method Summary collapse
- ._default_logger ⇒ Object
- .environment=(env) ⇒ Object
- .expectant_reader(*attributes) ⇒ Object
- .gateway ⇒ Object
- .instantiate ⇒ Object
Instance Method Summary collapse
- #api_version ⇒ Object
- #baseUrl ⇒ Object
- #ca_file ⇒ Object
- #http ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #logger ⇒ Object
- #port ⇒ Object
- #server ⇒ Object
- #ssl? ⇒ Boolean
- #user_agent ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
46 47 48 49 50 |
# File 'lib/gamerocket/configuration.rb', line 46 def initialize( = {}) [:environment, :apiKey, :secretKey, :custom_user_agent, :logger].each do |attr| instance_variable_set "@#{attr}", [attr] end end |
Class Attribute Details
.apiKey=(value) ⇒ Object (writeonly)
Sets the attribute apiKey
6 7 8 |
# File 'lib/gamerocket/configuration.rb', line 6 def apiKey=(value) @apiKey = value end |
.custom_user_agent=(value) ⇒ Object (writeonly)
Sets the attribute custom_user_agent
6 7 8 |
# File 'lib/gamerocket/configuration.rb', line 6 def custom_user_agent=(value) @custom_user_agent = value end |
.logger ⇒ Object
42 43 44 |
# File 'lib/gamerocket/configuration.rb', line 42 def self.logger @logger ||=_default_logger end |
.secretKey=(value) ⇒ Object (writeonly)
Sets the attribute secretKey
6 7 8 |
# File 'lib/gamerocket/configuration.rb', line 6 def secretKey=(value) @secretKey = value end |
Instance Attribute Details
#apiKey ⇒ Object (readonly)
Returns the value of attribute apiKey.
8 9 10 |
# File 'lib/gamerocket/configuration.rb', line 8 def apiKey @apiKey end |
#secretKey ⇒ Object (readonly)
Returns the value of attribute secretKey.
8 9 10 |
# File 'lib/gamerocket/configuration.rb', line 8 def secretKey @secretKey end |
Class Method Details
._default_logger ⇒ Object
111 112 113 114 115 |
# File 'lib/gamerocket/configuration.rb', line 111 def self._default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end |
.environment=(env) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/gamerocket/configuration.rb', line 21 def self.environment=(env) unless [:development, :production].include?(env) raise ArgumentError, "#{env.inspect} is not a valid environment" end @environment = env end |
.expectant_reader(*attributes) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/gamerocket/configuration.rb', line 10 def self.expectant_reader(*attributes) attributes.each do |attribute| (class << self; self; end).send(:define_method, attribute) do attribute_value = instance_variable_get("@#{attribute}") raise ConfigurationError.new(attribute.to_s, "needs to be set") unless attribute_value attribute_value end end end |
.gateway ⇒ Object
28 29 30 |
# File 'lib/gamerocket/configuration.rb', line 28 def self.gateway GameRocket::Gateway.new(instantiate) end |
.instantiate ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/gamerocket/configuration.rb', line 32 def self.instantiate config = new( :custom_user_agent => @custom_user_agent, :environment => environment, :logger => logger, :apiKey => apiKey, :secretKey => secretKey ) end |
Instance Method Details
#api_version ⇒ Object
52 53 54 |
# File 'lib/gamerocket/configuration.rb', line 52 def api_version API_VERSION end |
#baseUrl ⇒ Object
56 57 58 |
# File 'lib/gamerocket/configuration.rb', line 56 def baseUrl "#{protocol}://#{server}:#{port}/api/#{API_VERSION}" end |
#ca_file ⇒ Object
60 61 62 63 64 65 |
# File 'lib/gamerocket/configuration.rb', line 60 def ca_file case @environment when :production File.(File.join(File.dirname(_FILE_), "..", "ssl", "www_gamerocket_io.ca.crt" )) end end |
#http ⇒ Object
67 68 69 |
# File 'lib/gamerocket/configuration.rb', line 67 def http Http.new(self) end |
#inspect ⇒ Object
117 118 119 |
# File 'lib/gamerocket/configuration.rb', line 117 def inspect super.gsub(/@secretKey=\".*\"/, '@secrectKey="[FILTERED]"') end |
#logger ⇒ Object
71 72 73 |
# File 'lib/gamerocket/configuration.rb', line 71 def logger @logger ||=self.class._default_logger end |
#port ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/gamerocket/configuration.rb', line 75 def port case @environment when :development ENV['GATEWAY_PORT'] || 8180 when :production 443 end end |
#server ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/gamerocket/configuration.rb', line 88 def server case @environment when :development "localhost" when :production "www.gamerocket.io" end end |
#ssl? ⇒ Boolean
97 98 99 100 101 102 103 104 |
# File 'lib/gamerocket/configuration.rb', line 97 def ssl? case @environment when :development false when :production true end end |
#user_agent ⇒ Object
106 107 108 109 |
# File 'lib/gamerocket/configuration.rb', line 106 def user_agent base_user_agent = "GameRocket Ruby Gem #{GameRocket::Version::String}" @custom_user_agent ? "#{base_user_agent} (#{@custom_user_agent}" : base_user_agent end |