fbgraph 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/README.textile CHANGED
@@ -1,4 +1,4 @@
1
- h2. FBGRaph (0.0.8)
1
+ h2. FBGRaph (0.1.1)
2
2
 
3
3
  p. Facebook Open Graph API Gem.
4
4
 
@@ -230,4 +230,5 @@ h2. Contributors
230
230
 
231
231
  "Mark Bates":http://github.com/markbates
232
232
 
233
+ "Florent Guilleux":http://github.com/Florent2
233
234
 
data/Rakefile CHANGED
@@ -2,14 +2,14 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('fbgraph', '0.1.1') do |p|
5
+ Echoe.new('fbgraph', '0.1.4') do |p|
6
6
  p.description = "A Gem for Facebook Open Graph API"
7
7
  p.url = "http://github.com/nsanta/fbgraph"
8
8
  p.author = "Nicolas Santa"
9
9
  p.email = "nicolas55ar@gmail.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
11
  p.development_dependencies = ['echoe', 'rspec']
12
- p.runtime_dependencies = ['oauth2' , 'json', 'hashie']
12
+ p.runtime_dependencies = ['oauth2' , 'json', 'hashie' , 'rest-client']
13
13
  end
14
14
 
15
15
  Spec::Rake::SpecTask.new(:rspec) do |t|
data/fbgraph.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fbgraph}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Nicolas Santa"]
@@ -28,12 +28,14 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency(%q<oauth2>, [">= 0"])
29
29
  s.add_runtime_dependency(%q<json>, [">= 0"])
30
30
  s.add_runtime_dependency(%q<hashie>, [">= 0"])
31
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
31
32
  s.add_development_dependency(%q<echoe>, [">= 0"])
32
33
  s.add_development_dependency(%q<rspec>, [">= 0"])
33
34
  else
34
35
  s.add_dependency(%q<oauth2>, [">= 0"])
35
36
  s.add_dependency(%q<json>, [">= 0"])
36
37
  s.add_dependency(%q<hashie>, [">= 0"])
38
+ s.add_dependency(%q<rest-client>, [">= 0"])
37
39
  s.add_dependency(%q<echoe>, [">= 0"])
38
40
  s.add_dependency(%q<rspec>, [">= 0"])
39
41
  end
@@ -41,6 +43,7 @@ Gem::Specification.new do |s|
41
43
  s.add_dependency(%q<oauth2>, [">= 0"])
42
44
  s.add_dependency(%q<json>, [">= 0"])
43
45
  s.add_dependency(%q<hashie>, [">= 0"])
46
+ s.add_dependency(%q<rest-client>, [">= 0"])
44
47
  s.add_dependency(%q<echoe>, [">= 0"])
45
48
  s.add_dependency(%q<rspec>, [">= 0"])
46
49
  end
data/lib/fbgraph.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'oauth2'
2
2
  require 'json'
3
3
  require 'hashie'
4
+ require 'rest_client'
5
+ require 'uri'
4
6
 
5
7
 
6
8
  require 'fbgraph/client'
@@ -12,8 +12,8 @@ module FBGraph
12
12
 
13
13
 
14
14
  def process_callback(code, options = {})
15
- @client.consumer = @client.oauth_client.web_server.get_access_token(code, options)
16
- @client.access_token = @client.consumer.token
15
+ @client.auth = @client.oauth_client.web_server.get_access_token(code, options)
16
+ @client.access_token = @client.auth.token
17
17
  end
18
18
 
19
19
  end
data/lib/fbgraph/base.rb CHANGED
@@ -2,7 +2,7 @@ module FBGraph
2
2
 
3
3
  class Base
4
4
 
5
- attr_reader :objects , :connection_type
5
+ attr_reader :objects , :connection_type , :logger
6
6
 
7
7
  def initialize(client)
8
8
  @client = client
@@ -39,28 +39,29 @@ module FBGraph
39
39
  def info!(parsed = true)
40
40
  if @objects.is_a? Array
41
41
  @params.merge!({:ids => @objects.join(',')})
42
- uri = build_open_graph_path(nil,nil, @params)
42
+ path = build_open_graph_path(nil,nil, @params)
43
43
  elsif @objects.is_a? String
44
- uri = build_open_graph_path(@objects , @connection_type, @params)
44
+ path = build_open_graph_path(@objects , @connection_type, @params)
45
45
  end
