added sample #1

Merged
merged 2 commits into from Jan 27, 2012
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitlySharpSample", "BitlySharpSample\BitlySharpSample.csproj", "{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|iPhoneSimulator = Debug|iPhoneSimulator
+ Release|iPhoneSimulator = Release|iPhoneSimulator
+ Debug|iPhone = Debug|iPhone
+ Release|iPhone = Release|iPhone
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhone.ActiveCfg = Debug|iPhone
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhone.Build.0 = Debug|iPhone
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhone.ActiveCfg = Release|iPhone
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhone.Build.0 = Release|iPhone
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
+ {32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = BitlySharpSample\BitlySharpSample.csproj
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,41 @@
+//
+// Copyright 2012 abhatia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace BitlySharpSample
+{
+ [Register ("AppDelegate")]
+ public partial class AppDelegate : UIApplicationDelegate
+ {
+ UIWindow _Window;
+ RootViewController _RootController;
+
+ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
+ {
+ _Window = new UIWindow(UIScreen.MainScreen.Bounds);
+ _RootController = new RootViewController();
+
+ _Window.RootViewController = _RootController;
+ _Window.MakeKeyAndVisible();
+ return true;
+ }
+ }
+}
+
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}</ProjectGuid>
+ <ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>BitlySharpSample</RootNamespace>
+ <AssemblyName>BitlySharpSample</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <MtouchDebug>true</MtouchDebug>
+ <MtouchProfiling>true</MtouchProfiling>
+ <MtouchLink>None</MtouchLink>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\iPhoneSimulator\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <MtouchLink>None</MtouchLink>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\iPhone\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <CodesignKey>iPhone Developer</CodesignKey>
+ <MtouchDebug>true</MtouchDebug>
+ <MtouchProfiling>true</MtouchProfiling>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\iPhone\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ <CodesignKey>iPhone Developer</CodesignKey>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Core" />
+ <Reference Include="monotouch" />
+ <Reference Include="MonoTouch.Dialog-1" />
+ <Reference Include="System.Web.Services" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Info.plist" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Main.cs" />
+ <Compile Include="AppDelegate.cs" />
+ <Compile Include="ViewControllers\RootViewController.cs" />
+ <Compile Include="..\..\..\src\bitly.cs">
+ <Link>Bitly\bitly.cs</Link>
+ </Compile>
+ <Compile Include="ViewControllers\BitlyViewController.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <Folder Include="ViewControllers\" />
+ <Folder Include="Bitly\" />
+ </ItemGroup>
+</Project>
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>UIDeviceFamily</key>
+ <array>
+ <integer>1</integer>
+ <integer>2</integer>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,34 @@
+//
+// Copyright 2012 abhatia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace BitlySharpSample
+{
+ public class Application
+ {
+ // This is the main entry point of the application.
+ static void Main(string[] args)
+ {
+ // if you want to use a different Application Delegate class from "AppDelegate"
+ // you can specify it here.
+ UIApplication.Main(args, null, "AppDelegate");
+ }
+ }
+}
@@ -0,0 +1,138 @@
+//
+// Copyright 2012 abhatia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+using System;
+using MonoTouch.Dialog;
+using Bitly;
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+
+namespace BitlySharpSample
+{
+ public class BitlyViewController : DialogViewController
+ {
+ // Credentials go here.
+ const string USER_NAME = "";
+ const string APIKEY = "";
+
+ private static Api _BitlyApi;
+
+ Action<string> ShortenUrlAction;
+ Action<string> ExpandUrlAction;
+
+ EntryElement ShortenUrlElement;
+ EntryElement ExpandUrlElement;
+
+ StringElement ResultElement;
+
+ public BitlyViewController()
+ : base(new RootElement("Shorten URL"), true)
+ {
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ }
+
+ public override void LoadView()
+ {
+ base.LoadView();
+ }
+
+ public override void ViewDidLoad()
+ {
+ base.ViewDidLoad();
+
+ _BitlyApi = new Api(USER_NAME, APIKEY);
+ ShortenUrlAction = ShortenUrlActionHandler;
+ ExpandUrlAction = ExpandUrlActionHandler;
+
+ ShortenUrlElement = new EntryElement("Url to Shorten:", "", "");
+ ExpandUrlElement = new EntryElement("Btly Url to Expand: ", "", "");
+
+ var urlSection = new Section("URLs") {
+ ShortenUrlElement,
+ ExpandUrlElement,
+ };
+
+ var operationSection = new Section("") {
+ new StringElement("Shorten URL", () => {
+ ShortenUrlAction.BeginInvoke(ShortenUrlElement.Value, (ar) => {}, null);
+ }),
+ new StringElement("Expand URL", () => {
+ ExpandUrlAction.BeginInvoke(ExpandUrlElement.Value, (ar) => {}, null);
+ }),
+ };
+
+ ResultElement = new StringElement("");
+
+ var resultSection = new Section("Result") {
+ ResultElement,
+ };
+
+ this.Root.Add(new Section[] { urlSection, operationSection, resultSection });
+ }
+
+ public void ShortenUrlActionHandler(string url)
+ {
+ if(string.IsNullOrWhiteSpace(url)) {
+ NotifyInvalidUrl();
+ return;
+ }
+ var result = _BitlyApi.Shorten(url);
+ UpdateResultElement(result);
+ }
+
+ public void ExpandUrlActionHandler(string url)
+ {
+ if(string.IsNullOrWhiteSpace(url)) {
+ NotifyInvalidUrl();
+ return;
+ }
+
+ var result = _BitlyApi.Expand(url);
+ UpdateResultElement(result);
+ }
+
+ private void UpdateResultElement(string result)
+ {
+ ResultElement.Value = result;
+
+ using(var pool = new NSAutoreleasePool()) {
+ pool.BeginInvokeOnMainThread(()=>{
+ this.ReloadData();
+ });
+ }
+ }
+
+ public void NotifyInvalidUrl()
+ {
+ var alert = new UIAlertView("Invaid URL", "Invalid URL Specified. Try again...", null, "OK", null);
+ alert.Show();
+ }
+
+ public override void ViewWillLayoutSubviews()
+ {
+ base.ViewWillLayoutSubviews();
+ }
+
+ public override void ViewDidAppear(bool animated)
+ {
+ base.ViewDidAppear(animated);
+ }
+
+ }
+}
+
Oops, something went wrong.