refacebook 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.txt CHANGED
@@ -10,15 +10,9 @@ ReFacebook is a facebook library and Sinatra extension.
10
10
 
11
11
  * Need to document the code.
12
12
  * Need helpers to make life easier.
13
- * Abstract the session store so it's not reliant on the set and get. Also,
14
- remove the :store option eventually since that seems like a copout method
15
- and doesn't add simplicity.
16
- * Make the api spit out an exception if call returns error.
17
13
  * Have a better example application with fbml, api, and all that good stuff.
18
- * Write unit tests
19
14
  * Test with ruby 1.9, remove json dep if 1.9 since json is included.
20
15
 
21
-
22
16
  == SYNOPSIS:
23
17
 
24
18
  To see how to use the library please look at examples/example.rb
@@ -26,7 +20,7 @@ To see how to use the library please look at examples/example.rb
26
20
  == REQUIREMENTS:
27
21
 
28
22
  RubyGems
29
- * json
23
+ * json or json-jruby
30
24
  * memcache-client
31
25
 
32
26
  == INSTALL:
data/Rakefile CHANGED
@@ -3,6 +3,14 @@
3
3
  require 'rubygems'
4
4
  require './lib/refacebook.rb'
5
5
 
6
+ begin
7
+ require 'spec/rake/spectask'
8
+ rescue LoadError
9
+ puts 'To use rspec for testing you must install rspec gem:'
10
+ puts '$ sudo gem install rspec'
11
+ exit
12
+ end
13
+
6
14
  begin
7
15
  require 'jeweler'
8
16
  Jeweler::Tasks.new do |gemspec|
@@ -14,12 +22,9 @@ begin
14
22
  gemspec.authors = ["Abhi Yerra"]
15
23
  gemspec.rubyforge_project = "refacebook"
16
24
 
17
- if defined?(JRUBY_VERSION)
18
- gemspec.add_dependency("json-jruby", [">= 1.1.3"])
19
- else
20
- gemspec.add_dependency("json", [">= 1.1.4"])
21
- end
22
-
25
+ # Should use json-jruby if using JRuby
26
+ gemspec.add_dependency("json-jruby", [">= 1.1.3"])
27
+ gemspec.add_dependency("json", [">= 1.1.4"])
23
28
  gemspec.add_dependency("memcache-client", [">= 1.7.1"])
24
29
  end
25
30
  rescue LoadError
@@ -52,4 +57,10 @@ rescue LoadError
52
57
  puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
53
58
  end
54
59
 
60
+ desc "Runnings the specs"
61
+ Spec::Rake::SpecTask.new do |t|
62
+ t.spec_files = FileList['spec/**/*_spec.rb']
63
+ end
64
+
65
+ task :default => :spec
55
66
  # vim: syntax=Ruby
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 4
3
3
  :major: 0
4
- :patch: 1
4
+ :patch: 2
data/lib/refacebook.rb CHANGED
@@ -63,24 +63,34 @@ module ReFacebook
63
63
  @session_key = nil
64
64
  end
65
65
 
66
+ # FIXME: Implement.
67
+ def batch_run *args
68
+ raise
69
+ end
70
+
66
71
  def method_missing method, *args
67
72
  request = {}
68
73
 
69
- args[0].each {|k,v| request[k.to_s] = v } if args[0]
74
+ args[0].each do |k,v|
75
+ request[k.to_s] = v.kind_of?(Array) ? v.to_json : v
76
+ end if args[0]
70
77
 
71
78
  request['api_key'] = @api_key
72
- request['format'] = 'json' unless request['json']
79
+ request['format'] = 'json' unless request['format']
73
80
  request['method'] = method.to_s.gsub(/_/, '.')
74
- request['session_key'] = @session_key if @session
81
+ request['session_key'] = @session_key if @session_key
75
82
  request['v'] = '1.0' unless request['v']
76
83
 
77
84
  request['sig'] = generate_sig(request.sort)
78
85
 
79
- # FIXME: Implement.
80
- return if request['method'].eql? 'batch.run'
81
-
82
86
  req = Net::HTTP.post_form(URI.parse(APIRestServer), request)
83
- JSON.parse("[#{req.body}]")
87
+ ret = JSON.parse("[#{req.body}]")[0]
88
+
89
+ if ret.class == Hash && ret.has_key?('error_code')
90
+ raise APIError.new(ret), ret['error_msg']
91
+ end
92
+
93
+ ret
84
94
  end
