Class: Geckoboard::DatasetsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/geckoboard/datasets_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ DatasetsClient

Returns a new instance of DatasetsClient.



5
6
7
# File 'lib/geckoboard/datasets_client.rb', line 5

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/geckoboard/datasets_client.rb', line 3

def connection
  @connection
end

Instance Method Details

#delete(dataset_id) ⇒ Object



19
20
21
22
23
# File 'lib/geckoboard/datasets_client.rb', line 19

def delete(dataset_id)
  path = dataset_path(dataset_id)
  connection.delete(path)
  true
end

#find_or_create(dataset_id, fields: nil, unique_by: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/geckoboard/datasets_client.rb', line 9

def find_or_create(dataset_id, fields: nil, unique_by: nil)
  path = dataset_path(dataset_id)
  body = { fields: hashify_fields(fields) }
  body[:unique_by] = unique_by unless unique_by.nil?
  response = connection.put(path, body.to_json)

  data = JSON.parse(response.body)
  Dataset.new(self, data.fetch('id'), data.fetch('fields'))
end

#post_data(dataset_id, data, options) ⇒ Object



31
32
33
34
35
36
# File 'lib/geckoboard/datasets_client.rb', line 31

def post_data(dataset_id, data, options)
  path = "#{dataset_path(dataset_id)}/data"
  body = options.merge({ data: data }).to_json
  connection.post(path, body)
  true
end

#put_data(dataset_id, data) ⇒ Object



25
26
27
28
29
# File 'lib/geckoboard/datasets_client.rb', line 25

def put_data(dataset_id, data)
  path = "#{dataset_path(dataset_id)}/data"
  connection.put(path, { data: data }.to_json)
  true
end