geckoboard-ruby 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec98d0225989a8d02c83f7d46bf34ce25c88e3da
4
- data.tar.gz: d5e3effe54d256a1f16cba2898f51352cf1975a2
3
+ metadata.gz: 761434e8773946c7a9a6f111acc2aa2814c44ff5
4
+ data.tar.gz: 6fd826b8679091d0c49126e495fce06c2a687d1c
5
5
  SHA512:
6
- metadata.gz: 95d796bc880855c11290d9ceeb6b4885fb640cbf9cab6ae10e662e1093193ee582dc3b24d910d4ecb590a8e8290a306a6bb06a4939575bf7550208d93e273539
7
- data.tar.gz: 6ccab0a19bf2f50637a66db7263871d43b9f84e91d56c5cf8b597314e3e475186503a0481187d87e981a3268fd26559187b5c64bb10452b109618a565887190a
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', currency: 'USD'),
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)
@@ -16,6 +16,10 @@ module Geckoboard
16
16
  client.put_data(id, payload_formatter.format(data))
17
17
  end
18
18
 
19
+ def post(data, options = {})
20
+ client.post_data(id, payload_formatter.format(data), options)
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def payload_formatter
@@ -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
- response = connection.put(path, { fields: hashify_fields(fields) }.to_json)
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 :currency
42
+ attr_reader :currency_code
43
43
 
44
- def initialize(id, name: nil, currency: nil)
45
- raise ArgumentError, "`currency:' is a required argument" if currency.nil?
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
- @currency = currency
48
+ @currency_code = currency_code
49
49
  end
50
50
 
51
51
  def to_hash
52
- super.merge(type: :money, currency: currency)
52
+ super.merge(type: :money, currency_code: currency_code)
53
53
  end
54
54
  end
55
55
 
@@ -1,3 +1,3 @@
1
1
  module Geckoboard
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.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-08-31 00:00:00.000000000 Z
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: