Class: Unsplash::Client
- Inherits:
-
Object
- Object
- Unsplash::Client
- Defined in:
- lib/unsplash/client.rb
Overview
Common functionality across Unsplash API objects.
Direct Known Subclasses
Collection, 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 11 |
# File 'lib/unsplash/client.rb', line 8 def initialize(attrs = {}) @attributes = OpenStruct.new(attrs) add_utm_to_links 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.
65 66 67 |
# File 'lib/unsplash/client.rb', line 65 def connection @@connection ||= Connection.new end |
.connection=(conn) ⇒ Unsplash::Connection
Assign a default connection object.
72 73 74 |
# File 'lib/unsplash/client.rb', line 72 def connection=(conn) @@connection = conn end |
Instance Method Details
#connection ⇒ Unsplash::Connection
The connection object being used to communicate with Unsplash.
39 40 41 |
# File 'lib/unsplash/client.rb', line 39 def connection self.class.connection end |
#reload! ⇒ Unspash::Client
(Re)load full object details from Unsplash.
15 16 17 18 19 20 21 22 23 |
# File 'lib/unsplash/client.rb', line 15 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.
27 28 29 |
# File 'lib/unsplash/client.rb', line 27 def to_h @attributes.to_h end |