Skip to content

Commit

Permalink
Handle nil objects and creation of events. Allow specifying fields to…
Browse files Browse the repository at this point in the history
… fetch
  • Loading branch information
mmangino committed May 26, 2010
1 parent 9d7aa16 commit d81103d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/mogli/client.rb
Expand Up @@ -67,6 +67,7 @@ def map_data(data,klass=nil)
#protected

def extract_hash_or_array(hash_or_array,klass)
return nil if hash_or_array == false
return hash_or_array if hash_or_array.nil? or hash_or_array.kind_of?(Array)
return extract_fetching_array(hash_or_array,klass) if hash_or_array.has_key?("data")
return hash_or_array
Expand All @@ -85,6 +86,7 @@ def extract_fetching_array(hash,klass)
end

def map_to_class(hash_or_array,klass)
return nil if hash_or_array.nil?
if hash_or_array.kind_of?(Array)
hash_or_array.map! {|i| create_instance(klass,i)}
else
Expand Down
1 change: 1 addition & 0 deletions lib/mogli/event.rb
@@ -1,6 +1,7 @@
module Mogli
class Event < Model
define_properties :id, :name, :description, :start_time, :end_time, :location, :privacy, :updated_time
creation_properties :start_time, :end_time, :link, :name, :description, :privacy

hash_populating_accessor :venue, "Address"
hash_populating_accessor :owner, "User", "Page"
Expand Down
2 changes: 1 addition & 1 deletion mogli.gemspec
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = 'mogli'
s.version = '0.0.8'
s.version = '0.0.9'
s.summary = "Open Graph Library for Ruby"
s.description = %{Simple library for accessing the facebook Open Graph API}
s.files = Dir['lib/**/*.rb']
Expand Down
6 changes: 6 additions & 0 deletions spec/client_spec.rb
Expand Up @@ -68,6 +68,7 @@
result = client.post("1/feed","Post",:message=>"message")
end.should raise_error
end

it "creates objects of the returned type" do
Mogli::Client.should_receive(:post).and_return({:id=>123434})
client = Mogli::Client.new("1234")
Expand Down Expand Up @@ -147,6 +148,11 @@
user.client.should == client
end

it "returns nil if Facebook says false" do
Mogli::Client.should_receive(:get).and_return(false)
client.get_and_map(148800401968,"User").should be_nil
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."}})
Expand Down

0 comments on commit d81103d

Please sign in to comment.