imgurz 0.0.4 → 0.0.5
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 +4 -4
- data/lib/imgurz/client.rb +8 -1
- data/tests/test.rb +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e081cfb22b562214c3e2600734e643337a097bd
|
4
|
+
data.tar.gz: f158b61f632a01e77a2d3c4ad541597545c270ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc1402a678a457fe1e8ebe2b43bb87e4d5d8c398f86fb6ff10d59b4f1b400e78ff09aee8b3577879e533652e0c63cb086a98306944452a4cf941dfef268d78b
|
7
|
+
data.tar.gz: 96afce5580597df87bd5393572dd53e1ff4a218ce6c45cb7b08bed684925b174be99f38de744948ba71ebbda2e46cd4106ce4f850e77c6291be42017b777907a
|
data/lib/imgurz/client.rb
CHANGED
@@ -17,6 +17,11 @@ module Imgurz
|
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
|
+
def into(album_id)
|
21
|
+
@album_id = album_id
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
20
25
|
def upload(image)
|
21
26
|
return self.upload_file(image) if image.kind_of?(File) # already a file
|
22
27
|
self.upload_file_at(image) # we assume that a path is given
|
@@ -44,7 +49,9 @@ module Imgurz
|
|
44
49
|
self.as_anonymous unless @method
|
45
50
|
request['Authorization'] = "Client-ID #{key}" if @method=='anonymous'
|
46
51
|
request['Authorization'] = "Bearer #{key}" if @method=='registered'
|
47
|
-
|
52
|
+
data = {image:file_content}
|
53
|
+
data[:album] = @album_id if @album_id
|
54
|
+
request.set_form_data(data)
|
48
55
|
response = http.request(request)
|
49
56
|
JSON.parse response.body
|
50
57
|
end
|
data/tests/test.rb
CHANGED
@@ -8,16 +8,21 @@ YOUR_CLIENT_SECRET = ''
|
|
8
8
|
YOUR_TOKEN = ''
|
9
9
|
YOUR_REFRESH_TOKEN = ''
|
10
10
|
|
11
|
-
|
11
|
+
YOUR_ALBUM_ID = nil
|
12
|
+
YOUR_TEST_IMAGE = 'tests/lama.gif'
|
12
13
|
|
13
14
|
# Upload using a path, as an anononymous user
|
14
15
|
client = Imgurz::Client.new YOUR_CLIENT_ID
|
15
|
-
puts client.anonymous.upload(
|
16
|
+
puts client.anonymous.upload(YOUR_TEST_IMAGE)
|
16
17
|
|
17
18
|
# Upload using a path, as a registered user (with a token)
|
18
19
|
client = Imgurz::Client.new YOUR_TOKEN
|
19
|
-
puts client.as_regsitered.upload(
|
20
|
+
puts client.as_regsitered.upload(YOUR_TEST_IMAGE)
|
21
|
+
|
22
|
+
# Upload using a path, as a registered user (with a token), into an album
|
23
|
+
client = Imgurz::Client.new YOUR_TOKEN
|
24
|
+
puts client.as_regsitered.into(YOUR_ALBUM_ID).upload(YOUR_TEST_IMAGE)
|
20
25
|
|
21
|
-
# Refresh token
|
26
|
+
# # Refresh token
|
22
27
|
token = Imgurz::Token.new(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
|
23
28
|
puts token.refresh(YOUR_REFRESH_TOKEN)
|