dune 0.0.1 → 0.1.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 +66 -0
- data/lib/dune/client.rb +6 -1
- data/lib/dune/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bbc650dd384fb869326503b247b1d3202eb2c0ac8a92ee6fa10fa967871cd2f
|
4
|
+
data.tar.gz: 1899809b39c3f68ae0cfef7e2b13e285e87a33fd9a66fc82bef2bd178e52a1c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1632b6be1611b97e3f43d9e903b08d6676809a5dd33f429c70097e4813c77da1ed0dd6dcb1d53e3004b732d3661e104a322d095ad62cf94f0d015b7101714a0f
|
7
|
+
data.tar.gz: 88277ef5a9718aac522c6324fec4865f31644c0009274b2a83e6088f160ce0149a5dea1eb53834abb259e7b857bf20abed815fbca232ee5d24a794f97690ec76
|
data/README.md
CHANGED
@@ -2,4 +2,70 @@
|
|
2
2
|
|
3
3
|
Welcome to the Ruby SDK of the [Dune Analytics API](https://dune.com/docs/api/)
|
4
4
|
|
5
|
+
## Installation
|
5
6
|
|
7
|
+
`dune` is available as a gem on [Rubygems](https://rubygems.org/) To install it, add it to your `Gemfile`
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
source "https://rubygems.org"
|
11
|
+
|
12
|
+
gem "dune"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
To use the Dune API you'll need to request an API key. The Dune API is currently in private beta.
|
18
|
+
|
19
|
+
**[Official API Documentation](https://dune.com/docs/api/)**
|
20
|
+
|
21
|
+
#### Setting up the client
|
22
|
+
|
23
|
+
The underlying HTTP client is [Faraday](https://lostisland.github.io/faraday/)
|
24
|
+
|
25
|
+
Here's the properties that can be provided to the constructor
|
26
|
+
|
27
|
+
| property | required | description |
|
28
|
+
|--------------------|----------|--------------------------------------------------|
|
29
|
+
| `api_key` | true | the API key |
|
30
|
+
| `faraday_settings` | false | a hash provided to `Faraday.new` |
|
31
|
+
| logger | false | an instance of Logger, defaults to a null logger |
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require "dune"
|
35
|
+
|
36
|
+
dune = Dune::Client.new(api_key: ENV["DUNE_API_KEY"])
|
37
|
+
dune.connection #=> returns a Faraday::Connection
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Available methods
|
41
|
+
|
42
|
+
All methods will return the parsed JSON response as a hash.
|
43
|
+
|
44
|
+
Should the request fail the call will fail with a `Dune::Error` that contains the faraday `response` as a property
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
dune = Dune::Client.new(api_key: ENV["DUNE_API_KEY"])
|
48
|
+
|
49
|
+
# execute a query
|
50
|
+
query_id = 312527 # https://dune.com/queries/312527
|
51
|
+
query_response = dune.query(query_id) # calls POST /query/312527/execute
|
52
|
+
|
53
|
+
# get status of a query
|
54
|
+
dune.execution_status(query_response["execution_id"]) # calls GET /execution/312527/status
|
55
|
+
|
56
|
+
# get the results of an execution
|
57
|
+
dune.execution(query_response["execution_id"]) # calls GET/execution/312527/results
|
58
|
+
|
59
|
+
# cancel an execution
|
60
|
+
dune.cancel(query_response["execution_id"]) # calls POST /execution/312527/cancel
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Supplying parameters
|
64
|
+
|
65
|
+
Supplying parameters works by invoking the same `query` method. Make sure your query in Dune accepts parameters.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
dex_by_volume_query_id = 312527
|
69
|
+
json = JSON.generate({ query_parameters: { grouping_parameter: 2 } })
|
70
|
+
dune.query(dex_by_volume_query_id, json)
|
71
|
+
```
|
data/lib/dune/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Dune
|
2
2
|
class Client
|
3
|
-
attr_accessor :api_key, :connection
|
3
|
+
attr_accessor :api_key, :connection, :logger
|
4
4
|
|
5
5
|
def initialize(api_key:, faraday_settings: {}, logger: Logger.new(IO::NULL))
|
6
6
|
@api_key = api_key
|
@@ -9,18 +9,22 @@ class Dune
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def query(id, body = nil, headers = nil, &block)
|
12
|
+
logger.debug("#{self} #{__method__} with #{id}")
|
12
13
|
parse(connection.post("query/#{id}/execute", body, headers, &block))
|
13
14
|
end
|
14
15
|
|
15
16
|
def execution_status(id, params = nil, headers = nil, &block)
|
17
|
+
logger.debug("#{self} #{__method__} with #{id}")
|
16
18
|
parse(connection.get("execution/#{id}/status", params, headers, &block))
|
17
19
|
end
|
18
20
|
|
19
21
|
def execution(id, params = nil, headers = nil, &block)
|
22
|
+
logger.debug("#{self} #{__method__} with #{id}")
|
20
23
|
parse(connection.get("execution/#{id}/results", params, headers, &block))
|
21
24
|
end
|
22
25
|
|
23
26
|
def cancel(id, params = nil, headers = nil, &block)
|
27
|
+
logger.debug("#{self} #{__method__} with #{id}")
|
24
28
|
parse(connection.post("execution/#{id}/cancel", params, headers, &block))
|
25
29
|
end
|
26
30
|
|
@@ -32,6 +36,7 @@ class Dune
|
|
32
36
|
else
|
33
37
|
error = Dune::Error.new("Dune API replied with status #{response.status}")
|
34
38
|
error.response = response
|
39
|
+
logger.error(error)
|
35
40
|
raise error
|
36
41
|
end
|
37
42
|
end
|
data/lib/dune/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shellandbull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|