Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rest-api-examples
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
snac
rest-api-examples
Commits
1c95434f
Commit
1c95434f
authored
Sep 26, 2017
by
Robbie Hott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial read relations from icid list
parent
8251cf43
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
read_relations_from_list.php
read/read_relations_from_list.php
+62
-0
No files found.
read/read_relations_from_list.php
0 → 100644
View file @
1c95434f
<?php
/**
* SNAC Export from List example
*
* For the full license, see the LICENSE file in the repository root
*
* @author Robbie Hott
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @copyright 2017 the Rector and Visitors of the University of Virginia, and
* the Regents of the University of California
*/
$row
=
0
;
// Open the first argument as the csv file to read (argv[1] should be the CBW csv file)
if
(
isset
(
$argv
[
1
])
&&
((
$handle
=
fopen
(
$argv
[
1
],
"r"
))
!==
FALSE
))
{
// Loop over the data in the CSV file
while
((
$data
=
fgetcsv
(
$handle
))
!==
FALSE
)
{
if
(
$row
++
>=
1
)
{
// ignore the header row
// Build a SNAC query with an Identity Constellation Array (JSON object)
$snacArray
=
array
(
"command"
=>
"read_constellation"
,
"constellationid"
=>
$data
[
0
]
);
// Encode Associative Array as JSON object
$query
=
json_encode
(
$snacArray
,
JSON_PRETTY_PRINT
);
// Use CURL to send reconciliation request to the REST API
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
"http://api.snaccooperative.org/"
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
array
(
'Content-Type: application/json'
,
'Content-Length: '
.
strlen
(
$query
)
));
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
'PUT'
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$query
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
$responseJSON
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
// Decode JSON response into an Associative Array
$response
=
json_decode
(
$responseJSON
,
true
);
}
}
fclose
(
$handle
);
}
else
{
// If something happened, then just print out usage
echo
"Download from list of ICIDs
\n
"
.
"Usage: php read_from_list.php list.csv [directory] [type]
\n\n
"
.
"The list.csv file should have a header and the first column should contain ICIDs.
\n
"
.
"Type must be a valid type: eac-cpf, constellation_json
\n
"
;
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment