giphyrb 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3269d612a4d65ab52aee537e67361d5c6442ccc8
4
- data.tar.gz: 4a2e1a9c3bec82d830a1840675de27842d9fe47b
3
+ metadata.gz: 28476508077c9a3104e73b7950cff9bb157651a9
4
+ data.tar.gz: b461c649458865a3bc69f7c3aa0485ddc474854a
5
5
  SHA512:
6
- metadata.gz: 7d29b2607aa8d52d8365e6c4a23a7bee4a8b8cf93a298bf630bf7581d2da4c72ef79f1e291e7a39c204340dbe6aecce13726e4e87c23bf90a4c58f29bcc97f1d
7
- data.tar.gz: ad6fc01e3b4d2af3f21839a9df5b6ae860c10d8138dc63cc45dfeaae2e063f92cb9464997276b806bc4b0330315e8f2d2be20eac24afbf7025b0bc97b5238f28
6
+ metadata.gz: '09ccf6f52f57cefd611a4158d97101866b5bc1aa8349e1026607f68dea180d41fbbf022c4621ed98be2928b74e2bf5bc000df6cc3382857ac08e8a67be5c9630'
7
+ data.tar.gz: 21400e4c36e5b4e3772e1272846147e7e76fa07673ebaed5097815496eaf3fc451b4219e48a857621ec49d0edfdde91f5a26cd7f8e393087774eba29edb94115
data/lib/giphyrb.rb CHANGED
@@ -5,14 +5,15 @@ require_relative 'responses/search'
5
5
  require_relative 'responses/trending'
6
6
  require_relative 'responses/translate'
7
7
  require_relative 'responses/random'
8
+ require_relative 'responses/sticker_pack'
8
9
 
9
10
  module GiphyRB
10
11
  class Giphy
11
12
 
12
13
  ENDPOINT = 'http://api.giphy.com'
13
14
  API_VERSION = 'v1'
14
- VERSION = '0.2'
15
- DESCRIPTION ='A simple Giphy API Wrapper supporting Stickers API (except Stickers pack)'
15
+ VERSION = '0.2.1'
16
+ DESCRIPTION ='A simple Giphy API Wrapper supporting Stickers API and Stickers packs (untested)'
16
17
 
17
18
  # Initialize the client
18
19
  def initialize(api_key:true)
@@ -22,7 +23,7 @@ module GiphyRB
22
23
  # Search all GIPHY GIFs for a word or phrase. Punctuation will be stripped and ignored. Use a plus or url encode for phrases.
23
24
  # @param query [String] Search query term or phrase
24
25
  # @param limit [Int] The maximum number of records to return (default=5)
25
- # @param offset [Int] An optional results offset. (default=0)
26
+ # @param offset [Int] An optional results offset (default=0)
26
27
  # @param rating [String] Filters results by specified rating (default=g)
27
28
  # @param lang [String] Specify default language for regional content; use a 2-letter ISO 639-1 language code (default=nil)
28
29
  # @return [Responses::Search]
@@ -35,7 +36,7 @@ module GiphyRB
35
36
 
36
37
  # Fetch GIFs currently trending online. Hand curated by the GIPHY editorial team. The data returned mirrors the GIFs showcased on the GIPHY homepage.
37
38
  # @param limit [Int] The maximum number of records to return (default=5)
38
- # @param offset [Int] An optional results offset. (default=0)
39
+ # @param offset [Int] An optional results offset (default=0)
39
40
  # @param rating [String] Filters results by specified rating (default=g)
40
41
  # @return [Responses::Trending]
41
42
  def trending(limit=5, offset=0, rating='g')
@@ -86,7 +87,7 @@ module GiphyRB
86
87
  # Replicates the functionality and requirements of the classic GIPHY search, but returns animated stickers rather than GIFs.
87
88
  # @param query [String] Search query term or phrase
88
89
  # @param limit [Int] The maximum number of records to return (default=5)
89
- # @param offset [Int] An optional results offset. (default=0)
90
+ # @param offset [Int] An optional results offset (default=0)
90
91
  # @param rating [String] Filters results by specified rating (default=g)
91
92
  # @param lang [String] Specify default language for regional content; use a 2-letter ISO 639-1 language code (default=nil)
92
93
  # @return [Responses::Search]
@@ -99,7 +100,7 @@ module GiphyRB
99
100
 
100
101
  # Fetch Stickers currently trending online. Hand curated by the GIPHY editorial team.
101
102
  # @param limit [Int] The maximum number of records to return (default=5)
102
- # @param offset [Int] An optional results offset. (default=0)
103
+ # @param offset [Int] An optional results offset (default=0)
103
104
  # @param rating [String] Filters results by specified rating (default=g)
104
105
  # @return [Responses::Trending]
105
106
  def sticker_trending(limit=5, offset=0, rating='g')
@@ -127,6 +128,45 @@ module GiphyRB
127
128
  Responses::Random.new(result, tag)
128
129
  end
129
130
 
