Browse code

Created json library for jamendo and tests

Blackbeard authored on 2018-09-14 22:50:16
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,49 @@
1
+#!/bin/sh
2
+#. ../../helpers.sh 
3
+
4
+# This file is free software, go thank RMS
5
+## PRAISE RMS, LORD AND SAVIOR
6
+
7
+#==============================
8
+#     DATA DEFINITIONS      #
9
+#==============================
10
+# URL is a valid api.jamando URL
11
+# JSON is a file from jamendo
12
+
13
+
14
+
15
+
16
+#==============================
17
+#        DOWLOAD JSON        #
18
+#==============================
19
+# URL -> JSON
20
+# Outputs the JSON on URL 
21
+function _json_downloadUrl {
22
+    local input_url="$1"
23
+    helpers_downloadStdout "$input_url"
24
+}
25
+
26
+
27
+# JSON VALUE -> LIST OF VALUES
28
+# Outputs a list of value(not nested) from a JSON
29
+function json_getValue {
30
+    local json_file="$1" 
31
+    local value="$2"
32
+    echo "$json_file"   \
33
+	| jq ".results[] | .${value}" 
34
+
35
+}
36
+
37
+# JSON OUTSIDE_VALUE NESTED_VALUE -> LIST OF NESTED_VALUES
38
+# Outputs a list of value(nested) from a JSON
39
+function json_getValueNested {
40
+        local json_file="$1" 
41
+        local outside_value="$2"
42
+	local nested_value="$3a"
43
+	
44
+    echo "$json_file"   \
45
+	| jq ".results[] | .${outside_value}[] | .${nested_value}" 
46
+}
47
+
48
+
49
+
0 50
new file mode 100755
... ...
@@ -0,0 +1,60 @@
1
+#! /bin/sh
2
+# file: tests/backend/jamendo/json-test.sh
3
+
4
+#==============================
5
+#         BASIC JSON          #
6
+#==============================
7
+
8
+
9
+test_json_downloadUrl() {
10
+     # If this test fails, might be related to wget vs curl vs ftp, make sure
11
+     # the file is correct
12
+    local expected_string="$(cat "../../files/json-tests/playlist-tracks.json")"
13
+    local tested_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
14
+    
15
+    local function_string="$(_json_downloadUrl "$tested_url")"
16
+    
17
+    assertEquals "$expected_string"  "$function_string"
18
+}
19
+
20
+test_json_getValue() {
21
+    local expected_string="$(cat "../../files/json-tests/name-user-playlists.test")"
22
+    local playlists_url="https://api.jamendo.com/v3.0/playlists/?client_id=73efbf98&format=jsonpretty&user_id=6766768&limit=all"
23
+    local tested_jsonFile="$(_json_downloadUrl "$playlists_url")"
24
+    local tested_value="name"
25
+    
26
+    local function_string="$(json_getValue "$tested_jsonFile" "$tested_value")"
27
+    
28
+    assertEquals "$expected_string"  "$function_string"
29
+}
30
+
31
+
32
+test_json_getValueNested() {
33
+    local expected_string="$(cat "../../files/json-tests/name-tracks-playlist.test")"
34
+    local testing_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
35
+
36
+    local tested_jsonFile="$(_json_downloadUrl "$testing_url")"
37
+    local tested_outsideValue="tracks"
38
+    local tested_nestedValue="name"
39
+    
40
+    local function_string="$(json_getValueNested "$tested_jsonFile" "$tested_outsideValue" "$tested_nestedValue")"
41
+    
42
+    assertEquals "$expected_string"  "$function_string"
43
+}
44
+
45
+
46
+
47
+#==============================
48
+#     PLAYLISTS URLS         #
49
+#==============================
50
+
51
+
52
+
53
+oneTimeSetUp() {
54
+    # load proper libraries
55
+    . ../../../lib/helpers.sh
56
+    . ../../../lib/backend/jamendo/json.sh 
57
+}
58
+
59
+. ../../../lib/shunit2 
60
+
0 61
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+"Copelandia - Arctic Cave"
2
+"Sacred (Original Mix)"
3
+"Phanatoplexy"
4
+"Return on Earth(original mix)"
5
+"Psilofunk"
0 6
\ No newline at end of file
1 7
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+"psychic-testing"
2
+"Rock Awesome"
3
+"Electronic to study"
4
+"Just Relax"
5
+"Fiesta"
0 6
\ No newline at end of file
1 7
new file mode 100644
... ...
@@ -0,0 +1,96 @@
1
+{
2
+	"headers":{
3
+		"status":"success",
4
+		"code":0,
5
+		"error_message":"",
6
+		"warnings":"",
7
+		"results_count":1
8
+	},
9
+	"results":[
10
+		{
11
+			"id":"500439691",
12
+			"name":"psychic-testing",
13
+			"creationdate":"2018-08-24",
14
+			"user_id":"6766768",
15
+			"user_name":"b7009294@nwytg.net",
16
+			"zip":"https:\/\/mp3d.jamendo.com\/download\/p500439691\/mp32\/",
17
+			"tracks":[
18
+				{
19
+					"id":"500682",
20
+					"name":"Copelandia - Arctic Cave",
21
+					"album_id":"58648",
22
+					"artist_id":"356365",
23
+					"duration":"523",
24
+					"artist_name":"digitaldawn",
25
+					"playlistadddate":"2018-08-24 17:25:48",
26
+					"position":"1",
27
+					"license_ccurl":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/",
28
+					"album_image":"https:\/\/imgjam2.jamendo.com\/albums\/s58\/58648\/covers\/1.200.jpg",
29
+					"image":"https:\/\/imgjam1.jamendo.com\/albums\/s58\/58648\/covers\/1.200.jpg",
30
+					"audio":"https:\/\/mp3l.jamendo.com\/?trackid=500682&format=mp31&from=app-73efbf98",
31
+					"audiodownload":"https:\/\/mp3d.jamendo.com\/download\/track\/500682\/mp32\/"
32
+				},
33
+				{
34
+					"id":"1452060",
35
+					"name":"Sacred (Original Mix)",
36
+					"album_id":null,
37
+					"artist_id":"500527",
38
+					"duration":"452",
39
+					"artist_name":"=Shinson=",
40
+					"playlistadddate":"2018-08-24 17:25:56",
41
+					"position":"2",
42
+					"license_ccurl":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/",
43
+					"album_image":"https:\/\/imgjam2.jamendo.com\/track\/s1452\/1452060\/covers\/1.200.jpg",
44
+					"image":"https:\/\/imgjam1.jamendo.com\/track\/s1452\/1452060\/covers\/1.200.jpg",
45
+					"audio":"https:\/\/mp3l.jamendo.com\/?trackid=1452060&format=mp31&from=app-73efbf98",
46
+					"audiodownload":"https:\/\/mp3d.jamendo.com\/download\/track\/1452060\/mp32\/"
47
+				},
48
+				{
49
+					"id":"1254745",
50
+					"name":"Phanatoplexy",
51
+					"album_id":null,
52
+					"artist_id":"1634",
53
+					"duration":"446",
54
+					"artist_name":"Nebulis",
55
+					"playlistadddate":"2018-08-24 17:26:00",
56
+					"position":"3",
57
+					"license_ccurl":"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/",
58
+					"album_image":"https:\/\/imgjam2.jamendo.com\/track\/s1254\/1254745\/covers\/1.200.jpg",
59
+					"image":"https:\/\/imgjam1.jamendo.com\/track\/s1254\/1254745\/covers\/1.200.jpg",
60
+					"audio":"https:\/\/mp3l.jamendo.com\/?trackid=1254745&format=mp31&from=app-73efbf98",
61
+					"audiodownload":"https:\/\/mp3d.jamendo.com\/download\/track\/1254745\/mp32\/"
62
+				},
63
+				{
64
+					"id":"1398163",
65
+					"name":"Return on Earth(original mix)",
66
+					"album_id":null,
67
+					"artist_id":"440149",
68
+					"duration":"473",
69
+					"artist_name":"GOARU",
70
+					"playlistadddate":"2018-08-24 17:26:04",
71
+					"position":"4",
72
+					"license_ccurl":"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/",
73
+					"album_image":"https:\/\/imgjam2.jamendo.com\/track\/s1398\/1398163\/covers\/1.200.jpg",
74
+					"image":"https:\/\/imgjam1.jamendo.com\/track\/s1398\/1398163\/covers\/1.200.jpg",
75
+					"audio":"https:\/\/mp3l.jamendo.com\/?trackid=1398163&format=mp31&from=app-73efbf98",
76
+					"audiodownload":"https:\/\/mp3d.jamendo.com\/download\/track\/1398163\/mp32\/"
77
+				},
78
+				{
79
+					"id":"46477",
80
+					"name":"Psilofunk",
81
+					"album_id":"5597",
82
+					"artist_id":"4165",
83
+					"duration":"498",
84
+					"artist_name":"Quantica",
85
+					"playlistadddate":"2018-08-24 17:26:07",
86
+					"position":"5",
87
+					"license_ccurl":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/",
88
+					"album_image":"https:\/\/imgjam2.jamendo.com\/albums\/s5\/5597\/covers\/1.200.jpg",
89
+					"image":"https:\/\/imgjam2.jamendo.com\/albums\/s5\/5597\/covers\/1.200.jpg",
90
+					"audio":"https:\/\/mp3l.jamendo.com\/?trackid=46477&format=mp31&from=app-73efbf98",
91
+					"audiodownload":"https:\/\/mp3d.jamendo.com\/download\/track\/46477\/mp32\/"
92
+				}
93
+			]
94
+		}
95
+	]
96
+}
0 97
\ No newline at end of file