imgurz 0.0.6 → 0.0.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/imgurz/client.rb +8 -2
  3. data/tests/test.rb +24 -19
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c03333d542173eaf1a8024475689e102f3989234
4
- data.tar.gz: 0265d56c9077663a94801572565d8a6ca54d4240
3
+ metadata.gz: 4ed99bad31499a206ad08cc846483ec8af2c8cc7
4
+ data.tar.gz: ba9c09266a5dc6a3faf63bf0958375ffe45bbb06
5
5
  SHA512:
6
- metadata.gz: 806dc308e8cc6c02da1104c66211429d497a26a447f33413422d284546ebbeb054a363c82830e0b0ea60b2c4874409d2f5008c40a38b218a7f50116705a4fdc6
7
- data.tar.gz: 09fd87926402eec8b29c3813e8264c4dbafe1e4748e86147e4709d047a5b1577a4af3487d12263abcf5dbc14814bedd94ae8b78e5e4d0ff8fb24b5344f2bd8bf
6
+ metadata.gz: b491bee5ac1e3fd98b1f0920bb1076503cd95937b91c0b749176eee7741d6c70f459715c2ef5317730e621704aa74272d14c8ef6c009dd63ba431903a8d8a463
7
+ data.tar.gz: cbb773d4b1b4509ca0303061825be3f81d826d0bc918e7912d31337669c42f75e1faa8e048962534c69cf35e4a723b3fc57d502a1519542057de60d599115261
data/lib/imgurz/client.rb CHANGED
@@ -24,6 +24,7 @@ module Imgurz
24
24
 
25
25
  def upload(image)
26
26
  return self.upload_file(image) if image.kind_of?(File) # already a file
27
+ return self.upload_url(image) if image.kind_of?(String) and image.start_with?('http') # an URL
27
28
  self.upload_file_at(image) # we assume that a path is given
28
29
  end
29
30
 
@@ -39,8 +40,13 @@ module Imgurz
39
40
  content = [file.read].pack('m')
40
41
  self.upload_image_content(content)
41
42
  end
43
+
44
+ def upload_url(url)
45
+ return false unless url.kind_of?(String) and url.start_with?('http')
46
+ self.upload_image_content(url,'url')
47
+ end
42
48
 
43
- def upload_image_content(file_content)
49
+ def upload_image_content(file_content, type=nil)
44
50
  return false unless file_content.kind_of?(String)
45
51
  uri = URI.parse Imgurz::IMAGE_ENDPOINT
46
52
  http = Net::HTTP.new(uri.host, uri.port)
@@ -49,7 +55,7 @@ module Imgurz
49
55
  self.as_anonymous unless @method
50
56
  request['Authorization'] = "Client-ID #{key}" if @method=='anonymous'
51
57
  request['Authorization'] = "Bearer #{key}" if @method=='registered'
52
- data = {image:file_content}
58
+ data = {image:file_content, type:type}
53
59
  data[:album] = @album_id if @album_id
54
60
  request.set_form_data(data)
55
61
  response = http.request(request)
data/tests/test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require './lib/imgurz'
2
2
 
3
3
  # To create one go to https://api.imgur.com/oauth2/addclient
4
- YOUR_CLIENT_ID = ''
4
+ YOUR_CLIENT_ID = 'da4e49401979bdb'
5
5
  YOUR_CLIENT_SECRET = ''
6
6
 
7
7
  # To get one go to https://api.imgur.com/oauth2#authorization
@@ -10,25 +10,30 @@ YOUR_REFRESH_TOKEN = ''
10
10
 
11
11
  YOUR_ALBUM_ID = nil
12
12
  YOUR_TEST_IMAGE = 'tests/lama.gif'
13
+ YOUR_TEST_URL = 'http://i.lide.li/uploads/images/d8d4.gif'
13
14
 
14
15
  DELETE_HASH = ''
15
16
 
16
- # Upload using a path, as an anononymous user
17
+ # # Upload using a path, as an anononymous user
17
18
  client = Imgurz::Client.new YOUR_CLIENT_ID
18
- puts client.anonymous.upload(YOUR_TEST_IMAGE)
19
-
20
- # Upload using a path, as a registered user (with a token)
21
- client = Imgurz::Client.new YOUR_TOKEN
22
- puts client.as_regsitered.upload(YOUR_TEST_IMAGE)
23
-
24
- # Upload using a path, as a registered user (with a token), into an album
25
- client = Imgurz::Client.new YOUR_TOKEN
26
- puts client.as_regsitered.into(YOUR_ALBUM_ID).upload(YOUR_TEST_IMAGE)
27
-
28
- # # Refresh token
29
- token = Imgurz::Token.new(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
30
- puts token.refresh(YOUR_REFRESH_TOKEN)
31
-
32
- # Delete an image as a registered user, using a deletehash
33
- client = Imgurz::Client.new YOUR_TOKEN
34
- puts client.as_regsitered.delete(DELETE_HASH)
19
+ puts client.as_anonymous.upload(YOUR_TEST_IMAGE)
20
+ #
21
+ # Upload using an url, as an anonymous user
22
+ # client = Imgurz::Client.new YOUR_CLIENT_ID
23
+ # puts client.as_anonymous.upload(YOUR_TEST_URL)
24
+ #
25
+ # # Upload using a path, as a registered user (with a token)
26
+ # client = Imgurz::Client.new YOUR_TOKEN
27
+ # puts client.as_regsitered.upload(YOUR_TEST_IMAGE)
28
+ #
29
+ # # Upload using a path, as a registered user (with a token), into an album
30
+ # client = Imgurz::Client.new YOUR_TOKEN
31
+ # puts client.as_regsitered.into(YOUR_ALBUM_ID).upload(YOUR_TEST_IMAGE)
32
+ #
33
+ # # # Refresh token
34
+ # token = Imgurz::Token.new(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
35
+ # puts token.refresh(YOUR_REFRESH_TOKEN)
36
+ #
37
+ # # Delete an image as a registered user, using a deletehash
38
+ # client = Imgurz::Client.new YOUR_TOKEN
39
+ # puts client.as_regsitered.delete(DELETE_HASH)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgurz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Zielony