numerousapp 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/numerousapp.rb +100 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7018d2d603b7836ff5ce90f71f2cdf324ffb60d9
|
4
|
+
data.tar.gz: 4d7b0bd9d9e9d3307b0e68546dfced0e193ff457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2e36d7ad7e315684c349c757097e1e1094e403535186abb76b874cb7ec804b92b58d7652c837d41cacc89138117bacdf77fafc509f98dff126f3c6a5134681
|
7
|
+
data.tar.gz: 92a86c605f1357060f10a5fc1f0f6b1ddc846b281ab9c61cfd365f5df11a715d61eb25ddf3c5f2b39bc11badb62191eb915b80c6dbc08b340c0e645d54cd50f5
|
data/lib/numerousapp.rb
CHANGED
@@ -212,7 +212,7 @@ class NumerousClientInternals
|
|
212
212
|
|
213
213
|
protected
|
214
214
|
|
215
|
-
VersionString = '
|
215
|
+
VersionString = '20150415-1.2.0'
|
216
216
|
|
217
217
|
MethMap = {
|
218
218
|
GET: Net::HTTP::Get,
|
@@ -383,9 +383,9 @@ class NumerousClientInternals
|
|
383
383
|
raise NumerousNetworkError.new(e)
|
384
384
|
end
|
385
385
|
et = Time.now - t0
|
386
|
-
# We report the elapsed round-trip time,
|
387
|
-
# OR if you preset the :serverResponseTimes to be an array
|
388
|
-
# then we keep the last N response times, thusly:
|
386
|
+
# We report the elapsed round-trip time, as a scalar (by default)
|
387
|
+
# OR if you preset the :serverResponseTimes to be an array
|
388
|
+
# of length N then we keep the last N response times, thusly:
|
389
389
|
begin
|
390
390
|
times = @statistics[:serverResponseTimes]
|
391
391
|
times.insert(0, et)
|
@@ -534,19 +534,20 @@ class NumerousClientInternals
|
|
534
534
|
#
|
535
535
|
# There is a bug in the NumerousApp server which can
|
536
536
|
# cause collections to show duplicates of certain events
|
537
|
-
# (or interactions/stream items). Explaining the bug in
|
538
|
-
|
539
|
-
|
540
|
-
|
537
|
+
# (or interactions/stream items). Explaining the bug in
|
538
|
+
# great detail is beyond the scope here; suffice to say
|
539
|
+
# it only happens for events that were recorded
|
540
|
+
# nearly-simultaneously and happen to be getting reported
|
541
|
+
# right at a chunking boundary.
|
541
542
|
#
|
542
543
|
# So we are filtering them out here. For a more involved
|
543
544
|
# discussion of this, see the python implementation. This
|
544
|
-
# filtering "works" because it knows pragmatically
|
545
|
-
# the bug can show up
|
545
|
+
# filtering "works" because it knows pragmatically
|
546
|
+
# how/where the bug can show up
|
546
547
|
#
|
547
|
-
# Turning off duplicate filtering is
|
548
|
+
# Turning off duplicate filtering is for testing (only).
|
548
549
|
#
|
549
|
-
# Not all API's
|
550
|
+
# Not all API's need dupfiltering, hence the APIInfo test
|
550
551
|
#
|
551
552
|
if (not filterInfo) # the easy case, not filtering
|
552
553
|
block.call i
|
@@ -577,18 +578,18 @@ class NumerousClientInternals
|
|
577
578
|
# then delay the amount of time the server told us to delay.
|
578
579
|
#
|
579
580
|
# The arguments supplied to us are:
|
580
|
-
# nr is the Numerous
|
581
|
+
# nr is the Numerous
|
581
582
|
# tparams is a Hash containing:
|
582
583
|
# :attempt : the attempt number. Zero on the very first try
|
583
584
|
# :rateRemaining : X-Rate-Limit-Remaining reported by the server
|
584
585
|
# :rateReset : time (in seconds) until fresh rate granted
|
585
|
-
# :resultCode : HTTP code from
|
586
|
-
# :resp : the full-on response object
|
586
|
+
# :resultCode : HTTP code from server (e.g., 409, 200, etc)
|
587
|
+
# :resp : the full-on response object
|
587
588
|
# :request : information about the original request
|
588
|
-
# :statistics : place to record
|
589
|
+
# :statistics : place to record informational stats
|
589
590
|
# :debug : current debug level
|
590
591
|
#
|
591
|
-
# td is the data you supplied as "throttleData" to
|
592
|
+
# td is the data you supplied as "throttleData" to Numerous.new()
|
592
593
|
# up is a tuple useful for calling the original system throttle policy:
|
593
594
|
# up[0] is the Proc
|
594
595
|
# up[1] is the td for *that* function
|
@@ -599,18 +600,18 @@ class NumerousClientInternals
|
|
599
600
|
#
|
600
601
|
# It's really (really really) important to understand the return value and
|
601
602
|
# the fact that we are invoked AFTER each request:
|
602
|
-
# false :
|
603
|
-
# about the success or failure of the request; it simply means
|
604
|
-
# this most recent request (response) is the one to
|
603
|
+
# false : means "don't do more retries". It does not imply anything
|
604
|
+
# about the success or failure of the request; it simply means
|
605
|
+
# this most recent request (response) is the one to use as
|
605
606
|
# the final answer
|
606
607
|
#
|
607
608
|
# true : means that the response is, indeed, to be interpreted as some
|
608
|
-
# sort of rate-limit failure and should be discarded. The
|
609
|
-
# request will be sent again. Obviously it's a very
|
610
|
-
# return true in cases where the server might
|
611
|
-
# anything non-idempotent.
|
609
|
+
# sort of rate-limit failure and should be discarded. The
|
610
|
+
# original request will be sent again. Obviously it's a very
|
611
|
+
# bad idea to return true in cases where the server might
|
612
|
+
# have done anything non-idempotent.
|
612
613
|
#
|
613
|
-
# All of this seems overly general for what
|
614
|
+
# All of this seems overly general for what amounts to "sleep sometimes"
|
614
615
|
#
|
615
616
|
|
616
617
|
ThrottleDefault = Proc.new do |nr, tparams, td, up|
|
@@ -644,7 +645,7 @@ class NumerousClientInternals
|
|
644
645
|
# voluntary arbitrary limit
|
645
646
|
if rateleft >= 0 and rateleft < td[:voluntary]
|
646
647
|
stats[:throttleVoluntaryBackoff] += 1
|
647
|
-
# arbitrary ..
|
648
|
+
# arbitrary .. 1sec if more than half left, 3 secs if less
|
648
649
|
if (rateleft*2) > td[:voluntary]
|
649
650
|
sleep(1)
|
650
651
|
else
|
@@ -688,8 +689,10 @@ end
|
|
688
689
|
# In those cases there is no useful return value from the method; the
|
689
690
|
# method succeeds or else raises an exception (containing the failure code).
|
690
691
|
#
|
691
|
-
# For the collection operations the server returns a JSON array
|
692
|
-
# representations, possibly "chunked" into multiple
|
692
|
+
# For the collection operations the server returns a JSON array
|
693
|
+
# of dictionary representations, possibly "chunked" into multiple
|
694
|
+
# request/response operations.
|
695
|
+
#
|
693
696
|
# The enumerator methods (e.g., "metrics") implement lazy-fetch and hide
|
694
697
|
# the details of the chunking from you. They simply yield each individual
|
695
698
|
# item (string-key Hash) to your block.
|
@@ -1137,7 +1140,7 @@ class NumerousMetric < NumerousClientInternals
|
|
1137
1140
|
|
1138
1141
|
if not actualId
|
1139
1142
|
# well, see if it looks like an int
|
1140
|
-
i = id.to_i #
|
1143
|
+
i = id.to_i # raises exception if id bogus type here
|
1141
1144
|
if i == id
|
1142
1145
|
actualId = i.to_s
|
1143
1146
|
end
|
@@ -1159,7 +1162,7 @@ class NumerousMetric < NumerousClientInternals
|
|
1159
1162
|
# read/update/delete a metric
|
1160
1163
|
metric: {
|
1161
1164
|
path: '/v1/metrics/%{metricId}' ,
|
1162
|
-
PUT: {
|
1165
|
+
PUT: { # note that PUT has a /v2 interface but GET does not (yet?).
|
1163
1166
|
path: '/v2/metrics/%{metricId}'
|
1164
1167
|
},
|
1165
1168
|
DELETE: {
|
@@ -1248,6 +1251,27 @@ class NumerousMetric < NumerousClientInternals
|
|
1248
1251
|
DELETE: {
|
1249
1252
|
successCodes: [ 204 ]
|
1250
1253
|
}
|
1254
|
+
},
|
1255
|
+
|
1256
|
+
# permissions collection
|
1257
|
+
permissionsCollection: {
|
1258
|
+
path: '/v1/metrics/%{metricId}/permissions',
|
1259
|
+
# GET the permissions collection
|
1260
|
+
GET: {
|
1261
|
+
next: 'nextURL',
|
1262
|
+
list: 'permissions'
|
1263
|
+
}
|
1264
|
+
},
|
1265
|
+
|
1266
|
+
# individual permissions : GET, PUT, DELETE
|
1267
|
+
permission: {
|
1268
|
+
path: '/v1/metrics/%{metricId}/permissions/%{userId}',
|
1269
|
+
defaults: {
|
1270
|
+
userId: 'me' # default userId meaning "myself"
|
1271
|
+
},
|
1272
|
+
DELETE: {
|
1273
|
+
successCodes: [ 204 ]
|
1274
|
+
}
|
1251
1275
|
}
|
1252
1276
|
|
1253
1277
|
}
|
@@ -1420,6 +1444,16 @@ class NumerousMetric < NumerousClientInternals
|
|
1420
1444
|
return self
|
1421
1445
|
end
|
1422
1446
|
|
1447
|
+
# Enumerate the permissions of a metric.
|
1448
|
+
#
|
1449
|
+
# @yield [p] permissions
|
1450
|
+
# @yieldparam p [Hash] String-key representation of one permission
|
1451
|
+
# @return [NumerousMetric] self
|
1452
|
+
def permissions(&block)
|
1453
|
+
@nr.chunkedIterator(APIInfo[:permissionsCollection], {metricId:@id}, block)
|
1454
|
+
return self
|
1455
|
+
end
|
1456
|
+
|
1423
1457
|
|
1424
1458
|
# Obtain a specific metric event from the server
|
1425
1459
|
#
|
@@ -1455,6 +1489,42 @@ class NumerousMetric < NumerousClientInternals
|
|
1455
1489
|
return @nr.simpleAPI(api)
|
1456
1490
|
end
|
1457
1491
|
|
1492
|
+
# Obtain a specific permission resource for the given user
|
1493
|
+
#
|
1494
|
+
# @param [String] userId The specific user ID
|
1495
|
+
# @return [Hash] The string-key hash of the permission
|
1496
|
+
# @raise [NumerousError] Not found (.code will be 404)
|
1497
|
+
#
|
1498
|
+
def get_permission(userId=nil)
|
1499
|
+
api = getAPI(:permission, :GET, {userId: userId})
|
1500
|
+
return @nr.simpleAPI(api)
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
# Set a permission for the given user
|
1504
|
+
# @param [Hash] perms
|
1505
|
+
# string-key hash of subscription parameters
|
1506
|
+
# @param [String] userId
|
1507
|
+
# Optional (keyword arg). UserId (defaults to you)
|
1508
|
+
def set_permission(perms, userId=nil)
|
1509
|
+
# if you don't specify a userId but DO have a userId
|
1510
|
+
# in the perms, use that one
|
1511
|
+
if (not userId) and perms.key? 'userId'
|
1512
|
+
userId = perms['userId']
|
1513
|
+
end
|
1514
|
+
api = getAPI(:permission, :PUT, {userId: userId})
|
1515
|
+
return @nr.simpleAPI(api, jdict:perms)
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
# Delete a permission resource for the given user
|
1519
|
+
#
|
1520
|
+
# @param [String] userId The specific user ID
|
1521
|
+
#
|
1522
|
+
def delete_permission(userId)
|
1523
|
+
api = getAPI(:permission, :DELETE, {userId: userId})
|
1524
|
+
ignored = @nr.simpleAPI(api)
|
1525
|
+
return nil
|
1526
|
+
end
|
1527
|
+
|
1458
1528
|
# Subscribe to a metric.
|
1459
1529
|
#
|
1460
1530
|
# See the NumerousApp API docs for what should be
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numerousapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Webber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Classes implementing the NumerousApp REST APIs for metrics. Requires
|
14
14
|
Ruby 2.x
|