46
- puts "FBGRAPH [GET]: #{uri}"
47
- result = @client.consumer.get(uri)
46
+ puts "FBGRAPH [GET]: #{path}"
47
+ puts "ACCESS TOKEN: #{@client.access_token}"
48
+ result = @client.consumer[path].get
48
49
  return parse_json(result, parsed)
49
50
  end
50
51
 
51
52
 
52
53
  def publish!(data = {},parsed = true)
53
54
  @params.merge!(data)
54
- uri = build_open_graph_path(@objects , @connection_type)
55
- puts "FBGRAPH [POST]: #{uri}"
56
- result = @client.consumer.post(uri , @params , multipart_header)
55
+ path = build_open_graph_path(@objects , @connection_type)
56
+ puts "FBGRAPH [POST]: #{path}"
57
+ result = @client.consumer[path].post(@params)
57
58
  return parse_json(result, parsed)
58
59
  end
59
60
 
60
61
  def delete!(parsed = true)
61
- uri = build_open_graph_path(@objects , nil)
62
- puts "FBGRAPH [DELETE]: #{uri}"
63
- result = @client.consumer.delete(uri , @params)
62
+ path = build_open_graph_path(@objects , nil)
63
+ puts "FBGRAPH [DELETE]: #{path}"
64
+ result = @client.consumer[path].post(@params.merge(:method => :delete))
64
65
  return parse_json(result, parsed)
65
66
  end
66
67
 
@@ -77,24 +78,16 @@ module FBGraph
77
78
  private
78
79
 
79
80
  def parse_json(result, parsed)
80
- return parsed ? Hashie::Mash.new(JSON.parse(result)) : result
81
+ return parsed ? Hashie::Mash.new(JSON.parse(result.body)) : result.body
81
82
  end
82
83
 
84
+
85
+
83
86
  def build_open_graph_path(objects,connection_type = nil , params = {})
84
- request = "/" + [objects , connection_type].compact.join('/')
87
+ params.merge!(:access_token => @client.access_token)
88
+ request = [objects , connection_type].compact.join('/')
85
89
  request += "?"+params.to_a.map{|p| p.join('=')}.join('&') unless params.empty?
86
- request
87
- end
88
-
89
- def multipart_header
90
- if multipart?
91
- header = {"Content-Disposition" => "form-data", "name" => "control-name"}
92
- end
93
- header || {}
94
- end
95
-
96
- def multipart?
97
- %w(photos).include?(@connection_type) || %w(photo post).include?(@objects)
90
+ URI.encode(request)
98
91
  end
99
92
 
100
93
  end
@@ -1,15 +1,15 @@
1
1
  module FBGraph
2
2
 
3
3
  class Client
4
- attr_accessor :client_id , :secret_id , :facebook_uri , :access_token , :consumer
4
+ attr_accessor :client_id , :secret_id , :facebook_uri , :access_token , :consumer , :auth
5
5
 
6
6
 
7
7
  def initialize(options)
8
- self.client_id , self.secret_id = options[:client_id] , options[:secret_id]
8
+ @client_id , @secret_id = options[:client_id] , options[:secret_id]
9
9
  @facebook_uri = 'https://graph.facebook.com'
10
- if self.access_token = options[:token]
11
- self.consumer = OAuth2::AccessToken.new(oauth_client , self.access_token)
12
- end
10
+ @access_token = options[:token]
11
+ @consumer = RestClient::Resource.new(@facebook_uri)
12
+ @auth = OAuth2::AccessToken.new(oauth_client , @access_token)
13
13
  return true
14
14
  end
15
15
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nicolas Santa
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :runtime
76
76
  version_requirements: *id003
77
77
  - !ruby/object:Gem::Dependency
78
- name: echoe
78
+ name: rest-client
79
79
  prerelease: false
80
80
  requirement: &id004 !ruby/object:Gem::Requirement
81
81
  requirements:
@@ -84,10 +84,10 @@ dependencies:
84
84
  segments:
85
85
  - 0
86
86
  version: "0"
87
- type: :development
87
+ type: :runtime
88
88
  version_requirements: *id004
89
89
  - !ruby/object:Gem::Dependency
90
- name: rspec
90
+ name: echoe
91
91
  prerelease: false
92
92
  requirement: &id005 !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -98,6 +98,18 @@ dependencies:
98
98
  version: "0"
99
99
  type: :development
100
100
  version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ version_requirements: *id006
101
113
  description: A Gem for Facebook Open Graph API
102
114
  email: nicolas55ar@gmail.com
103
115
  executables: []
metadata.gz.sig CHANGED
Binary file