koala 2.5.0 → 3.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/Gemfile +1 -1
- data/ISSUE_TEMPLATE +25 -0
- data/PULL_REQUEST_TEMPLATE +11 -0
- data/changelog.md +66 -4
- data/code_of_conduct.md +64 -12
- data/koala.gemspec +3 -0
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +13 -102
- data/lib/koala/api/graph_batch_api.rb +112 -65
- data/lib/koala/api/graph_collection.rb +19 -12
- data/lib/koala/api/graph_error_checker.rb +1 -1
- data/lib/koala/api.rb +49 -25
- data/lib/koala/configuration.rb +49 -0
- data/lib/koala/errors.rb +1 -1
- data/lib/koala/http_service/multipart_request.rb +6 -10
- data/lib/koala/http_service/request.rb +135 -0
- data/lib/koala/http_service/response.rb +6 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -4
- data/lib/koala/http_service.rb +18 -76
- data/lib/koala/oauth.rb +7 -7
- data/lib/koala/realtime_updates.rb +26 -21
- data/lib/koala/test_users.rb +9 -8
- data/lib/koala/version.rb +1 -1
- data/lib/koala.rb +6 -8
- data/readme.md +50 -109
- data/spec/cases/api_spec.rb +99 -69
- data/spec/cases/configuration_spec.rb +11 -0
- data/spec/cases/graph_api_batch_spec.rb +73 -42
- data/spec/cases/graph_api_spec.rb +15 -29
- data/spec/cases/graph_collection_spec.rb +47 -34
- data/spec/cases/graph_error_checker_spec.rb +6 -1
- data/spec/cases/http_service/request_spec.rb +242 -0
- data/spec/cases/http_service/response_spec.rb +24 -0
- data/spec/cases/http_service_spec.rb +102 -296
- data/spec/cases/koala_spec.rb +7 -5
- data/spec/cases/oauth_spec.rb +40 -1
- data/spec/cases/realtime_updates_spec.rb +51 -13
- data/spec/cases/test_users_spec.rb +56 -2
- data/spec/cases/uploadable_io_spec.rb +31 -31
- data/spec/fixtures/cat.m4v +0 -0
- data/spec/fixtures/facebook_data.yml +4 -6
- data/spec/fixtures/mock_facebook_responses.yml +29 -69
- data/spec/fixtures/vcr_cassettes/app_test_accounts.yml +97 -0
- data/spec/integration/graph_collection_spec.rb +8 -5
- data/spec/spec_helper.rb +2 -2
- data/spec/support/graph_api_shared_examples.rb +143 -336
- data/spec/support/koala_test.rb +8 -10
- data/spec/support/mock_http_service.rb +9 -9
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +31 -11
- data/.autotest +0 -12
- data/Guardfile +0 -6
- data/autotest/discover.rb +0 -1
- data/lib/koala/api/rest_api.rb +0 -135
- data/spec/support/rest_api_shared_examples.rb +0 -168
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6941f9efa1f2d1a275581f20b5d10977f3d73fdd
|
|
4
|
+
data.tar.gz: 726f62799f0c20c9266515dc6d68bc333e9995d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10d6e349ebe3e89487f9052840d12d27b52b5fce77cb649fb97e2554855bf39c12acf60da93c3c5e55bf2f0ea66b9533310c50cad23006da331b4e253dfa4e77
|
|
7
|
+
data.tar.gz: 67c74e5c4af1c273d4c1e7edae915897753b610357763bf398b8c8b6107853dbbdaf86ac174951e2efddadd9aa5a611cb343c0655388e7a75b407ba80823a1c4
|
data/.travis.yml
CHANGED
|
@@ -3,15 +3,17 @@ sudo: false
|
|
|
3
3
|
cache: bundler
|
|
4
4
|
rvm:
|
|
5
5
|
# MRI
|
|
6
|
-
- 2.0
|
|
7
6
|
- 2.1
|
|
8
7
|
- 2.2
|
|
9
|
-
- 2.3.
|
|
8
|
+
- 2.3.1
|
|
9
|
+
- 2.4.0
|
|
10
10
|
# Rubinius is failing due to segfaults on Travis (and takes significantly longer to run)
|
|
11
11
|
# those builds will be restored later
|
|
12
12
|
# jruby
|
|
13
|
-
- jruby-19mode
|
|
13
|
+
# - jruby-19mode
|
|
14
14
|
bundler_args: --without development
|
|
15
15
|
addons:
|
|
16
16
|
code_climate:
|
|
17
17
|
repo_token: 7af99d9225b4c14640f9ec3cb2e24d2f7103ac49417b0bd989188fb6c25f2909
|
|
18
|
+
after_success:
|
|
19
|
+
- bundle exec codeclimate-test-reporter
|
data/Gemfile
CHANGED
data/ISSUE_TEMPLATE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Thanks for using Koala! Sorry you've run into an issue 😓 Here are some questions to help get things figured out as quickly as possible.
|
|
2
|
+
|
|
3
|
+
You don't have to fill this all out -- it's more of a guide. If in doubt, delete any sections that aren't relevant and open the issue. I want to help.
|
|
4
|
+
|
|
5
|
+
[ ] This is a Koala bug/issue/documentation problem.
|
|
6
|
+
|
|
7
|
+
Koala is a labor of love both from me and from the awesome community members who answer questions here. Much as we'd love to be able to help with everything, I have to focus my time on issues with the gem itself and can't help with questions on how to _use_ Facebook. (Plus, Facebook is huge!)
|
|
8
|
+
|
|
9
|
+
If you have questions about using the Facebook API, [facebook.stackoverflow.com](http://facebook.stackoverflow.com) is a great resource.
|
|
10
|
+
|
|
11
|
+
_For code issues:_
|
|
12
|
+
|
|
13
|
+
[ ] What I'm doing works on the [Graph API explorer](https://developers.facebook.com/tools/explorer/)/curl/another tool.
|
|
14
|
+
|
|
15
|
+
Seeing an example of what works helps diagnose what doesn't work.
|
|
16
|
+
|
|
17
|
+
[ ] I'm using the newest version
|
|
18
|
+
[ ] Here's code to replicate the issue:
|
|
19
|
+
|
|
20
|
+
Obviously not all code can be shared -- feel free to put variables in place of any sensitive information and describe what should be used to replicate it.
|
|
21
|
+
|
|
22
|
+
Thanks for submitting an issue! Looking forward to working with you to figure it out.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Note: Koala has a [code of conduct](https://github.com/arsduo/koala/blob/master/code_of_conduct.md). Check it out.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Thanks for submitting a pull request to Koala! A huge portion of the gem has been built by awesome people (like you) from the Ruby community.
|
|
2
|
+
|
|
3
|
+
Here are a few things that will help get your pull request merged in quickly. None of this is required -- you can delete anything not relevant. If in doubt, open the PR! I want to help.
|
|
4
|
+
|
|
5
|
+
[ ] My PR has tests and they pass!
|
|
6
|
+
[ ] The live tests pass for my changes (`LIVE=true rspec` -- unrelated failures are okay).
|
|
7
|
+
[ ] The PR is based on the most recent master commit and has no merge conflicts.
|
|
8
|
+
|
|
9
|
+
If you have any questions, feel free to open an issue or comment on your PR!
|
|
10
|
+
|
|
11
|
+
Note: Koala has a [code of conduct](https://github.com/arsduo/koala/blob/master/code_of_conduct.md). Check it out.
|
data/changelog.md
CHANGED
|
@@ -1,4 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
v3.0.0 (2017-03-17)
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
Most users should not see any difference upgrading from 2.x to 3.0. Most of the changes are
|
|
5
|
+
internal to how requests go from a graph method (like `get_connections`) through the API to the
|
|
6
|
+
HTTP layer and back. If you're not using API#api or HTTPService.make_request directly, upgrading
|
|
7
|
+
should (in theory) require no code changes. (Let me know if you run into any issues.)
|
|
8
|
+
|
|
9
|
+
**Key breaking changes:**
|
|
10
|
+
|
|
11
|
+
* Koala now requires Ruby 2.1+ (or equivalent for JRuby, etc.)
|
|
12
|
+
* API#api now returns a Koala::HTTPService::Response object; graph_call handles further processing
|
|
13
|
+
* GraphBatchAPI no longer inherits from API (the interface is otherwise unchanged)
|
|
14
|
+
* Empty response bodies in batch API calls will raise a JSON::ParserError rather than returning nil
|
|
15
|
+
* HTTPService.make_request now requires an HTTPService::Request object (Koala.make_request does
|
|
16
|
+
not)
|
|
17
|
+
* HTTPService behavior *should not* change, but in edge cases might. (If so, please let me know.)
|
|
18
|
+
* API#search now requires a "type"/:type argument, matching Facebook's behavior (improving their
|
|
19
|
+
cryptic error message)
|
|
20
|
+
|
|
21
|
+
New features:
|
|
22
|
+
|
|
23
|
+
* Koala now supports global configuration for tokens, secrets, etc! See the readme.
|
|
24
|
+
* GraphCollection now exposes #headers, allowing access to etag/rate limiting/etc. info (thanks,
|
|
25
|
+
pawandubey and jessieay!) (#589)
|
|
26
|
+
|
|
27
|
+
Updated features:
|
|
28
|
+
|
|
29
|
+
* Koala.config now uses a dedicated Koala::Configuration object
|
|
30
|
+
* TestUser#befriend will provide the appsecret_proof if a secret is set (thanks, kwasimensah!)
|
|
31
|
+
* API#search now requires an object type parameter to be included, matching Facebook's API (#575)
|
|
32
|
+
* RealtimeUpdates will now only fetch the app access token if necessary, avoiding unnecessary calls
|
|
33
|
+
|
|
34
|
+
Removed features:
|
|
35
|
+
|
|
36
|
+
* Removed support for the Rest API, since Facebook removed support for it (#568)
|
|
37
|
+
* Removed support for FQL, which Facebook removed on August 8, 2016 (#569)
|
|
38
|
+
* Removed legacy duplication of serveral constants in the Koala module (#569)
|
|
39
|
+
* Removed API#get_comments_for_urls, which pointed to a no-longer-extant endpoint(#570)
|
|
40
|
+
|
|
41
|
+
Internal improvements:
|
|
42
|
+
|
|
43
|
+
* Completely rewrote HTTPService.make_request and several others, extracting most logic into
|
|
44
|
+
HTTPService::Request (#566)
|
|
45
|
+
* API#api now returns a Koala::HTTPService::Response object (#584)
|
|
46
|
+
* GraphBatchAPI no longer inherits from API (#580)
|
|
47
|
+
* GraphBatchAPI has been refactored to be simpler and more readable (thanks, acuppy!) (#551)
|
|
48
|
+
* Use the more secure JSON.parse instead of JSON.load (thanks, lautis!) (#567)
|
|
49
|
+
* Use JSON's quirks_mode option to remove hacky JSON hack (#573 -- thanks sakuro for the
|
|
50
|
+
suggestion!)
|
|
51
|
+
* The gemspec now allows both JSON 1.8 and 2.0 (#596) (thanks, pawandubey!)
|
|
52
|
+
* Remove Autotest and Guard references (no longer used/needed)
|
|
53
|
+
|
|
54
|
+
Testing improvements:
|
|
55
|
+
|
|
56
|
+
* Fixed a bunch of failing mocked specs
|
|
57
|
+
|
|
58
|
+
Others:
|
|
59
|
+
|
|
60
|
+
* Added an issue and pull request template
|
|
61
|
+
* Updated Code of Conduct to 1.4
|
|
62
|
+
|
|
63
|
+
v2.5.0 (2017-02-17)
|
|
2
64
|
======
|
|
3
65
|
|
|
4
66
|
New features:
|
|
@@ -13,7 +75,7 @@ Internal improvements:
|
|
|
13
75
|
|
|
14
76
|
* Remove MultiJson dependency (thanks, sakuro!)
|
|
15
77
|
|
|
16
|
-
v2.4.0
|
|
78
|
+
v2.4.0 (2016-07-08)
|
|
17
79
|
======
|
|
18
80
|
|
|
19
81
|
**Note:** Koala is no longer officially supported on Ruby 1.9.3 (which was [end-of-lifed back in
|
|
@@ -36,7 +98,7 @@ Testing improvements:
|
|
|
36
98
|
* Test Koala against Ruby 2.3.0 (thanks, thedrow!)
|
|
37
99
|
|
|
38
100
|
|
|
39
|
-
v2.3.0
|
|
101
|
+
v2.3.0 (2016-04-10)
|
|
40
102
|
======
|
|
41
103
|
|
|
42
104
|
Updated features:
|
|
@@ -57,7 +119,7 @@ Testing improvements:
|
|
|
57
119
|
* Removed pended specs that were no longer relevant
|
|
58
120
|
* Improved https regex in test suite (thanks, lucaskds!)
|
|
59
121
|
|
|
60
|
-
v2.2.0
|
|
122
|
+
v2.2.0 (2015-08-11)
|
|
61
123
|
======
|
|
62
124
|
|
|
63
125
|
Updated features:
|
data/code_of_conduct.md
CHANGED
|
@@ -1,22 +1,74 @@
|
|
|
1
|
-
# Contributor Code of Conduct
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Our Pledge
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
6
22
|
|
|
7
23
|
Examples of unacceptable behavior by participants include:
|
|
8
24
|
|
|
9
|
-
* The use of sexualized language or imagery
|
|
10
|
-
|
|
11
|
-
* Trolling
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
12
28
|
* Public or private harassment
|
|
13
|
-
* Publishing
|
|
14
|
-
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
15
63
|
|
|
16
|
-
Project maintainers
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
17
67
|
|
|
18
|
-
|
|
68
|
+
## Attribution
|
|
19
69
|
|
|
20
|
-
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
21
72
|
|
|
22
|
-
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/koala.gemspec
CHANGED
|
@@ -21,6 +21,9 @@ Gem::Specification.new do |gem|
|
|
|
21
21
|
gem.extra_rdoc_files = ["readme.md", "changelog.md"]
|
|
22
22
|
gem.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala"]
|
|
23
23
|
|
|
24
|
+
gem.required_ruby_version = '>= 2.1'
|
|
25
|
+
|
|
24
26
|
gem.add_runtime_dependency("faraday")
|
|
25
27
|
gem.add_runtime_dependency("addressable")
|
|
28
|
+
gem.add_runtime_dependency("json", ">= 1.8")
|
|
26
29
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'koala/api'
|
|
2
|
+
require 'koala/api/graph_batch_api'
|
|
2
3
|
|
|
3
4
|
module Koala
|
|
4
5
|
module Facebook
|
|
@@ -65,13 +66,13 @@ module Koala
|
|
|
65
66
|
def process_binary_args
|
|
66
67
|
# collect binary files
|
|
67
68
|
@args.each_pair do |key, value|
|
|
68
|
-
if UploadableIO.binary_content?(value)
|
|
69
|
+
if HTTPService::UploadableIO.binary_content?(value)
|
|
69
70
|
@files ||= {}
|
|
70
71
|
# we use a class-level counter to ensure unique file identifiers across multiple batch operations
|
|
71
72
|
# (this is thread safe, since we just care about uniqueness)
|
|
72
73
|
# so remove the file from the original hash and add it to the file store
|
|
73
74
|
id = "op#{identifier}_file#{@files.keys.length}"
|
|
74
|
-
@files[id] = @args.delete(key).is_a?(UploadableIO) ? value : UploadableIO.new(value)
|
|
75
|
+
@files[id] = @args.delete(key).is_a?(HTTPService::UploadableIO) ? value : HTTPService::UploadableIO.new(value)
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
end
|
|
@@ -81,9 +82,5 @@ module Koala
|
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
84
|
end
|
|
84
|
-
|
|
85
|
-
# @private
|
|
86
|
-
# legacy support for when BatchOperation lived directly under Koala::Facebook
|
|
87
|
-
BatchOperation = GraphBatchAPI::BatchOperation
|
|
88
85
|
end
|
|
89
86
|
end
|
|
@@ -32,7 +32,6 @@ module Koala
|
|
|
32
32
|
# for the active user from the cookie provided by Facebook.
|
|
33
33
|
# See the Koala and Facebook documentation for more information.
|
|
34
34
|
module GraphAPIMethods
|
|
35
|
-
|
|
36
35
|
# Objects
|
|
37
36
|
|
|
38
37
|
# Get information about a Facebook object.
|
|
@@ -107,7 +106,7 @@ module Koala
|
|
|
107
106
|
# @return true if successful, false (or an APIError) if not
|
|
108
107
|
def delete_object(id, options = {}, &block)
|
|
109
108
|
# Deletes the object with the given ID from the graph.
|
|
110
|
-
raise AuthenticationError.new(nil, nil, "Delete requires an access token") unless
|
|
109
|
+
raise AuthenticationError.new(nil, nil, "Delete requires an access token") unless access_token
|
|
111
110
|
graph_call(id, {}, "delete", options, &block)
|
|
112
111
|
end
|
|
113
112
|
|
|
@@ -157,7 +156,7 @@ module Koala
|
|
|
157
156
|
# @return a hash containing the new object's id
|
|
158
157
|
def put_connections(id, connection_name, args = {}, options = {}, &block)
|
|
159
158
|
# Posts a certain connection
|
|
160
|
-
raise AuthenticationError.new(nil, nil, "Write operations require an access token") unless
|
|
159
|
+
raise AuthenticationError.new(nil, nil, "Write operations require an access token") unless access_token
|
|
161
160
|
|
|
162
161
|
graph_call("#{id}/#{connection_name}", args, "post", options, &block)
|
|
163
162
|
end
|
|
@@ -175,7 +174,7 @@ module Koala
|
|
|
175
174
|
# @return (see #delete_object)
|
|
176
175
|
def delete_connections(id, connection_name, args = {}, options = {}, &block)
|
|
177
176
|
# Deletes a given connection
|
|
178
|
-
raise AuthenticationError.new(nil, nil, "Delete requires an access token") unless
|
|
177
|
+
raise AuthenticationError.new(nil, nil, "Delete requires an access token") unless access_token
|
|
179
178
|
graph_call("#{id}/#{connection_name}", args, "delete", options, &block)
|
|
180
179
|
end
|
|
181
180
|
|
|
@@ -336,7 +335,7 @@ module Koala
|
|
|
336
335
|
# @return (see #delete_object)
|
|
337
336
|
def delete_like(id, options = {}, &block)
|
|
338
337
|
# Unlikes a given object for the logged-in user
|
|
339
|
-
raise AuthenticationError.new(nil, nil, "Unliking requires an access token") unless
|
|
338
|
+
raise AuthenticationError.new(nil, nil, "Unliking requires an access token") unless access_token
|
|
340
339
|
graph_call("#{id}/likes", {}, "delete", options, &block)
|
|
341
340
|
end
|
|
342
341
|
|
|
@@ -344,14 +343,16 @@ module Koala
|
|
|
344
343
|
# See {http://developers.facebook.com/docs/reference/api/#searching Facebook documentation} for more information.
|
|
345
344
|
#
|
|
346
345
|
# @param search_terms the query to search for
|
|
347
|
-
# @param args additional arguments, such as
|
|
346
|
+
# @param args object type and any additional arguments, such as fields, etc.
|
|
348
347
|
# @param options (see #get_object)
|
|
349
348
|
# @param block (see Koala::Facebook::API#api)
|
|
350
349
|
#
|
|
351
350
|
# @return [Koala::Facebook::API::GraphCollection] an array of search results
|
|
352
351
|
def search(search_terms, args = {}, options = {}, &block)
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
# Normally we wouldn't enforce Facebook API behavior, but the API fails with cryptic error
|
|
353
|
+
# messages if you fail to include a type term. For a convenience method, that is valuable.
|
|
354
|
+
raise ArgumentError, "type must be includedin args when searching" unless args[:type] || args["type"]
|
|
355
|
+
graph_call("search", args.merge("q" => search_terms), "get", options, &block)
|
|
355
356
|
end
|
|
356
357
|
|
|
357
358
|
# Convenience Methods
|
|
@@ -359,45 +360,6 @@ module Koala
|
|
|
359
360
|
# except to support cases where the Facebook API requires non-standard input
|
|
360
361
|
# such as JSON-encoding arguments, posts directly to objects, etc.
|
|
361
362
|
|
|
362
|
-
# Make an FQL query.
|
|
363
|
-
# Convenience method equivalent to get_object("fql", :q => query).
|
|
364
|
-
#
|
|
365
|
-
# @param query the FQL query to perform
|
|
366
|
-
# @param args (see #get_object)
|
|
367
|
-
# @param options (see #get_object)
|
|
368
|
-
# @param block (see Koala::Facebook::API#api)
|
|
369
|
-
#
|
|
370
|
-
# @return the result of the FQL query.
|
|
371
|
-
def fql_query(query, args = {}, options = {}, &block)
|
|
372
|
-
get_object("fql", args.merge(:q => query), options, &block)
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
# Make an FQL multiquery.
|
|
376
|
-
# This method simplifies the result returned from multiquery into a more logical format.
|
|
377
|
-
#
|
|
378
|
-
# @param queries a hash of query names => FQL queries
|
|
379
|
-
# @param args (see #get_object)
|
|
380
|
-
# @param options (see #get_object)
|
|
381
|
-
# @param block (see Koala::Facebook::API#api)
|
|
382
|
-
#
|
|
383
|
-
# @example
|
|
384
|
-
# @api.fql_multiquery({
|
|
385
|
-
# "query1" => "select post_id from stream where source_id = me()",
|
|
386
|
-
# "query2" => "select fromid from comment where post_id in (select post_id from #query1)"
|
|
387
|
-
# })
|
|
388
|
-
# # returns {"query1" => [obj1, obj2, ...], "query2" => [obj3, ...]}
|
|
389
|
-
# # instead of [{"name":"query1", "fql_result_set":[]},{"name":"query2", "fql_result_set":[]}]
|
|
390
|
-
#
|
|
391
|
-
# @return a hash of FQL results keyed to the appropriate query
|
|
392
|
-
def fql_multiquery(queries = {}, args = {}, options = {}, &block)
|
|
393
|
-
resolved_results = if results = get_object("fql", args.merge(:q => JSON.dump(queries)), options)
|
|
394
|
-
# simplify the multiquery result format
|
|
395
|
-
results.inject({}) {|outcome, data| outcome[data["name"]] = data["fql_result_set"]; outcome}
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
block ? block.call(resolved_results) : resolved_results
|
|
399
|
-
end
|
|
400
|
-
|
|
401
363
|
# Get a page's access token, allowing you to act as the page.
|
|
402
364
|
# Convenience method for @api.get_object(page_id, :fields => "access_token").
|
|
403
365
|
#
|
|
@@ -430,21 +392,6 @@ module Koala
|
|
|
430
392
|
block ? block.call(access_token_info) : access_token_info
|
|
431
393
|
end
|
|
432
394
|
|
|
433
|
-
# Fetches the comments from fb:comments widgets for a given set of URLs (array or comma-separated string).
|
|
434
|
-
# See https://developers.facebook.com/blog/post/490.
|
|
435
|
-
#
|
|
436
|
-
# @param urls the URLs for which you want comments
|
|
437
|
-
# @param args (see #get_object)
|
|
438
|
-
# @param options (see #get_object)
|
|
439
|
-
# @param block (see Koala::Facebook::API#api)
|
|
440
|
-
#
|
|
441
|
-
# @returns a hash of urls => comment arrays
|
|
442
|
-
def get_comments_for_urls(urls = [], args = {}, options = {}, &block)
|
|
443
|
-
return [] if urls.empty?
|
|
444
|
-
args.merge!(:ids => urls.respond_to?(:join) ? urls.join(",") : urls)
|
|
445
|
-
get_object("comments", args, options, &block)
|
|
446
|
-
end
|
|
447
|
-
|
|
448
395
|
# App restrictions require you to JSON-encode the restriction value. This
|
|
449
396
|
# is neither obvious nor intuitive, so this convenience method is
|
|
450
397
|
# provided.
|
|
@@ -463,13 +410,13 @@ module Koala
|
|
|
463
410
|
# Those methods use get_page to request another set of results from Facebook.
|
|
464
411
|
#
|
|
465
412
|
# @note You'll rarely need to use this method unless you're using Sinatra or another non-Rails framework
|
|
466
|
-
# (see {Koala::Facebook::GraphCollection GraphCollection} for more information).
|
|
413
|
+
# (see {Koala::Facebook::API::GraphCollection GraphCollection} for more information).
|
|
467
414
|
#
|
|
468
415
|
# @param params an array of arguments to graph_call
|
|
469
|
-
# as returned by {Koala::Facebook::GraphCollection.parse_page_url}.
|
|
416
|
+
# as returned by {Koala::Facebook::API::GraphCollection.parse_page_url}.
|
|
470
417
|
# @param block (see Koala::Facebook::API#api)
|
|
471
418
|
#
|
|
472
|
-
# @return Koala::Facebook::GraphCollection the appropriate page of results (an empty array if there are none)
|
|
419
|
+
# @return Koala::Facebook::API::GraphCollection the appropriate page of results (an empty array if there are none)
|
|
473
420
|
def get_page(params, &block)
|
|
474
421
|
graph_call(*params, &block)
|
|
475
422
|
end
|
|
@@ -518,44 +465,8 @@ module Koala
|
|
|
518
465
|
end
|
|
519
466
|
end
|
|
520
467
|
|
|
521
|
-
# Make a call directly to the Graph API.
|
|
522
|
-
# (See any of the other methods for example invocations.)
|
|
523
|
-
#
|
|
524
|
-
# @param path the Graph API path to query (no leading / needed)
|
|
525
|
-
# @param args (see #get_object)
|
|
526
|
-
# @param verb the type of HTTP request to make (get, post, delete, etc.)
|
|
527
|
-
# @options (see #get_object)
|
|
528
|
-
#
|
|
529
|
-
# @yield response when making a batch API call, you can pass in a block
|
|
530
|
-
# that parses the results, allowing for cleaner code.
|
|
531
|
-
# The block's return value is returned in the batch results.
|
|
532
|
-
# See the code for {#get_picture} or {#fql_multiquery} for examples.
|
|
533
|
-
# (Not needed in regular calls; you'll probably rarely use this.)
|
|
534
|
-
#
|
|
535
|
-
# @raise [Koala::Facebook::APIError] if Facebook returns an error
|
|
536
|
-
#
|
|
537
|
-
# @return the result from Facebook
|
|
538
|
-
def graph_call(path, args = {}, verb = "get", options = {}, &post_processing)
|
|
539
|
-
# enable appsecret_proof by default
|
|
540
|
-
options = {:appsecret_proof => true}.merge(options) if @app_secret
|
|
541
|
-
result = api(path, args, verb, options) do |response|
|
|
542
|
-
error = check_response(response.status, response.body, response.headers)
|
|
543
|
-
raise error if error
|
|
544
|
-
end
|
|
545
|
-
|
|
546
|
-
# turn this into a GraphCollection if it's pageable
|
|
547
|
-
result = GraphCollection.evaluate(result, self)
|
|
548
|
-
|
|
549
|
-
# now process as appropriate for the given call (get picture header, etc.)
|
|
550
|
-
post_processing ? post_processing.call(result) : result
|
|
551
|
-
end
|
|
552
|
-
|
|
553
468
|
private
|
|
554
469
|
|
|
555
|
-
def check_response(http_status, body, headers)
|
|
556
|
-
GraphErrorChecker.new(http_status, body, headers).error_if_appropriate
|
|
557
|
-
end
|
|
558
|
-
|
|
559
470
|
def parse_media_args(media_args, method)
|
|
560
471
|
# photo and video uploads can accept different types of arguments (see above)
|
|
561
472
|
# so here, we parse the arguments into a form directly usable in put_connections
|
|
@@ -573,7 +484,7 @@ module Koala
|
|
|
573
484
|
fb_expected_arg_name = method == "photos" ? :url : :file_url
|
|
574
485
|
args.merge!(fb_expected_arg_name => media_args.first)
|
|
575
486
|
else
|
|
576
|
-
args["source"] = Koala::UploadableIO.new(*media_args.slice(0, 1 + args_offset))
|
|
487
|
+
args["source"] = Koala::HTTPService::UploadableIO.new(*media_args.slice(0, 1 + args_offset))
|
|
577
488
|
end
|
|
578
489
|
|
|
579
490
|
[target_id, method, args, options]
|