Class: NumerousClientInternals

Inherits:
Object
  • Object
show all
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

Numerous, NumerousMetric

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apiKey = nil, server: 'api.numerousapp.com', throttle: nil, throttleData: nil) ⇒ NumerousClientInternals

Returns a new instance of NumerousClientInternals.

Parameters:

  • apiKey (String) (defaults to: nil)

    API authentication key

  • server (String) (defaults to: 'api.numerousapp.com')

    Optional (keyword arg). Server name.

  • throttle (Proc) (defaults to: nil)

    Optional throttle policy

  • throttleData (Any) (defaults to: nil)

    Optional data for throttle



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

#agentStringString

Returns User agent string sent to the server.

Returns:

  • (String)

    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

#debugLevelFixnum (readonly)

Returns Current debugging level; use debug() method to change.

Returns:

  • (Fixnum)

    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

#serverNameString (readonly)

Returns FQDN of the target NumerousApp server.

Returns:

  • (String)

    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

#statisticsObject (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

Parameters:

  • lvl (Fixnum) (defaults to: 1)

    The desired debugging level. Greater than zero turns on debugging.

Returns:

  • (Fixnum)

    the previous debugging 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

Note:

If you are calling this you are probably doing something wrong.

This is primarily for testing; control filtering of bogus duplicates

Parameters:

  • f (Boolean)

    New value for duplicate filtering flag.

Returns:

  • (Boolean)

    Previous value of duplicate filtering flag.



207
208
209
210
211
# File 'lib/numerousapp.rb', line 207

def setBogusDupFilter(f)
    prev = @filterDuplicates
    @filterDuplicates = f
    return prev
end

#to_sString

String representation of Numerous

Returns:

  • (String)

    Human-appropriate string representation.



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