apify 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apify.gemspec +4 -4
- data/lib/apify/client.rb +13 -3
- data/spec/apify/client_spec.rb +9 -1
- metadata +15 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.3
|
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.5.
|
8
|
+
s.version = "0.5.3"
|
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{2011-
|
12
|
+
s.date = %q{2011-03-02}
|
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 = [
|
@@ -109,7 +109,7 @@ Gem::Specification.new do |s|
|
|
109
109
|
s.homepage = %q{http://github.com/makandra/apify}
|
110
110
|
s.rdoc_options = ["--charset=UTF-8"]
|
111
111
|
s.require_paths = ["lib"]
|
112
|
-
s.rubygems_version = %q{1.3.
|
112
|
+
s.rubygems_version = %q{1.3.7}
|
113
113
|
s.summary = %q{Compact definition of JSON APIs for Rails applications.}
|
114
114
|
s.test_files = [
|
115
115
|
"spec/apify/action_spec.rb",
|
@@ -154,7 +154,7 @@ Gem::Specification.new do |s|
|
|
154
154
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
155
155
|
s.specification_version = 3
|
156
156
|
|
157
|
-
if Gem::Version.new(Gem::
|
157
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
158
158
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
159
159
|
s.add_runtime_dependency(%q<jsonschema>, [">= 0"])
|
160
160
|
s.add_runtime_dependency(%q<rest-client>, [">= 1.6.1"])
|
data/lib/apify/client.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'json'
|
4
4
|
require 'restclient'
|
5
5
|
require 'apify/errors'
|
6
|
+
require 'cgi'
|
6
7
|
|
7
8
|
module Apify
|
8
9
|
class Client
|
@@ -34,9 +35,13 @@ module Apify
|
|
34
35
|
private
|
35
36
|
|
36
37
|
def request(method, path, args = nil)
|
37
|
-
url = build_url(path)
|
38
38
|
params = args ? { :args => args.to_json } : {}
|
39
|
-
[:get, :
|
39
|
+
if [:get, :delete].include?(method)
|
40
|
+
url = build_url(path, params)
|
41
|
+
params = {}
|
42
|
+
else
|
43
|
+
url = build_url(path)
|
44
|
+
end
|
40
45
|
json = RestClient.send(method, url, params)
|
41
46
|
JSON.parse(json)
|
42
47
|
rescue RestClient::Unauthorized => e
|
@@ -45,7 +50,7 @@ module Apify
|
|
45
50
|
raise Apify::RequestFailed.new("API request failed with status #{e.http_code}", e.http_body)
|
46
51
|
end
|
47
52
|
|
48
|
-
def build_url(path)
|
53
|
+
def build_url(path, params = {})
|
49
54
|
url = ""
|
50
55
|
url << @protocol
|
51
56
|
url << '://'
|
@@ -53,6 +58,11 @@ module Apify
|
|
53
58
|
url << @host
|
54
59
|
url << ":#{@port}" if @port
|
55
60
|
url << path
|
61
|
+
unless params.empty?
|
62
|
+
url << '?'
|
63
|
+
url << params.collect { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
|
64
|
+
end
|
65
|
+
url
|
56
66
|
end
|
57
67
|
|
58
68
|
end
|
data/spec/apify/client_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe Apify::Client do
|
|
35
35
|
WebMock.should have_requested(:get, "http://host/api/ping")
|
36
36
|
end
|
37
37
|
|
38
|
-
it "should
|
38
|
+
it "should serialize params into the URL for GET requests" do
|
39
39
|
client = Apify::Client.new(:host => 'host')
|
40
40
|
args = { :name => 'Jack' }
|
41
41
|
stub_request(:get, 'http://host/api/hello').with(:query => { :args => args.to_json }).to_return(:body => '{}')
|
@@ -43,6 +43,14 @@ describe Apify::Client do
|
|
43
43
|
WebMock.should have_requested(:get, "http://host/api/hello").with(:query => { :args => args.to_json })
|
44
44
|
end
|
45
45
|
|
46
|
+
it "should serialize params into the URL for DELETE requests" do
|
47
|
+
client = Apify::Client.new(:host => 'host')
|
48
|
+
args = { :name => 'Jack' }
|
49
|
+
stub_request(:delete, 'http://host/api/terminate').with(:query => { :args => args.to_json }).to_return(:body => '{}')
|
50
|
+
client.delete('/api/terminate', args)
|
51
|
+
WebMock.should have_requested(:delete, "http://host/api/terminate").with(:query => { :args => args.to_json })
|
52
|
+
end
|
53
|
+
|
46
54
|
it "should connect using SSL" do
|
47
55
|
client = Apify::Client.new(:host => 'host', :protocol => 'https')
|
48
56
|
stub_request(:get, 'https://host/api/ping').to_return(:body => '{}')
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Henning Koch
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
+
date: 2011-03-02 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: json
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: jsonschema
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
39
44
|
segments:
|
40
45
|
- 0
|
41
46
|
version: "0"
|
@@ -45,9 +50,11 @@ dependencies:
|
|
45
50
|
name: rest-client
|
46
51
|
prerelease: false
|
47
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
48
54
|
requirements:
|
49
55
|
- - ">="
|
50
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 13
|
51
58
|
segments:
|
52
59
|
- 1
|
53
60
|
- 6
|
@@ -163,23 +170,27 @@ rdoc_options:
|
|
163
170
|
require_paths:
|
164
171
|
- lib
|
165
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
166
174
|
requirements:
|
167
175
|
- - ">="
|
168
176
|
- !ruby/object:Gem::Version
|
177
|
+
hash: 3
|
169
178
|
segments:
|
170
179
|
- 0
|
171
180
|
version: "0"
|
172
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
173
183
|
requirements:
|
174
184
|
- - ">="
|
175
185
|
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
176
187
|
segments:
|
177
188
|
- 0
|
178
189
|
version: "0"
|
179
190
|
requirements: []
|
180
191
|
|
181
192
|
rubyforge_project:
|
182
|
-
rubygems_version: 1.3.
|
193
|
+
rubygems_version: 1.3.7
|
183
194
|
signing_key:
|
184
195
|
specification_version: 3
|
185
196
|
summary: Compact definition of JSON APIs for Rails applications.
|