rfql 0.1.alpha.4 → 0.1.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +2 -0
- data/lib/rfql.rb +1 -1
- data/lib/rfql/request.rb +20 -15
- data/lib/rfql/response.rb +19 -13
- data/lib/rfql/response/fql_error.rb +8 -3
- data/lib/rfql/response/json.rb +9 -5
- data/lib/rfql/response/json/parsed.rb +14 -12
- data/lib/rfql/response/json/parsed/error.rb +10 -10
- data/lib/rfql/response/json/parsed/records.rb +3 -3
- data/lib/rfql/response/json/raw.rb +2 -3
- data/rfql.gemspec +3 -3
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
data/lib/rfql.rb
CHANGED
data/lib/rfql/request.rb
CHANGED
@@ -47,37 +47,42 @@ module RFQL
|
|
47
47
|
end.join('&')
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def response(json_format = :parsed, options = {})
|
51
51
|
begin
|
52
|
-
|
52
|
+
response!(json_format, options)
|
53
53
|
rescue RFQL::Response::FQLError
|
54
54
|
nil
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
#
|
59
|
-
|
58
|
+
# Examples:
|
59
|
+
# RFQL.request.select('aid, owner, name, object_id').from('album').where(:aid => "20531316728_324257").response
|
60
|
+
# RFQL.request.query('SELECT aid, owner, name, object_id FROM album WHERE aid="20531316728_324257"').response
|
61
|
+
def response!(json_format = :parsed, options = {})
|
60
62
|
raise ArgumentError, "illegal format" unless [:raw, :parsed].include?(json_format)
|
63
|
+
|
61
64
|
unless options.is_a?(Hash) and (options.keys - [:open_uri_options, :json_parse_options, :force_execution]).blank?
|
62
65
|
raise ArgumentError, "illegal options"
|
63
66
|
end
|
64
67
|
|
65
|
-
if options.delete(:force_execution)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
return @response
|
68
|
+
if not options.delete(:force_execution) and @cached_response
|
69
|
+
case json_format
|
70
|
+
when :raw then return @cached_response.raw
|
71
|
+
when :parsed then return @cached_response
|
72
|
+
end
|
71
73
|
end
|
72
74
|
|
73
|
-
json_parse_opts
|
74
|
-
open_uri_read_opts = options[:open_uri_options]
|
75
|
+
json_parse_opts = options[:json_parse_options] || {}
|
76
|
+
open_uri_read_opts = options[:open_uri_options] || {}
|
75
77
|
|
76
|
-
@
|
78
|
+
@cached_response = RFQL::Response::JSON.new self, options.merge(:format => :parsed)
|
77
79
|
|
78
|
-
raise RFQL::Response::FQLError.new(@
|
80
|
+
raise RFQL::Response::FQLError.new(@cached_response) if @cached_response.is_a?(RFQL::Response::JSON::Parsed::Error)
|
79
81
|
|
80
|
-
|
82
|
+
case json_format
|
83
|
+
when :raw then @cached_response.raw
|
84
|
+
when :parsed then @cached_response
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
83
88
|
end
|
data/lib/rfql/response.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
|
3
2
|
require 'rfql/response/json'
|
4
3
|
require 'rfql/response/fql_error'
|
5
4
|
|
6
5
|
module RFQL
|
7
6
|
module Response
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
RFQL::Response::JSON.new(request, options)
|
7
|
+
def self.read(request, open_uri_options = {})
|
8
|
+
request_url = request.respond_to?(:to_url) ? request.to_url : request.to_s
|
9
|
+
begin
|
10
|
+
URI.parse(request_url).read(open_uri_options)
|
11
|
+
rescue OpenURI::HTTPError => e
|
12
|
+
raise RFQL::Response::FQLError.new(e.message, e.io, request)
|
13
|
+
#raise RFQL::Response::HTTPError.new(e.message, e.io, request)
|
16
14
|
end
|
15
|
+
end
|
16
|
+
def initialize(request, options = {})
|
17
|
+
options[:format] ||= :json_parsed
|
18
|
+
|
19
|
+
raise ArgumentError, 'illegal format' unless [:json_raw, :json_parsed].include?(options[:format])
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
options[:format] =
|
22
|
+
case options[:format]
|
23
|
+
when :json_raw then :raw
|
24
|
+
when :json_parsed then :parsed
|
25
|
+
end
|
26
|
+
|
27
|
+
RFQL::Response::JSON.new(request, options)
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
module RFQL
|
2
2
|
module Response
|
3
3
|
class FQLError < StandardError
|
4
|
-
attr_reader :
|
5
|
-
def initialize(
|
6
|
-
|
4
|
+
attr_reader :request, :io, :data
|
5
|
+
def initialize(message, io, request)
|
6
|
+
super(message)
|
7
|
+
@io, @request = io, request
|
8
|
+
begin
|
9
|
+
@data = ::JSON.parse @io.readlines.join("\n")
|
10
|
+
rescue Exception
|
11
|
+
end
|
7
12
|
end
|
8
13
|
end
|
9
14
|
end
|
data/lib/rfql/response/json.rb
CHANGED
@@ -7,13 +7,17 @@ require 'rfql/response/json/parsed/error'
|
|
7
7
|
module RFQL
|
8
8
|
module Response
|
9
9
|
class JSON
|
10
|
+
# Overwriting self.new in order to return another object depending to the format option
|
10
11
|
def self.new(request, options = {})
|
11
|
-
|
12
|
-
|
12
|
+
defaults = { :format => :parsed, :open_uri_options => {}, :json_parse_options => {} }
|
13
|
+
options = defaults.merge(options)
|
14
|
+
|
15
|
+
format = options.delete(:format)
|
16
|
+
raise ArgumentError, 'illegal format' unless [:raw, :parsed].include? format
|
13
17
|
|
14
|
-
case
|
15
|
-
|
16
|
-
|
18
|
+
case format
|
19
|
+
when :raw then RFQL::Response::JSON::Raw.new(request, options[:open_uri_options])
|
20
|
+
when :parsed then RFQL::Response::JSON::Parsed.new(request, options)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -3,23 +3,25 @@ module RFQL
|
|
3
3
|
module Response
|
4
4
|
class JSON
|
5
5
|
class Parsed
|
6
|
-
attr_reader :request, :
|
6
|
+
attr_reader :request, :raw, :data
|
7
|
+
# Overwriting of self.new in order to return a different type of object
|
8
|
+
# in some cases
|
7
9
|
def self.new(request, options = {})
|
8
|
-
|
10
|
+
defaults = { :open_uri_options => {}, :json_parse_options => {} }
|
11
|
+
options = defaults.merge(options)
|
12
|
+
|
13
|
+
json_raw_data = RFQL::Response::JSON::Raw.new(request, options[:open_uri_options])
|
14
|
+
json_parsed_data = ::JSON.parse(json_raw_data, options[:json_parse_options])
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
if json_parsed_response.is_a?(Hash) and json_parsed_response.has_key?('error_code')
|
13
|
-
RFQL::Response::JSON::Parsed::Error.new(request, json_parsed_response)
|
14
|
-
elsif json_parsed_response.is_a?(Array)
|
15
|
-
RFQL::Response::JSON::Parsed::Records.new(request, json_parsed_response)
|
16
|
+
if json_parsed_data.is_a?(Hash) and json_parsed_data['data'].is_a?(Array)
|
17
|
+
RFQL::Response::JSON::Parsed::Records.new(request, json_raw_data, json_parsed_data['data'])
|
16
18
|
else
|
17
|
-
super(request,
|
19
|
+
super(request, json_raw_data, json_parsed_data)
|
18
20
|
end
|
19
21
|
end
|
20
|
-
|
21
|
-
def initialize(request,
|
22
|
-
@request, @
|
22
|
+
private
|
23
|
+
def initialize(request, json_raw_data, json_parsed_data)
|
24
|
+
@request, @raw, @data = request, json_raw_data, json_parsed_data
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -3,18 +3,18 @@ module RFQL
|
|
3
3
|
class JSON
|
4
4
|
class Parsed
|
5
5
|
class Error < Hash
|
6
|
-
attr_reader :request
|
7
|
-
def initialize(request, hash)
|
8
|
-
@request = request
|
6
|
+
attr_reader :request, :raw
|
7
|
+
def initialize(request, raw, hash)
|
8
|
+
@request, @raw = request, raw
|
9
9
|
merge!(hash)
|
10
10
|
# FIXME SyntaxError, dunno why
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
# hash.keys.each do |key|
|
12
|
+
# self.class.class_eval<<-"RB"
|
13
|
+
# def #{key}
|
14
|
+
# send :fetch, #{key}
|
15
|
+
# end
|
16
|
+
# RB
|
17
|
+
# end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -3,9 +3,9 @@ module RFQL
|
|
3
3
|
class JSON
|
4
4
|
class Parsed
|
5
5
|
class Records < Array
|
6
|
-
attr_reader :request
|
7
|
-
def initialize(request, array)
|
8
|
-
@request = request
|
6
|
+
attr_reader :request, :raw
|
7
|
+
def initialize(request, raw, array)
|
8
|
+
@request, @raw = request, raw
|
9
9
|
super(array)
|
10
10
|
end
|
11
11
|
end
|
@@ -3,10 +3,9 @@ module RFQL
|
|
3
3
|
class JSON
|
4
4
|
class Raw < String
|
5
5
|
attr_reader :request
|
6
|
-
def initialize(request,
|
6
|
+
def initialize(request, open_uri_options = {})
|
7
7
|
@request = request
|
8
|
-
|
9
|
-
super RFQL::Response.read(request, options)
|
8
|
+
super RFQL::Response.read(request, open_uri_options)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
data/rfql.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "rfql"
|
5
|
-
s.version = "0.1.alpha.
|
5
|
+
s.version = "0.1.alpha.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["De Santis Maurizio"]
|
9
9
|
s.cert_chain = ["/home/mau/.gem_keys/gem-public_cert.pem"]
|
10
|
-
s.date = "2012-
|
10
|
+
s.date = "2012-03-28"
|
11
11
|
s.description = "RFQL - Ruby interface for Facebook Query Language"
|
12
12
|
s.email = "desantis.maurizio@gmail.com"
|
13
13
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/rfql.rb", "lib/rfql/core_ext/object/blank.rb", "lib/rfql/query.rb", "lib/rfql/query/methods.rb", "lib/rfql/query/quoting.rb", "lib/rfql/request.rb", "lib/rfql/request/delegations.rb", "lib/rfql/response.rb", "lib/rfql/response/fql_error.rb", "lib/rfql/response/json.rb", "lib/rfql/response/json/parsed.rb", "lib/rfql/response/json/parsed/error.rb", "lib/rfql/response/json/parsed/null.rb", "lib/rfql/response/json/parsed/records.rb", "lib/rfql/response/json/raw.rb"]
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rfql", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = "rfql"
|
19
|
-
s.rubygems_version = "1.8.
|
19
|
+
s.rubygems_version = "1.8.20"
|
20
20
|
s.signing_key = "/home/mau/.gem_keys/gem-private_key.pem"
|
21
21
|
s.summary = "It lets you use ORM-style code for fetching data from Facebook through the Facebook Query Language"
|
22
22
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.alpha.
|
4
|
+
version: 0.1.alpha.5
|
5
5
|
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,7 +50,7 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2012-
|
53
|
+
date: 2012-03-28 00:00:00.000000000 Z
|
54
54
|
dependencies: []
|
55
55
|
description: RFQL - Ruby interface for Facebook Query Language
|
56
56
|
email: desantis.maurizio@gmail.com
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '1.2'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project: rfql
|
126
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.20
|
127
127
|
signing_key:
|
128
128
|
specification_version: 3
|
129
129
|
summary: It lets you use ORM-style code for fetching data from Facebook through the
|
metadata.gz.sig
CHANGED
Binary file
|