Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

added sample #1

Merged
merged 2 commits into from about 2 years ago

2 participants

Anuj James Clancey
Anuj

added sample, but the request keeps returning http 500

James Clancey Clancey merged commit 9c2be9b into from January 27, 2012
James Clancey Clancey closed this January 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jan 27, 2012
Anuj added sample 924bc62
Anuj updated bitlycontroller e802a12
This page is out of date. Refresh to see the latest.
26  sample/BitlySharpSample/BitlySharpSample.sln
... ...
@@ -0,0 +1,26 @@
  1
+
  2
+Microsoft Visual Studio Solution File, Format Version 11.00
  3
+# Visual Studio 2010
  4
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitlySharpSample", "BitlySharpSample\BitlySharpSample.csproj", "{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}"
  5
+EndProject
  6
+Global
  7
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
  8
+		Debug|iPhoneSimulator = Debug|iPhoneSimulator
  9
+		Release|iPhoneSimulator = Release|iPhoneSimulator
  10
+		Debug|iPhone = Debug|iPhone
  11
+		Release|iPhone = Release|iPhone
  12
+	EndGlobalSection
  13
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
  14
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhone.ActiveCfg = Debug|iPhone
  15
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhone.Build.0 = Debug|iPhone
  16
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
  17
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
  18
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhone.ActiveCfg = Release|iPhone
  19
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhone.Build.0 = Release|iPhone
  20
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
  21
