apify 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -2
- data/VERSION +1 -1
- data/apify.gemspec +2 -2
- data/app/views/apify/api/_protocol.html.erb +1 -1
- data/lib/apify/client.rb +1 -2
- data/spec/apify/client_spec.rb +23 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -59,7 +59,7 @@ If you are planning to consume your Apify API with the `Apify::Client` class, yo
|
|
59
59
|
- API actions can take arguments. Those are serialized into a **single** HTTP parameter `args` as JSON. This is to simplify client code that consumes your API (nested params are hard).
|
60
60
|
- Successful responses are returned with a status of 200 (OK).
|
61
61
|
- The body of a successful response is always a hash, serialized as JSON.
|
62
|
-
- Requests that have errors are returned with a status
|
62
|
+
- Requests that have errors are returned with a status that is **not** 200. The body of a error response is an error message in the response's content type (won't be JSON in most cases).
|
63
63
|
|
64
64
|
|
65
65
|
Defining API actions
|
@@ -210,7 +210,11 @@ Errors can be caught and inspected like this:
|
|
210
210
|
puts "Response: #{e.response_body}"
|
211
211
|
end
|
212
212
|
|
213
|
-
|
213
|
+
Use the `:protocol` option to connect using SSL:
|
214
|
+
|
215
|
+
client = Apify::Client.new(:host => 'api.site.com', :user => 'api', :password => 'secret', :protocol => 'https')
|
216
|
+
|
217
|
+
An example for an API client can be found under the `examples/client` directory inside the repository.
|
214
218
|
|
215
219
|
|
216
220
|
Dealing with dates and timestamps
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/apify.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apify}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Henning Koch"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-03}
|
13
13
|
s.description = %q{Compact definition of JSON APIs for Rails applications. }
|
14
14
|
s.email = %q{github@makandra.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<ul>
|
20
20
|
<li>Successful requests are returned with a status of 200 (OK).</li>
|
21
21
|
<li>The body of a successful response is always a hash, serialized as JSON.</li>
|
22
|
-
<li>Requests that have errors are returned with a status
|
22
|
+
<li>Requests that have errors are returned with a status that is <strong>not</strong> 200. The body of a error response is an error message in the response's content type (won't be JSON in most cases).</li>
|
23
23
|
<li>You can download an example for a successful response value by appending <code>?example=value</code> to the action URL.</li>
|
24
24
|
<li>You can download a <a href="http://json-schema.org/">JSON schema</a> for a successful response by appending <code>?schema=value</code> to the URL. The API guarantees that all responses conform to this schema.</li>
|
25
25
|
</ul>
|
data/lib/apify/client.rb
CHANGED
@@ -35,8 +35,7 @@ module Apify
|
|
35
35
|
|
36
36
|
def request(method, path, args = nil)
|
37
37
|
url = build_url(path)
|
38
|
-
args
|
39
|
-
params = { :args => args.to_json }
|
38
|
+
params = args ? { :args => args.to_json } : {}
|
40
39
|
[:get, :head].include?(method) and params = { :params => params }
|
41
40
|
json = RestClient.send(method, url, params)
|
42
41
|
JSON.parse(json)
|
data/spec/apify/client_spec.rb
CHANGED
@@ -22,19 +22,40 @@ describe Apify::Client do
|
|
22
22
|
|
23
23
|
it "should call API methods with arguments" do
|
24
24
|
client = Apify::Client.new(:host => 'host')
|
25
|
-
stub_request(:post, 'http://host/api/hello').to_return(:
|
25
|
+
stub_request(:post, 'http://host/api/hello').to_return(:body => '{}')
|
26
26
|
args = { :name => 'Jack' }
|
27
27
|
client.post('/api/hello', args)
|
28
28
|
WebMock.should have_requested(:post, "http://host/api/hello").with(:body => { :args => args.to_json })
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'should not transmit an args parameter if the arguments are blank' do
|
32
|
+
client = Apify::Client.new(:host => 'host')
|
33
|
+
stub_request(:get, 'http://host/api/ping').to_return(:body => '{}')
|
34
|
+
client.get('/api/ping')
|
35
|
+
WebMock.should have_requested(:get, "http://host/api/ping")
|
36
|
+
end
|
37
|
+
|
31
38
|
it "should call GET actions correctly" do
|
32
39
|
client = Apify::Client.new(:host => 'host')
|
33
40
|
args = { :name => 'Jack' }
|
34
|
-
stub_request(:get, 'http://host/api/hello').with(:query => { :args => args.to_json }).to_return(:
|
41
|
+
stub_request(:get, 'http://host/api/hello').with(:query => { :args => args.to_json }).to_return(:body => '{}')
|
35
42
|
client.get('/api/hello', args)
|
36
43
|
WebMock.should have_requested(:get, "http://host/api/hello").with(:query => { :args => args.to_json })
|
37
44
|
end
|
38
45
|
|
46
|
+
it "should connect using SSL" do
|
47
|
+
client = Apify::Client.new(:host => 'host', :protocol => 'https')
|
48
|
+
stub_request(:get, 'https://host/api/ping').to_return(:body => '{}')
|
49
|
+
client.get('/api/ping')
|
50
|
+
WebMock.should have_requested(:get, "https://host/api/ping")
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should allow to use a non-standard port' do
|
54
|
+
client = Apify::Client.new(:host => 'host', :port => '8080')
|
55
|
+
stub_request(:get, 'http://host:8080/api/ping').to_return(:body => '{}')
|
56
|
+
client.get('/api/ping')
|
57
|
+
WebMock.should have_requested(:get, "http://host:8080/api/ping")
|
58
|
+
end
|
59
|
+
|
39
60
|
end
|
40
61
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Henning Koch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-03 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|