Class: NumerousClientInternals
- Inherits:
-
Object
- Object
- NumerousClientInternals
- Defined in:
- lib/numerousapp.rb
Overview
NumerousClientInternals
Handles details of talking to the numerousapp.com server, including the (basic) authentication, handling chunked APIs, json vs multipart APIs, fixing up a few server response quirks, and so forth. It is not meant for use outside of Numerous and NumerousMetric.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agentString ⇒ String
User agent string sent to the server.
-
#debugLevel ⇒ Fixnum
readonly
Current debugging level; change via debug() method.
-
#serverName ⇒ String
readonly
FQDN of the target NumerousApp server.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
Instance Method Summary collapse
-
#debug(lvl = 1) ⇒ Fixnum
Set the debug level.
-
#initialize(apiKey = nil, server: 'api.numerousapp.com', throttle: nil, throttleData: nil) ⇒ NumerousClientInternals
constructor
A new instance of NumerousClientInternals.
-
#setBogusDupFilter(f) ⇒ Boolean
This is primarily for testing; control filtering of bogus duplicates.
-
#to_s ⇒ String
String representation of Numerous.
Constructor Details
#initialize(apiKey = nil, server: 'api.numerousapp.com', throttle: nil, throttleData: nil) ⇒ NumerousClientInternals
Returns a new instance of NumerousClientInternals.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/numerousapp.rb', line 126 def initialize(apiKey=nil, server:'api.numerousapp.com', throttle:nil, throttleData:nil) # specifying apiKey=nil asks us to get key from various default places. if not apiKey apiKey = Numerous.numerousKey() end @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @serverName = server @serverPort = u.port @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere @need_restart = true # port will be opened in simpleAPI # Throttling: # # arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # throttlePolicy "tuple" is: # [ 0 ] - Proc # [ 1 ] - specific data for Proc # [ 2 ] - "up" tuple for chained policy # # and the default policy uses the "data" as a hash of parameters: # :voluntary -- the threshold point for voluntary backoff # :volmaxdelay -- arbitrary maximum *voluntary delay* time # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40, volmaxdelay: 5} # you can keep the dflt throttle but just alter the voluntary # parameters, this way: if throttleData and not throttle voluntary = voluntary.merge(throttleData) end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # stats are "infotainment" @debugLevel = 0 end |
Instance Attribute Details
#agentString ⇒ String
Returns User agent string sent to the server.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/numerousapp.rb', line 126 def initialize(apiKey=nil, server:'api.numerousapp.com', throttle:nil, throttleData:nil) # specifying apiKey=nil asks us to get key from various default places. if not apiKey apiKey = Numerous.numerousKey() end @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @serverName = server @serverPort = u.port @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere @need_restart = true # port will be opened in simpleAPI # Throttling: # # arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # throttlePolicy "tuple" is: # [ 0 ] - Proc # [ 1 ] - specific data for Proc # [ 2 ] - "up" tuple for chained policy # # and the default policy uses the "data" as a hash of parameters: # :voluntary -- the threshold point for voluntary backoff # :volmaxdelay -- arbitrary maximum *voluntary delay* time # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40, volmaxdelay: 5} # you can keep the dflt throttle but just alter the voluntary # parameters, this way: if throttleData and not throttle voluntary = voluntary.merge(throttleData) end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # stats are "infotainment" @debugLevel = 0 end |
#debugLevel ⇒ Fixnum (readonly)
Returns Current debugging level; change via debug() method.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/numerousapp.rb', line 126 def initialize(apiKey=nil, server:'api.numerousapp.com', throttle:nil, throttleData:nil) # specifying apiKey=nil asks us to get key from various default places. if not apiKey apiKey = Numerous.numerousKey() end @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @serverName = server @serverPort = u.port @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere @need_restart = true # port will be opened in simpleAPI # Throttling: # # arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # throttlePolicy "tuple" is: # [ 0 ] - Proc # [ 1 ] - specific data for Proc # [ 2 ] - "up" tuple for chained policy # # and the default policy uses the "data" as a hash of parameters: # :voluntary -- the threshold point for voluntary backoff # :volmaxdelay -- arbitrary maximum *voluntary delay* time # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40, volmaxdelay: 5} # you can keep the dflt throttle but just alter the voluntary # parameters, this way: if throttleData and not throttle voluntary = voluntary.merge(throttleData) end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # stats are "infotainment" @debugLevel = 0 end |
#serverName ⇒ String (readonly)
Returns FQDN of the target NumerousApp server.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/numerousapp.rb', line 126 def initialize(apiKey=nil, server:'api.numerousapp.com', throttle:nil, throttleData:nil) # specifying apiKey=nil asks us to get key from various default places. if not apiKey apiKey = Numerous.numerousKey() end @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @serverName = server @serverPort = u.port @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere @need_restart = true # port will be opened in simpleAPI # Throttling: # # arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # throttlePolicy "tuple" is: # [ 0 ] - Proc # [ 1 ] - specific data for Proc # [ 2 ] - "up" tuple for chained policy # # and the default policy uses the "data" as a hash of parameters: # :voluntary -- the threshold point for voluntary backoff # :volmaxdelay -- arbitrary maximum *voluntary delay* time # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40, volmaxdelay: 5} # you can keep the dflt throttle but just alter the voluntary # parameters, this way: if throttleData and not throttle voluntary = voluntary.merge(throttleData) end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # stats are "infotainment" @debugLevel = 0 end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
177 178 179 |
# File 'lib/numerousapp.rb', line 177 def statistics @statistics end |
Instance Method Details
#debug(lvl = 1) ⇒ Fixnum
Set the debug level
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/numerousapp.rb', line 193 def debug(lvl=1) prev = @debugLevel @debugLevel = lvl # need to make sure we have started an http session # (normally deferred until first API call) if @debugLevel > 0 # this is hokey, but it is what it is... it's for debug anyway # we have to restart the session with debug on @http = Net::HTTP.new(@serverName, @serverPort) @http.use_ssl = true # always required by NumerousApp @http.set_debug_output $stderr @http = @http.start() @need_restart = false else @need_restart = true # will force a new http session end return prev end |
#setBogusDupFilter(f) ⇒ Boolean
If you are calling this you are probably doing something wrong.
This is primarily for testing; control filtering of bogus duplicates
220 221 222 223 224 |
# File 'lib/numerousapp.rb', line 220 def setBogusDupFilter(f) prev = @filterDuplicates @filterDuplicates = f return prev end |
#to_s ⇒ String
String representation of Numerous
183 184 185 186 |
# File 'lib/numerousapp.rb', line 183 def to_s() oid = (2 * self.object_id).to_s(16) # XXX "2*" matches native to_s return "<Numerous {#{@serverName}} @ 0x#{oid}>" end |