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; use debug() method to change.
-
#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 |
# 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 @serverName = server @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @http = Net::HTTP.new(server, u.port) @http.use_ssl = true # always required by NumerousApp @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere # throttling. # The arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # the 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 # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40} # you can keep the dflt throttle but just alter the voluntary param, this way: if throttleData and not throttle voluntary = throttleData end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # statistics 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 |
# 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 @serverName = server @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @http = Net::HTTP.new(server, u.port) @http.use_ssl = true # always required by NumerousApp @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere # throttling. # The arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # the 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 # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40} # you can keep the dflt throttle but just alter the voluntary param, this way: if throttleData and not throttle voluntary = throttleData end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # statistics are "infotainment" @debugLevel = 0 end |
#debugLevel ⇒ Fixnum (readonly)
Returns Current debugging level; use debug() method to change.
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 |
# 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 @serverName = server @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @http = Net::HTTP.new(server, u.port) @http.use_ssl = true # always required by NumerousApp @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere # throttling. # The arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # the 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 # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40} # you can keep the dflt throttle but just alter the voluntary param, this way: if throttleData and not throttle voluntary = throttleData end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # statistics 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 |
# 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 @serverName = server @auth = { user: apiKey, password: "" } u = URI.parse("https://"+server) @http = Net::HTTP.new(server, u.port) @http.use_ssl = true # always required by NumerousApp @agentString = "NW-Ruby-NumerousClass/" + VersionString + " (Ruby #{RUBY_VERSION}) NumerousAPI/v2" @filterDuplicates = true # see discussion elsewhere # throttling. # The arbitraryMaximum is just that: under no circumstances will we retry # any particular request more than that. Tough noogies. # # the 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 # @arbitraryMaximumTries = 10 voluntary = { voluntary: 40} # you can keep the dflt throttle but just alter the voluntary param, this way: if throttleData and not throttle voluntary = throttleData end @throttlePolicy = [ThrottleDefault, voluntary, nil] if throttle @throttlePolicy = [throttle, throttleData, @throttlePolicy] end @statistics = Hash.new { |h, k| h[k] = 0 } # statistics are "infotainment" @debugLevel = 0 end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
174 175 176 |
# File 'lib/numerousapp.rb', line 174 def statistics @statistics end |
Instance Method Details
#debug(lvl = 1) ⇒ Fixnum
Set the debug level
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/numerousapp.rb', line 189 def debug(lvl=1) prev = @debugLevel @debugLevel = lvl if @debugLevel > 0 @http.set_debug_output $stderr else @http.set_debug_output nil 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
207 208 209 210 211 |
# File 'lib/numerousapp.rb', line 207 def setBogusDupFilter(f) prev = @filterDuplicates @filterDuplicates = f return prev end |
#to_s ⇒ String
String representation of Numerous
179 180 181 182 |
# File 'lib/numerousapp.rb', line 179 def to_s() oid = (2 * self.object_id).to_s(16) # XXX "2*" makes it match native to_s return "<Numerous {#{@serverName}} @ 0x#{oid}>" end |