imgurz 0.0.3
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/lib/imgurz/client.rb +41 -0
- data/lib/imgurz.rb +12 -0
- data/tests/lama.gif +0 -0
- data/tests/upload.rb +8 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecc71374331fee56f55c92f1bf27cb6546ac7086
|
4
|
+
data.tar.gz: ed5bae0509c89e72c615d6987788d9c6f16a0414
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb0e70f517d3b4c4b75e0e9b53060b741a862049d1f2cac2c4d9e93dba348744361fa9d75fd47ac6e27f232040d3c418d767dca93cee2282ac6aec63ab5b0cb5
|
7
|
+
data.tar.gz: 90e245e88b73bc4930679a3d84906d751ec166e85f3ae3507784840e6d776b4d90bb30e185a03bc0eeacdb072f02749d10a45b3feeec0e944fa49e3ae0d5741b
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Imgurz
|
2
|
+
extend self
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
class Client < Struct.new(:client_key)
|
9
|
+
|
10
|
+
def upload(image)
|
11
|
+
return self.upload_file(image) if image.kind_of?(File) # already a file
|
12
|
+
self.upload_file_at(image) # we assume that a path is given
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload_file_at(file_path)
|
16
|
+
return false unless file_path.kind_of?(String)
|
17
|
+
File.open(file_path, 'rb') { |file|
|
18
|
+
return self.upload_file(file)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload_file(file)
|
23
|
+
return false unless file.kind_of?(File)
|
24
|
+
content = [file.read].pack('m')
|
25
|
+
self.upload_image_content(content)
|
26
|
+
end
|
27
|
+
|
28
|
+
def upload_image_content(file_content)
|
29
|
+
return false unless file_content.kind_of?(String)
|
30
|
+
uri = URI.parse Imgurz::ENDPOINT
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
http.use_ssl = true
|
33
|
+
request = Net::HTTP::Post.new uri.path
|
34
|
+
request['Authorization'] = "Client-ID #{client_key}"
|
35
|
+
request.set_form_data(image:file_content)
|
36
|
+
response = http.request(request)
|
37
|
+
JSON.parse response.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/imgurz.rb
ADDED
data/tests/lama.gif
ADDED
Binary file
|
data/tests/upload.rb
ADDED
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imgurz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxime Zielony
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Fast, simple.
|
14
|
+
email: dev@xumi.fr
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/imgurz.rb
|
20
|
+
- lib/imgurz/client.rb
|
21
|
+
- tests/upload.rb
|
22
|
+
- tests/lama.gif
|
23
|
+
homepage: https://github.com/xumi/imgurz
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.1.10
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Upload images to Imgur
|
47
|
+
test_files: []
|