koala 1.0.0.beta → 1.1.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 (69) hide show
  1. data/.autotest +12 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGELOG +42 -4
  5. data/Gemfile +7 -0
  6. data/LICENSE +1 -1
  7. data/Manifest +5 -2
  8. data/Rakefile +13 -14
  9. data/autotest/discover.rb +1 -0
  10. data/koala.gemspec +35 -20
  11. data/lib/koala/batch_operation.rb +74 -0
  12. data/lib/koala/graph_api.rb +196 -143
  13. data/lib/koala/graph_batch_api.rb +87 -0
  14. data/lib/koala/graph_collection.rb +54 -0
  15. data/lib/koala/http_services/net_http_service.rb +92 -0
  16. data/lib/koala/http_services/typhoeus_service.rb +37 -0
  17. data/lib/koala/http_services.rb +15 -124
  18. data/lib/koala/oauth.rb +181 -0
  19. data/lib/koala/realtime_updates.rb +5 -14
  20. data/lib/koala/rest_api.rb +13 -8
  21. data/lib/koala/test_users.rb +21 -8
  22. data/lib/koala/uploadable_io.rb +175 -0
  23. data/lib/koala.rb +48 -240
  24. data/readme.md +60 -28
  25. data/spec/cases/api_base_spec.rb +101 -0
  26. data/spec/cases/graph_and_rest_api_spec.rb +31 -0
  27. data/spec/cases/graph_api_batch_spec.rb +609 -0
  28. data/spec/cases/graph_api_spec.rb +25 -0
  29. data/spec/cases/http_services/http_service_spec.rb +129 -0
  30. data/spec/cases/http_services/net_http_service_spec.rb +532 -0
  31. data/spec/cases/http_services/typhoeus_service_spec.rb +152 -0
  32. data/spec/cases/koala_spec.rb +55 -0
  33. data/spec/cases/oauth_spec.rb +409 -0
  34. data/spec/cases/realtime_updates_spec.rb +184 -0
  35. data/spec/cases/rest_api_spec.rb +25 -0
  36. data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +47 -34
  37. data/spec/cases/uploadable_io_spec.rb +193 -0
  38. data/spec/fixtures/cat.m4v +0 -0
  39. data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +12 -14
  40. data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +408 -306
  41. data/spec/spec_helper.rb +19 -0
  42. data/spec/support/graph_api_shared_examples.rb +495 -0
  43. data/spec/support/json_testing_fix.rb +18 -0
  44. data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
  45. data/spec/support/mock_http_service.rb +96 -0
  46. data/spec/support/rest_api_shared_examples.rb +285 -0
  47. data/spec/support/setup_mocks_or_live.rb +51 -0
  48. data/spec/support/uploadable_io_shared_examples.rb +76 -0
  49. metadata +110 -64
  50. data/init.rb +0 -2
  51. data/spec/koala/api_base_tests.rb +0 -102
  52. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
  53. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
  54. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -63
  55. data/spec/koala/graph_api/graph_api_tests.rb +0 -86
  56. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -154
  57. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  58. data/spec/koala/net_http_service_tests.rb +0 -430
  59. data/spec/koala/oauth/oauth_tests.rb +0 -409
  60. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  61. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
  62. data/spec/koala/rest_api/rest_api_tests.rb +0 -118
  63. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
  64. data/spec/koala/typhoeus_service_tests.rb +0 -156
  65. data/spec/koala_spec.rb +0 -18
  66. data/spec/koala_spec_helper.rb +0 -70
  67. data/spec/koala_spec_without_mocks.rb +0 -19
  68. data/spec/mock_http_service.rb +0 -96
  69. /data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
