tana 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +532 -0
- data/lib/tana/api/client.rb +26 -0
- data/lib/tana/client.rb +20 -0
- data/lib/tana/configuration/content.rb +8 -0
- data/lib/tana/configuration/loader.rb +29 -0
- data/lib/tana/container.rb +15 -0
- data/lib/tana/endpoints/add/action.rb +44 -0
- data/lib/tana/import.rb +7 -0
- data/lib/tana/models/node.rb +19 -0
- data/lib/tana/models/root.rb +16 -0
- data/lib/tana/requests/add.rb +35 -0
- data/lib/tana/requests/level_a.rb +12 -0
- data/lib/tana/requests/level_b.rb +12 -0
- data/lib/tana/requests/level_c.rb +12 -0
- data/lib/tana/requests/level_d.rb +12 -0
- data/lib/tana/requests/level_e.rb +12 -0
- data/lib/tana/requests/level_f.rb +12 -0
- data/lib/tana/requests/level_g.rb +12 -0
- data/lib/tana/requests/level_h.rb +12 -0
- data/lib/tana/requests/level_i.rb +12 -0
- data/lib/tana/requests/node.rb +46 -0
- data/lib/tana/responses/level_a.rb +12 -0
- data/lib/tana/responses/level_b.rb +12 -0
- data/lib/tana/responses/level_c.rb +12 -0
- data/lib/tana/responses/level_d.rb +12 -0
- data/lib/tana/responses/level_e.rb +12 -0
- data/lib/tana/responses/level_f.rb +12 -0
- data/lib/tana/responses/level_g.rb +12 -0
- data/lib/tana/responses/level_h.rb +12 -0
- data/lib/tana/responses/level_i.rb +12 -0
- data/lib/tana/responses/node.rb +15 -0
- data/lib/tana/responses/root.rb +12 -0
- data/lib/tana.rb +24 -0
- data/tana.gemspec +38 -0
- data.tar.gz.sig +0 -0
- metadata +240 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 940bd1cd9810385144c4d2bb50f9ab20dcf6050ebfff71b890b614ec473739d1
|
4
|
+
data.tar.gz: ff0b98fd1ffc5ebad0b926c8cb0670394007a83145bf7cfa9d827c0c3f95d609
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e0334319f9672dd5dbfa143e06040701930760785c794a930c99adddd328ff688cf8d9523ec2f4aeaf1eb55c21e76f5bed7862e4bb3eeb3ae9946d4c22a878f
|
7
|
+
data.tar.gz: 0ee14bb0daef1726355c8c7fcab2779b3f7c43fcf0e988207918fc63177824df6d54c42dedaf032cc35cb69ac2d3332b46b796f2a224a6b65aca2d6aa9397f15
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
_�8W����D�fs;� 3�d�D�U��?�2�s�����&�L�|I�l/��xf�������2�#���s'��M�2�eصlr��+����P��/K�r�[(��K�K>���)�+�[s��ɤ:��7fQ��3���ə\|��&���䈱a�F�Qݔ*���;�e�CU-�~>;8�9��$+:оD#�Z��w��@�
|
2
|
+
--_�o�؟���s�Fs_���92�6����S��p�c1�^��I��T�JL��J�۩��ۻ75��W]1D�����G$ %����2���H�=5%��z��́��0���t����9�;�M �����x�\�ʒX�����_��o[\�>6�X༐�����l�N21ړy5 �G��!��)
|
data/LICENSE.adoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Hippocratic License
|
2
|
+
|
3
|
+
Version: 2.1.0.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
11
|
+
liability.
|
12
|
+
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
21
|
+
following terms and conditions:
|
22
|
+
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
27
|
+
property right held by Licensor.
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
30
|
+
the License and the above copyright notice (and if included by the
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
+
free to create modifications of the Software and distribute only the
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
+
hereunder) shall end immediately.
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
+
[arabic]
|
44
|
+
. Human Rights Principles.
|
45
|
+
[loweralpha]
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
48
|
+
Compact that define recognized principles of international human rights
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
+
manner consistent with Human Rights Principles.
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
+
unless the Rules require otherwise.
|
63
|
+
+
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
+
documents and information concerning the arbitration shall be public and
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
88
|
+
apply.
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
+
Human Rights Principles.
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
+
the terms and conditions of this License against Licensee through
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
+
may not terminate this License with Licensee.
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
+
the court may modify this License to affect the original purpose that
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
+
against any party.
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
+
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
@@ -0,0 +1,532 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
:api_link: link:https://tana.inc/docs/input-api[Input API]
|
6
|
+
:bundler_inline_link: link:https://alchemists.io/articles/ruby_bundler_inline[Bundler Inline]
|
7
|
+
:data_link: link:https://alchemists.io/articles/ruby_data[Data]
|
8
|
+
:dry_monads_link: link:https://dry-rb.org/gems/dry-monads[Dry Monads]
|
9
|
+
:dry_schema_link: link:https://dry-rb.org/gems/dry-schema[Dry Schema]
|
10
|
+
:dry_validation_link: link:https://dry-rb.org/gems/dry-validation[Dry Validation]
|
11
|
+
:function_composition_link: link:https://alchemists.io/articles/ruby_function_composition[Function Composition]
|
12
|
+
:pattern_matching_link: link:https://alchemists.io/articles/ruby_pattern_matching[Pattern Matching]
|
13
|
+
:tana_link: link:https://tana.inc[Tana]
|
14
|
+
:transactable_link: link:https://alchemists.io/projects/transactable[Transactable]
|
15
|
+
|
16
|
+
= Tana
|
17
|
+
|
18
|
+
This gem is a monadic API client for the {tana_link} Personal Knowledge Management (PKM) system. This allows you to build more sophisticated workflows atop the {api_link} using a design which leverages {function_composition_link} for a powerful, fault tolerant, workflow.
|
19
|
+
|
20
|
+
With this gem, you have a convenient building block to automate your workflows or even use this gem to transfer data from other PKM systems into {tana_link}. 🎉
|
21
|
+
|
22
|
+
toc::[]
|
23
|
+
|
24
|
+
== Features
|
25
|
+
|
26
|
+
* Provides an API client which implements Tana's limited, early access {api_link}.
|
27
|
+
* Provides HTTP request and response verification using {dry_schema_link} and {dry_validation_link}.
|
28
|
+
* Uses {function_composition_link} -- coupled with {transactable_link} -- to process each HTTP request and response.
|
29
|
+
|
30
|
+
== Requirements
|
31
|
+
|
32
|
+
. link:https://www.ruby-lang.org[Ruby].
|
33
|
+
. {tana_link}.
|
34
|
+
|
35
|
+
== Setup
|
36
|
+
|
37
|
+
To install _with_ security, run:
|
38
|
+
|
39
|
+
[source,bash]
|
40
|
+
----
|
41
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
42
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/projects/tana/gems.pem)
|
43
|
+
gem install tana --trust-policy HighSecurity
|
44
|
+
----
|
45
|
+
|
46
|
+
To install _without_ security, run:
|
47
|
+
|
48
|
+
[source,bash]
|
49
|
+
----
|
50
|
+
gem install tana
|
51
|
+
----
|
52
|
+
|
53
|
+
You can also add the gem directly to your project:
|
54
|
+
|
55
|
+
[source,bash]
|
56
|
+
----
|
57
|
+
bundle add tana
|
58
|
+
----
|
59
|
+
|
60
|
+
Once the gem is installed, you only need to require it:
|
61
|
+
|
62
|
+
[source,ruby]
|
63
|
+
----
|
64
|
+
require "tana"
|
65
|
+
----
|
66
|
+
|
67
|
+
== Usage
|
68
|
+
|
69
|
+
All interaction is via a `Tana` instance.
|
70
|
+
|
71
|
+
=== Initialization
|
72
|
+
|
73
|
+
You can initialize the API client -- using the defaults as described in the _Environment_ section below -- as follows:
|
74
|
+
|
75
|
+
[source,ruby]
|
76
|
+
----
|
77
|
+
client = Tana.new
|
78
|
+
----
|
79
|
+
|
80
|
+
Further customization can be done via a block:
|
81
|
+
|
82
|
+
[source,ruby]
|
83
|
+
----
|
84
|
+
client = Tana.new do |config|
|
85
|
+
config.accept = "application/json" # Use custom HTTP header.
|
86
|
+
config.token = "abc123" # Use custom/personal API key.
|
87
|
+
config.url = "https://api.tana.inc" # Use custom API root.
|
88
|
+
end
|
89
|
+
----
|
90
|
+
|
91
|
+
=== Environment
|
92
|
+
|
93
|
+
Environment variable support can be managed using link:https://direnv.net[direnv]. These are the defaults:
|
94
|
+
|
95
|
+
[source,bash]
|
96
|
+
----
|
97
|
+
TANA_API_ACCEPT=application/json
|
98
|
+
TANA_API_TOKEN=
|
99
|
+
TANA_API_URL=https://europe-west1-tagr-prod.cloudfunctions.net
|
100
|
+
----
|
101
|
+
|
102
|
+
_You must provide a `TANA_API_TOKEN` value to make authenticated API requests._ This can be done by creating an API token via the API tokens UI:
|
103
|
+
|
104
|
+
image:https://alchemists.io/images/projects/tana/screenshots/api_tokens.png[API Tokens,width=714,height=334,role=focal_point]
|
105
|
+
|
106
|
+
Here are the steps to view and make use of the UI shown above:
|
107
|
+
|
108
|
+
. Click on _Settings_ within your Tana client.
|
109
|
+
. Click on _API tokens_.
|
110
|
+
. Click `Create` if you haven't already.
|
111
|
+
. Copy and paste your API token as value for `TANA_API_TOKEN` key.
|
112
|
+
. Refresh your environment accordingly.
|
113
|
+
|
114
|
+
=== Identification
|
115
|
+
|
116
|
+
When making API requests, you'll often need to acquire the IDs of the nodes you wish to add. This can be done two ways. The first is by selecting the node you are interested in, using `CONTROL + K` to launch the command prompt, and fuzzy type for _Copy link_. Example:
|
117
|
+
|
118
|
+
image:https://alchemists.io/images/projects/tana/screenshots/copy_link.png[Copy Link,width=793,height=512,role=focal_point]
|
119
|
+
|
120
|
+
Once copied the URL might look like `https://app.tana.inc?nodeid=z-p8LdQk6I76` but you'll only need the ID (i.e. `z-p8LdQk6I76`) for API requests.
|
121
|
+
|
122
|
+
For supertags/fields, you can select the node you are interested in using `CONTROL + K` to launch the command prompt and fuzzy type for _Show API schema_. Example:
|
123
|
+
|
124
|
+
image:https://alchemists.io/images/projects/tana/screenshots/show_api_schema.png[Show API Schema,width=578,height=875,role=focal_point]
|
125
|
+
|
126
|
+
=== Endpoints
|
127
|
+
|
128
|
+
At the moment, {tana_link} only provides the {api_link} which is a single endpoint for adding nodes only. This API has the following limitations:
|
129
|
+
|
130
|
+
* Rate Limiting
|
131
|
+
** One call per second per token.
|
132
|
+
** Max 100 nodes created per call.
|
133
|
+
** Max 5,000 characters in one request.
|
134
|
+
* Additional Limitations
|
135
|
+
** Can't target a relative Today node.
|
136
|
+
** Must know the IDs of the supertag.
|
137
|
+
** Each payload is capped at five kilobytes.
|
138
|
+
** Can't add a checkbox child to a normal node.
|
139
|
+
** No support for child templates.
|
140
|
+
** No support for in-application links (i.e. anything that is not a http/https scheme).
|
141
|
+
|
142
|
+
==== Add
|
143
|
+
|
144
|
+
To add nodes (i.e. {api_link}), you only need to send the `#add` message. Here's a quick example of adding a simple node to your {tana_link} Inbox.
|
145
|
+
|
146
|
+
[source,ruby]
|
147
|
+
----
|
148
|
+
client = Tana.new
|
149
|
+
|
150
|
+
result = client.add(
|
151
|
+
{
|
152
|
+
targetNodeId: "INBOX",
|
153
|
+
nodes: [
|
154
|
+
{
|
155
|
+
name: "With plain node",
|
156
|
+
description: "A demonstration."
|
157
|
+
}
|
158
|
+
]
|
159
|
+
}
|
160
|
+
)
|
161
|
+
|
162
|
+
result
|
163
|
+
# Success(#<data Tana::Models::Root children=[#<data Tana::Models::Node id="agite1C3Tben", name="With plain node", description="A demonstration.", type="node", children=[]>]>)
|
164
|
+
----
|
165
|
+
|
166
|
+
The above will yield the following in your {tana_link} Inbox:
|
167
|
+
|
168
|
+
image:https://alchemists.io/images/projects/tana/screenshots/inbox.png[Inbox,width=784,height=517,role=focal_point]
|
169
|
+
|
170
|
+
You'll also notice, the result is a monad (i.e. {dry_monads_link}) which means you'll only get a `Success` or `Failure` which you can pipe with additional functionality or use {pattern_matching_link}.
|
171
|
+
|
172
|
+
For successes, you'll be given a {data_link} object with a simple Object API for accessing the children of the response. At the root, you'll have a `Tana::Models::Root` instance which can be one or more `Tana::Models::Node` children. When you unpack the `Success` -- and to illustrate further -- you'll end up with the following:
|
173
|
+
|
174
|
+
[source,ruby]
|
175
|
+
----
|
176
|
+
Tana::Models::Root[
|
177
|
+
children: [
|
178
|
+
Tana::Models::Node[
|
179
|
+
id: "agite1C3Tben",
|
180
|
+
name: "With plain node",
|
181
|
+
description: "A demonstration.",
|
182
|
+
type: "node",
|
183
|
+
children: []
|
184
|
+
]
|
185
|
+
]
|
186
|
+
]
|
187
|
+
----
|
188
|
+
|
189
|
+
This simplifies and reduces the amount of work you have to do in your own program when processing the API result. For a `Failure`, you either get a `HTTP::Response` or a structured response that is a plain `Hash`. Example:
|
190
|
+
|
191
|
+
[source,ruby]
|
192
|
+
----
|
193
|
+
{
|
194
|
+
"formErrors" => ["Invalid input"],
|
195
|
+
"fieldErrors" => {}
|
196
|
+
}
|
197
|
+
----
|
198
|
+
|
199
|
+
Usually, errors are due to invalid authentication credentials or wrong data format. To experiment further, you can use this {bundler_inline_link} script:
|
200
|
+
|
201
|
+
[source,ruby]
|
202
|
+
----
|
203
|
+
#! /usr/bin/env ruby
|
204
|
+
# frozen_string_literal: true
|
205
|
+
|
206
|
+
# Save as `demo`, then `chmod 755 demo`, and run as `./demo`.
|
207
|
+
|
208
|
+
require "bundler/inline"
|
209
|
+
|
210
|
+
gemfile true do
|
211
|
+
source "https://rubygems.org"
|
212
|
+
|
213
|
+
gem "amazing_print"
|
214
|
+
gem "debug"
|
215
|
+
gem "tana"
|
216
|
+
end
|
217
|
+
|
218
|
+
require "base64"
|
219
|
+
|
220
|
+
include Dry::Monads[:result]
|
221
|
+
|
222
|
+
render = lambda do |result|
|
223
|
+
case result
|
224
|
+
in Success(record) then puts record
|
225
|
+
in Failure(HTTP::Response => error) then puts error.body
|
226
|
+
in Failure(error) then ap error.errors
|
227
|
+
else abort "Unable to process result."
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
client = Tana.new
|
232
|
+
----
|
233
|
+
|
234
|
+
When you save the above and run it locally, you have a quick way to experiment with the API print out the results by using the `render` function which uses {pattern_matching_link} that I hinted at earlier. The following are additional examples you can experiment with by adding to the above script:
|
235
|
+
|
236
|
+
*With Nesting*
|
237
|
+
|
238
|
+
The following will allow you to create a deeply nested set of nodes. At the moment, your are limited to ten levels deep due to recursion limitations with the {dry_schema_link} and {dry_validation_link} gems.
|
239
|
+
|
240
|
+
[source,ruby]
|
241
|
+
----
|
242
|
+
render.call client.add(
|
243
|
+
{
|
244
|
+
targetNodeId: "INBOX",
|
245
|
+
nodes: [
|
246
|
+
{
|
247
|
+
name: "One",
|
248
|
+
children: [
|
249
|
+
{
|
250
|
+
name: "Two",
|
251
|
+
children: [
|
252
|
+
{
|
253
|
+
name: "Three",
|
254
|
+
children: [
|
255
|
+
{
|
256
|
+
name: "Four",
|
257
|
+
children: [
|
258
|
+
{
|
259
|
+
name: "Five",
|
260
|
+
children: [
|
261
|
+
{
|
262
|
+
name: "Six",
|
263
|
+
children: [
|
264
|
+
{
|
265
|
+
name: "Seven",
|
266
|
+
children: [
|
267
|
+
{
|
268
|
+
name: "Eight",
|
269
|
+
children: [
|
270
|
+
name: "Nine",
|
271
|
+
children: [
|
272
|
+
{name: "Ten"}
|
273
|
+
]
|
274
|
+
]
|
275
|
+
}
|
276
|
+
]
|
277
|
+
}
|
278
|
+
]
|
279
|
+
}
|
280
|
+
]
|
281
|
+
}
|
282
|
+
]
|
283
|
+
}
|
284
|
+
]
|
285
|
+
}
|
286
|
+
]
|
287
|
+
}
|
288
|
+
]
|
289
|
+
}
|
290
|
+
]
|
291
|
+
}
|
292
|
+
)
|
293
|
+
----
|
294
|
+
|
295
|
+
*With Field*
|
296
|
+
|
297
|
+
The following allows you to create a node with a field (_you'll want to replace the attribute ID with your ID_).
|
298
|
+
|
299
|
+
[source,ruby]
|
300
|
+
----
|
301
|
+
render.call client.add(
|
302
|
+
{
|
303
|
+
targetNodeId: "INBOX",
|
304
|
+
nodes: [
|
305
|
+
{
|
306
|
+
name: "With field",
|
307
|
+
description: "A demonstration.",
|
308
|
+
children: [
|
309
|
+
{
|
310
|
+
attributeId: "zM582yzfcs-q",
|
311
|
+
type: "field",
|
312
|
+
children: [
|
313
|
+
{name: "💡 Idea"}
|
314
|
+
]
|
315
|
+
}
|
316
|
+
]
|
317
|
+
}
|
318
|
+
]
|
319
|
+
}
|
320
|
+
)
|
321
|
+
----
|
322
|
+
|
323
|
+
*With Supertags*
|
324
|
+
|
325
|
+
The following allows you to create a node with supertags (_you'll want to replace the IDs with your own IDs_).
|
326
|
+
|
327
|
+
[source,ruby]
|
328
|
+
----
|
329
|
+
render.call client.add(
|
330
|
+
{
|
331
|
+
targetNodeId: "INBOX",
|
332
|
+
nodes: [
|
333
|
+
{
|
334
|
+
name: "With supertags",
|
335
|
+
description: "A demonstration.",
|
336
|
+
supertags: [
|
337
|
+
{id: "S9aMn7puHzUT"},
|
338
|
+
{id: "iWKs80kHI0SK"}
|
339
|
+
]
|
340
|
+
}
|
341
|
+
]
|
342
|
+
}
|
343
|
+
)
|
344
|
+
----
|
345
|
+
|
346
|
+
*With Reference*
|
347
|
+
|
348
|
+
The following will allow you to create a node with a reference to another node (_you'll want to replace with your own ID_):
|
349
|
+
|
350
|
+
[source,ruby]
|
351
|
+
----
|
352
|
+
render.call client.add(
|
353
|
+
{
|
354
|
+
targetNodeId: "INBOX",
|
355
|
+
nodes: [
|
356
|
+
{
|
357
|
+
dataType: "reference",
|
358
|
+
id: "H-vAUdPi8taR"
|
359
|
+
}
|
360
|
+
]
|
361
|
+
}
|
362
|
+
)
|
363
|
+
----
|
364
|
+
|
365
|
+
*With Date*
|
366
|
+
|
367
|
+
The following will allow you to create a node with a date:
|
368
|
+
|
369
|
+
[source,ruby]
|
370
|
+
----
|
371
|
+
render.call client.add(
|
372
|
+
{
|
373
|
+
targetNodeId: "INBOX",
|
374
|
+
nodes: [
|
375
|
+
{
|
376
|
+
dataType: "date",
|
377
|
+
name: "2024-01-01T00:00:00Z"
|
378
|
+
}
|
379
|
+
]
|
380
|
+
}
|
381
|
+
)
|
382
|
+
----
|
383
|
+
|
384
|
+
*With URL*
|
385
|
+
|
386
|
+
The following will allow you to create a node with a URL field (_you'll want to replace with your own ID):
|
387
|
+
|
388
|
+
[source,ruby]
|
389
|
+
----
|
390
|
+
render.call client.add(
|
391
|
+
{
|
392
|
+
targetNodeId: "INBOX",
|
393
|
+
nodes: [
|
394
|
+
{
|
395
|
+
type: "field",
|
396
|
+
attributeId: "OceDtN8c0CbR",
|
397
|
+
children: [
|
398
|
+
{
|
399
|
+
dataType: "url",
|
400
|
+
name: "https://alchemists.io"
|
401
|
+
}
|
402
|
+
]
|
403
|
+
}
|
404
|
+
]
|
405
|
+
}
|
406
|
+
)
|
407
|
+
----
|
408
|
+
|
409
|
+
*With Checkbox*
|
410
|
+
|
411
|
+
The following will allow you to create a node with a checkbox:
|
412
|
+
|
413
|
+
[source,ruby]
|
414
|
+
----
|
415
|
+
render.call client.add(
|
416
|
+
{
|
417
|
+
targetNodeId: "INBOX",
|
418
|
+
nodes: [
|
419
|
+
{
|
420
|
+
name: "With checkbox",
|
421
|
+
dataType: "boolean",
|
422
|
+
value: true
|
423
|
+
}
|
424
|
+
]
|
425
|
+
}
|
426
|
+
)
|
427
|
+
----
|
428
|
+
|
429
|
+
*With Attachment*
|
430
|
+
|
431
|
+
The following will allow you to create a node with an attachment. This requires the _Base64_ gem as shown required in the script above because you need to encode your attachment before making the API request.
|
432
|
+
|
433
|
+
[source,ruby]
|
434
|
+
----
|
435
|
+
render.call client.add(
|
436
|
+
{
|
437
|
+
targetNodeId: "INBOX",
|
438
|
+
nodes: [
|
439
|
+
{
|
440
|
+
dataType: "file",
|
441
|
+
file: Base64.strict_encode64(Pathname("sunglasses.jpeg").read),
|
442
|
+
filename: "sunglasses.jpeg",
|
443
|
+
contentType: "image/jpeg"
|
444
|
+
}
|
445
|
+
]
|
446
|
+
}
|
447
|
+
)
|
448
|
+
----
|
449
|
+
|
450
|
+
*With Schema Field*
|
451
|
+
|
452
|
+
The following will allow you to create a Schema field:
|
453
|
+
|
454
|
+
[source,ruby]
|
455
|
+
----
|
456
|
+
render.call client.add(
|
457
|
+
{
|
458
|
+
targetNodeId: "SCHEMA",
|
459
|
+
nodes: [
|
460
|
+
{
|
461
|
+
name: "demo",
|
462
|
+
description: "With Schema field.",
|
463
|
+
supertags: [{id: "SYS_T02"}]
|
464
|
+
}
|
465
|
+
]
|
466
|
+
}
|
467
|
+
)
|
468
|
+
----
|
469
|
+
|
470
|
+
*With Schema Supertag*
|
471
|
+
|
472
|
+
The following will allow you to create a Schema supertag:
|
473
|
+
|
474
|
+
[source,ruby]
|
475
|
+
----
|
476
|
+
render.call client.add(
|
477
|
+
{
|
478
|
+
targetNodeId: "SCHEMA",
|
479
|
+
nodes: [
|
480
|
+
{
|
481
|
+
name: "demo",
|
482
|
+
description: "With Schema supertag.",
|
483
|
+
supertags: [{id: "SYS_T01"}]
|
484
|
+
}
|
485
|
+
]
|
486
|
+
}
|
487
|
+
)
|
488
|
+
----
|
489
|
+
|
490
|
+
== Development
|
491
|
+
|
492
|
+
To contribute, run:
|
493
|
+
|
494
|
+
[source,bash]
|
495
|
+
----
|
496
|
+
git clone https://github.com/bkuhlmann/tana
|
497
|
+
cd tana
|
498
|
+
bin/setup
|
499
|
+
----
|
500
|
+
|
501
|
+
You can also use the IRB console for direct access to all objects:
|
502
|
+
|
503
|
+
[source,bash]
|
504
|
+
----
|
505
|
+
bin/console
|
506
|
+
----
|
507
|
+
|
508
|
+
== Tests
|
509
|
+
|
510
|
+
To test, run:
|
511
|
+
|
512
|
+
[source,bash]
|
513
|
+
----
|
514
|
+
bin/rake
|
515
|
+
----
|
516
|
+
|
517
|
+
== link:https://alchemists.io/policies/license[License]
|
518
|
+
|
519
|
+
== link:https://alchemists.io/policies/security[Security]
|
520
|
+
|
521
|
+
== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
|
522
|
+
|
523
|
+
== link:https://alchemists.io/policies/contributions[Contributions]
|
524
|
+
|
525
|
+
== link:https://alchemists.io/projects/tana/versions[Versions]
|
526
|
+
|
527
|
+
== link:https://alchemists.io/community[Community]
|
528
|
+
|
529
|
+
== Credits
|
530
|
+
|
531
|
+
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
|
532
|
+
* Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/monads"
|
4
|
+
|
5
|
+
module Tana
|
6
|
+
module API
|
7
|
+
# A low-level API client for making basic HTTP requests.
|
8
|
+
class Client
|
9
|
+
include Import[:configuration, :http]
|
10
|
+
include Dry::Monads[:result]
|
11
|
+
|
12
|
+
def post path, body = nil, **parameters
|
13
|
+
call __method__, path, json: body, params: parameters
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def call method, path, **options
|
19
|
+
http.auth("Bearer #{configuration.token}")
|
20
|
+
.headers(accept: configuration.accept)
|
21
|
+
.public_send(method, "#{configuration.url}/#{path}", options)
|
22
|
+
.then { |response| response.status.success? ? Success(response) : Failure(response) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|