-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
309 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
0) exchange access_token for access token | ||
|
||
1) get user data | ||
* basic info | ||
* work info | ||
* education | ||
* interested in | ||
* meeting for | ||
2) annotate connections | ||
* friends | ||
* activities | ||
* interests | ||
* music | ||
* books | ||
* television | ||
1) make klass arg be a proc that can determine type of object (for page/user on posts) | ||
2) Handle paging in associations | ||
3) | ||
|
||
3) add things that require permission with exception if not granted | ||
|
||
|
||
allow embedding into other classes | ||
class User < ActiveRecord::Base | ||
acts_as_ogli :id=>:facebook_id,:class=>Ogli::User | ||
end | ||
|
||
allows user.facebook.activities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Action < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Ogli | ||
class Activity < Hashie::Mash | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Book < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ module User | |
|
||
|
||
def user(id) | ||
self.class.get(api_path(id)) | ||
get_and_map(id,Ogli::User) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Ogli | ||
class Comment < Hashie::Dash | ||
include Model | ||
|
||
define_properties :id, :message, :created_time | ||
|
||
hash_populating_accessor :from, "User" | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Interest < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Ogli | ||
module Model | ||
def client=(val) | ||
@client=val | ||
end | ||
|
||
def client | ||
@client || Ogli::Client.new | ||
end | ||
|
||
def initialize(hash={},client=nil) | ||
self.client=client | ||
super(hash) | ||
end | ||
|
||
def self.included(other) | ||
other.extend(ClassMethods) | ||
end | ||
|
||
|
||
module ClassMethods | ||
|
||
|
||
def define_properties(*args) | ||
args.each do |arg| | ||
property arg | ||
end | ||
end | ||
|
||
def hash_populating_accessor(name,klass) | ||
define_method "#{name}=" do |hash| | ||
instance_variable_set("@#{name}",client.map_data(hash,klass)) | ||
end | ||
define_method "#{name}" do | ||
instance_variable_get "@#{name}" | ||
end | ||
end | ||
|
||
def has_association(name,klass) | ||
define_method name do | ||
if (ret=instance_variable_get("@#{name}")).nil? | ||
ret = client.get_and_map("/#{id}/#{name}",klass) | ||
instance_variable_set("@#{name}",ret) | ||
end | ||
return ret | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Movie < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Music < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Ogli | ||
class Post < Hashie::Dash | ||
include Model | ||
define_properties :id, :to, :message, :picture, :link, :name, :caption, | ||
:description, :source, :icon, :attribution, :actions, :likes, | ||
:created_time, :updated_time | ||
|
||
hash_populating_accessor :actions, "Action" | ||
hash_populating_accessor :comments, "Comment" | ||
hash_populating_accessor :from, "User" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ogli | ||
class Television < Hashie::Mash | ||
include Model | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
|
||
module Ogli | ||
class User < Hashie::Mash | ||
include Model | ||
|
||
has_association :activities,Ogli::Activity | ||
has_association :friends, Ogli::User | ||
has_association :interests, Ogli::Interest | ||
has_association :music, Ogli::Music | ||
has_association :books, Ogli::Book | ||
has_association :movies, Ogli::Movie | ||
has_association :television, Ogli::Television | ||
has_association :posts, Ogli::Post | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require "spec_helper" | ||
describe Ogli::Client do | ||
|
||
let :client do | ||
Ogli::Client.new | ||
end | ||
|
||
|
||
describe "creation" do | ||
it "allows creating with an access_token" do | ||
client = Ogli::Client.new("myaccesstoken") | ||
client.access_token.should == "myaccesstoken" | ||
end | ||
|
||
it "sets the access_token into the default params" do | ||
client = Ogli::Client.new("myaccesstoken") | ||
client.default_params.should == {:access_token=>"myaccesstoken"} | ||
end | ||
|
||
it "allow creation with no access token" do | ||
client = Ogli::Client.new | ||
client.access_token.should be_nil | ||
end | ||
|
||
it "doesn't include the access_token param when not passed" do | ||
client = Ogli::Client.new | ||
client.default_params.should == {} | ||
end | ||
end | ||
|
||
describe "Making requests" do | ||
|
||
end | ||
|
||
describe "result mapping" do | ||
|
||
let :user_data do | ||
{"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" } | ||
end | ||
|
||
it "returns the raw value with no class specified" do | ||
client.map_data(user_data).should be_an_instance_of(Hash) | ||
end | ||
|
||
it "returns the array if no class is specified and there is only a data parameter" do | ||
client.map_data({"data"=>[user_data,user_data]}).should be_an_instance_of(Array) | ||
end | ||
|
||
|
||
it "creates an instance of the class when specified" do | ||
user = client.map_data(user_data,Ogli::User) | ||
user.should be_an_instance_of(Ogli::User) | ||
user.id.should == 12451752 | ||
end | ||
|
||
it "creates an array of instances when the data is an array" do | ||
users = client.map_data([user_data,user_data],Ogli::User) | ||
users.should be_an_instance_of(Array) | ||
users.each {|i| i.should be_an_instance_of(Ogli::User) } | ||
users.size.should == 2 | ||
end | ||
|
||
it "creates an array of instances when the data is just a hash with a single data parameter" do | ||
users = client.map_data({"data"=>[user_data,user_data]},Ogli::User) | ||
users.should be_an_instance_of(Array) | ||
users.each {|i| i.should be_an_instance_of(Ogli::User) } | ||
users.size.should == 2 | ||
end | ||
|
||
it "sets the client in the newly created instance" do | ||
user = client.map_data(user_data,Ogli::User) | ||
user.client.should == client | ||
end | ||
|
||
it "raises an exception when there is just an error" do | ||
lambda do | ||
client.map_data({"error"=>{"type"=>"OAuthAccessTokenException","message"=>"An access token is required to request this resource."}}) | ||
end.should raise_error | ||
end | ||
|
||
it "should set the message on the exception" do | ||
begin | ||
client.map_data({"error"=>{"type"=>"OAuthAccessTokenException","message"=>"An access token is required to request this resource."}}) | ||
fail "Exception not raised!" | ||
rescue Exception => e | ||
e.message.should == "OAuthAccessTokenException: An access token is required to request this resource." | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "spec_helper" | ||
|
||
describe Ogli::Post do | ||
|
||
it "populates from as the user from a hash" do | ||
post = Ogli::Post.new("from"=> {"id" => "12451752", "name" => "Mike Mangino"}) | ||
post.from.should be_an_instance_of(Ogli::User) | ||
post.from.id.should == "12451752" | ||
post.from.name.should == "Mike Mangino" | ||
end | ||
|
||
it "populates comments from a hash array" do | ||
post = Ogli::Post.new ({"comments"=>{"data"=>[{"id"=>1,"message"=>"message1"},{"id"=>2}]}},Ogli::Client.new("my_api_key")) | ||
post.comments.size.should == 2 | ||
post.comments.each {|c| c.should be_an_instance_of(Ogli::Comment)} | ||
post.comments.first.id.should == 1 | ||
post.comments.first.client.access_token.should == "my_api_key" | ||
end | ||
|
||
end |
Oops, something went wrong.