forked from mmangino/mogli
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beginning of code to make and parse responses
- Loading branch information
Showing
8 changed files
with
106 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 | ||
|
||
3) add things that require permission with exception if not granted |
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,3 @@ | ||
require "httparty" | ||
require "hashie" | ||
require "ogli" |
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 | ||
|
||
end | ||
|
||
require "ogli/user" | ||
require "ogli/client" |
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,53 @@ | ||
require "ogli/client/user" | ||
|
||
module Ogli | ||
class Client | ||
attr_reader :access_token | ||
attr_reader :default_params | ||
|
||
def api_path(path) | ||
"http://graph.facebook.com/#{path}" | ||
end | ||
|
||
def initialize(access_token = nil) | ||
@access_token = access_token | ||
@default_params = @access_token ? {:access_token=>access_token} : {} | ||
end | ||
|
||
def map_data(data,klass=nil) | ||
raise_error_if_necessary(data) | ||
hash_or_array = extract_hash_or_array(data) | ||
hash_or_array = map_to_class(hash_or_array,klass) if klass | ||
hash_or_array | ||
end | ||
|
||
include HTTParty | ||
include User | ||
|
||
protected | ||
|
||
def extract_hash_or_array(hash_or_array) | ||
return hash_or_array if hash_or_array.kind_of?(Array) | ||
return hash_or_array["data"] if hash_or_array.keys.size == 1 and hash_or_array.has_key?("data") | ||
return hash_or_array | ||
end | ||
|
||
def map_to_class(hash_or_array,klass) | ||
if hash_or_array.kind_of?(Array) | ||
hash_or_array = hash_or_array.map {|i| klass.new(i)} | ||
else | ||
hash_or_array = klass.new(hash_or_array) | ||
end | ||
end | ||
|
||
def raise_error_if_necessary(data) | ||
if data.kind_of?(Hash) | ||
if data.keys.size == 1 and data["error"] | ||
type = data["error"]["type"] | ||
message = data["error"]["message"] | ||
raise Exception.new("#{type}: #{message}") | ||
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,11 @@ | ||
module Ogli | ||
class Client | ||
module User | ||
|
||
|
||
def user(id) | ||
self.class.get(api_path(id)) | ||
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,5 @@ | ||
module Ogli | ||
class User < 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,9 @@ | ||
require "spec_helper" | ||
describe Ogli::Client do | ||
let :client do | ||
Ogli::Client.new | ||
end | ||
# it "fetches a user by id" do | ||
# client.user(12451752).should == {:id=>12451752} | ||
# 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,2 @@ | ||
require "rubygems" | ||
require (Pathname(__FILE__).dirname + '../init') |