apiture 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +14 -0
- data/lib/apiture/api_base.rb +2 -1
- data/lib/apiture/data_model.rb +1 -1
- data/lib/apiture/middleware/set_form_parameter.rb +14 -0
- data/lib/apiture/swagger/node.rb +10 -1
- data/lib/apiture/swagger/parameter.rb +1 -0
- data/lib/apiture/uri.rb +1 -2
- data/lib/apiture/version.rb +1 -1
- data/spec/apiture_spec.rb +24 -1
- data/spec/files/jsonplaceholder.yml +30 -0
- data/spec/fixtures/vcr_cassettes/jsonplaceholder_createPost.yml +59 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43c92cdbf01d3a08d09f7c9f142326e68d571933
|
4
|
+
data.tar.gz: 64c58f798e154f7508efc272ee60cf9095f18b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7e72e4e47a2b83fc42324f71b21c363257cac465cac965330888d7310cc3a82a9e01a75c407cb7290f97e059c00570ed13b5cbbdedad00ec393d097a46d5109
|
7
|
+
data.tar.gz: 4e26f7d33a5d0ed70b12c77017d2eb4574c52a3622bf5da0c0dcbcceb3fd4819b1194c9721695d330cf838f3ab30c673ed6bfbd6a7e46d6f8e296591b18bcba9
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "apiture"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/lib/apiture/api_base.rb
CHANGED
data/lib/apiture/data_model.rb
CHANGED
@@ -13,7 +13,7 @@ module Apiture
|
|
13
13
|
h = context.get_attribute(parameter_name)
|
14
14
|
return nil unless h
|
15
15
|
|
16
|
-
json = definition.properties.reduce({}) do |m, (name,
|
16
|
+
json = definition.properties.reduce({}) do |m, (name, _)|
|
17
17
|
name = name.to_sym
|
18
18
|
m[name] = h[name] if h[name]; m
|
19
19
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'apiture/middleware/set_parameter_base'
|
2
|
+
|
3
|
+
module Apiture
|
4
|
+
module Middleware
|
5
|
+
class SetFormParameter < SetParameterBase
|
6
|
+
def apply_parameter_value(env, value)
|
7
|
+
unless value.nil?
|
8
|
+
env[:params][@name] = value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
data/lib/apiture/swagger/node.rb
CHANGED
@@ -5,11 +5,17 @@ module Apiture
|
|
5
5
|
class Node
|
6
6
|
include Apiture::Utils::Inflections
|
7
7
|
|
8
|
+
@attribute_names = nil
|
9
|
+
@list_names = nil
|
10
|
+
@hash_names = nil
|
11
|
+
@validates_children = nil
|
12
|
+
|
8
13
|
class << self
|
9
14
|
def inherited(base)
|
10
15
|
base.instance_variable_set(:@attribute_names, attribute_names.dup)
|
11
16
|
base.instance_variable_set(:@list_names, list_names.dup)
|
12
17
|
base.instance_variable_set(:@hash_names, hash_names.dup)
|
18
|
+
base.instance_variable_set(:@validates_children, nil)
|
13
19
|
end
|
14
20
|
|
15
21
|
def attribute_names
|
@@ -27,15 +33,18 @@ module Apiture
|
|
27
33
|
def attribute(name, options = {})
|
28
34
|
name = name.to_sym
|
29
35
|
(@attribute_names ||= []) << name
|
30
|
-
attr_accessor name
|
31
36
|
if options[:type] == :boolean
|
37
|
+
attr_accessor name
|
32
38
|
define_method("#{name}?".to_sym) do
|
33
39
|
!!send(name)
|
34
40
|
end
|
35
41
|
elsif options[:symbolize]
|
42
|
+
attr_reader name
|
36
43
|
define_method("#{name}=".to_sym) do |value|
|
37
44
|
instance_variable_set("@#{name}".to_sym, value.nil? ? nil : value.to_sym)
|
38
45
|
end
|
46
|
+
else
|
47
|
+
attr_accessor name
|
39
48
|
end
|
40
49
|
(@validates_children ||= []) << name if options[:validate]
|
41
50
|
end
|
data/lib/apiture/uri.rb
CHANGED
data/lib/apiture/version.rb
CHANGED
data/spec/apiture_spec.rb
CHANGED
@@ -11,7 +11,10 @@ describe Apiture do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def load_api(name)
|
14
|
-
|
14
|
+
unless name.index('.')
|
15
|
+
name += ".json"
|
16
|
+
end
|
17
|
+
fn = File.join(File.dirname(__FILE__), 'files', name)
|
15
18
|
Apiture.load_api(fn)
|
16
19
|
end
|
17
20
|
|
@@ -225,4 +228,24 @@ describe Apiture do
|
|
225
228
|
end
|
226
229
|
end
|
227
230
|
end
|
231
|
+
|
232
|
+
describe "JSONPlaceholder API" do
|
233
|
+
before do
|
234
|
+
JSONPlaceholder = load_api("jsonplaceholder.yml")
|
235
|
+
@client = configure_client(JSONPlaceholder.new)
|
236
|
+
end
|
237
|
+
|
238
|
+
after do
|
239
|
+
Object.send(:remove_const, :JSONPlaceholder)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should support parameters in form" do
|
243
|
+
VCR.use_cassette("jsonplaceholder_createPost") do
|
244
|
+
resp = @client.create_post(title: "foo", body: "bar", user_id: 1)
|
245
|
+
expect(resp.status).to eq 201
|
246
|
+
expect(resp.body["id"]).to eq 101
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
228
251
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
swagger: "2.0"
|
3
|
+
info:
|
4
|
+
title: JSONPlaceholder
|
5
|
+
description: Test API
|
6
|
+
version: "1"
|
7
|
+
host: jsonplaceholder.typicode.com
|
8
|
+
basePath: "/"
|
9
|
+
schemes:
|
10
|
+
- http
|
11
|
+
produces:
|
12
|
+
- application/json
|
13
|
+
paths:
|
14
|
+
/posts:
|
15
|
+
post:
|
16
|
+
summary: Create a post
|
17
|
+
operationId: createPost
|
18
|
+
parameters:
|
19
|
+
- name: title
|
20
|
+
in: form
|
21
|
+
required: true
|
22
|
+
type: string
|
23
|
+
- name: body
|
24
|
+
in: form
|
25
|
+
required: true
|
26
|
+
type: string
|
27
|
+
- name: userId
|
28
|
+
in: form
|
29
|
+
required: true
|
30
|
+
type: integer
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://jsonplaceholder.typicode.com/posts?body=bar&title=foo&userId=1
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- apiture-rb/0.2.1
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Content-Length:
|
15
|
+
- '0'
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: Created
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
X-Powered-By:
|
28
|
+
- Express
|
29
|
+
Vary:
|
30
|
+
- Origin, X-HTTP-Method-Override, Accept-Encoding
|
31
|
+
Access-Control-Allow-Credentials:
|
32
|
+
- 'true'
|
33
|
+
Cache-Control:
|
34
|
+
- no-cache
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Expires:
|
38
|
+
- "-1"
|
39
|
+
X-Content-Type-Options:
|
40
|
+
- nosniff
|
41
|
+
Content-Type:
|
42
|
+
- application/json; charset=utf-8
|
43
|
+
Content-Length:
|
44
|
+
- '15'
|
45
|
+
Etag:
|
46
|
+
- W/"f-Je9hRGS1lnrngFIuH64GAA"
|
47
|
+
Date:
|
48
|
+
- Sat, 11 Jun 2016 14:55:02 GMT
|
49
|
+
Via:
|
50
|
+
- 1.1 vegur
|
51
|
+
body:
|
52
|
+
encoding: UTF-8
|
53
|
+
string: |-
|
54
|
+
{
|
55
|
+
"id": 101
|
56
|
+
}
|
57
|
+
http_version:
|
58
|
+
recorded_at: Sat, 11 Jun 2016 14:55:02 GMT
|
59
|
+
recorded_with: VCR 2.9.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calvin Yu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,7 +125,8 @@ dependencies:
|
|
125
125
|
description: 'Create clients for REST APIs from their Swagger specification '
|
126
126
|
email:
|
127
127
|
- me@sourcebender.com
|
128
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- console
|
129
130
|
extensions: []
|
130
131
|
extra_rdoc_files: []
|
131
132
|
files:
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- README.md
|
136
137
|
- Rakefile
|
137
138
|
- apiture.gemspec
|
139
|
+
- bin/console
|
138
140
|
- lib/apiture.rb
|
139
141
|
- lib/apiture/api_base.rb
|
140
142
|
- lib/apiture/api_builder.rb
|
@@ -148,6 +150,7 @@ files:
|
|
148
150
|
- lib/apiture/middleware/convert_json_body.rb
|
149
151
|
- lib/apiture/middleware/debug.rb
|
150
152
|
- lib/apiture/middleware/set_body_parameter.rb
|
153
|
+
- lib/apiture/middleware/set_form_parameter.rb
|
151
154
|
- lib/apiture/middleware/set_header.rb
|
152
155
|
- lib/apiture/middleware/set_parameter_base.rb
|
153
156
|
- lib/apiture/middleware/set_path_parameter.rb
|
@@ -178,6 +181,7 @@ files:
|
|
178
181
|
- spec/files/github.json
|
179
182
|
- spec/files/harvest.json
|
180
183
|
- spec/files/honeybadger.json
|
184
|
+
- spec/files/jsonplaceholder.yml
|
181
185
|
- spec/files/mandrill.json
|
182
186
|
- spec/files/pivotal_tracker.json
|
183
187
|
- spec/files/slack.json
|
@@ -186,6 +190,7 @@ files:
|
|
186
190
|
- spec/fixtures/vcr_cassettes/github_getUser.yml
|
187
191
|
- spec/fixtures/vcr_cassettes/harvest_invoiceList.yml
|
188
192
|
- spec/fixtures/vcr_cassettes/honeybadger.yml
|
193
|
+
- spec/fixtures/vcr_cassettes/jsonplaceholder_createPost.yml
|
189
194
|
- spec/fixtures/vcr_cassettes/mandrill_messageSend.yml
|
190
195
|
- spec/fixtures/vcr_cassettes/mandrill_userPing.yml
|
191
196
|
- spec/fixtures/vcr_cassettes/pivotal_tracker_create_story.yml
|
@@ -224,6 +229,7 @@ test_files:
|
|
224
229
|
- spec/files/github.json
|
225
230
|
- spec/files/harvest.json
|
226
231
|
- spec/files/honeybadger.json
|
232
|
+
- spec/files/jsonplaceholder.yml
|
227
233
|
- spec/files/mandrill.json
|
228
234
|
- spec/files/pivotal_tracker.json
|
229
235
|
- spec/files/slack.json
|
@@ -232,6 +238,7 @@ test_files:
|
|
232
238
|
- spec/fixtures/vcr_cassettes/github_getUser.yml
|
233
239
|
- spec/fixtures/vcr_cassettes/harvest_invoiceList.yml
|
234
240
|
- spec/fixtures/vcr_cassettes/honeybadger.yml
|
241
|
+
- spec/fixtures/vcr_cassettes/jsonplaceholder_createPost.yml
|
235
242
|
- spec/fixtures/vcr_cassettes/mandrill_messageSend.yml
|
236
243
|
- spec/fixtures/vcr_cassettes/mandrill_userPing.yml
|
237
244
|
- spec/fixtures/vcr_cassettes/pivotal_tracker_create_story.yml
|