abhiyerra-refacebook 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +1 -7
- data/Rakefile +17 -6
- data/VERSION.yml +1 -1
- data/lib/refacebook.rb +26 -7
- data/spec/api_spec.rb +62 -0
- metadata +14 -4
- data/test/test_refacebook.rb +0 -8
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
|
18
|
-
|
19
|
-
|
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
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
|
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['
|
79
|
+
request['format'] = 'json' unless request['format']
|
73
80
|
request['method'] = method.to_s.gsub(/_/, '.')
|
74
|
-
request['session_key'] = @session_key if @
|
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
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abhiyerra-refacebook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhi Yerra
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-14 00:00:00 -07:00
|
13
13
|
default_executable: refacebook
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.1.3
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.4
|
34
|
+
version:
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: memcache-client
|
27
37
|
type: :runtime
|
@@ -50,7 +60,7 @@ files:
|
|
50
60
|
- examples/example.rb
|
51
61
|
- lib/refacebook.rb
|
52
62
|
- lib/refacebook/sinatra.rb
|
53
|
-
-
|
63
|
+
- spec/api_spec.rb
|
54
64
|
has_rdoc: true
|
55
65
|
homepage: http://github.com/abhiyerra/refacebook
|
56
66
|
post_install_message:
|
@@ -78,5 +88,5 @@ signing_key:
|
|
78
88
|
specification_version: 2
|
79
89
|
summary: ReFacebook is a facebook library and Sinatra extension.
|
80
90
|
test_files:
|
81
|
-
-
|
91
|
+
- spec/api_spec.rb
|
82
92
|
- examples/example.rb
|