geckoboard-ruby 0.1.0 → 0.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.
- checksums.yaml +4 -4
- data/README.md +16 -13
- data/lib/geckoboard/datasets_client.rb +14 -2
- data/lib/geckoboard/field_types.rb +61 -0
- data/lib/geckoboard/version.rb +1 -1
- data/lib/geckoboard.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec98d0225989a8d02c83f7d46bf34ce25c88e3da
|
4
|
+
data.tar.gz: d5e3effe54d256a1f16cba2898f51352cf1975a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95d796bc880855c11290d9ceeb6b4885fb640cbf9cab6ae10e662e1093193ee582dc3b24d910d4ecb590a8e8290a306a6bb06a4939575bf7550208d93e273539
|
7
|
+
data.tar.gz: 6ccab0a19bf2f50637a66db7263871d43b9f84e91d56c5cf8b597314e3e475186503a0481187d87e981a3268fd26559187b5c64bb10452b109618a565887190a
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# geckoboard-ruby
|
2
2
|
[](https://circleci.com/gh/geckoboard/geckoboard-ruby)
|
3
3
|
|
4
|
-
Ruby client library for Geckoboard (https://developer.geckoboard.com).
|
4
|
+
Ruby client library for Geckoboard (https://developer.geckoboard.com/api-reference/ruby).
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -35,18 +35,21 @@ client.ping # => true
|
|
35
35
|
Verify an existing dataset or create a new one.
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
dataset = client.datasets.find_or_create('sales.gross', fields:
|
39
|
-
amount:
|
40
|
-
|
41
|
-
|
42
|
-
},
|
43
|
-
timestamp: {
|
44
|
-
type: :datetime,
|
45
|
-
name: 'Time'
|
46
|
-
}
|
47
|
-
})
|
38
|
+
dataset = client.datasets.find_or_create('sales.gross', fields: [
|
39
|
+
Geckoboard::MoneyField.new(:amount, name: 'Amount', currency: 'USD'),
|
40
|
+
Geckoboard::DateTimeField.new(:timestamp, name: 'Time'),
|
41
|
+
])
|
48
42
|
```
|
49
43
|
|
44
|
+
Available field types:
|
45
|
+
|
46
|
+
- `DateField`
|
47
|
+
- `DateTimeField`
|
48
|
+
- `NumberField`
|
49
|
+
- `PercentageField`
|
50
|
+
- `StringField`
|
51
|
+
- `MoneyField`
|
52
|
+
|
50
53
|
### Delete
|
51
54
|
|
52
55
|
Delete a dataset and all data therein.
|
@@ -69,11 +72,11 @@ Replace all data in the dataset.
|
|
69
72
|
dataset.put([
|
70
73
|
{
|
71
74
|
timestamp: DateTime.new(2016, 1, 2, 12, 0, 0),
|
72
|
-
amount:
|
75
|
+
amount: 40900
|
73
76
|
},
|
74
77
|
{
|
75
78
|
timestamp: DateTime.new(2016, 1, 3, 12, 0, 0),
|
76
|
-
amount:
|
79
|
+
amount: 16400
|
77
80
|
},
|
78
81
|
])
|
79
82
|
```
|
@@ -6,9 +6,9 @@ module Geckoboard
|
|
6
6
|
@connection = connection
|
7
7
|
end
|
8
8
|
|
9
|
-
def find_or_create(dataset_id, fields:
|
9
|
+
def find_or_create(dataset_id, fields: nil)
|
10
10
|
path = dataset_path(dataset_id)
|
11
|
-
response = connection.put(path, { fields: fields }.to_json)
|
11
|
+
response = connection.put(path, { fields: hashify_fields(fields) }.to_json)
|
12
12
|
|
13
13
|
data = JSON.parse(response.body)
|
14
14
|
Dataset.new(self, data.fetch('id'), data.fetch('fields'))
|
@@ -31,5 +31,17 @@ module Geckoboard
|
|
31
31
|
def dataset_path(dataset_id)
|
32
32
|
"/datasets/#{CGI.escape(dataset_id)}"
|
33
33
|
end
|
34
|
+
|
35
|
+
def hashify_fields(fields)
|
36
|
+
return fields if fields.is_a? Hash
|
37
|
+
|
38
|
+
unless fields.respond_to?(:inject) && fields.all? { |field| field.is_a? Field }
|
39
|
+
raise ArgumentError, "`fields:' must be either a hash of field definitions, or collection of `Geckoboard::Field' objects"
|
40
|
+
end
|
41
|
+
|
42
|
+
fields.inject({}) do |hash, field|
|
43
|
+
hash.merge(field.id => field.to_hash)
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Geckoboard
|
2
|
+
class Field
|
3
|
+
attr_reader :id, :name
|
4
|
+
|
5
|
+
def initialize(id, name: nil)
|
6
|
+
raise ArgumentError, "`name:' is a required argument" if name.nil?
|
7
|
+
|
8
|
+
@id = id
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
{ name: name }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class StringField < Field
|
18
|
+
def to_hash
|
19
|
+
super.merge(type: :string)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class NumberField < Field
|
24
|
+
def to_hash
|
25
|
+
super.merge(type: :number)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class DateField < Field
|
30
|
+
def to_hash
|
31
|
+
super.merge(type: :date)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class DateTimeField < Field
|
36
|
+
def to_hash
|
37
|
+
super.merge(type: :datetime)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class MoneyField < Field
|
42
|
+
attr_reader :currency
|
43
|
+
|
44
|
+
def initialize(id, name: nil, currency: nil)
|
45
|
+
raise ArgumentError, "`currency:' is a required argument" if currency.nil?
|
46
|
+
|
47
|
+
super(id, name: name)
|
48
|
+
@currency = currency
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash
|
52
|
+
super.merge(type: :money, currency: currency)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class PercentageField < Field
|
57
|
+
def to_hash
|
58
|
+
super.merge(type: :percentage)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/geckoboard/version.rb
CHANGED
data/lib/geckoboard.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geckoboard-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Upton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/geckoboard/dataset.rb
|
90
90
|
- lib/geckoboard/datasets_client.rb
|
91
91
|
- lib/geckoboard/errors.rb
|
92
|
+
- lib/geckoboard/field_types.rb
|
92
93
|
- lib/geckoboard/payload_formatter.rb
|
93
94
|
- lib/geckoboard/version.rb
|
94
95
|
homepage: https://github.com/geckoboard/geckoboard-ruby
|