Skip to content

Commit

Permalink
1.3.0 (#85)
Browse files Browse the repository at this point in the history
* myget pre-release packages

* standart 2.0 + package updates

* Remove fallback version

* Send direct message implementation (#74)

* Send direct message

* GetMediaCommentsAsync failed when caption is null

* send message improvements

* #75 get friendship status

* travis ci, dotnet 2.0

* Removed framework version from travis

* netstandard2.0

* Improved user info part of API

* Access modifiers and general code refactoring

* readme update

* Adjusted explore feed (no pagination)

* Clean up

* Code inspection corrections

* Added a better logging mechanism to reach more details. (#78)

* Added a better loging mechanism with more details.

* Linked to previous changes.

* Update appveyor.yml

* Adjusted logger

* More corrections to logger

* GetTagFeedAsync»InstaMedia»InstaUserShort should be InstaUser (#80)

From log: api is proving whole fields of InstaUser

* Explore feed add pagination

* Add user story feed

* Get story feed corrected

* Save session data implemented

* Change state saving to return stream

* Added GetUserMediaAsync by user pk method. (#82)

* GetTagFeedAsync»InstaMedia»InstaUserShort should be InstaUser
From log: api is proving whole fields of InstaUser

* Make InstaApi instantiable.

* get user media by pk.

* Update InstaApiBuilder.cs

* Revert "Added GetUserMediaAsync by user pk method. (#82)"

This reverts commit d138c93.

* Added recent and ranked recipients

* Added massaging demo sample
  • Loading branch information
a-legotin authored Nov 5, 2017
1 parent 350c43c commit 94fba9d
Show file tree
Hide file tree
Showing 237 changed files with 2,748 additions and 1,068 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: csharp
dist: trusty
dotnet: 1.0.1
language: csharp
mono: none
dotnet: 2.0.0
solution: InstaSharper.sln

script:
- cd InstaSharper
- dotnet --info
- dotnet restore
- dotnet build --framework netstandard1.6
- dotnet build --framework netstandard2.0
2 changes: 1 addition & 1 deletion InstaSharper.Examples/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
</configuration>
10 changes: 7 additions & 3 deletions InstaSharper.Examples/InstaSharper.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="InstaSharper, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\InstaSharper.1.2.6\lib\net452\InstaSharper.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\InstaSharper\bin\release\net452\InstaSharper.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -50,11 +51,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Utils\DebugFileLogger.cs" />
<Compile Include="Samples\Basics.cs" />
<Compile Include="Samples\CommentMedia.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Samples\IDemoSample.cs" />
<Compile Include="Samples\Messaging.cs" />
<Compile Include="Samples\SaveLoadState.cs" />
<Compile Include="Samples\Stories.cs" />
<Compile Include="Samples\UploadPhoto.cs" />
<Compile Include="Utils\ConsoleUtils.cs" />
<Compile Include="Utils\StringExtensions.cs" />
Expand Down
50 changes: 28 additions & 22 deletions InstaSharper.Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using InstaSharper.API;
using InstaSharper.API.Builder;
using InstaSharper.Classes;
using InstaSharper.Classes.Android.DeviceInfo;
using InstaSharper.Examples.Samples;
using InstaSharper.Logger;

namespace InstaSharper.Examples
{
Expand All @@ -17,6 +20,9 @@ public class Program
private static void Main(string[] args)
{
var result = Task.Run(MainAsync).GetAwaiter().GetResult();
if (result)
return;
Console.ReadKey();
}

public static async Task<bool> MainAsync()
Expand All @@ -32,12 +38,14 @@ public static async Task<bool> MainAsync()
};

// create new InstaApi instance using Builder
_instaApi = new InstaApiBuilder()
var device = AndroidDeviceGenerator.GetByName(AndroidDevices.SAMSUNG_NOTE3);
var requestMessage = ApiRequestMessage.FromDevice(device);
_instaApi = InstaApiBuilder.CreateBuilder()
.SetUser(userSession)
.UseLogger(new DebugFileLogger()) // use logger for requests and debug messages
.SetRequestDelay(TimeSpan.FromSeconds(1)) // set delay between requests
.SetApiRequestMessage(requestMessage)
.UseLogger(new DebugLogger(LogLevel.Info)) // use logger for requests and debug messages
.SetRequestDelay(TimeSpan.FromSeconds(2))
.Build();

// login
Console.WriteLine($"Logging in as {userSession.UserName}");
var logInResult = await _instaApi.LoginAsync();
Expand All @@ -50,27 +58,25 @@ public static async Task<bool> MainAsync()
Console.WriteLine("Press 1 to start basic demo samples");
Console.WriteLine("Press 2 to start upload photo demo sample");
Console.WriteLine("Press 3 to start comment media demo sample");
Console.WriteLine("Press 4 to start stories demo sample");
Console.WriteLine("Press 5 to start demo with saving state of API instance");
Console.WriteLine("Press 6 to start messaging demo sample");

var samplesMap = new Dictionary<ConsoleKey, IDemoSample>
{
[ConsoleKey.D1] = new Basics(_instaApi),
[ConsoleKey.D2] = new UploadPhoto(_instaApi),
[ConsoleKey.D3] = new CommentMedia(_instaApi),
[ConsoleKey.D4] = new Stories(_instaApi),
[ConsoleKey.D5] = new SaveLoadState(_instaApi),
[ConsoleKey.D6] = new Messaging(_instaApi)
};
var key = Console.ReadKey();
Console.WriteLine(Environment.NewLine);
switch (key.Key)
{
case ConsoleKey.D1:
var basics = new Basics(_instaApi);
await basics.DoShow();
break;
case ConsoleKey.D2:
var upload = new UploadPhoto(_instaApi);
await upload.DoShow();
break;
case ConsoleKey.D3:
var comment = new CommentMedia(_instaApi);
await comment.DoShow();
break;
default:
break;
}
if (samplesMap.ContainsKey(key.Key))
await samplesMap[key.Key].DoShow();
Console.WriteLine("Done. Press esc key to exit...");

key = Console.ReadKey();
return key.Key == ConsoleKey.Escape;
}
Expand All @@ -87,4 +93,4 @@ public static async Task<bool> MainAsync()
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion InstaSharper.Examples/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
8 changes: 4 additions & 4 deletions InstaSharper.Examples/Samples/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace InstaSharper.Examples.Samples
{
internal class Basics
internal class Basics : IDemoSample
{
/// <summary>
/// Config values
Expand Down Expand Up @@ -49,7 +49,7 @@ public async Task DoShow()
if (userFeed.Succeeded)
{
Console.WriteLine(
$"Feed items (in {userFeed.Value.Pages} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}");
$"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}");
foreach (var media in userFeed.Value.Medias)
ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength);
//like first 10 medias from user timeline feed
Expand All @@ -66,10 +66,10 @@ public async Task DoShow()
if (tagFeed.Succeeded)
{
Console.WriteLine(
$"Tag feed items (in {tagFeed.Value.Pages} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}");
$"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}");
foreach (var media in tagFeed.Value.Medias)
ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength);
}
}
}
}
}
4 changes: 2 additions & 2 deletions InstaSharper.Examples/Samples/CommentMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace InstaSharper.Examples.Samples
{
internal class CommentMedia
internal class CommentMedia : IDemoSample
{
private readonly IInstaApi _instaApi;

Expand All @@ -21,4 +21,4 @@ public async Task DoShow()
: $"Unable to create comment: {commentResult.Info.Message}");
}
}
}
}
9 changes: 9 additions & 0 deletions InstaSharper.Examples/Samples/IDemoSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace InstaSharper.Examples.Samples
{
internal interface IDemoSample
{
Task DoShow();
}
}
44 changes: 44 additions & 0 deletions InstaSharper.Examples/Samples/Messaging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using InstaSharper.API;

