Class: Imgur::Model
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_keys ⇒ Object
-
#initialize(attributes) ⇒ Model
constructor
A new instance of Model.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Model
Returns a new instance of Model.
7 8 9 10 |
# File 'lib/imgur/model.rb', line 7 def initialize(attributes) self.attributes = attributes self.errors = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
26 27 28 29 |
# File 'lib/imgur/model.rb', line 26 def method_missing(meth, *args, &block) return attributes[meth.to_s] if meth.to_s.in? attribute_keys super end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/imgur/model.rb', line 5 def attributes @attributes end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/imgur/model.rb', line 5 def errors @errors end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/imgur/model.rb', line 5 def response @response end |
Class Method Details
.find_by_id(id) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/imgur/model.rb', line 12 def self.find_by_id(id) response = get("/#{id}", headers: headers) return unless response["success"] == true album_data = ActiveSupport::JSON.decode(response.body)["data"] return unless album_data.present? new(album_data) end |
Instance Method Details
#attribute_keys ⇒ Object
22 23 24 |
# File 'lib/imgur/model.rb', line 22 def attribute_keys @keys ||= attributes.keys end |