Jump to content

Newb here.. load API?


Luke

Recommended Posts

have you tried the swagger docs? you can get to them from the dashboard in the links section. that links section also has a github link with api documentation as well

Link to comment
Share on other sites

TinkeringTot

I am familiar with java and javascript.

 

However, I'm not familiar enough to know what/how to use an API.

 

I code in Notepad++ or Eclipse.  Is it possible to view/use the API in these?

Link to comment
Share on other sites

TinkeringTot

have you tried the swagger docs? you can get to them from the dashboard in the links section. that links section also has a github link with api documentation as well

 

Thanks! That is exactly what I was looking for.

 

The swagger part. I still have no idea what to do with the API documentation.

Link to comment
Share on other sites

Cheesegeezer

Thanks! That is helpful.  I've managed to do a few things of little importance.  Is there a sub forum with a group of people that wouldn't mind helping me through an issue or two as I learn?  The issue may not be related to the API.

I would just use this thread, unfortunately i'm no good with JS so cant help.

Link to comment
Share on other sites

TinkeringTot

Thanks! That is helpful.  I've managed to do a few things of little importance.  Is there a sub forum with a group of people that wouldn't mind helping me through an issue or two as I learn?  The issue may not be related to the API.

Link to comment
Share on other sites

TinkeringTot

Alright, I am working with a script Mongoose made that I linked to above.

I've added years, ratings, and code to run through boxsets.

 

Though my boxsets all end up at the very end of the div.  I'm not sure why. Can anyone offer some assistance?

https://drive.google.com/file/d/0BybYJG8wuuLnVWJ0dnFfOHBfeVk/edit?usp=sharing 

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="server">
<p>Enter the details of your server</p>
IP Address (eg 192.168.1.100)<input type="text" id="serverField" value="192.168.1.100"/><br/>
Port (normally 8096)<input type="text" id="serverPort" value="8096"/><br/>
<p>
<input type="button" id="serverButton" value="Go"/>
</div>
<div id="userChoice" style="display:none">
Choose a user:
</div>
<div id="collectionChoice" style="display:none">
Choose a collection:
</div>
<div id="collectionView" style="display:none">
</div>
<script>
var serverIP;
var userId;
var collectionId;
var serverPort;
var collectionName;


$("#serverButton").click(function(){
	serverIP = $("#serverField").val();
	serverPort = $("#serverPort").val();
	$.getJSON('http://'+serverIP+':'+serverPort+'/mediabrowser/Users', function(data){
  		for(var j=0;j<data.length;j++)
			$("#userChoice").append("<br/><a href='#' onClick='userSelected(\""+data[j].Id+"\")'>"+data[j].Name+"</a>");
		$("#server").hide();
		$("#userChoice").show();
  });
});

function userSelected(thisUserId)
{
	userId=thisUserId;
	$.getJSON('http://'+serverIP+':'+serverPort+'/mediabrowser/Users/'+userId+'/Items?sortBy=SortName', function(data){
  		for(var j=0;j<data.Items.length;j++)
			$("#collectionChoice").append("<br/><a href='#' onClick='collectionSelected(\""+data.Items[j].Id+"\",\""+data.Items[j].Name+"\")'>"+data.Items[j].Name+"</a>");

		$("#userChoice").hide();
		$("#collectionChoice").show();
  });
}

function collectionSelected(thisCollectionId,thisCollectionName)
{
	collectionId=thisCollectionId;
	//collectionId="ca943aab9c4ec8c8b08d4f8bac4b4fa0";
	collectionName=thisCollectionName
	var premiereYear;
	var premiereDate;
	$("#collectionView").append("<br/><b>"+collectionName+"</b><br/>");
	//$("#collectionView").append('<br/>http://'+serverIP+':'+serverPort+'/mediabrowser/Users/'+userId+'/Items?sortBy=SortName&SortOrder=Ascending&Fields=DateCreated&StartIndex=0&Limit=2000&ParentId='+collectionId+'&Filters=&NameStartsWithOrGreater=');
	$.getJSON('http://'+serverIP+':'+serverPort+'/mediabrowser/Users/'+userId+'/Items?sortBy=SortName&SortOrder=Ascending&Fields=DateCreated&StartIndex=0&Limit=2000&ParentId='+collectionId+'&Filters=&NameStartsWithOrGreater=', function(data){
		for(var j=0;j<data.Items.length;j++){
			premiereDate=""+data.Items[j].PremiereDate;
			if(premiereDate == "undefined"){
				premiereYear="";
			} else {
				premiereYear="("+premiereDate.substr(0,4)+") ";
			}
			if (data.Items[j].Type == "BoxSet"){
				//$("#collectionView").append("<br/>"+data.Items[j].Name+" "+premiereYear+" ("+data.Items[j].Type+") " +data.Items[j].Id);
				collectionSelected(data.Items[j].Id,data.Items[j].Name);
			} else {
				$("#collectionView").append("<br/>"+data.Items[j].Name+" ("+data.Items[j].OfficialRating+") "+premiereYear);
			}
			
		}
		$("#collectionChoice").hide();
		$("#collectionView").show();

	});
}
</script>
</body>
</html>

Link to comment
Share on other sites

MongooseMan

At a guess (given 5 minutes of looking at the code) I'd say its because getJson is an async call, which JavaScript doesn't wait for.

So, it'll finish appending all the non-boxset items before it gets the response from the getJson call and therefore appends those afterwards.

Make sense?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...