namespace InstaSharper.Examples.Samples
{
internal class Messaging : IDemoSample
{
private readonly IInstaApi _instaApi;

public Messaging(IInstaApi instaApi)
{
_instaApi = instaApi;
}

public async Task DoShow()
{
var recipientsResult = await _instaApi.GetRankedRecipientsAsync();
if (!recipientsResult.Succeeded)
{
Console.WriteLine("Unable to get ranked recipients");
return;
}
Console.WriteLine($"Got {recipientsResult.Value.Items.Count} ranked threads");
foreach (var thread in recipientsResult.Value.Items)
Console.WriteLine($"Threadname: {thread.ThreadTitle}, users: {thread.Users.Count}");

var inboxThreads = await _instaApi.GetDirectInboxAsync();
if (!inboxThreads.Succeeded)
{
Console.WriteLine("Unable to get inbox");
return;
}
Console.WriteLine($"Got {inboxThreads.Value.Inbox.Threads.Count} inbox threads");
foreach (var thread in inboxThreads.Value.Inbox.Threads)
Console.WriteLine($"Threadname: {thread.Title}, users: {thread.Users.Count}");
var firstThread = inboxThreads.Value.Inbox.Threads.FirstOrDefault();
var sendMessageResult = await _instaApi.SendDirectMessage($"{firstThread.Users.FirstOrDefault()?.Pk}",
firstThread.ThreadId, "test");
Console.WriteLine(sendMessageResult.Succeeded ? "Message sent" : "Unable to send message");
}
}
}
41 changes: 41 additions & 0 deletions InstaSharper.Examples/Samples/SaveLoadState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Threading.Tasks;
using InstaSharper.API;
using InstaSharper.API.Builder;

