the-city-admin 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
data/examples/measurements.rb
CHANGED
@@ -23,11 +23,23 @@ else
|
|
23
23
|
puts "Metrices: #{metric_list.count}"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
|
27
|
+
# The next line is the same as: TheCity::MetricMeasurementList.new({:metric_id => metric_list[0].id})
|
28
|
+
measurement_list = metric_list[0].measurements
|
27
29
|
if metric_list.empty?
|
28
30
|
puts "No measurements in list"
|
29
31
|
else
|
30
32
|
puts "Measurements: #{measurement_list.count}"
|
31
33
|
end
|
32
34
|
|
35
|
+
|
36
|
+
# The next line is the same as: TheCity::MetricMeasurementValues.new({:metric_id => metric_list[0].id})
|
37
|
+
values = metric_list[0].measurement_values
|
38
|
+
if values.empty?
|
39
|
+
puts "No values returned"
|
40
|
+
else
|
41
|
+
puts "Measurement values: #{values.count}"
|
42
|
+
values.each_with_index { |value, indx| puts "#{indx+1}) #{value}" }
|
43
|
+
end
|
44
|
+
|
33
45
|
puts "####################################"
|
data/lib/api/metric.rb
CHANGED
@@ -32,17 +32,29 @@ module TheCity
|
|
32
32
|
end
|
33
33
|
|
34
34
|
|
35
|
-
#
|
35
|
+
# Measurement information.
|
36
36
|
#
|
37
|
-
# @return [
|
37
|
+
# @return [MetricMeasurementList]
|
38
38
|
def measurements
|
39
39
|
return @measurement_list unless @measurement_list.nil?
|
40
40
|
return nil unless self.id
|
41
|
-
|
42
|
-
|
43
|
-
@measurement_list = MetricMeasurementList.new(reader)
|
41
|
+
|
42
|
+
@measurement_list = MetricMeasurementList.new({:metric_id => self.id})
|
44
43
|
return @measurement_list
|
45
44
|
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
# Measurement values list information.
|
49
|
+
#
|
50
|
+
# @return [MetricMeasurementValues]
|
51
|
+
def measurement_values
|
52
|
+
return @measurement_values unless @measurement_values.nil?
|
53
|
+
return nil unless self.id
|
54
|
+
|
55
|
+
@measurement_values = MetricMeasurementValues.new({:metric_id => self.id})
|
56
|
+
return @measurement_values
|
57
|
+
end
|
46
58
|
end
|
47
59
|
|
48
60
|
end
|
@@ -9,14 +9,15 @@ module TheCity
|
|
9
9
|
# @param options A hash of options for loading the list.
|
10
10
|
#
|
11
11
|
# Options:
|
12
|
+
# :metric_id - The ID of the metric to load the measurements for. (required)
|
12
13
|
# :page - The page number to get.
|
13
14
|
# :reader - The Reader to use to load the data.
|
14
15
|
#
|
15
16
|
#
|
16
17
|
# Examples:
|
17
|
-
# MetricMeasurementList.new({:
|
18
|
+
# MetricMeasurementList.new({:metric_id => 12345})
|
18
19
|
#
|
19
|
-
# MetricMeasurementList.new({:
|
20
|
+
# MetricMeasurementList.new({:metric_id => 12345, :page => 2})
|
20
21
|
#
|
21
22
|
def initialize(options = {})
|
22
23
|
@options = options
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class MetricMeasurementValues < ApiObject
|
4
|
+
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
tc_attr_accessor :values
|
8
|
+
|
9
|
+
# Loads the metric measurement values by the specified metric ID.
|
10
|
+
#
|
11
|
+
# @param metric_id The ID of the user to load.
|
12
|
+
#
|
13
|
+
# Returns a new {Metric} object.
|
14
|
+
def self.load_by_id(metric_id)
|
15
|
+
metric_reader = MetricReader.new(metric_id)
|
16
|
+
self.new(metric_reader.load_feed)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Constructor.
|
21
|
+
#
|
22
|
+
# @param options A hash of options for loading the list.
|
23
|
+
#
|
24
|
+
# Options:
|
25
|
+
# :metric_id - The ID of the metric to load the measurements values for. (required)
|
26
|
+
# :reader - The Reader to use to load the data.
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# Examples:
|
30
|
+
# MetricMeasurementValues.new({:metric_id => 12345})
|
31
|
+
#
|
32
|
+
def initialize(options = {})
|
33
|
+
options[:reader] = TheCity::MetricMeasurementValuesReader.new(options) if options[:reader].nil?
|
34
|
+
@json_data = options[:reader].load_feed
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get the specified account admin privilege.
|
38
|
+
#
|
39
|
+
# @param index The index of the admin privilege to get.
|
40
|
+
#
|
41
|
+
# @return Number
|
42
|
+
def [](index)
|
43
|
+
@json_data['values'][index] if @json_data['values'][index]
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# This method is needed for Enumerable.
|
48
|
+
def each &block
|
49
|
+
@json_data['values'].each{ |value| yield(value) }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Alias the count method
|
53
|
+
alias :size :count
|
54
|
+
|
55
|
+
# Checks if the list is empty.
|
56
|
+
#
|
57
|
+
# @return True on empty, false otherwise.
|
58
|
+
def empty?
|
59
|
+
@json_data['values'].empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class MetricMeasurementValuesReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param options A hash of options for requesting data from the server.
|
8
|
+
# :: metric_id is required
|
9
|
+
# @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
|
10
|
+
def initialize(options = {}, cacher = nil)
|
11
|
+
metric_id = options.delete(:metric_id)
|
12
|
+
@url_data_path = "/metrics/#{metric_id}/measurements/values"
|
13
|
+
|
14
|
+
# The object to store and load the cache.
|
15
|
+
@cacher = cacher unless cacher.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
data/thecity_admin_api.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the-city-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/api/metric_list.rb
|
101
101
|
- lib/api/metric_measurement.rb
|
102
102
|
- lib/api/metric_measurement_list.rb
|
103
|
+
- lib/api/metric_measurement_values.rb
|
103
104
|
- lib/api/pledge.rb
|
104
105
|
- lib/api/pledge_list.rb
|
105
106
|
- lib/api/role.rb
|
@@ -169,6 +170,7 @@ files:
|
|
169
170
|
- lib/readers/metric_list_reader.rb
|
170
171
|
- lib/readers/metric_measurement_list_reader.rb
|
171
172
|
- lib/readers/metric_measurement_reader.rb
|
173
|
+
- lib/readers/metric_measurement_values_reader.rb
|
172
174
|
- lib/readers/metric_reader.rb
|
173
175
|
- lib/readers/pledge_list_reader.rb
|
174
176
|
- lib/readers/pledge_reader.rb
|