gfycat 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64271a93cb5c774cfd0d470cade8446549cd9571
4
+ data.tar.gz: 08074bfeace31807be18156b9f76c73e130bfdfd
5
+ SHA512:
6
+ metadata.gz: 7ba5ec75a96aca6b91e303c7fa623faacfff540dff55f82e9173af750caf011fab96f7ccb7e5320decd749249ba8990c2762213a964117465f8b1e9f6b776845
7
+ data.tar.gz: 64885e112c01ee13ea1834b1e1fc4abf9fe919c9250fef74f61dff5e59ffaaa5b2be09ff30ca32ca8d417cc9b05848913c5894d3fc8e84ae727c7f859c34865f
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .ruby-version
4
+ .ruby-gemset
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 protomouse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Gfycat
2
+
3
+ A Ruby interface to the Gfycat API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "gfycat"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gfycat
18
+
19
+ ## Usage
20
+
21
+ ```irb
22
+ 2.1.0 :001 > require "gfycat"
23
+ => true
24
+ 2.1.0 :002 > client = Gfycat::Client.new
25
+ => #<Gfycat::Client:0x0000010120ca68 @client=#<Gfycat::JsonClient:0x000001011fc1e0 @conn=#<Faraday::Connection:0x000001011ffdb8 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.9.0"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x000001011f75c8 @handlers=[Gfycat::Middleware::Response::SnakeCaseKeys, FaradayMiddleware::ParseJson, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTP:0x000001011f7028 URL:http://gfycat.com/cajax>, @proxy=nil>>>
26
+ 2.1.0 :003 > name = client.transcode!("http://24.media.tumblr.com/tumblr_mdtean9phV1rkbqbko1_500.gif")
27
+ => "SilkyCarelessAmericanbobtail"
28
+ 2.1.0 :004 > client.get(name)
29
+ => #<Gfycat::Resources::Item:0x00000101575628 @gfy_id="silkycarelessamericanbobtail", @gfy_name="SilkyCarelessAmericanbobtail", @gfy_number=407030074, @user_name="anonymous", @width=502, @height=282, @frame_rate=10, @num_frames=15, @mp4_url=#<URI::HTTP:0x0000010157e480 URL:http://zippy.gfycat.com/SilkyCarelessAmericanbobtail.mp4>, @webm_url=#<URI::HTTP:0x0000010157e160 URL:http://zippy.gfycat.com/SilkyCarelessAmericanbobtail.webm>, @gif_url=#<URI::HTTP:0x0000010157de40 URL:http://zippy.gfycat.com/SilkyCarelessAmericanbobtail.gif>, @gif_size=504554, @mp4_size=168339, @webm_size=181618, @create_date=#<DateTime: 2014-05-16T13:51:21+00:00 ((2456794j,49881s,0n),+0s,2299161j)>, @views=1, @title=nil, @extra_lemmas=nil, @md5=nil, @tags=nil, @nsfw=nil, @sar=nil, @url=#<URI::HTTP:0x0000010157c9f0 URL:http://24.media.tumblr.com/tumblr_mdtean9phV1rkbqbko1_500.gif>, @source=nil, @dynamo=nil, @subreddit=nil, @reddit_id=nil, @reddit_id_text=nil, @upload_gif_name=nil>
30
+ 2.1.0 :005 > client.exists?("http://24.media.tumblr.com/tumblr_mdtean9phV1rkbqbko1_500.gif")
31
+ => true
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( http://github.com/<my-github-username>/gfycat/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gfycat/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gfycat"
8
+ spec.version = Gfycat::VERSION
9
+ spec.authors = ["protomouse"]
10
+ spec.email = ["root@protomou.se"]
11
+ spec.summary = %q{A Ruby interface to the Gfycat API.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/protomouse/gfycat"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "json", "~> 1.8.1"
22
+ spec.add_dependency "faraday", "~> 0.9.0"
23
+ spec.add_dependency "faraday_middleware", "~> 0.9.1"
24
+ spec.add_dependency "virtus"
25
+ spec.add_dependency "virtus-uri"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.5"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "webmock"
31
+ end
@@ -0,0 +1,17 @@
1
+ require "securerandom"
2
+ require "cgi"
3
+ require "virtus"
4
+ require "virtus/uri"
5
+ require "faraday"
6
+ require "faraday_middleware"
7
+
8
+ require "gfycat/version"
9
+ require "gfycat/middleware"
10
+ require "gfycat/patches"
11
+
12
+ module Gfycat
13
+ autoload :Attributes, "gfycat/attributes"
14
+ autoload :Client, "gfycat/client"
15
+ autoload :JsonClient, "gfycat/json_client"
16
+ autoload :Resources, "gfycat/resources"
17
+ end
@@ -0,0 +1,7 @@
1
+ module Gfycat
2
+
3
+ module Attributes
4
+ autoload :Enum, "gfycat/attributes/enum"
5
+ end
6
+
7
+ end
@@ -0,0 +1,21 @@
1
+ module Gfycat
2
+ module Attributes
3
+
4
+ class Enum
5
+ def self.[](*values)
6
+ class_name = self.name
7
+
8
+ Class.new(Virtus::Attribute) do
9
+ define_singleton_method :inspect do
10
+ sprintf("#<%s%s>", class_name, values)
11
+ end
12
+
13
+ define_method :coerce do |value|
14
+ value && values[value.to_i]
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Gfycat
2
+
3
+ class Client
4
+
5
+ def initialize(options = {})
6
+ @client = JsonClient.new(api_url, **options)
7
+ end
8
+
9
+ def transcode!(source)
10
+ response = @client.get(transcode_url, fetchUrl: source)
11
+ response["gfy_name"]
12
+ end
13
+
14
+ def get(name)
15
+ response = @client.get("get/#{name}")
16
+ Resources::Item.new(response["gfy_item"])
17
+ end
18
+
19
+ def exists?(url)
20
+ response = @client.get("checkUrl/#{CGI::escape(url)}")
21
+ !!response["url_known"]
22
+ end
23
+
24
+ protected
25
+ def api_url
26
+ "http://gfycat.com/cajax"
27
+ end
28
+
29
+ def transcode_url
30
+ "http://upload.gfycat.com/transcode/#{SecureRandom.hex(5)}"
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,24 @@
1
+ module Gfycat
2
+
3
+ class JsonClient
4
+
5
+ def initialize(url, options = {})
6
+ options = options.dup
7
+
8
+ @conn = Faraday.new(url: url) do |conn|
9
+ conn.response :snake_case_keys
10
+ conn.response :json, content_type: /\bjson$/
11
+
12
+ conn.options.update(options)
13
+
14
+ conn.adapter Faraday.default_adapter
15
+ end
16
+ end
17
+
18
+ def get(path, params = {})
19
+ @conn.get(path, params).body
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1 @@
1
+ require "gfycat/middleware/response"
@@ -0,0 +1,12 @@
1
+ module Gfycat
2
+ module Middleware
3
+
4
+ module Response
5
+ autoload :SnakeCaseKeys, "gfycat/middleware/response/snake_case_keys"
6
+
7
+ Faraday::Response.register_middleware \
8
+ snake_case_keys: lambda { SnakeCaseKeys }
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ module Gfycat
2
+ module Middleware
3
+ module Response
4
+
5
+ class SnakeCaseKeys < Faraday::Middleware
6
+
7
+ def call(env)
8
+ @app.call(env).on_complete do |env|
9
+ env[:body] = convert_value(env[:body])
10
+ end
11
+ end
12
+
13
+ protected
14
+ def convert_key(key)
15
+ key.to_s.strip.
16
+ gsub(" ", "_").
17
+ gsub(/::/, "/").
18
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
19
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
20
+ tr("-", "_").
21
+ squeeze("_").
22
+ downcase
23
+ end
24
+
25
+ def convert_value(value)
26
+ case value
27
+ when Array
28
+ value.map { |v| convert_value(v) }
29
+ when Hash
30
+ Hash[value.map { |k, v| [convert_key(k), convert_value(v)] }]
31
+ else
32
+ value
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1 @@
1
+ Dir[File.expand_path("../patches/**/*.rb", __FILE__)].each { |f| require f }
@@ -0,0 +1,11 @@
1
+ require "coercible"
2
+
3
+ class Coercible::Coercer::String
4
+
5
+ def parse_value(parser, value, method)
6
+ parser.strptime(value, "%s")
7
+ rescue ArgumentError
8
+ raise_unsupported_coercion(value, method)
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ module Gfycat
2
+
3
+ module Resources
4
+ autoload :Item, "gfycat/resources/item"
5
+ end
6
+
7
+ end
@@ -0,0 +1,41 @@
1
+ module Gfycat
2
+ module Resources
3
+
4
+ class Item
5
+ include Virtus.model
6
+ include Gfycat::Attributes
7
+
8
+ attribute :gfy_id, String
9
+ attribute :gfy_name, String
10
+ attribute :gfy_number, Integer
11
+ attribute :user_name, String
12
+ attribute :width, Integer
13
+ attribute :height, Integer
14
+ attribute :frame_rate, Integer
15
+ attribute :num_frames, Integer
16
+ attribute :mp4_url, Uri
17
+ attribute :webm_url, Uri
18
+ attribute :gif_url, Uri
19
+ attribute :gif_size, Integer
20
+ attribute :mp4_size, Integer
21
+ attribute :webm_size, Integer
22
+ attribute :create_date, DateTime
23
+ attribute :views, Integer
24
+ attribute :title, String
25
+ attribute :extra_lemmas, String
26
+ attribute :md5, String
27
+ attribute :tags, String
28
+ attribute :nsfw, Boolean
29
+ attribute :sar, String
30
+ attribute :url, Uri
31
+ attribute :source, Enum[:unknown]
32
+ attribute :dynamo, String
33
+ attribute :subreddit, String
34
+ attribute :reddit_id, Integer
35
+ attribute :reddit_id_text, String
36
+ attribute :upload_gif_name, String
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Gfycat
2
+ VERSION = "0.9.0"
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gfycat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - protomouse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: virtus-uri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Ruby interface to the Gfycat API.
140
+ email:
141
+ - root@protomou.se
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - gfycat.gemspec
152
+ - lib/gfycat.rb
153
+ - lib/gfycat/attributes.rb
154
+ - lib/gfycat/attributes/enum.rb
155
+ - lib/gfycat/client.rb
156
+ - lib/gfycat/json_client.rb
157
+ - lib/gfycat/middleware.rb
158
+ - lib/gfycat/middleware/response.rb
159
+ - lib/gfycat/middleware/response/snake_case_keys.rb
160
+ - lib/gfycat/patches.rb
161
+ - lib/gfycat/patches/timestamp_coercion.rb
162
+ - lib/gfycat/resources.rb
163
+ - lib/gfycat/resources/item.rb
164
+ - lib/gfycat/version.rb
165
+ homepage: https://github.com/protomouse/gfycat
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.2.2
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: A Ruby interface to the Gfycat API.
189
+ test_files: []