Skip to content

Commit

Permalink
Merge pull request #3 from coryleach/dev
Browse files Browse the repository at this point in the history
merge dev into master
  • Loading branch information
coryleach authored Jun 13, 2020
2 parents d2bdb46 + 4f7c340 commit e70510e
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude_paths:
- '*.md'
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<h1 align="center">Gameframe.Giphy 👋</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.1-blue.svg?cacheSeconds=2592000" />
<a href="https://twitter.com/Cory Leach">
<img alt="Twitter: coryleach" src="https://img.shields.io/twitter/follow/coryleach.svg?style=social" target="_blank" />
</a>
</p>

<!-- BADGE-START -->
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/d2749fdbc70f422a9d1efccb56d48bff)](https://www.codacy.com/manual/coryleach/UnityGiphy?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=coryleach/UnityGiphy&amp;utm_campaign=Badge_Grade)
![version](https://img.shields.io/github/package-json/v/coryleach/UnityGiphy)
[![openupm](https://img.shields.io/npm/v/com.gameframe.giphy?label=openupm&amp;registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.gameframe.giphy/)
[![license](https://img.shields.io/github/license/coryleach/UnityGiphy)](https://github.com/coryleach/UnityGiphy/blob/master/LICENSE)

[![twitter](https://img.shields.io/twitter/follow/coryleach.svg?style=social)](https://twitter.com/coryleach)
<!-- BADGE-END -->

This package contains a simple implementation of the Giphy API required to display random Gif images in Unity as MP4 videos.
This package does not provide a means to display a gif directly but does provide urls to gif version of the images.
Expand All @@ -15,15 +18,15 @@ Instead this package uses the mp4 links provided by giphy's api to display the g
#### Using UnityPackageManager (for Unity 2019.3 or later)
Open the package manager window (menu: Window > Package Manager)<br/>
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
https://github.com/coryleach/UnityGiphy.git#1.0.1<br/>
https://github.com/coryleach/UnityGiphy.git#2.0.0<br/>

#### Using UnityPackageManager (for Unity 2019.1 or later)

Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```js
{
"dependencies": {
"com.gameframe.giphy": "https://github.com/coryleach/UnityGiphy.git#1.0.1",
"com.gameframe.giphy": "https://github.com/coryleach/UnityGiphy.git#2.0.0",
...
},
}
Expand Down
20 changes: 13 additions & 7 deletions Runtime/GiphyConfig.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;

namespace Gameframe.Giphy
{
[CreateAssetMenu(menuName = "Gameframe/Giphy/Config")]
public class GiphyConfig : ScriptableObject
public class GiphyConfig : ScriptableObject, IGiphyConfig
{
public string apiKey = "";
public GiphyRating rating = GiphyRating.PG13;
public string lang = "en";
[SerializeField]
private string apiKey = "";
public string ApiKey => apiKey;

[SerializeField]
private GiphyRating rating = GiphyRating.PG13;
public GiphyRating Rating => rating;

[SerializeField]
private string lang = "en";
public string Lang => lang;
}
}

Expand Down
8 changes: 4 additions & 4 deletions Runtime/GiphyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public static class GiphyQuery
private const string searchApiUrl = "api.giphy.com/v1/gifs/search";
private const string randomApiUrl = "api.giphy.com/v1/gifs/random";

public static Task<GiphyQueryRandomResult> Random(GiphyConfig config, string tag)
public static Task<GiphyQueryRandomResult> Random(IGiphyConfig config, string tag)
{
var requestUrl = $"https://{randomApiUrl}?api_key={config.apiKey}&tag={UnityWebRequest.EscapeURL(tag)}&rating={config.rating.ToQueryString()}";
var requestUrl = $"https://{randomApiUrl}?api_key={config.ApiKey}&tag={UnityWebRequest.EscapeURL(tag)}&rating={config.Rating.ToQueryString()}";
return Query<GiphyQueryRandomResult>(requestUrl);
}

Expand All @@ -22,9 +22,9 @@ public static Task<GiphyQueryRandomResult> Random(string apiKey, string tag, Gip
return Query<GiphyQueryRandomResult>(requestUrl);
}

public static Task<GiphyQuerySearchResult> Search(GiphyConfig config, string query, int limit = 25, int offset = 0)
public static Task<GiphyQuerySearchResult> Search(IGiphyConfig config, string query, int limit = 25, int offset = 0)
{
var requestUrl = $"https://{searchApiUrl}?api_key={config.apiKey}&q={UnityWebRequest.EscapeURL(query)}&limit={limit}&offset={offset}&rating={config.rating.ToQueryString()}&lang={config.lang}";
var requestUrl = $"https://{searchApiUrl}?api_key={config.ApiKey}&q={UnityWebRequest.EscapeURL(query)}&limit={limit}&offset={offset}&rating={config.Rating.ToQueryString()}&lang={config.Lang}";
return Query<GiphyQuerySearchResult>(requestUrl);
}

Expand Down
64 changes: 44 additions & 20 deletions Runtime/GiphyQueryCommonResultData.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
using System;
using UnityEngine;

namespace Gameframe.Giphy
{
[Serializable]
public class GiphyQueryCommonResultData
{
public string type;
public string id;
public string url;
public string slug;
public string bitly_gif_url;
public string bitly_url;
public string embed_url;
public string username;
public string source;
public string title;
public string rating;
public string content_url;
public string source_tld;
public int is_sticker;
[SerializeField] private string type;
[SerializeField] private string id;
[SerializeField] private string url;
[SerializeField] private string slug;
[SerializeField] private string bitly_gif_url;
[SerializeField] private string bitly_url;
[SerializeField] private string embed_url;
[SerializeField] private string username;
[SerializeField] private string source;
[SerializeField] private string title;
[SerializeField] private string rating;
[SerializeField] private string content_url;
[SerializeField] private string source_tld;
[SerializeField] private int is_sticker;

public int IsSticker => is_sticker;
public string SourceTld => source_tld;
public string ContentUrl => content_url;
public string Rating => rating;
public string Title => title;
public string Source => source;
public string Username => username;
public string EmbedUrl => embed_url;
public string BitlyUrl => bitly_url;
public string BitlyGifUrl => bitly_gif_url;
public string Slug => slug;
public string Url => url;
public string Id => id;
public string Type1 => type;
}

[Serializable]
public class GiphyQueryMetaData
{
public int status;
public string msg;
public string response_id;
[SerializeField] private int status;
[SerializeField] private string msg;
[SerializeField] private string response_id;

public int Status => status;
public string Msg => msg;
public string ResponseId => response_id;
}

[Serializable]
public class GiphyQueryPaginationData
{
public int total_count;
public int count;
public int offset;
[SerializeField] private int total_count;
[SerializeField] private int count;
[SerializeField] private int offset;

public int TotalCount => total_count;
public int Count => count;
public int Offset => offset;
}
}
88 changes: 58 additions & 30 deletions Runtime/GiphyQueryRandomResultData.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
using System;
using UnityEngine;

namespace Gameframe.Giphy
{
[Serializable]
public class GiphyQueryRandomResult
{
public GiphyQueryRandomResultData data;
public GiphyQueryMetaData meta;
[SerializeField] private GiphyQueryRandomResultData data;
[SerializeField] private GiphyQueryMetaData meta;

public GiphyQueryRandomResultData Data => data;
public GiphyQueryMetaData Meta => meta;
}

[Serializable]
public class GiphyQueryRandomResultData : GiphyQueryCommonResultData
{
public GiphyGifResultImagesData images;

public string image_original_url;
public string image_url;
public string image_mp4_url;
public int image_frames;
public int image_width;
public int image_height;

public string fixed_height_downsampled_url;
public int fixed_height_downsampled_width;
public int fixed_height_downsampled_height;

public string fixed_width_downsampled_url;
public int fixed_width_downsampled_width;
public int fixed_width_downsampled_height;

public string fixed_height_small_url;
public string fixed_height_small_still_url;
public int fixed_height_small_width;
public int fixed_height_small_height;

public string fixed_width_small_url;
public string fixed_width_small_still_url;
public int fixed_width_small_width;
public int fixed_width_small_height;

public string caption;
[SerializeField] private GiphyGifResultImagesData images;

[SerializeField] private string image_original_url;
[SerializeField] private string image_url;
[SerializeField] private string image_mp4_url;
[SerializeField] private int image_frames;
[SerializeField] private int image_width;
[SerializeField] private int image_height;

[SerializeField] private string fixed_height_downsampled_url;
[SerializeField] private int fixed_height_downsampled_width;
[SerializeField] private int fixed_height_downsampled_height;

[SerializeField] private string fixed_width_downsampled_url;
[SerializeField] private int fixed_width_downsampled_width;
[SerializeField] private int fixed_width_downsampled_height;

[SerializeField] private string fixed_height_small_url;
[SerializeField] private string fixed_height_small_still_url;
[SerializeField] private int fixed_height_small_width;
[SerializeField] private int fixed_height_small_height;

[SerializeField] private string fixed_width_small_url;
[SerializeField] private string fixed_width_small_still_url;
[SerializeField] private int fixed_width_small_width;
[SerializeField] private int fixed_width_small_height;

[SerializeField] private string caption;

public GiphyGifResultImagesData Images => images;
public string ImageOriginalUrl => image_original_url;
public string ImageUrl => image_url;
public string ImageMp4Url => image_mp4_url;
public int ImageFrames => image_frames;
public int ImageWidth => image_width;
public int ImageHeight => image_height;

public string FixedHeightDownsampledUrl => fixed_height_downsampled_url;
public int FixedHeightDownsampledWidth => fixed_height_downsampled_width;
public int FixedHeightDownsampledHeight => fixed_height_downsampled_height;
public string FixedWidthDownsampledUrl => fixed_width_downsampled_url;
public int FixedWidthDownsampledWidth => fixed_width_downsampled_width;
public int FixedWidthDownsampledHeight => fixed_width_downsampled_height;
public string FixedHeightSmallUrl => fixed_height_small_url;
public string FixedHeightSmallStillUrl => fixed_height_small_still_url;
public int FixedHeightSmallWidth => fixed_height_small_width;
public int FixedHeightSmallHeight => fixed_height_small_height;
public string FixedWidthSmallUrl => fixed_width_small_url;
public string FixedWidthSmallStillUrl => fixed_width_small_still_url;
public int FixedWidthSmallWidth => fixed_width_small_width;
public int FixedWidthSmallHeight => fixed_width_small_height;
public string Caption => caption;
}
}
Loading

0 comments on commit e70510e

Please sign in to comment.