Merge pull request #3 from tparnell8/container

use container, and jsonp
This commit is contained in:
Tommy Parnell
2015-03-21 01:01:28 -04:00
6 changed files with 29 additions and 19 deletions

View File

@@ -1,11 +1,18 @@
namespace UntappedWidgetGenerator.Web
using Nancy.Bootstrapper;
using Nancy.Routing;
using Nancy.TinyIoc;
using UntappedWidgetGenerator.Interface;
namespace UntappedWidgetGenerator.Web
{
using Nancy;
public class Bootstrapper : DefaultNancyBootstrapper
{
// The bootstrapper enables you to reconfigure the composition of the framework,
// by overriding the various methods and properties.
// For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<IUntappedRepository, UntappedRepository>();
}
}
}

View File

@@ -1,22 +1,20 @@
using System.Collections.Generic;
using UntappedWidgetGenerator.Model;
using Nancy;
using UntappedWidgetGenerator.Interface;
namespace UntappedWidgetGenerator.Web
{
using Nancy;
public class IndexModule : NancyModule
{
public IndexModule()
public IndexModule(IUntappedRepository repository )
{
Get["/"] = x => View["Views/Index/Index.cshtml", "tparnell"];
Get["/{username}/browse"] = x => View["Views/Index/Index.cshtml", (string)x.username];
Get["/{username}/html"] = parameters =>
{
var info = new UntappedRepository().Get(parameters.username);
var info = repository.Get(parameters.username);
return View["Profile", info];
};
Get["/{username}"] = parameters => Response.AsJson(new UntappedRepository().Get((string)parameters.username));
Get["/{username}"] = parameters => Response.AsJson(repository.Get((string)parameters.username));
}
}
}

View File

@@ -32,10 +32,7 @@
$.fn.untappd = function (username) {
this.each(function () {
var that = this;
$.get("http://untappdwidget.azurewebsites.net/" + username)
.success(function (data) {
$(that).html(buildProfileTemplate(data,buildBadges(data)));
});
$.get("http://untappdwidget.azurewebsites.net/" + username, function(data) { $(that).html(buildProfileTemplate(data, buildBadges(data))); }, "jsonp");
});
};

View File

@@ -0,0 +1,9 @@
using UntappedWidgetGenerator.Model;
namespace UntappedWidgetGenerator.Interface
{
public interface IUntappedRepository
{
WidgetViewModel Get(string username);
}
}

View File

@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsQuery;
using UntappedWidgetGenerator.Interface;
using UntappedWidgetGenerator.Model;
namespace UntappedWidgetGenerator
{
public class UntappedRepository
public class UntappedRepository : IUntappedRepository
{
public WidgetViewModel Get(string username)
{

View File

@@ -42,6 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Interface\IUntappedRepository.cs" />
<Compile Include="Model\Badge.cs" />
<Compile Include="Model\WidgetViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />