numerousapp 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/numerousapp.rb +100 -30
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2df08c0abb56a4d38ce98c048fb814a37cb4ca37
4
- data.tar.gz: 50b9313c710e3ab6c27a32cd895c10b03671bdfb
3
+ metadata.gz: 7018d2d603b7836ff5ce90f71f2cdf324ffb60d9
4
+ data.tar.gz: 4d7b0bd9d9e9d3307b0e68546dfced0e193ff457
5
5
  SHA512:
6
- metadata.gz: 5e62912986ab1ce0f5377dd5a400c72fe749c61fa886689552cfa7c9e38c2f6747eb089d0d9f32129c669eaeb46990749d1c5dcd0051fdbd6f9b46c275b1d4c3
7
- data.tar.gz: f124700210064a362c407fb976272aa874eced217ca947991fb0b2cdb6428dfd47782650efb455b4915eee0e32b2e58a773750d86c6b996c63c9ac796a901492
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 = '20150222-1.1.0'
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, either as a scalar (default)
387
- # OR if you preset the :serverResponseTimes to be an array of length N
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 great
538
- # detail is beyond the scope here; suffice to say it only
539
- # happens for events that were recorded nearly-simultaneously
540
- # and happen to be getting reported right at a chunking boundary.
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 how/where
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 really meant only for testing.
548
+ # Turning off duplicate filtering is for testing (only).
548
549
  #
549
- # Not all API's require dupfiltering, hence the APIInfo test
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 (handled explicitly so you can write external funcs too)
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 the server (e.g., 409, 200, etc)
586
- # :resp : the full-on response object if you must have it
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 stats (purely informational stats)
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 the Numerous() constructor
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 : simply means "don't do more retries". It does not imply anything
603
- # about the success or failure of the request; it simply means that
604
- # this most recent request (response) is the one to "take" as
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 original
609
- # request will be sent again. Obviously it's a very bad idea to
610
- # return true in cases where the server might have done some
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 basically amounts to "sleep sometimes"
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 .. 1 second if more than half left, 3 seconds if less
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 of dictionary
692
- # representations, possibly "chunked" into multiple request/response operations.
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 # allow this to raise exception if id bogus type here
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: { # note that PUT has a /v2 interface but GET does not (yet?).
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.1.0
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-02-22 00:00:00.000000000 Z
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