Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Her

 Her

I presented Her at OpenCode #5.

8c4cee1129bc11fbe9a0b9379dce2cb1?s=128

Rémi Prévost

July 17, 2012
Tweet

Transcript

  1. Her Rémi Prévost — OpenCode #5

  2. “ Her is an ORM (Object Relational Mapper) that maps

    REST resources to Ruby objects. It is designed to build applications that are powered by a RESTful API instead of a database.
  3. SELECT * FROM users WHERE `id` = 1 GET /users/1

    SQL REST
  4. require "open-uri" class GitHub def self.fetch_repository(repo) begin res = open("https://api.github.com/repos/#{repo}")

    rescue return nil end Hashie::Mash.construct(JSON.parse(res.read)) end end @repository = GitHub.fetch_repository("remiprev/her") @repository.url # => "http://remiprev.github.com/her"
  5. class GitHub include HTTParty base_uri "https://api.github.com" def self.fetch_repository(repo) response =

    get("/repos/#{repo}") if response.success? Hashie::Mash.construct(JSON.parse(response.body)) else raise "Repository Not Found" end end end @repository = GitHub.fetch_repository("remiprev/her") @repository.url # => "http://remiprev.github.com/her"
  6. Her::API.setup :url => "https://api.github.com" do |c| c.use Her::Middleware::DefaultParseJSON c.use Faraday::Adapter::NetHttp

    end class Repo include Her::Model end @repository = Repo.find("remiprev/her") @repository.url # => "http://remiprev.github.com/her"
  7. class Repo include Her::Model def fresh? self.pushed_at > 1.week.ago end

    end @repository = Repo.find("remiprev/her") @repository.fresh? # => true
  8. • Associations/relations • APIs multiples • Hooks • Tests Autres

    fonctionnalités
  9. • Gestion des erreurs/exceptions • Mise en cache des objets

    À améliorer
  10. Merci! http://remiprev.github.com/her @remi