forked from gooddata/gooddata-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.rb
67 lines (52 loc) · 1.98 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This file shows how the GoodData Ruby API could be used from
# a client code
#
# Caution: this is far from describing the current functionality!
require 'gooddata'
# Note: this call will store the connection in a thread-local
# variable so this construction and following static method
# calls can be used even in a multi-threaded environment
#
# The connect call is not necessary if credentials are already
# stored in ~/.gooddata (e.g. using bin/gooddata auth:store)
GoodData.connect '[email protected]', '$3[r37'
# Connect to a specific project
GoodData.project = 'afawtv356b6usdfsdf34vt'
# ... or even during login time
GoodData.connect '[email protected]', '$3[r37', 'afawtv356b6usdfsdf34vt'
# Get a metadata object
a = Attribute[123]
a = Attribute['attr.country']
# Guess a model from a CSV data set
Model.guess 'data.csv'
# > [ { "type" => "ATTRIBUTE", "title" => "Country" }, ... ]
Model.add_dataset "title" => "Test", "columns" => [
{ "type" => "ATTRIBUTE", "title" => "Country" }
]
# > Dataset<"dataset.test">
# Populate a data set from a file
Dataset['dataset.test'].load 'data.csv'
# The previous line is actually a short cut for the following call:
p1.datasets['dataset.test'].load GoodData::Source::CsvFile.new 'data.csv'
# Populate a data set from the result of a SalesForce query
Dataset['dataset.test'].load GoodData::Source::SalesForce.new {
:username => "[email protected]",
:password => "blahblah",
:key => "mkjlnlkh845n4lhasdsdagddddddfa",
:query => "SELECT Id, Name FROM Account"
}
# Get a representation of a specific project
p1 = Project['afawtv356b6usdfsdf34vt']
p2 = Project['/gdc/projects/afawtv356b6usdfsdf34vt']
# Get a specific object by id from a specific project
a = p1.objects[123]
# > Attribute<"attr.country">
# ... or by identifier
a = p1.objects['attr.country']
# > Attribute<"attr.country">
##
# Create a data set from a model
p1.model.add_dataset "title" => "Test", "columns" => [
{ "type" => "ATTRIBUTE", "title" => "Country" }
]
# > Dataset<"dataset.test">