From e5590bc64b71d676470e4f1ba322b09d9b65981c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Va=CC=88nska=CC=88?= Date: Sun, 24 Mar 2013 11:41:12 +0200 Subject: [PATCH] Adds getting user of a clip Updates clip.json fixture to reflect the current data model. --- TODO.md | 3 ++- lib/kippt/clip.rb | 4 +++- lib/kippt/resource.rb | 10 +++++++++- spec/fixtures/clip.json | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 7a3f994..2348dce 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,8 @@ # Clip * [DONE] Getting the feed of authenticated user -* Getting the user of the clip +* [DONE] Getting the user of the clip +* Support for including list & via data * Getting the list of the clip * Getting the original clip the clip was created via * Getting the comments, likes & saves of a clip diff --git a/lib/kippt/clip.rb b/lib/kippt/clip.rb index cb7d44d..d458107 100644 --- a/lib/kippt/clip.rb +++ b/lib/kippt/clip.rb @@ -1,11 +1,13 @@ require "ostruct" require "kippt/resource" +require "kippt/user" class Kippt::Clip include Kippt::Resource attributes :url_domain, :updated, :is_starred, :title, - :url, :notes, :created, :list, :id, :resource_uri + :url, :notes, :created, :list, :id, :resource_uri, + :user => Kippt::User writable_attributes :is_starred, :title, :url, :notes, :list end diff --git a/lib/kippt/resource.rb b/lib/kippt/resource.rb index b5321a2..1024601 100644 --- a/lib/kippt/resource.rb +++ b/lib/kippt/resource.rb @@ -15,8 +15,16 @@ module ClassMethods def attributes(*attribs) @attribute_names ||= [] - @attribute_names += attribs.map {|attrib| attrib.to_sym } + hashes, other = attribs.partition {|attrib| attrib.is_a? Hash } + hashes = hashes.reduce({}, :update) + @attribute_names += other.map {|attrib| attrib.to_sym } def_delegators :attributes, *@attribute_names + @attribute_names += hashes.keys.map {|attrib| attrib.to_sym } + hashes.each do |attrib, object_class| + define_method(attrib) do + object_class.new(attributes.send(attrib)) + end + end end def boolean_attributes(*attribs) diff --git a/spec/fixtures/clip.json b/spec/fixtures/clip.json index cf44075..1264c53 100644 --- a/spec/fixtures/clip.json +++ b/spec/fixtures/clip.json @@ -1 +1 @@ -{"url_domain": "karrisaarinen.com", "updated": "1335090586", "is_starred": false, "title": "Karri Saarinen", "url": "http://karrisaarinen.com/", "notes": "My favorite designer-bro.", "created": "1335090567", "list": "/api/lists/44525/", "id": 10, "resource_uri": "/api/clips/10/"} +{"via": null, "saves": {"count": 0, "data": []}, "favicon_url": "https://www.google.com/s2/u/0/favicons?domain=karrisaarinen.com", "is_favorite": false, "likes": {"count": 0, "data": []}, "app_url": "/vesan/inspiration/clips/10", "title": "Karri Saarinen", "media": {"description": "We had a talk recently at Slush 2012 startup conference about how we're building Kippt with hacking design and generally being nice guys. Zen and the Art of Motorcycle Maintenance is one of my favorite books. It's a bestseller, but I think it's a great journey into the philosophy of science and art, and the metaphysics of quality.", "title": "Karri Saarinen", "provider": {"url": "https://kippt.com", "name": "Kippt"}, "images": {"tile": {"url": "https://d19weqihs4yh5u.cloudfront.net/links/3bcb19bd1912598f244b289c42647e2eba790636/350x200", "width": 350, "height": 200}, "original": {"url": "https://d19weqihs4yh5u.cloudfront.net/links/3bcb19bd1912598f244b289c42647e2eba790636/original", "width": 600, "height": 257}}, "article": {"html": "", "author_url": null, "author": null}, "type": "article"}, "is_read_later": false, "comments": {"count": 0, "data": []}, "id": 10, "type": "link", "updated": 1361128164, "user": {"username": "vesan", "bio": "Ruby developer at Kisko Labs. Dangerous, but not foolish.", "app_url": "/vesan", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/3b2958fd-db1d-4b80-acd1-d7e344fe5124/160x160", "twitter": "vesan", "id": 33, "github": "vesan", "website_url": "http://vesavanska.com/", "full_name": "Vesa V\u00e4nsk\u00e4", "dribbble": "vesan", "counts": {"follows": 21, "followed_by": 26}, "is_pro": true, "resource_uri": "/api/users/33/"}, "article": null, "is_starred": false, "url_domain": "karrisaarinen.com", "created": 1335097767, "url": "http://karrisaarinen.com/", "notes": "Cool site, bro #karri", "list": {"app_url": "/vesan/inspiration", "rss_url": "https://kippt.com/vesan/inspiration/feed/ef6bc29ac10dce9ccfbc30c94b613d5f", "updated": 1355490811, "description": "", "title": "Inspiration!", "created": 1335072037, "collaborators": {"count": 0, "data": []}, "slug": "inspiration", "user": {"username": "vesan", "bio": "Ruby developer at Kisko Labs. Dangerous, but not foolish.", "app_url": "/vesan", "twitter": "vesan", "counts": {"follows": 21, "followed_by": 26}, "github": "vesan", "avatar_url": "https://d19weqihs4yh5u.cloudfront.net/avatars/3b2958fd-db1d-4b80-acd1-d7e344fe5124/160x160", "is_pro": true, "full_name": "Vesa V\u00e4nsk\u00e4", "dribbble": "vesan", "id": 33, "website_url": "http://vesavanska.com/", "resource_uri": "/api/users/33/"}, "id": 44525, "is_private": true, "resource_uri": "/api/lists/44525/"}, "resource_uri": "/api/clips/10/"}