class Unsplash::Client

Common functionality across Unsplash API objects.

Public Class Methods

connection() click to toggle source

The connection object being used to communicate with Unsplash. @return [Unsplash::Connection] the connection

# File lib/unsplash/client.rb, line 45
def connection
  @@connection ||= Connection.new
end
connection=(conn) click to toggle source

Assign a default connection object. @param conn [Unsplash::Connection] the connection @return [Unsplash::Connection] the connection

# File lib/unsplash/client.rb, line 52
def connection=(conn)
  @@connection = conn
end
new(attrs = {}) click to toggle source

Build an Unsplash object with the given attributes. @param attrs [Hash]

# File lib/unsplash/client.rb, line 8
def initialize(attrs = {})
  @attributes = OpenStruct.new(attrs)
end

Public Instance Methods

connection() click to toggle source

The connection object being used to communicate with Unsplash. @return [Unsplash::Connection] the connection

# File lib/unsplash/client.rb, line 38
def connection
  self.class.connection
end
method_missing(method, *args, &block) click to toggle source

@private

# File lib/unsplash/client.rb, line 31
def method_missing(method, *args, &block)
  attribute = @attributes.send(method, *args, &block)
  attribute.is_a?(Hash) ? Client.new(attribute) : attribute
end
reload!() click to toggle source

(Re)load full object details from Unsplash. @return [Unspash::Client] Itself, with full details reloaded.

# 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() click to toggle source

Raw JSON as returned by Unsplash API. @return [Hash] json

# File lib/unsplash/client.rb, line 26
def to_h
  @attributes.to_h
end