namespace InstaSharper.Examples.Samples
{
internal class SaveLoadState : IDemoSample
{
private readonly IInstaApi _instaApi;

public SaveLoadState(IInstaApi instaApi)
{
_instaApi = instaApi;
}

public async Task DoShow()
{
var result = await _instaApi.GetCurrentUserAsync();
if (!result.Succeeded)
{
Console.WriteLine($"Unable to get current user using current API instance: {result.Info}");
return;
}
Console.WriteLine($"Got current user: {result.Value.UserName} using existing API instance");
var stream = _instaApi.GetStateDataAsStream();
var anotherInstance = InstaApiBuilder.CreateBuilder()
.SetRequestDelay(TimeSpan.FromSeconds(2))
.Build();
anotherInstance.LoadStateDataFromStream(stream);
var anotherResult = await anotherInstance.GetCurrentUserAsync();
if (!anotherResult.Succeeded)
{
Console.WriteLine($"Unable to get current user using current API instance: {result.Info}");
return;
}
Console.WriteLine(
$"Got current user: {anotherResult.Value.UserName} using new API instance without re-login");
}
}
}
35 changes: 35 additions & 0 deletions InstaSharper.Examples/Samples/Stories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Threading.Tasks;
using InstaSharper.API;

namespace InstaSharper.Examples.Samples
{
internal class Stories : IDemoSample
{
private readonly IInstaApi _instaApi;

public Stories(IInstaApi instaApi)
{
_instaApi = instaApi;
}

public async Task DoShow()
{
var result = await _instaApi.GetStoryFeedAsync();
if (!result.Succeeded)
{
Console.WriteLine($"Unable to get story feed: {result.Info}");
return;
}
var storyFeed = result.Value;
Console.WriteLine($"Got {storyFeed.Items.Count} story reels.");
foreach (var feedItem in storyFeed.Items)
{
Console.WriteLine($"User: {feedItem.User.FullName}");
foreach (var item in feedItem.Items)
Console.WriteLine(
$"Story item: {item.Caption?.Text ?? item.Code}, images:{item.ImageList?.Count ?? 0}, videos: {item.VideoList?.Count ?? 0}");
}
}
}
}
6 changes: 3 additions & 3 deletions InstaSharper.Examples/Samples/UploadPhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace InstaSharper.Examples.Samples
{
internal class UploadPhoto
internal class UploadPhoto : IDemoSample
{
private readonly IInstaApi _instaApi;

Expand All @@ -17,7 +17,7 @@ public UploadPhoto(IInstaApi instaApi)

public async Task DoShow()
{
var mediaImage = new MediaImage
var mediaImage = new InstaImage
{
Height = 1080,
Width = 1080,
Expand All @@ -29,4 +29,4 @@ public async Task DoShow()
: $"Unable to upload photo: {result.Info.Message}");
}
}
}
}
2 changes: 1 addition & 1 deletion InstaSharper.Examples/Utils/ConsoleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public static void PrintMedia(string header, InstaMedia media, int maxDescriptio
$"{header} [{media.User.UserName}]: {media.Caption?.Text.Truncate(maxDescriptionLength)}, {media.Code}, likes: {media.LikesCount}, multipost: {media.IsMultiPost}");
}
}
}
}
27 changes: 0 additions & 27 deletions InstaSharper.Examples/Utils/DebugFileLogger.cs

This file was deleted.

Loading

0 comments on commit 94fba9d

Please sign in to comment.