85
95
 
86
96
  private
@@ -93,4 +103,13 @@ module ReFacebook
93
103
  MD5.hexdigest(request_str.concat(@secret));
94
104
  end
95
105
  end
106
+
107
+ class APIError < StandardError
108
+ attr_reader :error_code, :error_msg
109
+
110
+ def initialize(response)
111
+ @error_code = response['error_code']
112
+ @error_msg = response['error_msg']
113
+ end
114
+ end
96
115
  end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,62 @@
1
+ $:.push('lib/')
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require "refacebook"
6
+
7
+ describe ReFacebook::API do
8
+ before(:each) do
9
+ @api = ReFacebook::API.new('2a7a86cd4ea39bb7ea4eaabb938acb86', '662361041ddcb4b3f7df0f4b092249ee')
10
+
11
+ violated "api was not created" unless @api
12
+ end
13
+
14
+ it "does a sample call without parameter" do
15
+ begin
16
+ token = @api.auth_createToken
17
+ token.class.should == String
18
+ rescue ReFacebook::APIError => e
19
+ violated "failed with #{e.error_code}: #{e.error_msg}"
20
+ end
21
+ end
22
+
23
+ it "does a sample call with parameter" do
24
+ begin
25
+ app_properties = @api.admin_getAppProperties :properties => ['application_name','callback_url']
26
+ app_properties = JSON.parse(app_properties)
27
+ app_properties['application_name'].should == 'traytwo'
28
+ rescue ReFacebook::APIError => e
29
+ violated "failed with #{e.error_code}: #{e.error_msg}"
30
+ end
31
+ end
32
+
33
+ it "does a call with an incorrect api key" do
34
+ # Bad secret key
35
+ @api = ReFacebook::API.new('2a7a86cd4ea39bb7ea4eaabb938acb8', '662361041ddcb4b3f7df0f4b092249ee')
36
+ begin
37
+ token = @api.auth_createToken
38
+ violated "api did not throw error"
39
+ rescue ReFacebook::APIError => e
40
+ e.error_code.should == 101
41
+ end
42
+ end
43
+
44
+ it "does a call with an incorrect secret key" do
45
+ # Bad secret key
46
+ @api = ReFacebook::API.new('2a7a86cd4ea39bb7ea4eaabb938acb86', '662361041ddcb4b3f7df0f4b092249e')
47
+ begin
48
+ token = @api.auth_createToken
49
+ violated "api did not throw error"
50
+ rescue ReFacebook::APIError => e
51
+ e.error_code.should == 104
52
+ end
53
+ end
54
+
55
+ it "does a batch.run" do
56
+ # violated "not implemented yet"
57
+ end
58
+
59
+ it "creates a session" do
60
+ # violated "not implemented yet"
61
+ end
62
+ end
metadata CHANGED
@@ -34,7 +34,7 @@ files:
34
34
  - examples/example.rb
35
35
  - lib/refacebook.rb
36
36
  - lib/refacebook/sinatra.rb
37
- - test/test_refacebook.rb
37
+ - spec/api_spec.rb
38
38
  required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '>='
@@ -48,13 +48,13 @@ requirements: []
48
48
 
49
49
  authors:
50
50
  - Abhi Yerra
51
- date: 2009-04-13 00:00:00 Z
51
+ date: 2009-04-14 00:00:00 Z
52
52
  platform: ruby
53
53
  test_files:
54
- - test/test_refacebook.rb
54
+ - spec/api_spec.rb
55
55
  - examples/example.rb
56
56
  version: !ruby/object:Gem::Version
57
- version: 0.4.1
57
+ version: 0.4.2
58
58
  require_paths:
59
59
  - lib
60
60
  dependencies:
@@ -68,6 +68,16 @@ dependencies:
68
68
  type: :runtime
69
69
  version_requirement:
70
70
  name: json-jruby
71
+ - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.1.4
77
+ version:
78
+ type: :runtime
79
+ version_requirement:
80
+ name: json
71
81
  - !ruby/object:Gem::Dependency
72
82
  version_requirements: !ruby/object:Gem::Requirement
73
83
  requirements:
@@ -1,8 +0,0 @@
1
- require "test/unit"
2
- require "refacebook"
3
-
4
- class TestRefacebook < Test::Unit::TestCase
5
- def test_sanity
6
- flunk "write tests or I will kneecap you"
7
- end
8
- end