simple_imgur 0.0.5 → 0.0.6

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.
@@ -0,0 +1,10 @@
1
+ module Imgur
2
+ class Album < Model
3
+ base_uri "https://api.imgur.com/3/album"
4
+
5
+ def images
6
+ @images ||= Imgur::Image.collection(attributes["images"])
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Imgur
2
+ class Configuration
3
+ attr_accessor :client_id
4
+
5
+ def initialize
6
+ self.client_id = nil
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Imgur
2
+ class Image < Model
3
+ base_uri "api.imgur.com/3/image"
4
+
5
+ def self.collection(images)
6
+ images.map do |image|
7
+ new(image)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module Imgur
2
+ class Model
3
+ include HTTParty
4
+
5
+ attr_accessor :errors, :response, :attributes
6
+
7
+ def initialize(attributes)
8
+ self.attributes = attributes
9
+ self.errors = []
10
+ end
11
+
12
+ def self.find_by_id(id)
13
+ response = get("/#{id}", headers: headers)
14
+ return unless response["success"] == true
15
+
16
+ album_data = ActiveSupport::JSON.decode(response.body)["data"]
17
+ return unless album_data.present?
18
+
19
+ new(album_data)
20
+ end
21
+
22
+ def attribute_keys
23
+ @keys ||= attributes.keys
24
+ end
25
+
26
+ def method_missing(meth, *args, &block)
27
+ return attributes[meth.to_s] if meth.to_s.in? attribute_keys
28
+ super
29
+ end
30
+
31
+ def self.headers
32
+ { "Authorization" => "Client-ID #{Imgur.config.client_id}" }
33
+ end
34
+ end
35
+ end
data/lib/imgur/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Imgur
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/imgur.rb CHANGED
@@ -1,17 +1,11 @@
1
1
  require "imgur/version"
2
2
 
3
- require "imgur/model"
4
- require "imgur/album"
5
- require "imgur/image"
6
-
7
3
  module Imgur
8
- class Configuration
9
- attr_accessor :client_id
4
+ autoload :Model, 'imgur/model'
5
+ autoload :Album, 'imgur/album'
6
+ autoload :Image, 'imgur/image'
10
7
 
11
- def initialize
12
- self.client_id = nil
13
- end
14
- end
8
+ autoload :Configuration, 'imgur/configuration'
15
9
 
16
10
  class << self
17
11
  attr_accessor :config
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_imgur
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robin Boutros
@@ -64,6 +64,10 @@ files:
64
64
  - Rakefile
65
65
  - imgur.gemspec
66
66
  - lib/imgur.rb
67
+ - lib/imgur/album.rb
68
+ - lib/imgur/configuration.rb
69
+ - lib/imgur/image.rb
70
+ - lib/imgur/model.rb
67
71
  - lib/imgur/version.rb
68
72
  has_rdoc: true
69
73
  homepage: https://github.com/niuage/imgur