imgur-api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imgur.rb +60 -70
- data/lib/imgur/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e9301fd3fdf16aa48bfbdefb3c64d70e992e2a3
|
4
|
+
data.tar.gz: 4cec4b4ee92dc2a8e834a5f92c84d94637c7b1cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4d1e25879fbbd72ce1430ca523514bfe8e98a948a67b63f4f238f942ebbcaaeb1d67a52adc7288cd58333e51871a4026753b9aca86ce13c0eeb0b678a441bb9
|
7
|
+
data.tar.gz: 9a8bdef60a68bf338b3481ebcd95e0e9a1420a669413ea0fdc9e1814a0217ba3eb3ab14465a72c450e8e28a0b8ee066d003c874963926a24e1554eb2a890e29d
|
data/lib/imgur.rb
CHANGED
@@ -42,14 +42,18 @@ module Imgur
|
|
42
42
|
resp = get(url).parsed_response
|
43
43
|
Album.new resp['data']
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def get_account(username)
|
47
47
|
url = API_PATH + ACCOUNT_PATH + username
|
48
48
|
resp = get(url).parsed_response
|
49
49
|
# The Imgur API doesn't send the username back
|
50
50
|
Account.new resp['data'], username
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
|
+
def update_album(album)
|
54
|
+
album.update self
|
55
|
+
end
|
56
|
+
|
53
57
|
def me
|
54
58
|
get_account 'me'
|
55
59
|
end
|
@@ -99,16 +103,10 @@ module Imgur
|
|
99
103
|
end
|
100
104
|
|
101
105
|
end
|
102
|
-
|
106
|
+
|
103
107
|
class Account
|
104
|
-
attr_accessor :id
|
105
|
-
|
106
|
-
attr_accessor :bio
|
107
|
-
attr_accessor :reputation
|
108
|
-
attr_accessor :created
|
109
|
-
attr_accessor :pro_expiration
|
110
|
-
attr_accessor :username
|
111
|
-
|
108
|
+
attr_accessor :id, :url, :bio, :reputation, :created, :pro_expiration,
|
109
|
+
:username
|
112
110
|
def initialize(data, username=nil)
|
113
111
|
@id = data['id']
|
114
112
|
@url = data['url']
|
@@ -120,25 +118,13 @@ module Imgur
|
|
120
118
|
end
|
121
119
|
@username = username
|
122
120
|
end
|
123
|
-
|
121
|
+
|
124
122
|
end
|
125
|
-
|
123
|
+
|
126
124
|
class Comment
|
127
|
-
attr_accessor :id
|
128
|
-
|
129
|
-
|
130
|
-
attr_accessor :author
|
131
|
-
attr_accessor :author
|
132
|
-
attr_accessor :author_id
|
133
|
-
attr_accessor :on_album
|
134
|
-
attr_accessor :ups
|
135
|
-
attr_accessor :downs
|
136
|
-
attr_accessor :points
|
137
|
-
attr_accessor :date
|
138
|
-
attr_accessor :parent_id
|
139
|
-
attr_accessor :deleted
|
140
|
-
attr_accessor :children
|
141
|
-
|
125
|
+
attr_accessor :id, :image_id, :caption, :author, :author_id, :on_album, :ups,
|
126
|
+
:downs, :points, :date, :parent_id, :deleted, :children
|
127
|
+
|
142
128
|
def initialize(data)
|
143
129
|
@id = data['id']
|
144
130
|
@image_id = data['image_id']
|
@@ -153,44 +139,32 @@ module Imgur
|
|
153
139
|
@parent_id = data['parent_id']
|
154
140
|
@deleted = deleted
|
155
141
|
end
|
156
|
-
|
142
|
+
|
157
143
|
def on_album?
|
158
144
|
@on_album
|
159
145
|
end
|
160
|
-
|
146
|
+
|
161
147
|
def upvotes
|
162
148
|
@ups
|
163
149
|
end
|
164
|
-
|
150
|
+
|
165
151
|
def downvotes
|
166
152
|
@downs
|
167
153
|
end
|
168
|
-
|
154
|
+
|
169
155
|
def has_parent?
|
170
156
|
@parent_id != nil
|
171
157
|
end
|
172
|
-
|
158
|
+
|
173
159
|
def deleted?
|
174
160
|
@deleted
|
175
161
|
end
|
176
162
|
end
|
177
163
|
|
178
164
|
class Album
|
179
|
-
attr_accessor :id
|
180
|
-
|
181
|
-
|
182
|
-
attr_accessor :date
|
183
|
-
attr_accessor :cover
|
184
|
-
attr_accessor :cover_width
|
185
|
-
attr_accessor :cover_height
|
186
|
-
attr_accessor :account_url
|
187
|
-
attr_accessor :privacy
|
188
|
-
attr_accessor :layout
|
189
|
-
attr_accessor :views
|
190
|
-
attr_accessor :link
|
191
|
-
attr_accessor :deletehash
|
192
|
-
attr_accessor :images_count
|
193
|
-
attr_accessor :images
|
165
|
+
attr_accessor :id, :title, :description, :date, :cover, :cover_width,
|
166
|
+
:cover_height, :account_url, :privacy, :layout, :views,
|
167
|
+
:link, :deletehash, :images_count, :images
|
194
168
|
|
195
169
|
def initialize(data)
|
196
170
|
@id = data['id']
|
@@ -211,14 +185,38 @@ module Imgur
|
|
211
185
|
@images << Image.new(img)
|
212
186
|
end
|
213
187
|
end
|
188
|
+
|
189
|
+
def update(client)
|
190
|
+
if @deletehash == nil
|
191
|
+
raise UpdateException.new 'Album must have a deletehash to update'
|
192
|
+
end
|
193
|
+
url = API_PATH + ALBUM_GET_PATH + @deletehash
|
194
|
+
image_ids = []
|
195
|
+
# Make sure we're only strings
|
196
|
+
@images.each do |img|
|
197
|
+
if img.is_a? Image
|
198
|
+
image_ids << img.id
|
199
|
+
elsif img.is_a? String
|
200
|
+
image_ids << img
|
201
|
+
end
|
202
|
+
end
|
203
|
+
body = {
|
204
|
+
ids: @images,
|
205
|
+
title: @title,
|
206
|
+
description: @description,
|
207
|
+
privacy: @privacy,
|
208
|
+
layout: @layout,
|
209
|
+
cover: @cover
|
210
|
+
}
|
211
|
+
puts body
|
212
|
+
client.post(url, body: body)
|
213
|
+
end
|
214
|
+
|
214
215
|
end
|
215
216
|
|
216
217
|
# Represents an image stored on the computer
|
217
218
|
class LocalImage
|
218
|
-
attr_accessor :file
|
219
|
-
attr_accessor :title
|
220
|
-
attr_accessor :description
|
221
|
-
attr_accessor :album_id
|
219
|
+
attr_accessor :file, :title, :description, :album_id
|
222
220
|
|
223
221
|
def initialize(file, options={})
|
224
222
|
if file.is_a? String
|
@@ -235,23 +233,9 @@ module Imgur
|
|
235
233
|
|
236
234
|
# Represents an image on Imgur
|
237
235
|
class Image
|
238
|
-
attr_accessor :id
|
239
|
-
|
240
|
-
|
241
|
-
attr_accessor :date # Time object of :datetime
|
242
|
-
attr_accessor :type
|
243
|
-
attr_accessor :animated
|
244
|
-
attr_accessor :width
|
245
|
-
attr_accessor :height
|
246
|
-
attr_accessor :size
|
247
|
-
attr_accessor :views
|
248
|
-
attr_accessor :bandwidth
|
249
|
-
attr_accessor :favorite
|
250
|
-
attr_accessor :nsfw
|
251
|
-
attr_accessor :section
|
252
|
-
attr_accessor :deletehash
|
253
|
-
attr_accessor :link
|
254
|
-
attr_accessor :html_link
|
236
|
+
attr_accessor :id, :title, :description, :date, :type, :animated, :width,
|
237
|
+
:height, :size, :views, :bandwidth, :favorite, :nsfw, :section,
|
238
|
+
:deletehash, :link, :html_link
|
255
239
|
|
256
240
|
def initialize(data)
|
257
241
|
@id = data['id']
|
@@ -277,7 +261,13 @@ module Imgur
|
|
277
261
|
|
278
262
|
class NotFoundException < Exception
|
279
263
|
def initialize(msg='404 Not Found')
|
280
|
-
super
|
264
|
+
super msg
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
class UpdateException < Exception
|
269
|
+
def initialize(msg)
|
270
|
+
super msg
|
281
271
|
end
|
282
272
|
end
|
283
273
|
|
data/lib/imgur/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgur-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- August
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|