rfql 0.1.alpha.4 → 0.1.alpha.5

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.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.1.alpha.5. Updating to Facebook FQL changes
2
+
1
3
  v0.1.alpha.4. RFQL::request -> RFQL.request
2
4
 
3
5
  v0.1.alpha.3. moved a require to the right place
data/lib/rfql.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rfql/query'
2
2
  require 'rfql/request'
3
3
  module RFQL
4
- VERSION = '0.1.alpha.4'
4
+ VERSION = '0.1.alpha.5'
5
5
  def self.request(obj = nil)
6
6
  RFQL::Request.new(obj)
7
7
  end
data/lib/rfql/request.rb CHANGED
@@ -47,37 +47,42 @@ module RFQL
47
47
  end.join('&')
48
48
  end
49
49
 
50
- def fetch(json_format = :parsed, options = {})
50
+ def response(json_format = :parsed, options = {})
51
51
  begin
52
- fetch!(json_format, options)
52
+ response!(json_format, options)
53
53
  rescue RFQL::Response::FQLError
54
54
  nil
55
55
  end
56
56
  end
57
57
 
58
- # Example: RFQL.request.query('SELECT aid, owner, name, object_id FROM album WHERE aid="20531316728_324257"').fetch
59
- def fetch!(json_format = :parsed, options = {})
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).blank? and @response and
66
- ( ( json_format == :parsed and ( @response.is_a?(RFQL::Response::JSON::Parsed) or
67
- @response.is_a?(RFQL::Response::JSON::Parsed::Records) or
68
- @response.is_a?(RFQL::Response::JSON::Parsed::Error) ) ) or
69
- ( json_format == :raw and @response.is_a?(RFQL::Response::JSON::Raw) ) )
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 = options[:json_parse_options] || {}
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
- @response = RFQL::Response::JSON.new(self, options.merge(:format => json_format))
78
+ @cached_response = RFQL::Response::JSON.new self, options.merge(:format => :parsed)
77
79
 
78
- raise RFQL::Response::FQLError.new(@response) if @response.is_a?(RFQL::Response::JSON::Parsed::Error)
80
+ raise RFQL::Response::FQLError.new(@cached_response) if @cached_response.is_a?(RFQL::Response::JSON::Parsed::Error)
79
81
 
80
- @response
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
- class << self
9
- def new(request, options = {})
10
- options[:format] ||= :json_parsed
11
- raise ArgumentError, 'illegal format' unless [:json_raw, :json_parsed].include?(options[:format])
12
-
13
- options[:format] = options[:format].to_s[/^json_(.*)/, 1].to_sym
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
- def read(request, options = {})
19
- request_url = request.respond_to?(:to_url) ? request.to_url : request.to_s
20
- URI.parse(request_url).read(options[:open_uri_options] || {})
21
- end
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 :error
5
- def initialize(error)
6
- @error = error
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
@@ -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
- options[:format] ||= :parsed
12
- raise ArgumentError, 'illegal format' unless [:raw, :parsed].include?(options[:format])
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 options[:format]
15
- when :raw then RFQL::Response::JSON::Raw.new(request, options)
16
- when :parsed then RFQL::Response::JSON::Parsed.new(request, options)
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, :response
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
- json_raw_response = RFQL::Response::JSON::Raw.new(request, options)
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
- json_parsed_response = ::JSON.parse(json_raw_response, options[:json_parse_options] || {})
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, json_parsed_response)
19
+ super(request, json_raw_data, json_parsed_data)
18
20
  end
19
21
  end
20
- private
21
- def initialize(request, json_parsed_response)
22
- @request, @response = request, json_parsed_response
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
- # hash.keys.each do |key|
12
- # self.class.class_eval<<-"RB"
13
- # def #{key}
14
- # send :fetch, #{key}
15
- # end
16
- # RB
17
- # end
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, options = {})
6
+ def initialize(request, open_uri_options = {})
7
7
  @request = request
8
- options[:format] = :json
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.4"
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-01-04"
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.12"
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
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-01-04 00:00:00.000000000 Z
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.12
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