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

Her

 Her

I presented Her at OpenCode #5.

Rémi Prévost

July 17, 2012
Tweet

More Decks by Rémi Prévost

Other Decks in Technology

Transcript

  1. “ 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.
  2. 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"
  3. 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"
  4. 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"
  5. class Repo include Her::Model def fresh? self.pushed_at > 1.week.ago end

    end @repository = Repo.find("remiprev/her") @repository.fresh? # => true