graph-api 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,16 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graph-api (0.9.2)
4
+ graph-api (0.9.5)
5
5
  json
6
6
  rake
7
+ rest-client
7
8
 
8
9
  GEM
9
10
  remote: http://rubygems.org/
10
11
  specs:
11
12
  diff-lcs (1.1.3)
12
13
  json (1.7.5)
14
+ mime-types (1.19)
13
15
  rake (0.9.2.2)
16
+ rest-client (1.6.7)
17
+ mime-types (>= 1.16)
14
18
  rspec (2.11.0)
15
19
  rspec-core (~> 2.11.0)
16
20
  rspec-expectations (~> 2.11.0)
data/graph_api.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.add_dependency('rake')
16
16
  gem.add_dependency('json')
17
+ gem.add_dependency('rest-client')
17
18
  gem.add_development_dependency('rspec')
18
19
 
19
20
  gem.files = `git ls-files`.split($/)
data/lib/graph_api.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'json'
2
+ require 'rest_client'
3
+
2
4
  # Public: Various methods useful for interfacing with Facebook Graph protocol.
3
5
  #
4
6
  # Example:
@@ -51,9 +53,9 @@ module GraphAPI
51
53
  # GraphAPI.config APP_SECRET: '124ca2a483f12723cafa7a5da33a3492',
52
54
  # CLIENT_ID: '234513432316919'
53
55
  #
54
- def self.config(consts)
56
+ def config(consts)
55
57
  consts.each do |const, value|
56
- self.const_set(const.to_s, value)
58
+ const_set(const.to_s, value)
57
59
  end
58
60
  end
59
61
 
@@ -62,7 +64,7 @@ module GraphAPI
62
64
  # callback_url - With CALLBACK_URL set to nil setting this parameter will use
63
65
  # the sent callback. This is useful when you're using dynamic
64
66
  # URIs with subdomains.
65
- def self.auth_url(callback_url=nil)
67
+ def auth_url(callback_url=nil)
66
68
  "https://graph.facebook.com/oauth/authorize?client_id=#{CLIENT_ID}" +
67
69
  "&redirect_uri=#{CALLBACK_URL or callback_url}" +
68
70
  "&scope=#{ACCESS_SCOPE.join(',')}"
@@ -76,7 +78,7 @@ module GraphAPI
76
78
  # callback_url - With CALLBACK_URL set to nil setting this parameter will use
77
79
  # the sent callback. This is useful when you're using dynamic
78
80
  # URIs with subdomains.
79
- def self.fetch_token(code, callback_url=nil)
81
+ def fetch_token(code, callback_url=nil)
80
82
  RestClient.get('https://graph.facebook.com/oauth/access_token', { client_id: CLIENT_ID,
81
83
  redirect_uri: (CALLBACK_URL or callback_url),
82
84
  client_secret: APP_SECRET,
@@ -90,13 +92,13 @@ module GraphAPI
90
92
  # access_token - The access token required for making the request on the Facebook users behalf.
91
93
  #
92
94
  # Returns a parsed JSON array returned from the Facebook service with a format like ['example' => 'some_data'].
93
- def self.request(url, access_token)
95
+ def request(url, access_token)
94
96
  JSON.parse(RestClient.get "https://graph.facebook.com#{url}&access_token=#{access_token}")
95
97
  end
96
98
 
97
99
  # Public: Returns a Facebook user array containing the fields set by the
98
100
  # USER_FIELDS constant and the access token for convenience.
99
- def self.request_user(access_token)
101
+ def request_user(access_token)
100
102
  request("/me?&fields=#{USER_FIELDS.join(',')}", access_token).
101
103
  merge('access_token' => access_token)
102
104
  end
@@ -107,7 +109,7 @@ module GraphAPI
107
109
  # callback_url - With CALLBACK_URL set to nil setting this parameter will use
108
110
  # the sent callback. This is useful when you're using dynamic
109
111
  # URIs with subdomains.
110
- def self.fetch_user(code, callback_url=nil)
112
+ def fetch_user(code, callback_url=nil)
111
113
  access_token = fetch_token(code, callback_url)
112
114
  request_user(access_token)
113
115
  end
@@ -115,7 +117,7 @@ module GraphAPI
115
117
  # Public: Fetches and returns the cover photo src for a Facebook user.
116
118
  #
117
119
  # access_token - This method requires an Facebook Authentication token.
118
- def self.fetch_photo(access_token)
120
+ def fetch_photo(access_token)
119
121
  albums = request('/me/albums?fields=id,cover_photo,type', access_token)['data']
120
122
  photo_id = albums.find{|x| x['type'] == 'profile'}['cover_photo']
121
123
  request("/#{photo_id}/?fields=source", access_token)['source']
@@ -124,7 +126,9 @@ module GraphAPI
124
126
  # Public: Fetches and returns the current thumbnail src for a Facebook user.
125
127
  #
126
128
  # access_token - This method requires an Facebook Authentication token.
127
- def self.fetch_thumbnail(access_token)
129
+ def fetch_thumbnail(access_token)
128
130
  request('/me?fields=picture', access_token)['picture']
129
131
  end
132
+
133
+ extend self
130
134
  end
@@ -1,3 +1,3 @@
1
1
  module GraphAPI
2
- VERSION = '0.9.4'
2
+ VERSION = '0.9.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec
48
64
  requirement: !ruby/object:Gem::Requirement