Sha256: 4cd172443ba3049e20a400fb41035249f3fa50f203bd2fb1652741288336f442
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
require 'hyperclient' class HalShop include Hyperclient entry_point 'http://hal-shop.heroku.com' http_options debug: true end def print_resources(resources) resources.each do |resource| if resource.is_a?(Array) print_resources(resource) else puts %{Found "#{resource.name}" at "#{resource.url}" } end end end def print_attributes(attributes) puts "-----------------------------" attributes.each do |attribute, value| puts %{#{attribute}: #{value}} end end api = HalShop.new puts "Let's inspect the API:" puts "\n" puts 'Links from the entry point:' print_resources(api.links) puts puts 'Resources at the entry point:' print_resources(api.embedded) puts puts "Let's see what stats we have:" print_attributes(api.embedded.stats.attributes) products = api.links["http://hal-shop.heroku.com/rels/products"].reload puts puts "And what's the inventory of products?" puts products.attributes['inventory_size'] puts puts 'What resources does products have?' print_resources(products.embedded.products) puts puts 'And links?' print_resources(products.links) puts puts 'Attributes of the first product?' print_attributes(products.embedded.products.first.attributes)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hyperclient-0.0.8 | examples/hal_shop.rb |
hyperclient-0.0.7 | examples/hal_shop.rb |