koala 2.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +32 -0
- data/Gemfile +5 -3
- data/ISSUE_TEMPLATE +25 -0
- data/PULL_REQUEST_TEMPLATE +11 -0
- data/changelog.md +161 -4
- data/code_of_conduct.md +64 -12
- data/koala.gemspec +5 -1
- data/lib/koala/api/batch_operation.rb +3 -6
- data/lib/koala/api/{graph_api.rb → graph_api_methods.rb} +29 -104
- 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 +4 -3
- data/lib/koala/api.rb +65 -26
- data/lib/koala/configuration.rb +56 -0
- data/lib/koala/errors.rb +22 -2
- data/lib/koala/http_service/request.rb +133 -0
- data/lib/koala/http_service/response.rb +6 -4
- data/lib/koala/http_service/uploadable_io.rb +0 -5
- data/lib/koala/http_service.rb +29 -76
- data/lib/koala/oauth.rb +8 -8
- 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 +7 -9
- data/readme.md +83 -109
- data/spec/cases/api_spec.rb +176 -69
- data/spec/cases/configuration_spec.rb +11 -0
- data/spec/cases/error_spec.rb +16 -3
- data/spec/cases/graph_api_batch_spec.rb +75 -44
- 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 +31 -2
- data/spec/cases/http_service/request_spec.rb +250 -0
- data/spec/cases/http_service/response_spec.rb +24 -0
- data/spec/cases/http_service_spec.rb +126 -286
- data/spec/cases/koala_spec.rb +7 -5
- data/spec/cases/oauth_spec.rb +41 -2
- 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 +41 -78
- 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 +152 -337
- data/spec/support/koala_test.rb +11 -13
- data/spec/support/mock_http_service.rb +11 -14
- data/spec/support/uploadable_io_shared_examples.rb +4 -4
- metadata +47 -48
- data/.autotest +0 -12
- data/.travis.yml +0 -17
- data/Guardfile +0 -6
- data/autotest/discover.rb +0 -1
- data/lib/koala/api/rest_api.rb +0 -135
- data/lib/koala/http_service/multipart_request.rb +0 -41
- data/spec/cases/multipart_request_spec.rb +0 -65
- data/spec/support/rest_api_shared_examples.rb +0 -168
@@ -1,168 +0,0 @@
|
|
1
|
-
shared_examples_for "Koala RestAPI" do
|
2
|
-
# REST_CALL
|
3
|
-
describe "when making a rest request" do
|
4
|
-
it "uses the proper path" do
|
5
|
-
method = double('methodName')
|
6
|
-
expect(@api).to receive(:api).with(
|
7
|
-
"method/#{method}",
|
8
|
-
anything,
|
9
|
-
anything,
|
10
|
-
anything
|
11
|
-
)
|
12
|
-
|
13
|
-
@api.rest_call(method)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "always uses the rest api" do
|
17
|
-
expect(@api).to receive(:api).with(
|
18
|
-
anything,
|
19
|
-
anything,
|
20
|
-
anything,
|
21
|
-
hash_including(:rest_api => true)
|
22
|
-
)
|
23
|
-
|
24
|
-
@api.rest_call('anything')
|
25
|
-
end
|
26
|
-
|
27
|
-
it "sets the read_only option to true if the method is listed in the read-only list" do
|
28
|
-
method = Koala::Facebook::API::READ_ONLY_METHODS.first
|
29
|
-
|
30
|
-
expect(@api).to receive(:api).with(
|
31
|
-
anything,
|
32
|
-
anything,
|
33
|
-
anything,
|
34
|
-
hash_including(:read_only => true)
|
35
|
-
)
|
36
|
-
|
37
|
-
@api.rest_call(method)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "sets the read_only option to false if the method is not inthe read-only list" do
|
41
|
-
method = "I'm not a read-only method"
|
42
|
-
|
43
|
-
expect(@api).to receive(:api).with(
|
44
|
-
anything,
|
45
|
-
anything,
|
46
|
-
anything,
|
47
|
-
hash_including(:read_only => false)
|
48
|
-
)
|
49
|
-
|
50
|
-
@api.rest_call(method)
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
it "takes an optional hash of arguments" do
|
55
|
-
args = {:arg1 => 'arg1'}
|
56
|
-
|
57
|
-
expect(@api).to receive(:api).with(
|
58
|
-
anything,
|
59
|
-
hash_including(args),
|
60
|
-
anything,
|
61
|
-
anything
|
62
|
-
)
|
63
|
-
|
64
|
-
@api.rest_call('anything', args)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "always asks for JSON" do
|
68
|
-
expect(@api).to receive(:api).with(
|
69
|
-
anything,
|
70
|
-
hash_including('format' => 'json'),
|
71
|
-
anything,
|
72
|
-
anything
|
73
|
-
)
|
74
|
-
|
75
|
-
@api.rest_call('anything')
|
76
|
-
end
|
77
|
-
|
78
|
-
it "passes any options provided to the API" do
|
79
|
-
options = {:a => 2}
|
80
|
-
|
81
|
-
expect(@api).to receive(:api).with(
|
82
|
-
anything,
|
83
|
-
hash_including('format' => 'json'),
|
84
|
-
anything,
|
85
|
-
hash_including(options)
|
86
|
-
)
|
87
|
-
|
88
|
-
@api.rest_call('anything', {}, options)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "uses get by default" do
|
92
|
-
expect(@api).to receive(:api).with(
|
93
|
-
anything,
|
94
|
-
anything,
|
95
|
-
"get",
|
96
|
-
anything
|
97
|
-
)
|
98
|
-
|
99
|
-
@api.rest_call('anything')
|
100
|
-
end
|
101
|
-
|
102
|
-
it "allows you to specify other http methods as the last argument" do
|
103
|
-
method = 'bar'
|
104
|
-
expect(@api).to receive(:api).with(
|
105
|
-
anything,
|
106
|
-
anything,
|
107
|
-
method,
|
108
|
-
anything
|
109
|
-
)
|
110
|
-
|
111
|
-
@api.rest_call('anything', {}, {}, method)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "throws an APIError if the status code >= 400" do
|
115
|
-
allow(Koala).to receive(:make_request).and_return(Koala::HTTPService::Response.new(500, '{"error_code": "An error occurred!"}', {}))
|
116
|
-
expect { @api.rest_call(KoalaTest.user1, {}) }.to raise_exception(Koala::Facebook::APIError)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
it "can use the beta tier" do
|
121
|
-
@api.rest_call("fql.query", {:query => "select first_name from user where uid = #{KoalaTest.user2_id}"}, :beta => true)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
shared_examples_for "Koala RestAPI with an access token" do
|
126
|
-
describe "#set_app_properties" do
|
127
|
-
it "sends Facebook the properties JSON-encoded as :properties" do
|
128
|
-
props = {:a => 2, :c => [1, 2, "d"]}
|
129
|
-
expect(@api).to receive(:rest_call).with(anything, hash_including(:properties => MultiJson.dump(props)), anything, anything)
|
130
|
-
@api.set_app_properties(props)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "calls the admin.setAppProperties method" do
|
134
|
-
expect(@api).to receive(:rest_call).with("admin.setAppProperties", anything, anything, anything)
|
135
|
-
@api.set_app_properties({})
|
136
|
-
end
|
137
|
-
|
138
|
-
it "includes any other provided arguments" do
|
139
|
-
args = {:c => 3, :d => "a"}
|
140
|
-
expect(@api).to receive(:rest_call).with(anything, hash_including(args), anything, anything)
|
141
|
-
@api.set_app_properties({:a => 2}, args)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "includes any http_options provided" do
|
145
|
-
opts = {:c => 3, :d => "a"}
|
146
|
-
expect(@api).to receive(:rest_call).with(anything, anything, opts, anything)
|
147
|
-
@api.set_app_properties({}, {}, opts)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "makes a POST" do
|
151
|
-
expect(@api).to receive(:rest_call).with(anything, anything, anything, "post")
|
152
|
-
@api.set_app_properties({})
|
153
|
-
end
|
154
|
-
|
155
|
-
it "can set app properties using the app's access token" do
|
156
|
-
oauth = Koala::Facebook::OAuth.new(KoalaTest.app_id, KoalaTest.secret)
|
157
|
-
app_token = oauth.get_app_access_token
|
158
|
-
@app_api = Koala::Facebook::API.new(app_token)
|
159
|
-
expect(@app_api.set_app_properties(KoalaTest.app_properties)).to be_truthy
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
shared_examples_for "Koala RestAPI without an access token" do
|
165
|
-
it "can't use set_app_properties" do
|
166
|
-
expect { @api.set_app_properties(:desktop => 0) }.to raise_error(Koala::Facebook::AuthenticationError)
|
167
|
-
end
|
168
|
-
end
|