koala 1.2.0 → 1.3.0

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.
Files changed (54) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +1 -0
  3. data/.travis.yml +4 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +43 -0
  6. data/Gemfile +14 -0
  7. data/Guardfile +6 -0
  8. data/koala.gemspec +4 -4
  9. data/lib/koala/api/batch_operation.rb +83 -0
  10. data/lib/koala/api/graph_api.rb +476 -0
  11. data/lib/koala/{graph_batch_api.rb → api/graph_batch_api.rb} +22 -17
  12. data/lib/koala/api/graph_collection.rb +107 -0
  13. data/lib/koala/api/legacy.rb +26 -0
  14. data/lib/koala/{rest_api.rb → api/rest_api.rb} +36 -10
  15. data/lib/koala/api.rb +93 -0
  16. data/lib/koala/http_service/multipart_request.rb +41 -0
  17. data/lib/koala/http_service/response.rb +18 -0
  18. data/lib/koala/http_service/uploadable_io.rb +187 -0
  19. data/lib/koala/http_service.rb +73 -23
  20. data/lib/koala/oauth.rb +173 -36
  21. data/lib/koala/realtime_updates.rb +89 -51
  22. data/lib/koala/test_users.rb +122 -32
  23. data/lib/koala/utils.rb +11 -4
  24. data/lib/koala/version.rb +1 -1
  25. data/lib/koala.rb +16 -95
  26. data/readme.md +30 -13
  27. data/spec/cases/api_spec.rb +28 -21
  28. data/spec/cases/error_spec.rb +10 -0
  29. data/spec/cases/graph_api_batch_spec.rb +100 -58
  30. data/spec/cases/graph_collection_spec.rb +23 -7
  31. data/spec/cases/http_service_spec.rb +14 -34
  32. data/spec/cases/koala_spec.rb +22 -4
  33. data/spec/cases/legacy_spec.rb +115 -0
  34. data/spec/cases/multipart_request_spec.rb +66 -0
  35. data/spec/cases/oauth_spec.rb +232 -108
  36. data/spec/cases/realtime_updates_spec.rb +154 -47
  37. data/spec/cases/test_users_spec.rb +276 -217
  38. data/spec/cases/uploadable_io_spec.rb +1 -1
  39. data/spec/cases/utils_spec.rb +29 -5
  40. data/spec/fixtures/mock_facebook_responses.yml +50 -26
  41. data/spec/spec_helper.rb +3 -0
  42. data/spec/support/custom_matchers.rb +28 -0
  43. data/spec/support/graph_api_shared_examples.rb +274 -70
  44. data/spec/support/koala_test.rb +27 -16
  45. data/spec/support/mock_http_service.rb +2 -2
  46. data/spec/support/rest_api_shared_examples.rb +46 -162
  47. metadata +33 -25
  48. data/lib/koala/batch_operation.rb +0 -74
  49. data/lib/koala/graph_api.rb +0 -270
  50. data/lib/koala/graph_collection.rb +0 -59
  51. data/lib/koala/uploadable_io.rb +0 -181
  52. data/spec/cases/graph_and_rest_api_spec.rb +0 -22
  53. data/spec/cases/graph_api_spec.rb +0 -22
  54. data/spec/cases/rest_api_spec.rb +0 -41
data/.gitignore CHANGED
@@ -2,4 +2,6 @@ pkg
2
2
  .project
3
3
  Gemfile.lock
4
4
  .rvmrc
5
- *.rbc
5
+ *.rbc
6
+ *~
7
+ .yardoc/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --order rand
data/.travis.yml CHANGED
@@ -7,3 +7,7 @@ rvm:
7
7
  - rbx-2.0
8
8
  - ree
9
9
  - jruby
10
+
11
+ branches:
12
+ except:
13
+ - rdoc
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --readme readme.md
2
+ --title "Koala Documentation"
3
+ --no-private
data/CHANGELOG CHANGED
@@ -1,3 +1,46 @@
1
+ v1.3
2
+ New methods:
3
+ -- OAuth#url_for_dialog creates URLs for Facebook dialog pages
4
+ -- API#set_app_restrictions handles JSON-encoding app restrictions
5
+ -- GraphCollection.parse_page_url now exposes useful functionality for non-Rails apps
6
+ -- RealtimeUpdates#subscription_path and TestUsers#test_user_accounts_path are now public
7
+ Updated methods:
8
+ -- REST API methods are now deprecated (see http://developers.facebook.com/blog/post/616/)
9
+ -- OAuth#url_for_access_token and #url_for_oauth_code now include any provided options as URL parameters
10
+ -- APIError#raw_response allows access to the raw error response received from Facebook
11
+ -- Utils.deprecate only prints each message once (no more spamming)
12
+ -- API#get_page_access_token now accepts additional arguments and HTTP options (like other calls)
13
+ -- TestUsers and RealtimeUpdates methods now take http_options arguments
14
+ -- All methods with http_options can now take :http_component => :response for the complete response
15
+ -- OAuth#get_user_info_from_cookies returns nil rather than an error if the cookies are expired (thanks, herzio)
16
+ -- TestUsers#delete_all now uses the Batch API and is much faster
17
+ Internal improvements:
18
+ -- FQL queries now use the Graph API behind-the-scenes
19
+ -- Cleaned up file and class organization, with aliases for backward compatibility
20
+ -- Added YARD documentation throughout
21
+ -- Fixed bugs in RealtimeUpdates, TestUsers, elsewhere
22
+ -- Reorganized file and class structure non-destructively
23
+ Testing improvements:
24
+ -- Expanded/improved test coverage
25
+ -- The test suite no longer users any hard-coded user IDs
26
+ -- KoalaTest.test_user_api allows access to the TestUsers instance
27
+ -- Configured tests to run in random order using RSpec 2.8.0rc1
28
+
29
+ v1.2.1
30
+ New methods:
31
+ -- RestAPI.set_app_properties handles JSON-encoding application properties
32
+ Updated methods:
33
+ -- OAuth.get_user_from_cookie works with the new signed cookie format (thanks, gmccreight!)
34
+ -- Beta server URLs are now correct
35
+ -- OAuth.parse_signed_request now raises an informative error if the signed_request is malformed
36
+ Internal improvements:
37
+ -- Koala::Multipart middleware properly encoding nested parameters (hashes) in POSTs
38
+ -- Updated readme, changelog, etc.
39
+ Testing improvements:
40
+ -- Live tests with test users now clean up all fake users they create
41
+ -- Removed duplicate test cases
42
+ -- Live tests with test users no longer delete each object they create, speeding things up
43
+
1
44
  v1.2
2
45
  New methods:
3
46
  -- API is now the main API class, contains both Graph and REST methods
data/Gemfile CHANGED
@@ -1,7 +1,21 @@
1
1
  source :rubygems
2
2
 
3
+ group :development do
4
+ gem "yard"
5
+ end
6
+
3
7
  group :development, :test do
4
8
  gem "typhoeus"
9
+
10
+ # Testing infrastructure
11
+ gem 'guard'
12
+ gem 'guard-rspec'
13
+
14
+ if RUBY_PLATFORM =~ /darwin/
15
+ # OS X integration
16
+ gem "ruby_gntp"
17
+ gem "rb-fsevent", "~> 0.4.3.1"
18
+ end
5
19
  end
6
20
 
7
21
  if defined? JRUBY_VERSION
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/koala.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'koala/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{koala}
7
7
  s.version = Koala::VERSION
8
- s.date = %q{2011-09-27}
8
+ s.date = %q{2011-10-04}
9
9
 
10
10
  s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.}
