Skip to content

Commit e00c257

Browse files
use case example of API endpoints (#40)
1 parent 33dd2d7 commit e00c257

7 files changed

Lines changed: 68 additions & 1 deletion

File tree

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"sphinx.ext.intersphinx",
4646
"sphinx.ext.linkcode",
4747
"myst_parser",
48+
"sphinxcontrib.video",
4849
]
4950

5051

docs/user_guide/example.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Use case example
2+
================
3+
4+
Here are two simple examples showing how you can use the API endpoints to access data. The first example demonstrates how to find all instruments associated with a field, and the second example demonstrates how to find all risers with a specified length and sort them by field.
5+
6+
To build your own application using your desired API endpoints, you can find a complete overview of the available API endpoints in the `4insight REST API`_ documentation.
7+
8+
.. caution::
9+
Do not use the INTERNAL API endpoints. You can however use the endpoints from version 1.0, 1.1 and 1.2.
10+
11+
.. code-block:: python
12+
13+
from fourinsight.api import UserSession
14+
15+
session = UserSession()
16+
17+
#Find the FlexTrackEntityId of the field
18+
field_name = "INSERT FIELD NAME HERE"
19+
field_url = f"https://api.4insight.io/v1.1/FieldsLookups?%24filter=Title%20eq%20%27{field_name}%27"
20+
field = session.get(field_url).json()
21+
field_id = field['value'][0]['FlexTrackEntityId']
22+
23+
#Find all instruments associated with the field
24+
instruments_url = f"https://api.4insight.io/v1.1/Instruments?%24filter=FlexTrackFieldEntityId%20eq%20{field_id}"
25+
instruments = session.get(instruments_url).json()
26+
all_instruments = instruments['value']
27+
28+
.. code-block:: python
29+
30+
from fourinsight.api import UserSession
31+
32+
session = UserSession()
33+
34+
# Set length of riser to filter by
35+
length_riser = 800
36+
37+
# Find all risers with the specified length and sort them by field
38+
riser_url = f"https://api.4insight.io/v1.1/Risers?%24filter=Length%20eq%20{length_riser}"
39+
riser = session.get(riser_url).json()['value']
40+
sorted_risers = sorted(riser, key=lambda x: x['FlexTrackFieldEntityId'])
41+
42+
# Find the field associated with each riser
43+
risers_with_fields = []
44+
for riser in sorted_risers:
45+
field_id = riser['FlexTrackFieldEntityId']
46+
field_url = f"https://api.4insight.io/v1.1/FieldsLookups?%24filter=FlexTrackEntityId%20eq%20{field_id}"
47+
try:
48+
field_title = session.get(field_url).json()['value'][0]['Title']
49+
riser["Field"] = field_title
50+
except:
51+
riser["Field"] = "Field not found"
52+
risers_with_fields.append(riser)
53+
54+
Additionally, here is a video on how to authorize and obtain the URL for the endpoint you wish to use, found under `Request URL`.
55+
56+
.. video:: fig/swagger.mp4
57+
:width: 800
58+
:height: 600
59+
60+
.. _4insight REST API: https://4insight-api-prod.4subsea.net/swagger/index.html
61+
62+

docs/user_guide/fig/swagger.mp4

9.35 MB
Binary file not shown.

docs/user_guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ User Guide
1818
api_calls
1919
logging
2020
developer
21+
example

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build-system]
22
requires = [
33
"setuptools>=46.4.0",
4-
"wheel"
4+
"wheel",
5+
"sphinxcontrib-video"
56
]
67
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ install_requires =
2525
oauthlib
2626
requests-oauthlib
2727
importlib_resources
28+
sphinxcontrib-video
2829

2930
[options.packages.find]
3031
include = fourinsight.api

tox-deploy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ deps =
77
build
88
sphinx==5.3.0
99
pydata_sphinx_theme==0.11.0
10+
sphinxcontrib-video
1011
commands =
1112
python -m build --outdir ./build
1213
sphinx-build -b html ./docs ./build/html

0 commit comments

Comments
 (0)