Skip to content

Commit e70510e

Browse files
authored
Merge pull request #3 from coryleach/dev
merge dev into master
2 parents d2bdb46 + 4f7c340 commit e70510e

14 files changed

Lines changed: 269 additions & 128 deletions

.codacy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exclude_paths:
2+
- '*.md'

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<h1 align="center">Gameframe.Giphy 👋</h1>
2-
<p>
3-
<img alt="Version" src="https://img.shields.io/badge/version-1.0.1-blue.svg?cacheSeconds=2592000" />
4-
<a href="https://twitter.com/Cory Leach">
5-
<img alt="Twitter: coryleach" src="https://img.shields.io/twitter/follow/coryleach.svg?style=social" target="_blank" />
6-
</a>
7-
</p>
2+
3+
<!-- BADGE-START -->
4+
[![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)
5+
![version](https://img.shields.io/github/package-json/v/coryleach/UnityGiphy)
6+
[![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/)
7+
[![license](https://img.shields.io/github/license/coryleach/UnityGiphy)](https://github.com/coryleach/UnityGiphy/blob/master/LICENSE)
8+
9+
[![twitter](https://img.shields.io/twitter/follow/coryleach.svg?style=social)](https://twitter.com/coryleach)
10+
<!-- BADGE-END -->
811

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

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

2225
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
2326
```js
2427
{
2528
"dependencies": {
26-
"com.gameframe.giphy": "https://github.com/coryleach/UnityGiphy.git#1.0.1",
29+
"com.gameframe.giphy": "https://github.com/coryleach/UnityGiphy.git#2.0.0",
2730
...
2831
},
2932
}

Runtime/GiphyConfig.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
using UnityEngine;
42

53
namespace Gameframe.Giphy
64
{
75
[CreateAssetMenu(menuName = "Gameframe/Giphy/Config")]
8-
public class GiphyConfig : ScriptableObject
6+
public class GiphyConfig : ScriptableObject, IGiphyConfig
97
{
10-
public string apiKey = "";
11-
public GiphyRating rating = GiphyRating.PG13;
12-
public string lang = "en";
8+
[SerializeField]
9+
private string apiKey = "";
10+
public string ApiKey => apiKey;
11+
12+
[SerializeField]
13+
private GiphyRating rating = GiphyRating.PG13;
14+
public GiphyRating Rating => rating;
15+
16+
[SerializeField]
17+
private string lang = "en";
18+
public string Lang => lang;
1319
}
1420
}
1521

Runtime/GiphyQuery.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public static class GiphyQuery
1010
private const string searchApiUrl = "api.giphy.com/v1/gifs/search";
1111
private const string randomApiUrl = "api.giphy.com/v1/gifs/random";
1212

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

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

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

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,63 @@
11
using System;
2+
using UnityEngine;
23

34
namespace Gameframe.Giphy
45
{
56
[Serializable]
67
public class GiphyQueryCommonResultData
78
{
8-
public string type;
9-
public string id;
10-
public string url;
11-
public string slug;
12-
public string bitly_gif_url;
13-
public string bitly_url;
14-
public string embed_url;
15-
public string username;
16-
public string source;
17-
public string title;
18-
public string rating;
19-
public string content_url;
20-
public string source_tld;
21-
public int is_sticker;
9+
[SerializeField] private string type;
10+
[SerializeField] private string id;
11+
[SerializeField] private string url;
12+
[SerializeField] private string slug;
13+
[SerializeField] private string bitly_gif_url;
14+
[SerializeField] private string bitly_url;
15+
[SerializeField] private string embed_url;
16+
[SerializeField] private string username;
17+
[SerializeField] private string source;
18+
[SerializeField] private string title;
19+
[SerializeField] private string rating;
20+
[SerializeField] private string content_url;
21+
[SerializeField] private string source_tld;
22+
[SerializeField] private int is_sticker;
23+
24+
public int IsSticker => is_sticker;
25+
public string SourceTld => source_tld;
26+
public string ContentUrl => content_url;
27+
public string Rating => rating;
28+
public string Title => title;
29+
public string Source => source;
30+
public string Username => username;
31+
public string EmbedUrl => embed_url;
32+
public string BitlyUrl => bitly_url;
33+
public string BitlyGifUrl => bitly_gif_url;
34+
public string Slug => slug;
35+
public string Url => url;
36+
public string Id => id;
37+
public string Type1 => type;
2238
}
2339

2440
[Serializable]
2541
public class GiphyQueryMetaData
2642
{
27-
public int status;
28-
public string msg;
29-
public string response_id;
43+
[SerializeField] private int status;
44+
[SerializeField] private string msg;
45+
[SerializeField] private string response_id;
46+
47+
public int Status => status;
48+
public string Msg => msg;
49+
public string ResponseId => response_id;
3050
}
3151

3252
[Serializable]
3353
public class GiphyQueryPaginationData
3454
{
35-
public int total_count;
36-
public int count;
37-
public int offset;
55+
[SerializeField] private int total_count;
56+
[SerializeField] private int count;
57+
[SerializeField] private int offset;
58+
59+
public int TotalCount => total_count;
60+
public int Count => count;
61+
public int Offset => offset;
3862
}
3963
}
Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,72 @@
11
using System;
2+
using UnityEngine;
23

34
namespace Gameframe.Giphy
45
{
56
[Serializable]
67
public class GiphyQueryRandomResult
78
{
8-
public GiphyQueryRandomResultData data;
9-
public GiphyQueryMetaData meta;
9+
[SerializeField] private GiphyQueryRandomResultData data;
10+
[SerializeField] private GiphyQueryMetaData meta;
11+
12+
public GiphyQueryRandomResultData Data => data;
13+
public GiphyQueryMetaData Meta => meta;
1014
}
1115

1216
[Serializable]
1317
public class GiphyQueryRandomResultData : GiphyQueryCommonResultData
1418
{
15-
public GiphyGifResultImagesData images;
16-
17-
public string image_original_url;
18-
public string image_url;
19-
public string image_mp4_url;
20-
public int image_frames;
21-
public int image_width;
22-
public int image_height;
23-
24-
public string fixed_height_downsampled_url;
25-
public int fixed_height_downsampled_width;
26-
public int fixed_height_downsampled_height;
27-
28-
public string fixed_width_downsampled_url;
29-
public int fixed_width_downsampled_width;
30-
public int fixed_width_downsampled_height;
31-
32-
public string fixed_height_small_url;
33-
public string fixed_height_small_still_url;
34-
public int fixed_height_small_width;
35-
public int fixed_height_small_height;
36-
37-
public string fixed_width_small_url;
38-
public string fixed_width_small_still_url;
39-
public int fixed_width_small_width;
40-
public int fixed_width_small_height;
41-
42-
public string caption;
19+
[SerializeField] private GiphyGifResultImagesData images;
20+
21+
[SerializeField] private string image_original_url;
22+
[SerializeField] private string image_url;
23+
[SerializeField] private string image_mp4_url;
24+
[SerializeField] private int image_frames;
25+
[SerializeField] private int image_width;
26+
[SerializeField] private int image_height;
27+
28+
[SerializeField] private string fixed_height_downsampled_url;
29+
[SerializeField] private int fixed_height_downsampled_width;
30+
[SerializeField] private int fixed_height_downsampled_height;
31+
32+
[SerializeField] private string fixed_width_downsampled_url;
33+
[SerializeField] private int fixed_width_downsampled_width;
34+
[SerializeField] private int fixed_width_downsampled_height;
35+
36+
[SerializeField] private string fixed_height_small_url;
37+
[SerializeField] private string fixed_height_small_still_url;
38+
[SerializeField] private int fixed_height_small_width;
39+
[SerializeField] private int fixed_height_small_height;
40+
41+
[SerializeField] private string fixed_width_small_url;
42+
[SerializeField] private string fixed_width_small_still_url;
43+
[SerializeField] private int fixed_width_small_width;
44+
[SerializeField] private int fixed_width_small_height;
45+
46+
[SerializeField] private string caption;
47+
48+
public GiphyGifResultImagesData Images => images;
49+
public string ImageOriginalUrl => image_original_url;
50+
public string ImageUrl => image_url;
51+
public string ImageMp4Url => image_mp4_url;
52+
public int ImageFrames => image_frames;
53+
public int ImageWidth => image_width;
54+
public int ImageHeight => image_height;
55+
56+
public string FixedHeightDownsampledUrl => fixed_height_downsampled_url;
57+
public int FixedHeightDownsampledWidth => fixed_height_downsampled_width;
58+
public int FixedHeightDownsampledHeight => fixed_height_downsampled_height;
59+
public string FixedWidthDownsampledUrl => fixed_width_downsampled_url;
60+
public int FixedWidthDownsampledWidth => fixed_width_downsampled_width;
61+
public int FixedWidthDownsampledHeight => fixed_width_downsampled_height;
62+
public string FixedHeightSmallUrl => fixed_height_small_url;
63+
public string FixedHeightSmallStillUrl => fixed_height_small_still_url;
64+
public int FixedHeightSmallWidth => fixed_height_small_width;
65+
public int FixedHeightSmallHeight => fixed_height_small_height;
66+
public string FixedWidthSmallUrl => fixed_width_small_url;
67+
public string FixedWidthSmallStillUrl => fixed_width_small_still_url;
68+
public int FixedWidthSmallWidth => fixed_width_small_width;
69+
public int FixedWidthSmallHeight => fixed_width_small_height;
70+
public string Caption => caption;
4371
}
4472
}

0 commit comments

Comments
 (0)