geckoboard-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/lib/geckoboard/connection.rb +8 -0
- data/lib/geckoboard/dataset.rb +4 -0
- data/lib/geckoboard/datasets_client.rb +11 -2
- data/lib/geckoboard/field_types.rb +5 -5
- data/lib/geckoboard/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 761434e8773946c7a9a6f111acc2aa2814c44ff5
|
4
|
+
data.tar.gz: 6fd826b8679091d0c49126e495fce06c2a687d1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6001b746389178795c7072919d982c116e217252be9be379c4ecf2ef0977b933f61c0b4e19e05878ea42e03aaaec428bdd6cf6b054c84d8d596d0d382e50099a
|
7
|
+
data.tar.gz: d80f695524f168add1407eb7bee8d2464a047210303d5b33cfd6128fba0b53ee5c25743ba6922f8a29b8f5793c002b32ec9842359830c4ccf66528844add6d64
|
data/README.md
CHANGED
@@ -36,9 +36,9 @@ Verify an existing dataset or create a new one.
|
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
dataset = client.datasets.find_or_create('sales.gross', fields: [
|
39
|
-
Geckoboard::MoneyField.new(:amount, name: 'Amount',
|
39
|
+
Geckoboard::MoneyField.new(:amount, name: 'Amount', currency_code: 'USD'),
|
40
40
|
Geckoboard::DateTimeField.new(:timestamp, name: 'Time'),
|
41
|
-
])
|
41
|
+
], unique_by: [:timestamp])
|
42
42
|
```
|
43
43
|
|
44
44
|
Available field types:
|
@@ -50,6 +50,8 @@ Available field types:
|
|
50
50
|
- `StringField`
|
51
51
|
- `MoneyField`
|
52
52
|
|
53
|
+
`unique_by` is an optional array of one or more field names whose values will be unique across all your records.
|
54
|
+
|
53
55
|
### Delete
|
54
56
|
|
55
57
|
Delete a dataset and all data therein.
|
@@ -81,6 +83,25 @@ dataset.put([
|
|
81
83
|
])
|
82
84
|
```
|
83
85
|
|
86
|
+
### Post
|
87
|
+
|
88
|
+
Append data to a dataset.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
dataset.post([
|
92
|
+
{
|
93
|
+
timestamp: DateTime.new(2016, 1, 2, 12, 0, 0),
|
94
|
+
amount: 40900
|
95
|
+
},
|
96
|
+
{
|
97
|
+
timestamp: DateTime.new(2016, 1, 3, 12, 0, 0),
|
98
|
+
amount: 16400
|
99
|
+
},
|
100
|
+
], delete_by: :timestamp)
|
101
|
+
```
|
102
|
+
|
103
|
+
`delete_by` is an optional field by which to order the truncation of records once the maximum record count has been reached. By default the oldest records (by insertion time) will be removed.
|
104
|
+
|
84
105
|
## Development
|
85
106
|
|
86
107
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -26,6 +26,14 @@ module Geckoboard
|
|
26
26
|
make_request(request)
|
27
27
|
end
|
28
28
|
|
29
|
+
def post(path, body)
|
30
|
+
request = Net::HTTP::Post.new(path)
|
31
|
+
request['Content-Type'] = 'application/json'
|
32
|
+
request.body = body
|
33
|
+
|
34
|
+
make_request(request)
|
35
|
+
end
|
36
|
+
|
29
37
|
private
|
30
38
|
|
31
39
|
def make_request(request)
|
data/lib/geckoboard/dataset.rb
CHANGED
@@ -6,9 +6,11 @@ module Geckoboard
|
|
6
6
|
@connection = connection
|
7
7
|
end
|
8
8
|
|
9
|
-
def find_or_create(dataset_id, fields: nil)
|
9
|
+
def find_or_create(dataset_id, fields: nil, unique_by: nil)
|
10
10
|
path = dataset_path(dataset_id)
|
11
|
-
|
11
|
+
body = { fields: hashify_fields(fields) }
|
12
|
+
body[:unique_by] = unique_by unless unique_by.nil?
|
13
|
+
response = connection.put(path, body.to_json)
|
12
14
|
|
13
15
|
data = JSON.parse(response.body)
|
14
16
|
Dataset.new(self, data.fetch('id'), data.fetch('fields'))
|
@@ -26,6 +28,13 @@ module Geckoboard
|
|
26
28
|
true
|
27
29
|
end
|
28
30
|
|
31
|
+
def post_data(dataset_id, data, options)
|
32
|
+
path = "#{dataset_path(dataset_id)}/data"
|
33
|
+
body = options.merge({ data: data }).to_json
|
34
|
+
connection.post(path, body)
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
29
38
|
private
|
30
39
|
|
31
40
|
def dataset_path(dataset_id)
|
@@ -39,17 +39,17 @@ module Geckoboard
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class MoneyField < Field
|
42
|
-
attr_reader :
|
42
|
+
attr_reader :currency_code
|
43
43
|
|
44
|
-
def initialize(id, name: nil,
|
45
|
-
raise ArgumentError, "`
|
44
|
+
def initialize(id, name: nil, currency_code: nil)
|
45
|
+
raise ArgumentError, "`currency_code:' is a required argument" if currency_code.nil?
|
46
46
|
|
47
47
|
super(id, name: name)
|
48
|
-
@
|
48
|
+
@currency_code = currency_code
|
49
49
|
end
|
50
50
|
|
51
51
|
def to_hash
|
52
|
-
super.merge(type: :money,
|
52
|
+
super.merge(type: :money, currency_code: currency_code)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
data/lib/geckoboard/version.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.3.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-
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,4 +117,3 @@ signing_key:
|
|
117
117
|
specification_version: 4
|
118
118
|
summary: Ruby client library for Geckoboard
|
119
119
|
test_files: []
|
120
|
-
has_rdoc:
|