131
+ # Returns the metadata for any Sticker pack.
132
+ # @return [Responses::ChildPack]
133
+ def list_sticker_pack()
134
+ params = {}
135
+ result = request'stickers/packs/', params
136
+ Responses::ChildPack.new(result)
137
+ end
138
+
139
+ # Returns the metadata for any Sticker pack.
140
+ # @param id [String] Filters results by specified Sticker Pack ID
141
+ # @param limit [Int] The maximum number of records to return (default=5)
142
+ # @param offset [Int] An optional results offset (default=0)
143
+ # @return [Responses::StickerPack]
144
+ def individual_sticker_pack_from_id(id, limit=5, offset=0)
145
+ params = {:limit => limit.to_i, :offset => offset.to_i}
146
+ result = request'stickers/packs/' + id.to_s, params
147
+ Responses::StickerPack.new(result)
148
+ end
149
+
150
+ # Returns the stickers within an individual sticker pack.
151
+ # @param id [String] Filters results by specified Sticker Pack ID
152
+ # @param limit [Int] The maximum number of records to return (default=5)
153
+ # @param offset [Int] An optional results offset (default=0)
154
+ # @return [Response]
155
+ def sticker_pack_from_id(id, limit=5, offset=0)
156
+ params = {:limit => limit.to_i, :offset => offset.to_i}
157
+ result = request'stickers/packs/' + id.to_s + '/stickers', params
158
+ Response.new(result)
159
+ end
160
+
161
+ # A Sticker pack is a recursive data structure and so packs may contain other packs. For example, the 'Reactions' pack would have an 'OMG' child pack. This endpoint lists all children packs of a given Sticker pack.
162
+ # @param id [String] Filters results by specified Sticker Pack ID
163
+ # @return [Response]
164
+ def children_pack_from_id(id)
165
+ params = {}
166
+ result = request'stickers/packs/' + id.to_s + '/children', params
167
+ Responses::ChildPack.new(result)
168
+ end
169
+
130
170
  private
131
171
 
132
172
  def request(url, params)
@@ -0,0 +1,24 @@
1
+ module GiphyRB
2
+
3
+ module Parts
4
+
5
+ class Ancestor
6
+
7
+ attr_reader :id, :slug, :display_name, :short_display_name, :featured_gif_id, :parent, :has_children, :banner_image
8
+
9
+ def initialize(arr)
10
+ @arr = arr
11
+ @id = arr['id'] unless arr['id'] == nil
12
+ @slug = arr['slug'] unless arr['slug'] == nil
13
+ @display_name = arr['display_name'] unless arr['display_name'] == nil
14
+ @short_display_name = arr['short_display_name'] unless arr['short_display_name'] == nil
15
+ @featured_gif_id = arr['featured_gif_id'] unless arr['featured_gif_id'] == nil
16
+ @parent = arr['parent'] unless arr['parent'] == nil
17
+ @has_children = arr['has_children'] unless arr['has_children'] == nil
18
+ @banner_image = arr['banner_image'] unless arr['banner_image'] == nil
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'gif'
2
+ require_relative 'user'
3
+
4
+ module GiphyRB
5
+
6
+ module Parts
7
+
8
+ class ChildPack
9
+
10
+ attr_reader :type, :id, :parent, :type, :content_type, :slug, :display_name, :short_display_name, :description, :banner_image, :has_children, :user, :featured_gif
11
+
12
+ def initialize(arr)
13
+ @arr = arr
14
+ @id = arr['id'] unless arr['id'] == nil
15
+ @parent = arr['parent'] unless arr['parent'] == nil
16
+ @type = arr['type'] unless arr['type'] == nil
17
+ @content_type = arr['content_type'] unless arr['content_type'] == nil
18
+ @slug = arr['slug'] unless arr['slug'] == nil
19
+ @display_name = arr['display_name'] unless arr['display_name'] == nil
20
+ @short_display_name = arr['short_display_name'] unless arr['short_display_name'] == nil
21
+ @description = arr['description'] unless arr['description'] == nil
22
+ @banner_image = arr['banner_image'] unless arr['banner_image'] == nil
23
+ @has_children = arr['has_children'] unless arr['has_children'] == nil
24
+ @user = User.new(arr['user']) unless arr['user'] == nil
25
+ @featured_gif = Gif.new(arr['featured_gif']) unless arr['featured_gif'] == nil
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
data/lib/parts/gif.rb CHANGED
@@ -32,6 +32,8 @@ module GiphyRB
32
32
  @images = parse_images(arr['images']) unless arr['images'] == nil
33
33
  end
34
34
 
35
+ private
36
+
35
37
  def parse_images(arr)
36
38
  images = {}
37
39
  arr.each do |name, data|
