Skip to content

artsy/artsy-ruby-client

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Artsy::Client Build Status Code Climate

A Ruby client for the Artsy APIv1.

Important

This project is obsolete. We have since released a public API that no longer requires a specific artsy-ruby-client gem. Check out our public API at developers.artsy.net.

Getting Started

require 'artsy_client'

Authenticate with a client ID and secret.

Artsy::Client.configure do |config|
  config.client_id = ...
  config.client_secret = ...
end

Artsy::Client.authenticate! # retrieves a short lived xapp_token

Alternatively, if you have an access token granted for offline access.

Artsy::Client.configure do |config|
  config.access_token = ... # access token granted for offline access
end

This token lasts for 25 years and can be obtained from the command-line.

curl -v "https://artsy.net/oauth2/access_token
  ?client_id=...
  &client_secret=...
  &email=...
  &password=...
  &grant_type=credentials
  &scope=offline_access"

The client also supports logging in with a username and password, however, using credentials sent in plain-text is not recommended.

Artsy::Client.configure do |config|
  config.client_id = ...
  config.client_secret = ...
  config.user_email = ...
  config.user_password = ...
end

Artsy::Client.authenticate! # retrieves a short lived access_token

Is Artsy Up?

Artsy::Client.up?

Who am I logged in as?

me = Artsy::Client.me
puts "#{me.name} <#{me.email}> (#{me.id})"

Andy Warhol

# an artist
andy_warhol = Artsy::Client.artist("andy-warhol")
puts "#{andy_warhol.name}, #{andy_warhol.years}"

# an artwork by Andy Warhol
andy_warhol_skull = Artsy::Client.artwork("andy-warhol-skull")
puts "#{andy_warhol_skull.title}, #{andy_warhol_skull.date} by #{andy_warhol_skull.artist.name}"

# 3 works by Andy Warhol
andy_warhol.artworks({ :size => 3 }).each do |artwork|
  puts "#{artwork.title}, #{artwork.date}"
end

Creating and Updating Artworks

Artworks must be created before they can be published.

artwork = Artsy::Client.create_artwork(title: 'Mona Lisa')
Artsy::Client.update_artwork(artwork.id, private: false, published: true)

Shows

Shows can be returned in a virtually infinite feed. Each response contains a set of results and a cursor for the next query.

cursor = nil
3.times do
  options = {}
  options[:cursor] = cursor if cursor
  r = Artsy::Client.shows_feed(options)
  r[:results].each do |show|
    puts "#{show.name}"
    show.artworks.each do |artwork|
      puts "  #{artwork.title}, #{artwork.date}"
    end
  end
  cursor = r[:next]
  break unless cursor
end

You can retrieve a sample show.

Artsy::Client.shows(sample: 1, status: :current, published_with_eligible_artworks: true).each do |show|
  puts "#{show.name} at #{show.partner.name}"
end

Featured Posts

Featured posts can be returned in a virtually infinite feed. Each response contains a set of results and a cursor for the next query.

cursor = nil
3.times do
  options = {}
  options[:cursor] = cursor if cursor
  r = Artsy::Client.featured_posts(options)
  r[:results].each do |post|
    puts "#{post.title}"
  end
  cursor = r[:next]
  break unless cursor
end

Autocomplete

Autocomplete search terms.

Artsy::Client.autocomplete('andy warhol').each do |search_query|
  puts search_query.query
end

Pages

Create content pages.

Artsy::Client.create_page(name: 'About', content: 'Foo bar baz.', published: true)

Logging

Setup verbose logging.

Artsy::Client.configure do |config|
  config.logger = Logger.new(STDOUT)
  config.logger.level = Logger::DEBUG
end

Contributing

Fork the project. Make your feature addition or bug fix with tests. Send a pull request. Bonus points for topic branches.

Copyright and License

MIT License, see LICENSE for details.

(c) 2013 Daniel Doubrovkine, Artsy Inc.

About

Artsy API Ruby Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages