Skip to content

Commit

Permalink
Add sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolavn committed Jun 20, 2016
1 parent c5b9ba6 commit 1fb0d05
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 33 deletions.
12 changes: 0 additions & 12 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/Class1.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MovieInfoApp.Models
{
//using Newtonsoft.Json;

class ActorModel
{
//[JsonProperty("id")]
public int Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MovieInfoApp.Models
{
//using Newtonsoft.Json;

class CreditsModel
{
//[JsonProperty("id")]
public int Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MovieInfoApp.Models
{
//using Newtonsoft.Json;

class EpisodeModel
{
//[JsonProperty("episode_number")]
public int EpisodeNumber { get; set; }

//[JsonProperty("season")]
public int Season { get; set; }
}
}
44 changes: 44 additions & 0 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/MovieDb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace MovieInfoApp
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

public class MovieDb
{
private static readonly Uri BaseUrl = new Uri("https://api.themoviedb.org/3/search/person");
private const string ApiKey = "xxx";

public static void Main()
{
var client = new HttpClient();

var result = GetActorInfoByName(client, "bruce willis");

Console.WriteLine();
}

private static string GetActorInfoByName(HttpClient client, string name)
{
string responseData;
var test = Uri.EscapeUriString(name);
string nameQuery = "query=" + Uri.EscapeUriString(name);
UriBuilder targetUrl = new UriBuilder(BaseUrl);

targetUrl.Query = "api_key=" + ApiKey;
targetUrl.Query = targetUrl.Query.Substring(1) + "&" + nameQuery;

client.BaseAddress = targetUrl.Uri;
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var response = client.GetAsync("").Result;
responseData = response.Content.ReadAsStringAsync().Result;

return responseData;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>39eda17e-8b18-452a-86af-a237168e3847</ProjectGuid>
<OutputType>Library</OutputType>
<ProjectGuid>{39EDA17E-8B18-452A-86AF-A237168E3847}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MovieInfoApp</RootNamespace>
<AssemblyName>MovieInfoApp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -29,26 +30,29 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>

<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>


<Reference Include="Microsoft.CSharp"/>

<Reference Include="System.Data"/>

<Reference Include="System.Net.Http"/>

<Reference Include="System.Xml"/>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Models\ActorModel.cs" />
<Compile Include="Models\CreditsModel.cs" />
<Compile Include="Models\EpisodeModel.cs" />
<Compile Include="MovieDb.cs" />
<Compile Include="UriExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -57,5 +61,4 @@
<Target Name="AfterBuild">
</Target>
-->

</Project>
</Project>
18 changes: 18 additions & 0 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/UriExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace MovieInfoApp
{
using System;
using System.Web;

public static class UriExtensions
{
public static Uri AddParameter(this Uri url, string paramName, string paramValue)
{
var uriBuilder = new UriBuilder(url);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query[paramName] = paramValue;
uriBuilder.Query = query.ToString();

return uriBuilder.Uri;
}
}
}

0 comments on commit 1fb0d05

Please sign in to comment.