11
11
  s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph and REST APIs, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
@@ -32,17 +32,17 @@ Gem::Specification.new do |s|
32
32
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
33
33
  s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
34
34
  s.add_runtime_dependency(%q<faraday>, ["~> 0.7.0"])
35
- s.add_development_dependency(%q<rspec>, ["~> 2.5"])
35
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0rc1"])
36
36
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
37
37
  else
38
38
  s.add_dependency(%q<multi_json>, ["~> 1.0"])
39
- s.add_dependency(%q<rspec>, ["~> 2.5"])
39
+ s.add_dependency(%q<rspec>, ["~> 2.8.0rc1"])
40
40
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
41
41
  s.add_dependency(%q<faraday>, ["~> 0.7.0"])
42
42
  end
43
43
  else
44
44
  s.add_dependency(%q<multi_json>, ["~> 1.0"])
45
- s.add_dependency(%q<rspec>, ["~> 2.5"])
45
+ s.add_dependency(%q<rspec>, ["~> 2.8.0rc1"])
46
46
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
47
47
  s.add_dependency(%q<faraday>, ["~> 0.7.0"])
48
48
  end
@@ -0,0 +1,83 @@
1
+ require 'koala/api'
2
+
3
+ module Koala
4
+ module Facebook
5
+ class GraphBatchAPI < API
6
+ # @private
7
+ class BatchOperation
8
+ attr_reader :access_token, :http_options, :post_processing, :files, :batch_api, :identifier
9
+
10
+ @identifier = 0
11
+
12
+ def self.next_identifier
13
+ @identifier += 1
14
+ end
15
+
16
+ def initialize(options = {})
17
+ @identifier = self.class.next_identifier
18
+ @args = (options[:args] || {}).dup # because we modify it below
19
+ @access_token = options[:access_token]
20
+ @http_options = (options[:http_options] || {}).dup # dup because we modify it below
21
+ @batch_args = @http_options.delete(:batch_args) || {}
22
+ @url = options[:url]
23
+ @method = options[:method].to_sym
24
+ @post_processing = options[:post_processing]
25
+
26
+ process_binary_args
27
+
28
+ raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token
29
+ end
30
+
31
+ def to_batch_params(main_access_token)
32
+ # set up the arguments
33
+ args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token))
34
+
35
+ response = {
36
+ :method => @method.to_s,
37
+ :relative_url => @url,
38
+ }
39
+
40
+ # handle batch-level arguments, such as name, depends_on, and attached_files
41
+ @batch_args[:attached_files] = @files.keys.join(",") if @files
42
+ response.merge!(@batch_args) if @batch_args
43
+
44
+ # for get and delete, we append args to the URL string
45
+ # otherwise, they go in the body
46
+ if args_string.length > 0
47
+ if args_in_url?
48
+ response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0
49
+ else
50
+ response[:body] = args_string if args_string.length > 0
51
+ end
52
+ end
53
+
54
+ response
55
+ end
56
+
57
+ protected
58
+
59
+ def process_binary_args
60
+ # collect binary files
61
+ @args.each_pair do |key, value|
62
+ if UploadableIO.binary_content?(value)
63
+ @files ||= {}
64
+ # we use a class-level counter to ensure unique file identifiers across multiple batch operations
65
+ # (this is thread safe, since we just care about uniqueness)
66
+ # so remove the file from the original hash and add it to the file store
67
+ id = "op#{identifier}_file#{@files.keys.length}"
68
+ @files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
69
+ end
70
+ end
71
+ end
72
+
73
+ def args_in_url?
74
+ @method == :get || @method == :delete
75
+ end
76
+ end
77
+ end
78
+
79
+ # @private
80
+ # legacy support for when BatchOperation lived directly under Koala::Facebook
81
+ BatchOperation = GraphBatchAPI::BatchOperation
82
+ end
83
+ end