@@ -0,0 +1,50 @@
1
+ require_relative 'gif'
2
+ require_relative 'user'
3
+ require_relative 'tag'
4
+ require_relative 'ancestor'
5
+
6
+ module GiphyRB
7
+
8
+ module Parts
9
+
10
+ class StickerPack
11
+
12
+ attr_reader :type, :id, :type, :content_type, :slug, :display_name, :short_display_name, :description, :banner_image, :has_children, :user, :featured_gif
13
+
14
+ def initialize(arr)
15
+ @arr = arr
16
+ @id = arr['id'] unless arr['id'] == nil
17
+ @display_name = arr['display_name'] unless arr['display_name'] == nil
18
+ @slug = arr['slug'] unless arr['slug'] == nil
19
+ @content_type = arr['content_type'] unless arr['content_type'] == nil
20
+ @short_display_name = arr['short_display_name'] unless arr['short_display_name'] == nil
21
+ @description = arr['description'] unless arr['description'] == nil
22
+ @banner_image = arr['banner_image'] unless arr['banner_image'] == nil
23
+ @has_children = arr['has_children'] unless arr['has_children'] == nil
24
+ @user = User.new(arr['user']) unless arr['user'] == nil
25
+ @featured_gif = Gif.new(arr['featured_gif']) unless arr['featured_gif'] == nil
26
+ @tags = parse_tags(arr['tags']) unless arr['tags'] == nil
27
+ end
28
+
29
+ private
30
+
31
+ def parse_tags(arr)
32
+ tags = []
33
+ arr.each do |tag|
34
+ tags[] = Tag.new(tag)
35
+ end
36
+ tags
37
+ end
38
+
39
+ def parse_ancestors(arr)
40
+ ancestors = []
41
+ arr.each do |tag|
42
+ ancestors[] = Ancestor.new(tag)
43
+ end
44
+ ancestors
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
data/lib/parts/tag.rb ADDED
@@ -0,0 +1,18 @@
1
+ module GiphyRB
2
+
3
+ module Parts
4
+
5
+ class Tag
6
+
7
+ attr_reader :tag, :rank
8
+
9
+ def initialize(arr)
10
+ @arr = arr
11
+ @tag = arr['tag'] unless arr['tag'] == nil
12
+ @rank = arr['rank'] unless arr['rank'] == nil
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../parts/child_pack'
2
+ require_relative '../parts/meta'
3
+ require_relative '../parts/pagination'
4
+
5
+ module GiphyRB
6
+
7
+ module Responses
8
+
9
+ class ChildPack
10
+
11
+ attr_reader :status, :gifs, :meta, :pagination
12
+
13
+ def initialize(arr)
14
+ @arr = arr
15
+ @status = 500
16
+ unless arr == nil
17
+ @meta = Parts::Meta.new(arr['meta']) unless arr['meta'] == nil
18
+ @pagination = Parts::Pagination.new(arr['pagination']) unless arr['pagination'] == nil
19
+ @status = @meta.status unless @meta == nil
20
+ generate arr['data'] unless arr['data'] == nil
21
+ end
22
+ end
23
+
24
+ def generate(stickers)
25
+ stickers = [].push(stickers) unless stickers == nil
26
+ @sticker_pack = []
27
+ stickers.each do |sticker|
28
+ @sticker_pack.push Parts::ChildPack.new(sticker)
29
+ end
30
+ @sticker_pack
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../parts/sticker_pack'
2
+ require_relative '../parts/meta'
3
+ require_relative '../parts/pagination'
4
+
5
+ module GiphyRB
6
+
7
+ module Responses
8
+
9
+ class StickerPack
10
+
11
+ attr_reader :status, :gifs, :meta, :pagination
12
+
13
+ def initialize(arr)
14
+ @arr = arr
15
+ @status = 500
16
+ unless arr == nil
17
+ @meta = Parts::Meta.new(arr['meta']) unless arr['meta'] == nil
18
+ @pagination = Parts::Pagination.new(arr['pagination']) unless arr['pagination'] == nil
19
+ @status = @meta.status unless @meta == nil
20
+ generate arr['data'] unless arr['data'] == nil
21
+ end
22
+ end
23
+
24
+ def generate(stickers)
25
+ stickers = [].push(stickers) unless stickers == nil
26
+ @sticker_pack = []
27
+ stickers.each do |sticker|
28
+ @sticker_pack.push Parts::StickerPack.new(sticker)
29
+ end
30
+ @sticker_pack
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giphyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Whaxion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple Giphy API Wrapper supporting Stickers API (except Stickers pack)
13
+ description: A simple Giphy API Wrapper supporting Stickers API and Stickers packs
14
+ (untested)
14
15
  email:
15
16
  - whaxion@gmail.com
16
17
  executables: []
@@ -22,14 +23,20 @@ files:
22
23
  - README.MD
23
24
  - giphyrb.gemspec
24
25
  - lib/giphyrb.rb
26
+ - lib/parts/ancestor.rb
27
+ - lib/parts/child_pack.rb
25
28
  - lib/parts/gif.rb
26
29
  - lib/parts/image.rb
27
30
  - lib/parts/meta.rb
28
31
  - lib/parts/pagination.rb
32
+ - lib/parts/sticker_pack.rb
33
+ - lib/parts/tag.rb
29
34
  - lib/parts/user.rb
30
35
  - lib/response.rb
36
+ - lib/responses/child_pack.rb
31
37
  - lib/responses/random.rb
32
38
  - lib/responses/search.rb
39
+ - lib/responses/sticker_pack.rb
33
40
  - lib/responses/translate.rb
34
41
  - lib/responses/trending.rb
35
42
  homepage: http://github.com/whaxion/giphyrb