+		{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
  22
+	EndGlobalSection
  23
+	GlobalSection(MonoDevelopProperties) = preSolution
  24
+		StartupItem = BitlySharpSample\BitlySharpSample.csproj
  25
+	EndGlobalSection
  26
+EndGlobal
41  sample/BitlySharpSample/BitlySharpSample/AppDelegate.cs
... ...
@@ -0,0 +1,41 @@
  1
+// 
  2
+//  Copyright 2012  abhatia
  3
+// 
  4
+//    Licensed under the Apache License, Version 2.0 (the "License");
  5
+//    you may not use this file except in compliance with the License.
  6
+//    You may obtain a copy of the License at
  7
+// 
  8
+//        http://www.apache.org/licenses/LICENSE-2.0
  9
+// 
  10
+//    Unless required by applicable law or agreed to in writing, software
  11
+//    distributed under the License is distributed on an "AS IS" BASIS,
  12
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+//    See the License for the specific language governing permissions and
  14
+//    limitations under the License.
  15
+using System;
  16
+using System.Collections.Generic;
  17
+using System.Linq;
  18
+
  19
+using MonoTouch.Foundation;
  20
+using MonoTouch.UIKit;
  21
+
  22
+namespace BitlySharpSample
  23
+{
  24
+	[Register ("AppDelegate")]
  25
+	public partial class AppDelegate : UIApplicationDelegate
  26
+	{
  27
+		UIWindow _Window;
  28
+		RootViewController _RootController;
  29
+
  30
+		public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  31
+		{
  32
+			_Window = new UIWindow(UIScreen.MainScreen.Bounds);
  33
+			_RootController = new RootViewController();
  34
+			
  35
+			_Window.RootViewController = _RootController;
  36
+			_Window.MakeKeyAndVisible();
  37
+			return true;
  38
+		}
  39
+	}
  40
+}
  41
+
83  sample/BitlySharpSample/BitlySharpSample/BitlySharpSample.csproj
... ...
@@ -0,0 +1,83 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3
+  <PropertyGroup>
  4
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5
+    <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
  6
+    <ProductVersion>10.0.0</ProductVersion>
  7
+    <SchemaVersion>2.0</SchemaVersion>
  8
+    <ProjectGuid>{32A1EDFE-2B3E-47B5-8877-9AF5FBADD70D}</ProjectGuid>
  9
+    <ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  10
+    <OutputType>Exe</OutputType>
  11
+    <RootNamespace>BitlySharpSample</RootNamespace>
  12
+    <AssemblyName>BitlySharpSample</AssemblyName>
  13
+  </PropertyGroup>
  14
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
  15
+    <DebugSymbols>true</DebugSymbols>
  16
+    <DebugType>full</DebugType>
  17
+    <Optimize>false</Optimize>
  18
+    <OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
  19
+    <DefineConstants>DEBUG;</DefineConstants>
  20
+    <ErrorReport>prompt</ErrorReport>
  21
+    <WarningLevel>4</WarningLevel>
  22
+    <ConsolePause>false</ConsolePause>
  23
+    <MtouchDebug>true</MtouchDebug>
  24
+    <MtouchProfiling>true</MtouchProfiling>
  25
+    <MtouchLink>None</MtouchLink>
  26
+  </PropertyGroup>
  27
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
  28
+    <DebugType>none</DebugType>
  29
+    <Optimize>false</Optimize>
  30
+    <OutputPath>bin\iPhoneSimulator\Release</OutputPath>
  31
+    <ErrorReport>prompt</ErrorReport>
  32
+    <WarningLevel>4</WarningLevel>
  33
+    <ConsolePause>false</ConsolePause>
  34
+    <MtouchLink>None</MtouchLink>
  35
+  </PropertyGroup>
  36
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
  37
+    <DebugSymbols>true</DebugSymbols>
  38
+    <DebugType>full</DebugType>
  39
+    <Optimize>false</Optimize>
  40
+    <OutputPath>bin\iPhone\Debug</OutputPath>
  41
+    <DefineConstants>DEBUG;</DefineConstants>
  42
+    <ErrorReport>prompt</ErrorReport>
  43
+    <WarningLevel>4</WarningLevel>
  44
+    <ConsolePause>false</ConsolePause>
  45
+    <CodesignKey>iPhone Developer</CodesignKey>
  46
+    <MtouchDebug>true</MtouchDebug>
  47
+    <MtouchProfiling>true</MtouchProfiling>
  48
+  </PropertyGroup>
  49
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
  50
+    <DebugType>none</DebugType>
  51
+    <Optimize>false</Optimize>
  52
+    <OutputPath>bin\iPhone\Release</OutputPath>
  53
+    <ErrorReport>prompt</ErrorReport>
  54
+    <WarningLevel>4</WarningLevel>
  55
+    <ConsolePause>false</ConsolePause>
  56
+    <CodesignKey>iPhone Developer</CodesignKey>
  57
+  </PropertyGroup>
  58
+  <ItemGroup>
  59
+    <Reference Include="System" />
  60
+    <Reference Include="System.Xml" />
  61
+    <Reference Include="System.Core" />
  62
+    <Reference Include="monotouch" />
  63
+    <Reference Include="MonoTouch.Dialog-1" />
  64
+    <Reference Include="System.Web.Services" />
  65
+  </ItemGroup>
  66
+  <ItemGroup>
  67
+    <None Include="Info.plist" />
  68
+  </ItemGroup>
  69
+  <ItemGroup>
  70
+    <Compile Include="Main.cs" />
  71
+    <Compile Include="AppDelegate.cs" />
  72
+    <Compile Include="ViewControllers\RootViewController.cs" />
  73
+    <Compile Include="..\..\..\src\bitly.cs">
  74
+      <Link>Bitly\bitly.cs</Link>
  75
+    </Compile>
  76
+    <Compile Include="ViewControllers\BitlyViewController.cs" />
  77
+  </ItemGroup>
  78
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  79
+  <ItemGroup>
  80
+    <Folder Include="ViewControllers\" />
  81
+    <Folder Include="Bitly\" />
  82
+  </ItemGroup>
  83
+</Project>
24  sample/BitlySharpSample/BitlySharpSample/Info.plist
... ...
@@ -0,0 +1,24 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3
+<plist version="1.0">
  4
+<dict>
  5
+	<key>UIDeviceFamily</key>
  6
+	<array>
  7
+		<integer>1</integer>
  8
+		<integer>2</integer>
  9
+	</array>
  10
+	<key>UISupportedInterfaceOrientations</key>
  11
+	<array>
  12
+		<string>UIInterfaceOrientationPortrait</string>
  13
+		<string>UIInterfaceOrientationLandscapeLeft</string>
  14
+		<string>UIInterfaceOrientationLandscapeRight</string>
  15
+	</array>
  16
+	<key>UISupportedInterfaceOrientations~ipad</key>
  17
+	<array>
  18
+		<string>UIInterfaceOrientationPortrait</string>
  19
+		<string>UIInterfaceOrientationPortraitUpsideDown</string>
  20
+		<string>UIInterfaceOrientationLandscapeLeft</string>
  21
+		<string>UIInterfaceOrientationLandscapeRight</string>
  22
+	</array>
  23
+</dict>
  24
+</plist>
34  sample/BitlySharpSample/BitlySharpSample/Main.cs
... ...
@@ -0,0 +1,34 @@
  1
+// 
  2
+//  Copyright 2012  abhatia
  3
+// 
  4
+//    Licensed under the Apache License, Version 2.0 (the "License");
  5
+//    you may not use this file except in compliance with the License.
  6
+//    You may obtain a copy of the License at
  7
+// 
  8
+//        http://www.apache.org/licenses/LICENSE-2.0
  9
+// 
  10
+//    Unless required by applicable law or agreed to in writing, software
  11
+//    distributed under the License is distributed on an "AS IS" BASIS,
  12
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+//    See the License for the specific language governing permissions and
  14
+//    limitations under the License.
  15
+using System;
  16
+using System.Collections.Generic;
  17
+using System.Linq;
  18
+
  19
+using MonoTouch.Foundation;
  20
+using MonoTouch.UIKit;
  21
+
  22
+namespace BitlySharpSample
  23
+{
  24
+	public class Application
  25
+	{
  26
+		// This is the main entry point of the application.
  27
+		static void Main(string[] args)
  28
+		{
  29
+			// if you want to use a different Application Delegate class from "AppDelegate"
  30
+			// you can specify it here.
  31
+			UIApplication.Main(args, null, "AppDelegate");
  32
+		}
  33
+	}
  34
+}
138  sample/BitlySharpSample/BitlySharpSample/ViewControllers/BitlyViewController.cs
... ...
@@ -0,0 +1,138 @@
  1
+// 
  2
+//  Copyright 2012  abhatia
  3
+// 
  4
+//    Licensed under the Apache License, Version 2.0 (the "License");
  5
+//    you may not use this file except in compliance with the License.
  6
+//    You may obtain a copy of the License at
  7
+// 
  8
+//        http://www.apache.org/licenses/LICENSE-2.0
  9
+// 
  10
+//    Unless required by applicable law or agreed to in writing, software
  11
+//    distributed under the License is distributed on an "AS IS" BASIS,
  12
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+//    See the License for the specific language governing permissions and
  14
+//    limitations under the License.
  15
+using System;
  16
+using MonoTouch.Dialog;
  17
+using Bitly;
  18
+using MonoTouch.Foundation;
  19
+using MonoTouch.UIKit;
  20
+
  21
+namespace BitlySharpSample
  22
+{
  23
+	public class BitlyViewController : DialogViewController
  24
+	{
  25
+		// Credentials go here.
  26
+		const string USER_NAME = "";
  27
+		const string APIKEY = "";
  28
+		
  29
+		private static Api _BitlyApi;
  30
+		
  31
+		Action<string> ShortenUrlAction;
  32
+		Action<string> ExpandUrlAction;
  33
+		
  34
+		EntryElement ShortenUrlElement;
  35
+		EntryElement ExpandUrlElement;
  36
+		
  37
+		StringElement ResultElement;
  38
+		
  39
+		public BitlyViewController()
  40
+			: base(new RootElement("Shorten URL"), true)
  41
+		{
  42
+		}
  43
+		
  44
+		protected override void Dispose(bool disposing)
  45
+		{
  46
+			base.Dispose(disposing);
  47
+		}
  48
+		
  49
+		public override void LoadView()
  50
+		{
  51
+			base.LoadView();
  52
+		}
  53
+		
  54
+		public override void ViewDidLoad()
  55
+		{
  56
+			base.ViewDidLoad();
  57
+			
  58
+			_BitlyApi = new Api(USER_NAME, APIKEY);
  59
+			ShortenUrlAction = ShortenUrlActionHandler;
  60
+			ExpandUrlAction = ExpandUrlActionHandler;
  61
+			
  62
+			ShortenUrlElement = new EntryElement("Url to Shorten:", "", "");
  63
+			ExpandUrlElement = new EntryElement("Btly Url to Expand: ", "", "");
  64
+			
  65
+			var urlSection = new Section("URLs") {
  66
+				ShortenUrlElement,
  67
+				ExpandUrlElement,
  68
+			};
  69
+			
  70
+			var operationSection = new Section("") {
  71
+				new StringElement("Shorten URL", () => { 
  72
+					ShortenUrlAction.BeginInvoke(ShortenUrlElement.Value, (ar) => {}, null);
  73
+				}),
  74
+				new StringElement("Expand URL", () => {
  75
+					ExpandUrlAction.BeginInvoke(ExpandUrlElement.Value, (ar) => {}, null);
  76
+				}),
  77
+			};
  78
+			
  79
+			ResultElement = new StringElement("");
  80
+			
  81
+			var resultSection = new Section("Result") {
  82
+				ResultElement,
  83
+			};
  84
+			
  85
+			this.Root.Add(new Section[] { urlSection, operationSection, resultSection });
  86
+		}
  87
+		
  88
+		public void ShortenUrlActionHandler(string url)
  89
+		{
  90
+			if(string.IsNullOrWhiteSpace(url)) {
  91
+				NotifyInvalidUrl();
  92
+				return;
  93
+			}
  94
+			var result = _BitlyApi.Shorten(url);
  95
+			UpdateResultElement(result);
  96
+		}
  97
+		
  98
+		public void ExpandUrlActionHandler(string url)
  99
+		{
  100
+			if(string.IsNullOrWhiteSpace(url)) {
  101
+				NotifyInvalidUrl();
  102
+				return;
  103
+			}
  104
+			
  105
+			var result = _BitlyApi.Expand(url);
  106
+			UpdateResultElement(result);
  107
+		}
  108
+		
  109
+		private void UpdateResultElement(string result)
  110
+		{
  111
+			ResultElement.Value = result;
  112
+			
  113
+			using(var pool = new NSAutoreleasePool()) {
  114
+				pool.BeginInvokeOnMainThread(()=>{
  115
+					this.ReloadData();
  116
+				});
  117
+			}
  118
+		}
  119
+		
  120
+		public void NotifyInvalidUrl()
  121
+		{
  122
+			var alert = new UIAlertView("Invaid URL", "Invalid URL Specified. Try again...", null, "OK", null);
  123
+			alert.Show();
  124
+		}
  125
+		
  126
+		public override void ViewWillLayoutSubviews()
  127
+		{
  128
+			base.ViewWillLayoutSubviews();
  129
+		}
  130
+		
  131
+		public override void ViewDidAppear(bool animated)
  132
+		{
  133
+			base.ViewDidAppear(animated);
  134
+		}
  135
+		
  136
+	}
  137
+}
  138
+
56  sample/BitlySharpSample/BitlySharpSample/ViewControllers/RootViewController.cs
... ...
@@ -0,0 +1,56 @@
  1
+// 
  2
+//  Copyright 2012  abhatia
  3
+// 
  4
+//    Licensed under the Apache License, Version 2.0 (the "License");
  5
+//    you may not use this file except in compliance with the License.
  6
+//    You may obtain a copy of the License at
  7
+// 
  8
+//        http://www.apache.org/licenses/LICENSE-2.0
  9
+// 
  10
+//    Unless required by applicable law or agreed to in writing, software
  11
+//    distributed under the License is distributed on an "AS IS" BASIS,
  12
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+//    See the License for the specific language governing permissions and
  14
+//    limitations under the License.
  15
+using System;
  16
+using MonoTouch.UIKit;
  17
+
  18
+namespace BitlySharpSample
  19
+{
  20
+	public class RootViewController : UINavigationController
  21
+	{
  22
+		public RootViewController()
  23
+			: base()
  24
+		{
  25
+		}
  26
+		
  27
+		protected override void Dispose(bool disposing)
  28
+		{
  29
+			base.Dispose(disposing);
  30
+		}
  31
+		
  32
+		public override void LoadView()
  33
+		{
  34
+			base.LoadView();
  35
+		}
  36
+		
  37
+		public override void ViewDidLoad()
  38
+		{
  39
+			base.ViewDidLoad();
  40
+			
  41
+			var controller = new BitlyViewController();
  42
+			this.PushViewController(controller, true);
  43
+		}
  44
+		
  45
+		public override void ViewWillLayoutSubviews()
  46
+		{
  47
+			base.ViewWillLayoutSubviews();
  48
+		}
  49
+		
  50
+		public override void ViewDidAppear(bool animated)
  51
+		{
  52
+			base.ViewDidAppear(animated);
  53
+		}
  54
+	}
  55
+}
  56
+
9  src/bitly.cs
@@ -18,6 +18,7 @@
18 18
 using System.Net;
19 19
 using System.IO;
20 20
 using System.Xml;
  21
+using System.Web;
21 22
 
22 23
 namespace Bitly
23 24
 {
@@ -36,14 +37,14 @@ public Api (string username, string apikey)
36 37
 			throw new ArgumentNullException("login", "A valid Bit.ly login is requied");
37 38
 			
38 39
 			this.username = username;
39  
-			this.apiKey = apiKey;
  40
+			this.apiKey = apikey;
40 41
 		}
41 42
 		
42 43
 		public string Shorten (string url)
43 44
 		{
44 45
 			if (string.IsNullOrEmpty(url) || string.IsNullOrWhiteSpace(url))
45 46
 				throw new ArgumentNullException("url", "A valid url must be provided");
46  
-			return getValue(url,"shorten");
  47
+			return getUrl(url,"shorten");
47 48
 		}
48 49
 
49 50
 		public string Expand (string url)
@@ -51,10 +52,10 @@ public string Expand (string url)
51 52
 			if (string.IsNullOrEmpty(url) || string.IsNullOrWhiteSpace(url))
52 53
 				throw new ArgumentNullException("url", "A valid url must be provided");
53 54
 			
54  
-			return getValue(url,"expand");
  55
+			return getUrl(url,"expand");
55 56
 		}
56 57
 		
57  
-		private static string getUrl(string url,string type)
  58
+		private string getUrl(string url,string type)
58 59
 		{
59 60
 			string output = string.Empty;
60 61
 			HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(string.Format(baseUrl,type,username,apiKey, HttpUtility.UrlEncode(url),"txt"));
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.