data/.autotest ADDED
@@ -0,0 +1,12 @@
1
+ # Override autotest default magic to rerun all tests every time a
2
+ # change is detected on the file system.
3
+ class Autotest
4
+
5
+ def get_to_green
6
+ begin
7
+ rerun_all_tests
8
+ wait_for_changes unless all_good
9
+ end until all_good
10
+ end
11
+
12
+ end
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ .project
3
+ Gemfile.lock
4
+ .rvmrc
5
+ *.rbc
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7 # (current default)
3
+ - 1.9.2
4
+ - rbx
5
+ - rbx-2.0
6
+ - ree
7
+ - jruby
8
+ - ruby-head
data/CHANGELOG CHANGED
@@ -1,15 +1,53 @@
1
+ v1.1
2
+ New methods:
3
+ -- Added Batch API support (thanks, seejohnrun and spiegela!)
4
+ -- includes file uploads, error handling, and FQL
5
+ -- Added GraphAPI#put_video
6
+ -- Added GraphAPI#get_comments_for_urls (thanks, amrnt!)
7
+ -- Added RestAPI#fql_multiquery, which simplifies the results (thanks, amrnt!)
8
+ -- HTTP services support global proxy and timeout settings (thanks, itchy!)
9
+ -- Net::HTTP supports global ca_path, ca_file, and verify_mode settings (thanks, spiegela!)
10
+ Updated methods:
11
+ -- RealtimeUpdates now uses a GraphAPI object instead of its own API
12
+ -- RestAPI#rest_call now has an optional last argument for method, for calls requiring POST, DELETE, etc. (thanks, sshilo!)
13
+ -- Filename can now be specified when uploading (e.g. for Ads API) (thanks, sshilo!)
14
+ -- get_objects([]) returns [] instead of a Facebook error in non-batch mode (thanks, aselder!)
15
+ Internal improvements:
16
+ -- Koala is now more compatible with other Rubies (JRuby, Rubinius, etc.)
17
+ -- HTTP services are more modular and can be changed on the fly (thanks, chadk!)
18
+ -- Includes support for uploading StringIOs and other non-files via Net::HTTP even when using TyphoeusService
19
+ -- Koala now uses multi_json to improve compatibility with Rubinius and other Ruby versions
20
+ -- Koala now uses the modern Typhoeus API (thanks, aselder!)
21
+ -- Koala now uses the current modern Net::HTTP interface (thanks, romanbsd!)
22
+ -- Fixed bugs and typos (thanks, waynn, mokevnin, and tikh!)
23
+
1
24
  v1.0
2
25
  New methods:
3
- -- Photo and file upload now supported through #put_picture and general support for file hashes (see documentation)
4
- -- Added a delete_like method (thanks to wassem)
5
- Internal improvements:
26
+ -- Photo and file upload now supported through #put_picture
27
+ -- Added UploadableIO class to manage file uploads
28
+ -- Added a delete_like method (thanks to waseem)
29
+ -- Added put_connection and delete_connection convenience methods
30
+ Updated methods:
31
+ -- Search can now search places, checkins, etc. (thanks, rickyc!)
32
+ -- You can now pass :beta => true in the http options to use Facebook's beta tier
33
+ -- TestUser#befriend now requires user info hashes (id and access token) due to Facebook API changes (thanks, pulsd and kbighorse!)
34
+ -- All methods now accept an http_options hash as their optional last parameter (thanks, spiegela!)
35
+ -- url_for_oauth_code can now take a :display option (thanks, netbe!)
36
+ -- Net::HTTP can now accept :timeout and :proxy options (thanks, gilles!)
37
+ -- Test users now supports using test accounts across multiple apps
38
+ Internal improvements:
6
39
  -- For public requests, Koala now uses http by default (instead of https) to improve speed
7
40
  -- This can be overridden through Koala.always_use_ssl= or by passing :use_ssl => true in the options hash for an api call
8
41
  -- Read-only REST API requests now go through the faster api-read server
9
42
  -- Replaced parse_signed_request with a version from Facebook that also supports the new signed params proposal
10
43
  -- Note: invalid requests will now raise exceptions rather than return nil, in keeping with other SDKs
11
- -- delete_object will now raise an error if there's no access token (like put_object and delete_like)
44
+ -- Delete methods will now raise an error if there's no access token (like put_object and delete_like)
45
+ -- Updated parse_signed_request to match Facebook's current implementation (thanks, imajes!)
46
+ -- APIError is now < StandardError, not Exception
47
+ -- Added KoalaError for non-API errors
48
+ -- Net::HTTP's SSL verification is no longer disabled by default
12
49
  Test improvements:
50
+ -- Incorporated joshk's awesome rewrite of the entire Koala test suite (thanks, joshk!)
13
51
  -- Expanded HTTP service tests (added Typhoeus test suite and additional Net::HTTP test cases)
14
52
  -- Live tests now verify that the access token has the necessary permissions before starting
15
53
  -- Replaced the 50-person network test, which often took 15+ minutes to run live, with a 5-person test
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ if defined? JRUBY_VERSION
6
+ gem "jruby-openssl"
7
+ end
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010 Alex Koppel
3
+ Copyright (c) 2010-2011 Alex Koppel
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/Manifest CHANGED
@@ -10,6 +10,7 @@ lib/koala/http_services.rb
10
10
  lib/koala/realtime_updates.rb
11
11
  lib/koala/rest_api.rb
12
12
  lib/koala/test_users.rb
13
+ lib/koala/uploadable_io.rb
13
14
  readme.md
14
15
  spec/facebook_data.yml
15
16
  spec/koala/api_base_tests.rb
@@ -20,15 +21,17 @@ spec/koala/graph_api/graph_api_no_access_token_tests.rb
20
21
  spec/koala/graph_api/graph_api_tests.rb
21
22
  spec/koala/graph_api/graph_api_with_access_token_tests.rb
22
23
  spec/koala/graph_api/graph_collection_tests.rb
24
+ spec/koala/http_services/http_service_tests.rb
25
+ spec/koala/http_services/net_http_service_tests.rb
26
+ spec/koala/http_services/typhoeus_service_tests.rb
23
27
  spec/koala/live_testing_data_helper.rb
24
- spec/koala/net_http_service_tests.rb
25
28
  spec/koala/oauth/oauth_tests.rb
26
29
  spec/koala/realtime_updates/realtime_updates_tests.rb
27
30
  spec/koala/rest_api/rest_api_no_access_token_tests.rb
28
31
  spec/koala/rest_api/rest_api_tests.rb
29
32
  spec/koala/rest_api/rest_api_with_access_token_tests.rb
30
33
  spec/koala/test_users/test_users_tests.rb
31
- spec/koala/typhoeus_service_tests.rb
34
+ spec/koala/uploadable_io/uploadable_io_tests.rb
32
35
  spec/koala_spec.rb
33
36
  spec/koala_spec_helper.rb
34
37
  spec/koala_spec_without_mocks.rb
data/Rakefile CHANGED
@@ -1,17 +1,16 @@
1
- # Rakefile
2
- require 'rubygems'
3
1
  require 'rake'
4
- require 'echoe'
5
2
 
