Class: Unsplash::Client
- Inherits:
-
Object
- Object
- Unsplash::Client
- Defined in:
- lib/unsplash/client.rb
Overview
Common functionality across Unsplash API objects.
Direct Known Subclasses
Category, Collection, CuratedBatch, Photo, Search, Stats, User
Class Method Summary collapse
-
.connection ⇒ Unsplash::Connection
The connection object being used to communicate with Unsplash.
-
.connection=(conn) ⇒ Unsplash::Connection
Assign a default connection object.
Instance Method Summary collapse
-
#connection ⇒ Unsplash::Connection
The connection object being used to communicate with Unsplash.
-
#initialize(attrs = {}) ⇒ Client
constructor
Build an Unsplash object with the given attributes.
-
#reload! ⇒ Unspash::Client
(Re)load full object details from Unsplash.
-
#to_h ⇒ Hash
Raw JSON as returned by Unsplash API.
Constructor Details
#initialize(attrs = {}) ⇒ Client
Build an Unsplash object with the given attributes.
8 9 10 |
# File 'lib/unsplash/client.rb', line 8 def initialize(attrs = {}) @attributes = OpenStruct.new(attrs) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Class Method Details
.connection ⇒ Unsplash::Connection
The connection object being used to communicate with Unsplash.
45 46 47 |
# File 'lib/unsplash/client.rb', line 45 def connection @@connection ||= Connection.new end |
.connection=(conn) ⇒ Unsplash::Connection
Assign a default connection object.
52 53 54 |
# File 'lib/unsplash/client.rb', line 52 def connection=(conn) @@connection = conn end |
Instance Method Details
#connection ⇒ Unsplash::Connection
The connection object being used to communicate with Unsplash.
38 39 40 |
# File 'lib/unsplash/client.rb', line 38 def connection self.class.connection end |
#reload! ⇒ Unspash::Client
(Re)load full object details from Unsplash.
14 15 16 17 18 19 20 21 22 |
# File 'lib/unsplash/client.rb', line 14 def reload! if links && links["self"] attrs = JSON.parse(connection.get(links["self"]).body) @attributes = OpenStruct.new(attrs) self else raise Unsplash::Error.new "Missing self link for #{self.class} with ID #{self.id}" end end |
#to_h ⇒ Hash
Raw JSON as returned by Unsplash API.
26 27 28 |
# File 'lib/unsplash/client.rb', line 26 def to_h @attributes.to_h end |