sk_api_schema 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sk_api_schema.rb +6 -6
- data/sk_api_schema.gemspec +2 -2
- data/spec/sk_api_schema_spec.rb +5 -5
- metadata +72 -62
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/sk_api_schema.rb
CHANGED
@@ -20,7 +20,7 @@ module SK
|
|
20
20
|
def registry
|
21
21
|
@registry ||={}
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def registry_reset
|
25
25
|
@registry = nil
|
26
26
|
end
|
@@ -72,7 +72,7 @@ module SK
|
|
72
72
|
# === Example
|
73
73
|
# obj = Invoice.new(:title =>'hello world', :number=>'4711')
|
74
74
|
#
|
75
|
-
# obj_hash = SK::Api::Schema.to_hash_from_schema(obj, 'v1.0')
|
75
|
+
# obj_hash = SK::Api::Schema.to_hash_from_schema(obj, 'v1.0')
|
76
76
|
# => { 'invoice' =>{'title'=>'hello world', 'number'=>'4711' } }
|
77
77
|
#
|
78
78
|
# obj_hash = SK::Api::Schema.to_hash_from_schema(obj, 'v1.0', :fields=>['title'])
|
@@ -80,13 +80,13 @@ module SK
|
|
80
80
|
#
|
81
81
|
# obj_hash = SK::Api::Schema.to_hash_from_schema(obj, 'v1.0', :class_name=>:document)
|
82
82
|
# => { 'document' =>{'title'=>'hello world' } }
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# === Parameter
|
85
85
|
# obj<Object>:: An ruby object which is returned as hash
|
86
86
|
# version<String>:: the schema version, must be a valid folder name see
|
87
87
|
# #self.read
|
88
88
|
# opts<Hash{Symbol=>Mixed} >:: additional options
|
89
|
-
#
|
89
|
+
#
|
90
90
|
# ==== opts Parameter
|
91
91
|
# class_name<String|Symbol>:: Name of the class to use as hash key. Should be
|
92
92
|
# a lowered, underscored name and it MUST have an existing schema file.
|
@@ -143,7 +143,7 @@ module SK
|
|
143
143
|
def parse_links(obj, schema)
|
144
144
|
links = []
|
145
145
|
schema['links'] && schema['links'].each do |link|
|
146
|
-
links << { 'rel' => link['rel'], 'href' => link['href'].gsub(/\{id\}/, obj.id) }
|
146
|
+
links << { 'rel' => link['rel'], 'href' => link['href'].gsub(/\{id\}/, "#{obj.id}") }
|
147
147
|
end
|
148
148
|
links.uniq
|
149
149
|
# return links only if not empty
|
@@ -170,7 +170,7 @@ module SK
|
|
170
170
|
setters += opts[:keep] if opts[:keep] && opts[:keep].is_a?(Array)
|
171
171
|
# kick readonly
|
172
172
|
props.delete_if { |k,v| !setters.include?("#{k}") }
|
173
|
-
#convert to type in schema
|
173
|
+
#convert to type in schema
|
174
174
|
props.each do |k,v|
|
175
175
|
if schema['properties']["#{k}"]['type'] == 'string' && !v.is_a?(String)
|
176
176
|
props[k] = "#{v}"
|
data/sk_api_schema.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sk_api_schema"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Georg Leciejewski"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-06-02"
|
13
13
|
s.description = "The SalesKing JSON Schema describes our business API in terms of available objects, their fields and links to url endpoints with related objects. Besides ruby users can use a smal lib with utility methods to load and test the schema files."
|
14
14
|
s.email = "gl@salesking.eu"
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/sk_api_schema_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe SK::Api::Schema, 'reading' do
|
|
5
5
|
before :each do
|
6
6
|
SK::Api::Schema.registry_reset
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should read json schema file" do
|
10
10
|
schema = SK::Api::Schema.read(:invoice, 'v1.0')
|
11
11
|
schema[:title].should == 'invoice'
|
@@ -24,7 +24,7 @@ describe SK::Api::Schema, 'reading' do
|
|
24
24
|
|
25
25
|
it "should read all json schemas" do
|
26
26
|
schemas = SK::Api::Schema.read_all('1.0')
|
27
|
-
|
27
|
+
|
28
28
|
file_path = File.join(File.dirname(__FILE__), '../json', 'v1.0', '*.json')
|
29
29
|
# just check file count
|
30
30
|
schemas.length.should == Dir.glob( file_path ).length
|
@@ -33,7 +33,7 @@ describe SK::Api::Schema, 'reading' do
|
|
33
33
|
it "should raise error if version folder does not exist" do
|
34
34
|
lambda{
|
35
35
|
SK::Api::Schema.read(:invoice, 'v3.0')
|
36
|
-
}.should raise_error
|
36
|
+
}.should raise_error
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should raise error if schema file does not exist" do
|
@@ -74,10 +74,10 @@ describe SK::Api::Schema, 'object parsing' do
|
|
74
74
|
it "should parse object with empty relations from schema" do
|
75
75
|
obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
|
76
76
|
# {"invoice"=>{"number"=>"911", "line_items"=>[], "archived_pdf"=>nil, "title"=>"Your Invoice", "date"=>nil, "id"=>"some-uuid", "client"=>nil, "due_date"=>nil}}
|
77
|
-
obj_hash.keys.should == ["invoice", "links"]
|
77
|
+
obj_hash.keys.sort.should == ["invoice", "links"]
|
78
78
|
obj_hash['invoice'].should include( "number"=>"911","line_items"=>[],"archived_pdf"=>nil,"id"=>"some-uuid", "title"=>"Your Invoice" )
|
79
79
|
client_obj_hash = SK::Api::Schema.to_hash_from_schema(@client, 'v1.0')
|
80
|
-
client_obj_hash.keys.should == ["client", "links"]
|
80
|
+
client_obj_hash.keys.sort.should == ["client", "links"]
|
81
81
|
client_obj_hash['client'].should include("number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil)
|
82
82
|
end
|
83
83
|
|
metadata
CHANGED
@@ -1,73 +1,73 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sk_api_schema
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Georg Leciejewski
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
|
18
|
+
date: 2012-06-02 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
22
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
22
|
-
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
23
30
|
prerelease: false
|
24
|
-
|
31
|
+
name: activesupport
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
36
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
prerelease: false
|
31
45
|
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
46
|
type: :development
|
39
|
-
|
40
|
-
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
50
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
prerelease: false
|
47
59
|
name: rcov
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
60
|
type: :development
|
55
|
-
|
56
|
-
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
description: The SalesKing JSON Schema describes our business API in terms of available
|
63
|
-
objects, their fields and links to url endpoints with related objects. Besides ruby
|
64
|
-
users can use a smal lib with utility methods to load and test the schema files.
|
61
|
+
version_requirements: *id003
|
62
|
+
description: The SalesKing JSON Schema describes our business API in terms of available objects, their fields and links to url endpoints with related objects. Besides ruby users can use a smal lib with utility methods to load and test the schema files.
|
65
63
|
email: gl@salesking.eu
|
66
64
|
executables: []
|
65
|
+
|
67
66
|
extensions: []
|
68
|
-
|
67
|
+
|
68
|
+
extra_rdoc_files:
|
69
69
|
- README.rdoc
|
70
|
-
files:
|
70
|
+
files:
|
71
71
|
- CHANGELOG.rdoc
|
72
72
|
- README.rdoc
|
73
73
|
- Rakefile
|
@@ -104,26 +104,36 @@ files:
|
|
104
104
|
- spec/spec_helper.rb
|
105
105
|
homepage: http://github.com/salesking/sk_api_schema
|
106
106
|
licenses: []
|
107
|
+
|
107
108
|
post_install_message:
|
108
109
|
rdoc_options: []
|
109
|
-
|
110
|
+
|
111
|
+
require_paths:
|
110
112
|
- lib
|
111
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
114
|
none: false
|
113
|
-
requirements:
|
114
|
-
- -
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
|
117
|
-
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
123
|
none: false
|
119
|
-
requirements:
|
120
|
-
- -
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
123
131
|
requirements: []
|
132
|
+
|
124
133
|
rubyforge_project:
|
125
134
|
rubygems_version: 1.8.24
|
126
135
|
signing_key:
|
127
136
|
specification_version: 3
|
128
137
|
summary: SalesKing API JSON Schema
|
129
138
|
test_files: []
|
139
|
+
|