6
- # gem management
7
- Echoe.new('koala', '1.0.0.beta') do |p|
8
- p.summary = "A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation."
9
- p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, 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."
10
- p.url = "http://github.com/arsduo/koala"
11
- p.author = ["Alex Koppel", "Chris Baclig", "Rafi Jacoby", "Context Optional"]
12
- p.email = "alex@alexkoppel.com"
13
- p.ignore_pattern = ["tmp/*", "script/*", "pkg/*"]
14
- p.runtime_dependencies = ["json >=1.0", "multipart-post >=1.0"]
15
- p.development_dependencies = []
16
- p.retain_gemspec = true
3
+ begin
4
+ require 'bundler/setup'
5
+ Bundler::GemHelper.install_tasks
6
+ rescue LoadError
7
+ puts 'although not required, bundler is recommened for running the tests'
8
+ end
9
+
10
+
11
+ task :default => :spec
12
+
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new do |t|
15
+ t.rspec_opts = ["--color", '--format doc']
17
16
  end
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/koala.gemspec CHANGED
@@ -1,35 +1,50 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{koala}
5
- s.version = "1.0.0.beta"
4
+ s.name = %q{koala}
5
+ s.version = "1.1.0"
6
+ s.date = %q{2011-07-18}
7
+
8
+ s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the REST API, realtime updates, and OAuth authentication.}
9
+ 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.}
10
+ s.homepage = %q{http://github.com/arsduo/koala}
6
11
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
12
  s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
9
- s.date = %q{2011-01-26}
10
- s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, 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.}
11
- s.email = %q{alex@alexkoppel.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "lib/koala/test_users.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "init.rb", "koala.gemspec", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "lib/koala/test_users.rb", "readme.md", "spec/facebook_data.yml", "spec/koala/api_base_tests.rb", "spec/koala/assets/beach.jpg", "spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb", "spec/koala/graph_api/graph_api_no_access_token_tests.rb", "spec/koala/graph_api/graph_api_tests.rb", "spec/koala/graph_api/graph_api_with_access_token_tests.rb", "spec/koala/graph_api/graph_collection_tests.rb", "spec/koala/live_testing_data_helper.rb", "spec/koala/net_http_service_tests.rb", "spec/koala/oauth/oauth_tests.rb", "spec/koala/realtime_updates/realtime_updates_tests.rb", "spec/koala/rest_api/rest_api_no_access_token_tests.rb", "spec/koala/rest_api/rest_api_tests.rb", "spec/koala/rest_api/rest_api_with_access_token_tests.rb", "spec/koala/test_users/test_users_tests.rb", "spec/koala/typhoeus_service_tests.rb", "spec/koala_spec.rb", "spec/koala_spec_helper.rb", "spec/koala_spec_without_mocks.rb", "spec/mock_facebook_responses.yml", "spec/mock_http_service.rb"]
14
- s.homepage = %q{http://github.com/arsduo/koala}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{koala}
18
- s.rubygems_version = %q{1.4.2}
19
- s.summary = %q{A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation.}
13
+ s.email = %q{alex@alexkoppel.com}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+
18
+ s.extra_rdoc_files = ["readme.md", "CHANGELOG"]
19
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala"]
20
+
21
+ s.require_paths = ["lib"]
22
+
23
+ s.rubygems_version = %q{1.4.2}
24
+
25
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
20
26
 
21
27
  if s.respond_to? :specification_version then
22
28
  s.specification_version = 3
23
29
 
24
30
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_runtime_dependency(%q<json>, [">= 1.0"])
26
- s.add_runtime_dependency(%q<multipart-post>, [">= 1.0"])
31
+ s.add_runtime_dependency(%q<multi_json>, ["~> 1.0"])
32
+ s.add_runtime_dependency(%q<multipart-post>, ["~> 1.0"])
33
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
34
+ s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
35
+ s.add_development_dependency(%q<typhoeus>, ["~> 0.2.4"])
27
36
  else
28
- s.add_dependency(%q<json>, [">= 1.0"])
29
- s.add_dependency(%q<multipart-post>, [">= 1.0"])
37
+ s.add_dependency(%q<multi_json>, ["~> 1.0"])
38
+ s.add_dependency(%q<multipart-post>, ["~> 1.0"])
39
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
40
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
41
+ s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
30
42
  end
31
43
  else
32
- s.add_dependency(%q<json>, [">= 1.0"])
33
- s.add_dependency(%q<multipart-post>, [">= 1.0"])
44
+ s.add_dependency(%q<multi_json>, ["~> 1.0"])
45
+ s.add_dependency(%q<multipart-post>, ["~> 1.0"])
46
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
47
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
48
+ s.add_dependency(%q<typhoeus>, ["~> 0.2.4"])
34
49
  end
35
50
  end
@@ -0,0 +1,74 @@
1
+ module Koala
2
+ module Facebook
3
+ class BatchOperation
4
+ attr_reader :access_token, :http_options, :post_processing, :files, :batch_api, :identifier
5
+
6
+ @identifier = 0
7
+
8
+ def self.next_identifier
9
+ @identifier += 1
10
+ end
11
+
12
+ def initialize(options = {})
13
+ @identifier = self.class.next_identifier
14
+ @args = (options[:args] || {}).dup # because we modify it below
15
+ @access_token = options[:access_token]
16
+ @http_options = (options[:http_options] || {}).dup # dup because we modify it below
17
+ @batch_args = @http_options.delete(:batch_args) || {}
18
+ @url = options[:url]
19
+ @method = options[:method].to_sym
20
+ @post_processing = options[:post_processing]
21
+
22
+ process_binary_args
23
+
24
+ raise Koala::KoalaError, "Batch operations require an access token, none provided." unless @access_token
25
+ end
26
+
27
+ def to_batch_params(main_access_token)
28
+ # set up the arguments
29
+ args_string = Koala.http_service.encode_params(@access_token == main_access_token ? @args : @args.merge(:access_token => @access_token))
30
+
31
+ response = {
32
+ :method => @method.to_s,
33
+ :relative_url => @url,
34
+ }
35
+
36
+ # handle batch-level arguments, such as name, depends_on, and attached_files
37
+ @batch_args[:attached_files] = @files.keys.join(",") if @files
38
+ response.merge!(@batch_args) if @batch_args
39
+
40
+ # for get and delete, we append args to the URL string
41
+ # otherwise, they go in the body
42
+ if args_string.length > 0
43
+ if args_in_url?
44
+ response[:relative_url] += (@url =~ /\?/ ? "&" : "?") + args_string if args_string.length > 0
45
+ else
46
+ response[:body] = args_string if args_string.length > 0
47
+ end
48
+ end
49
+
50
+ response
51
+ end
52
+
53
+ protected
54
+
55
+ def process_binary_args
56
+ # collect binary files
57
+ @args.each_pair do |key, value|
58
+ if UploadableIO.binary_content?(value)
59
+ @files ||= {}
60
+ # we use a class-level counter to ensure unique file identifiers across multiple batch operations
61
+ # (this is thread safe, since we just care about uniqueness)
62
+ # so remove the file from the original hash and add it to the file store
63
+ id = "op#{identifier}_file#{@files.keys.length}"
64
+ @files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
65
+ end
66
+ end
67
+ end
68
+
69
+ def args_in_url?
70
+ @method == :get || @method == :delete
71
+ end
72
+ end
73
+ end
74
+ end