Skip to content

Commit

Permalink
Add WLResourceRequest to call adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaychebbi committed Dec 3, 2015
1 parent 70ada63 commit 6af4a76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions xamarin/MFPNewsReader/MFPNewsReader/MyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ContentPage Padding="5, 25" Title="IBM Mobile First" BackgroundColor="#3498db">
<StackLayout Orientation="Vertical" Padding="0, 60, 0, 0">
<Label Text="IBM Mobile First" HorizontalOptions="Center" FontSize="Large" />
<Label Text="rss feed from developer.ibm.com" HorizontalOptions="Center" FontSize="Small" />
<StackLayout VerticalOptions="End" Padding="0, 60, 0, 40">
<Button Text="Connect" HorizontalOptions="Center" TextColor="White" x:Name="btnConnect" />
<Button Text="Invoke Procedure" HorizontalOptions="Center" TextColor="White" x:Name="btnInvokeProcedure" />
Expand All @@ -20,15 +21,15 @@
</MasterDetailPage.Master>

<MasterDetailPage.Detail>
<ContentPage Padding="5, 25" BindingContext="{Binding DetailPage}">
<ContentPage Padding="5, 25" BindingContext="{Binding DetailPage}" >

<StackLayout Orientation="Vertical">
<ListView ItemsSource="{Binding MyArticles}" RowHeight="100">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding ArticleTitle}" FontSize="Medium" TextColor="Blue"/>
<Label Text="{Binding ArticleTitle}" FontSize="Medium" TextColor="White"/>
<Label Text="{Binding ArticleText}" FontSize="Small" TextColor="Gray"/>
</StackLayout>
</ViewCell>
Expand Down
34 changes: 31 additions & 3 deletions xamarin/MFPNewsReader/MFPNewsReader/MyPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Xamarin.Forms;

using Worklight;
using System.Diagnostics;
//@author: ajaychebbi
namespace MFPNewsReader
{
Expand Down Expand Up @@ -35,9 +36,9 @@ private async void Connect()
DisplayAlert("Connection Status failed",resp.Message,"Close");
}
}
private async void InvokeProcedure()
private async void InvokeProcedureOld()
{
//Invoke Procedure
//Invoke Procedure - the old way
Articles.Clear ();
//Params for the invocation
WorklightProcedureInvocationData proceduerParams = new WorklightProcedureInvocationData("SampleHTTPAdapter", "getFeed", new object[] { });
Expand All @@ -58,6 +59,33 @@ private async void InvokeProcedure()
DisplayAlert("Connection Status failed",resp.Message,"Close");
}
}
}
private async void InvokeProcedure()
{
//Invoke Procedure - the new REST way
Articles.Clear();
//hopefully I can integrate oAuth with this sample soon
Uri adapterMethod = new Uri(App.wlClient.ServerUrl+ "/adapters/SampleHTTPAdapter/getFeed");
WorklightResourceRequest wlResReq = MFPNewsReader.App.wlClient.ResourceRequest(adapterMethod,"GET");
WorklightResponse resp = await wlResReq.Send();

if (resp.Success)
{
JsonArray jsonArray = (JsonArray)resp.ResponseJSON["rss"]["channel"]["item"];
foreach (JsonObject title in jsonArray)
{
System.Json.JsonValue titleString;
title.TryGetValue("title", out titleString);
System.Json.JsonValue itemString;
title.TryGetValue("description", out itemString);
Articles.Add(new Article(titleString, itemString));

}
}
else
{
DisplayAlert("Connection Status failed", resp.Message, "Close");
}
}
}
}

0 comments on commit 6af4a76

Please sign in to comment.