giphyrb 0.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 +7 -0
- data/LICENSE +21 -0
- data/README.MD +62 -0
- data/giphyrb.gemspec +14 -0
- data/lib/giphyrb.rb +73 -0
- data/lib/parts/gif.rb +46 -0
- data/lib/parts/image.rb +26 -0
- data/lib/parts/meta.rb +19 -0
- data/lib/parts/pagination.rb +19 -0
- data/lib/parts/user.rb +22 -0
- data/lib/response.rb +32 -0
- data/lib/responses/random.rb +19 -0
- data/lib/responses/search.rb +19 -0
- data/lib/responses/translate.rb +8 -0
- data/lib/responses/trending.rb +8 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31774a6f302e4b50bb9fd3554fedf0902bfd659e
|
4
|
+
data.tar.gz: 62f184a4939cddd5ece2076f8f6e6d86444a4d74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58afb5f6339f4bf295739935331f368829b7272af4af42a6a59f9d718776835adc920a6bd3a1e125a67d21ce077bb2e0c5f3cc5af8bb331877b589ff22d7d293
|
7
|
+
data.tar.gz: 9d82a50f883a566932a8bd074cf987744a358bf1bc5cbc54e348ee75e7ff3be29f4d45523163d98134d58e47447dd1da2454764886ec158c33fa21cd407fdc4e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Whaxion
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.MD
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# GiphyRB
|
2
|
+
## Installation
|
3
|
+
|
4
|
+
Add this line to your application's Gemfile:
|
5
|
+
|
6
|
+
gem 'giphyrb'
|
7
|
+
|
8
|
+
And then execute:
|
9
|
+
|
10
|
+
$ bundle
|
11
|
+
|
12
|
+
Or install it yourself as:
|
13
|
+
|
14
|
+
$ gem install giphyrb
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Create a Giphy object with
|
19
|
+
```ruby
|
20
|
+
giphy = GiphyRB::Giphy.new api_key: 'YOUR_API_KEY'
|
21
|
+
```
|
22
|
+
Now, you can use it to get some gifs
|
23
|
+
|
24
|
+
#### Trending
|
25
|
+
````ruby
|
26
|
+
giphy.trending(limit=5, offset=0, rating='g')
|
27
|
+
=> GiphyRB::Responses::Trending
|
28
|
+
````
|
29
|
+
|
30
|
+
#### Translate
|
31
|
+
````ruby
|
32
|
+
Giphy.translate(string)
|
33
|
+
=> GiphyRB::Responses::Translate
|
34
|
+
````
|
35
|
+
|
36
|
+
#### Search
|
37
|
+
````ruby
|
38
|
+
Giphy.search(query, limit=5, offset=0, rating='g', lang=nil)
|
39
|
+
=> GiphyRB::Responses::Search
|
40
|
+
````
|
41
|
+
|
42
|
+
#### Random
|
43
|
+
````ruby
|
44
|
+
Giphy.random(tag=nil, rating='g')
|
45
|
+
=> GiphyRB::Responses::Random
|
46
|
+
````
|
47
|
+
|
48
|
+
#### GIF by ID
|
49
|
+
````ruby
|
50
|
+
Giphy.from_id(id)
|
51
|
+
=> GiphyRB::Response
|
52
|
+
````
|
53
|
+
|
54
|
+
#### GIFs by IDs
|
55
|
+
````ruby
|
56
|
+
Giphy.from_ids(ids=[])
|
57
|
+
=> GiphyRB::Response
|
58
|
+
````
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
See [LICENSE](https://github.com/Whaxion/giphyrb/blob/master/LICENSE) for details.
|
data/giphyrb.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.summary = 'Giphy API wrapper'
|
3
|
+
s.description = 'A simple Giphy API Wrapper'
|
4
|
+
s.authors = ['Whaxion']
|
5
|
+
s.email = ['whaxion@gmail.com']
|
6
|
+
s.homepage = 'http://github.com/whaxion/giphyrb'
|
7
|
+
|
8
|
+
s.files = `git ls-files`.split("\n")
|
9
|
+
s.require_paths = ['lib']
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.name = 'giphyrb'
|
13
|
+
s.version = '0.1'
|
14
|
+
end
|
data/lib/giphyrb.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'responses/search'
|
5
|
+
require_relative 'responses/trending'
|
6
|
+
require_relative 'responses/translate'
|
7
|
+
require_relative 'responses/random'
|
8
|
+
|
9
|
+
module GiphyRB
|
10
|
+
class Giphy
|
11
|
+
|
12
|
+
ENDPOINT = 'http://api.giphy.com'
|
13
|
+
API_VERSION = 'v1'
|
14
|
+
|
15
|
+
def initialize(api_key:true)
|
16
|
+
@api_key = api_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def search(query, limit=5, offset=0, rating='g', lang=nil)
|
20
|
+
params = {:q => query, :limit => limit.to_i, :offset => offset.to_i, :rating => rating}
|
21
|
+
params[:lang] = lang unless lang == nil
|
22
|
+
result = request'gifs/search', params
|
23
|
+
Responses::Search.new(result, query)
|
24
|
+
end
|
25
|
+
|
26
|
+
def trending(limit=5, offset=0, rating='g')
|
27
|
+
params = {:limit => limit.to_i, :offset => offset.to_i, :rating => rating}
|
28
|
+
result = request'gifs/trending', params
|
29
|
+
Responses::Trending.new(result)
|
30
|
+
end
|
31
|
+
|
32
|
+
def translate(string)
|
33
|
+
params = {:s => string}
|
34
|
+
result = request'gifs/translate', params
|
35
|
+
Responses::Trending.new(result)
|
36
|
+
end
|
37
|
+
|
38
|
+
def random(tag=nil, rating='g')
|
39
|
+
params = {:tag => tag, :rating => rating}
|
40
|
+
result = request'gifs/random', params
|
41
|
+
Responses::Random.new(result, tag)
|
42
|
+
end
|
43
|
+
|
44
|
+
def from_id(id)
|
45
|
+
params = {}
|
46
|
+
result = request'gifs/' + id.to_s, params
|
47
|
+
Response.new(result)
|
48
|
+
end
|
49
|
+
|
50
|
+
def from_ids(ids=[])
|
51
|
+
ids = Array(ids)
|
52
|
+
ids = ids.join ','
|
53
|
+
params = {:ids => ids}
|
54
|
+
result = request'gifs/', params
|
55
|
+
Response.new(result)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def request(url, params)
|
61
|
+
params[:api_key] = @api_key
|
62
|
+
params[:fmt] = 'json'
|
63
|
+
uri = URI "#{ENDPOINT}/#{API_VERSION}/#{url}"
|
64
|
+
uri.query = URI.encode_www_form(params)
|
65
|
+
resp = Net::HTTP.get_response(uri)
|
66
|
+
result = nil
|
67
|
+
if resp.is_a?(Net::HTTPSuccess) || resp.is_a?(Net::HTTPNotFound) || resp.is_a?(Net::HTTPBadRequest) || resp.is_a?(Net::HTTPForbidden) || resp.is_a?(Net::HTTPTooManyRequests)
|
68
|
+
result = JSON.parse(resp.body)
|
69
|
+
end
|
70
|
+
result
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/parts/gif.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative 'image'
|
2
|
+
require_relative 'user'
|
3
|
+
|
4
|
+
module GiphyRB
|
5
|
+
|
6
|
+
module Parts
|
7
|
+
|
8
|
+
class Gif
|
9
|
+
|
10
|
+
attr_reader :type, :id, :slug, :url, :bitly_url, :embed_url, :username, :source, :rating, :content_url, :user, :source_tld, :source_post_url, :update_datetime, :import_datetime, :create_datetime, :trending_datetime, :title, :images
|
11
|
+
|
12
|
+
def initialize(arr)
|
13
|
+
@arr = arr
|
14
|
+
@type = arr['type'] unless arr['type'] == nil
|
15
|
+
@id = arr['id'] unless arr['id'] == nil
|
16
|
+
@slug = arr['slug'] unless arr['slug'] == nil
|
17
|
+
@url = arr['url'] unless arr['url'] == nil
|
18
|
+
@bitly_url = arr['bitly_url'] unless arr['bitly_url'] == nil
|
19
|
+
@embed_url = arr['embed_url'] unless arr['embed_url'] == nil
|
20
|
+
@username = arr['username'] unless arr['username'] == nil
|
21
|
+
@source = arr['source'] unless arr['source'] == nil
|
22
|
+
@rating = arr['rating'] unless arr['rating'] == nil
|
23
|
+
@content_url = arr['content_url'] unless arr['content_url'] == nil
|
24
|
+
@user = User.new(arr['user']) unless arr['user'] == nil
|
25
|
+
@source_tld = arr['source_tld'] unless arr['source_tld'] == nil
|
26
|
+
@source_post_url = arr['source_post_url'] unless arr['source_post_url'] == nil
|
27
|
+
@update_datetime = arr['update_datetime'] unless arr['update_datetime'] == nil
|
28
|
+
@import_datetime = arr['import_datetime'] unless arr['import_datetime'] == nil
|
29
|
+
@create_datetime = arr['create_datetime'] unless arr['create_datetime'] == nil
|
30
|
+
@trending_datetime = arr['trending_datetime'] unless arr['trending_datetime'] == nil
|
31
|
+
@title = arr['title'] unless arr['title'] == nil
|
32
|
+
@images = parse_images(arr['images']) unless arr['images'] == nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_images(arr)
|
36
|
+
images = {}
|
37
|
+
arr.each do |name, data|
|
38
|
+
images[name.to_s] = Image.new(name, data)
|
39
|
+
end
|
40
|
+
images
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/parts/image.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module GiphyRB
|
2
|
+
|
3
|
+
module Parts
|
4
|
+
|
5
|
+
class Image
|
6
|
+
|
7
|
+
attr_reader :name, :url, :width, :height, :size,:mp4, :mp4_size, :webp, :webp_size
|
8
|
+
|
9
|
+
def initialize(name, arr)
|
10
|
+
@name = name
|
11
|
+
@arr = arr
|
12
|
+
@url = arr['url']
|
13
|
+
@width = arr['width']
|
14
|
+
@height = arr['height']
|
15
|
+
@size = arr['size'] unless arr['size'] == nil
|
16
|
+
@mp4 = arr['mp4'] unless arr['mp4'] == nil
|
17
|
+
@mp4_size = arr['mp4_size'] unless arr['mp4_size'] == nil
|
18
|
+
@webp = arr['webp'] unless arr['webp'] == nil
|
19
|
+
@webp_size = arr['webp_size'] unless arr['webp_size'] == nil
|
20
|
+
@frames = arr['frames'] unless arr['frames'] == nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/parts/meta.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module GiphyRB
|
2
|
+
|
3
|
+
module Parts
|
4
|
+
|
5
|
+
class Meta
|
6
|
+
|
7
|
+
attr_reader :msg, :status, :response_id
|
8
|
+
|
9
|
+
def initialize(arr)
|
10
|
+
@arr = arr
|
11
|
+
@msg = arr['msg'] unless arr['msg'] == nil
|
12
|
+
@status = arr['status'] unless arr['status'] == nil
|
13
|
+
@response_id = arr['response_id'] unless arr['response_id'] == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GiphyRB
|
2
|
+
|
3
|
+
module Parts
|
4
|
+
|
5
|
+
class Pagination
|
6
|
+
|
7
|
+
attr_reader :offset, :total_count, :count
|
8
|
+
|
9
|
+
def initialize(arr)
|
10
|
+
@arr = arr
|
11
|
+
@offset = arr['offset'] unless arr['offset'] == nil
|
12
|
+
@total_count = arr['total_count'] unless arr['total_count'] == nil
|
13
|
+
@count = arr['count'] unless arr['count'] == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/parts/user.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module GiphyRB
|
2
|
+
|
3
|
+
module Parts
|
4
|
+
|
5
|
+
class User
|
6
|
+
|
7
|
+
attr_reader :avatar_url, :banner_url, :profile_url, :username, :display_name, :twitter
|
8
|
+
|
9
|
+
def initialize(arr)
|
10
|
+
@arr = arr
|
11
|
+
@avatar_url = arr['avatar_url'] unless arr['avatar_url'] == nil
|
12
|
+
@banner_url = arr['banner_url'] unless arr['banner_url'] == nil
|
13
|
+
@profile_url = arr['profile_url'] unless arr['profile_url'] == nil
|
14
|
+
@username = arr['username'] unless arr['username'] == nil
|
15
|
+
@display_name = arr['display_name'] unless arr['display_name'] == nil
|
16
|
+
@twitter = arr['twitter'] unless arr['twitter'] == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/response.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'parts/gif'
|
2
|
+
require_relative 'parts/meta'
|
3
|
+
require_relative 'parts/pagination'
|
4
|
+
|
5
|
+
module GiphyRB
|
6
|
+
|
7
|
+
class Response
|
8
|
+
|
9
|
+
attr_reader :status, :gifs, :meta, :pagination
|
10
|
+
|
11
|
+
def initialize(arr)
|
12
|
+
@arr = arr
|
13
|
+
@status = 500
|
14
|
+
unless arr == nil
|
15
|
+
@meta = Parts::Meta.new(arr['meta']) unless arr['meta'] == nil
|
16
|
+
@pagination = Parts::Pagination.new(arr['pagination']) unless arr['pagination'] == nil
|
17
|
+
@status = @meta.status unless @meta == nil
|
18
|
+
generate_gifs arr['data'] unless arr['data'] == nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_gifs(gifs)
|
23
|
+
gifs = [].push(gifs) unless gifs['type'] == nil
|
24
|
+
@gifs = []
|
25
|
+
gifs.each do |gif|
|
26
|
+
@gifs.push Parts::Gif.new(gif)
|
27
|
+
end
|
28
|
+
@gifs
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: giphyrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Whaxion
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple Giphy API Wrapper
|
14
|
+
email:
|
15
|
+
- whaxion@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.MD
|
22
|
+
- giphyrb.gemspec
|
23
|
+
- lib/giphyrb.rb
|
24
|
+
- lib/parts/gif.rb
|
25
|
+
- lib/parts/image.rb
|
26
|
+
- lib/parts/meta.rb
|
27
|
+
- lib/parts/pagination.rb
|
28
|
+
- lib/parts/user.rb
|
29
|
+
- lib/response.rb
|
30
|
+
- lib/responses/random.rb
|
31
|
+
- lib/responses/search.rb
|
32
|
+
- lib/responses/translate.rb
|
33
|
+
- lib/responses/trending.rb
|
34
|
+
homepage: http://github.com/whaxion/giphyrb
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.5.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Giphy API wrapper
|
58
|
+
test_files: []
|