sk_api_schema 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ coverage/*
2
+ rdoc/*
3
+ pkg/*
4
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ gemfile:
5
+ - Gemfile
data/CHANGELOG.rdoc CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  A more detailed view of the changes can be found in the {commit messages}[https://github.com/salesking/sk_api_schema/commits/]
4
4
 
5
+ 2012-06
6
+ * add due_date and due_days to order
7
+ * test with travis-ci.org
8
+
9
+ 2012-05
10
+ * fix date type definitions
11
+ * add empty links sections for address, line_item
12
+ * add payment_method to order
13
+ * deprecate gross_total for payment reminder
14
+
5
15
  2012-01
6
16
  * add notes field for client
7
17
 
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.rdoc CHANGED
@@ -1,12 +1,11 @@
1
1
  = SalesKing API Schema
2
2
 
3
- Our API is described with JSON Schema's (http://json-schema.org). A schema
4
- describes a resource(object) in a readable JSON format:
3
+ Our API is described with JSON Schema's (http://json-schema.org), describing our objects(resources) in a readable JSON format:
5
4
 
6
- {
5
+ {
7
6
  "title": "client",
8
7
  "properties": { ...},
9
- "links": [ .. ]
8
+ "links": [ .. ]
10
9
  }
11
10
  The properties-section defines the fields. CRUD actions and
12
11
  relationships with other resources are found in the link-section.
@@ -38,8 +37,8 @@ The schema main version(NOT the gem version) can be set with the "v" url paramet
38
37
  in any call, but is pretty useless as long as we are in v1.0
39
38
  my.salesking.eu/api/clients?v='1.0'
40
39
 
41
- The gem has its own version number. A new gem version indicates a change, but
42
- we first try it on our staging environment before any live instances are
40
+ The gem has its own version number. A new gem version indicates a change, but
41
+ we first try it on our staging environment before any live instances are
43
42
  updated and the schema becomes public available. The gem is used by SalesKing
44
43
  to deliver it's data BUT changes might not be directly reflected as stated.
45
44
  To see the current gem version use:
@@ -57,7 +56,7 @@ parameter:
57
56
 
58
57
  Please try to only request the fields you really need, to save computing power!
59
58
 
60
- == Object Structure Basic's
59
+ == Object Basic's
61
60
 
62
61
  Primary object types in SK are:
63
62
  * Documents
@@ -76,7 +75,7 @@ The third kind are supportive objects
76
75
  * Exports
77
76
  * Templates
78
77
 
79
- == Enpoints & Links
78
+ == Endpoints & Links
80
79
 
81
80
  Following list gives you a quick overview of relations with nested urls an how
82
81
  parameters work. You can find those in detail when looking at the link section
@@ -100,22 +99,24 @@ of each schema.
100
99
  # all invoices of a client
101
100
  /clients/:id/invoices
102
101
 
103
-
104
- == ToDo:
105
-
106
- Those relative urls in the link sections, need some love, so please don't rely on
107
- them to much right now.
108
-
109
102
  == Install
110
103
 
111
104
  gem install sk_api_schema
112
105
 
113
106
  == Test
114
107
 
115
- Before you run the tests use bundler to install all required gems:
108
+ {<img src="https://secure.travis-ci.org/salesking/sk_api_schema.png?branch=master" alt="Build Status" />}[http://travis-ci.org/salesking/sk_api_schema]
109
+
110
+ Install required gems with bundler and go for it:
116
111
  # git clone
117
112
  # cd into sk_api_schema dir
118
- BUNDLE_GEMFILE=ci/Gemfile bundle install
119
- BUNDLE_GEMFILE=ci/Gemfile bundle exec rake spec
113
+ bundle install
114
+ rake spec
115
+
116
+
117
+ == ToDo:
118
+
119
+ Those relative urls in the link sections, need some love, so please don't rely on
120
+ them to much right now.
120
121
 
121
- Copyright (c) 2010-2011 Georg Leciejewski, released under the MIT license
122
+ Copyright (c) 2010-2012 Georg Leciejewski, released under the MIT license
data/Rakefile CHANGED
@@ -1,42 +1,13 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
- require 'rdoc/task'
4
2
  require 'rspec'
5
3
  require 'rspec/core/rake_task'
6
-
7
- begin
8
- require 'jeweler'
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = "sk_api_schema"
11
- gem.summary = %Q{SalesKing API JSON Schema}
12
- gem.description = %Q{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.}
13
- gem.email = "gl@salesking.eu"
14
- gem.homepage = "http://github.com/salesking/sk_api_schema"
15
- gem.authors = ["Georg Leciejewski"]
16
- gem.add_dependency 'activesupport'
17
- gem.add_development_dependency "rspec"
18
- gem.add_development_dependency "rcov"
19
- end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
- end
24
-
25
- desc 'Default: run specs.'
26
- task :default => :spec
4
+ require 'rdoc/task'
5
+ require 'bundler/gem_helper'
6
+ Bundler::GemHelper.install_tasks
27
7
 
28
8
  desc "Run specs"
29
- RSpec::Core::RakeTask.new do |t|
30
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
31
- # Put spec opts in a file named .rspec in root
32
- end
33
-
34
- desc "Generate code coverage"
35
- RSpec::Core::RakeTask.new(:coverage) do |t|
36
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
37
- t.rcov = true
38
- t.rcov_opts = ['--exclude', 'spec']
39
- end
9
+ RSpec::Core::RakeTask.new
10
+ task :default => :spec
40
11
 
41
12
  desc 'Generate documentation.'
42
13
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -104,11 +104,11 @@
104
104
  "type":"string"
105
105
  },
106
106
  "lock_version":{
107
- "description": "Auto-incremented by SK to prevent concurrent updateing. First save wins.",
107
+ "description": "Auto-incremented to prevent concurrent updates. First save wins.",
108
108
  "type":"integer"
109
109
  },
110
110
  "price_total":{
111
- "description": "Deprecated use net_total_base_raw",
111
+ "description": "Deprecated use net_total_base",
112
112
  "readonly":true,
113
113
  "type":"number"
114
114
  },
@@ -133,7 +133,7 @@
133
133
  "type":"number"
134
134
  },
135
135
  "net_total_base":{
136
- "description": "Net total, 6 decimal places. Summmed items net_total_base_raw (incl discount)",
136
+ "description": "Net total, 6 decimal places incl. discount",
137
137
  "readonly":true,
138
138
  "type":"number"
139
139
  }
@@ -87,12 +87,7 @@
87
87
  "type":"number"
88
88
  },
89
89
  "net_total_base":{
90
- "description": "Net total, decimals places as set in precision, default 2",
91
- "readonly":true,
92
- "type":"number"
93
- },
94
- "net_total_base_raw":{
95
- "description": "Net total, 6 decimal places. Summmed items net_total_base_raw (incl discount)",
90
+ "description": "Net total, 6 decimal places incl. discount",
96
91
  "readonly":true,
97
92
  "type":"number"
98
93
  }
@@ -99,7 +99,7 @@
99
99
  "type":"string"
100
100
  },
101
101
  "lock_version":{
102
- "description": "Auto-incremented to prevent concurrent updateing. First save wins and increments version.",
102
+ "description": "Auto-incremented to prevent concurrent updates. First save wins and increments version.",
103
103
  "type":"integer"
104
104
  },
105
105
  "gross_total":{
@@ -118,12 +118,7 @@
118
118
  "type":"number"
119
119
  },
120
120
  "net_total_base":{
121
- "description": "Net total, decimals places as set in precision, default 2",
122
- "readonly":true,
123
- "type":"number"
124
- },
125
- "net_total_base_raw":{
126
- "description": "Net total unrounded, 6 decimal places. Summed items net_total_base_raw (incl discount)",
121
+ "description": "Net total, 6 decimal places incl. discount",
127
122
  "readonly":true,
128
123
  "type":"number"
129
124
  }
@@ -231,7 +226,8 @@
231
226
  "properties" : {
232
227
  "source" : {
233
228
  "title" : "Source document id",
234
- "description": "Copies the source document(excl. number,date) and returns a new draft document."
229
+ "description": "Copies the source document(excl. number,date) and returns a new draft document.",
230
+ "type" : "string"
235
231
  }
236
232
  }
237
233
  },
@@ -22,11 +22,11 @@
22
22
  "type":"string"
23
23
  },
24
24
  "due_days":{
25
- "description": "Used to calculate the due date of the invoice. Useless if date and due date are present.",
25
+ "description": "Used to calculate the due date of the document. Useless if date and due date are present.",
26
26
  "type":"integer"
27
27
  },
28
28
  "due_date":{
29
- "description": "Auto-calculated from date + due days if empty and the invoice is opened.",
29
+ "description": "Auto-calculated from date + due days if empty and the document is opened.",
30
30
  "format":"date",
31
31
  "type":"string"
32
32
  },
@@ -104,7 +104,7 @@
104
104
  "type":"string"
105
105
  },
106
106
  "lock_version":{
107
- "description": "Auto-incremented to prevent concurrent updateing. First save wins and increments version. ",
107
+ "description": "Auto-incremented to prevent concurrent updates. First save wins and increments version. ",
108
108
  "type":"integer"
109
109
  },
110
110
  "price_total":{
@@ -133,7 +133,7 @@
133
133
  "type":"number"
134
134
  },
135
135
  "net_total_base":{
136
- "description": "Net total, 6 decimal places. Summmed items net_total_base_raw (incl discount)",
136
+ "description": "Net total, 6 decimal places incl. discount",
137
137
  "readonly":true,
138
138
  "type":"number"
139
139
  }
@@ -229,12 +229,14 @@
229
229
  "properties" : {
230
230
  "source" : {
231
231
  "title" : "Source document id",
232
- "description": "Copies the source document(excl. number,date) and returns a new draft document. If the source is an Estimate or Order only line_items, client & tags are copied, so you can pass in additional fields."
232
+ "description": "Copies the source document(excl. number,date) and returns a new draft document. If the source is an Estimate or Order only line_items, client & tags are copied, so you can pass in additional fields.",
233
+ "type" : "string"
233
234
  },
234
235
  "cancel" : {
235
236
  "title" : "Cancel an invoice",
236
- "description": "Cancelling a document negates its line item values. A source id must be set.",
237
- "dependencies": ["source"]
237
+ "description": "Cancelling a document copies the source and negates its line item values. A source id must be set.",
238
+ "dependencies": ["source"],
239
+ "type":"boolean"
238
240
  }
239
241
  }
240
242
  },
data/json/v1.0/order.json CHANGED
@@ -21,6 +21,15 @@
21
21
  "format":"date",
22
22
  "type":"string"
23
23
  },
24
+ "due_days":{
25
+ "description": "Used to calculate the due date for the document. Useless if date and due date are present.",
26
+ "type":"integer"
27
+ },
28
+ "due_date":{
29
+ "description": "Auto-calculated from date + due days if empty and the document is opened.",
30
+ "format":"date",
31
+ "type":"string"
32
+ },
24
33
  "status":{
25
34
  "description": "Defaults to draft for new documents, unless otherwise stated. For new documents with status 'open' or 'closed' or doc where the status changes away from draft, following fields are set if empty: number(next in number schema), date(today), due date(due_days must be given). Only draft documents can be deleted.",
26
35
  "default":"draft",
@@ -95,7 +104,7 @@
95
104
  "type":"string"
96
105
  },
97
106
  "lock_version":{
98
- "description": "Auto-incremented to prevent concurrent updateing. First save wins and increments version.",
107
+ "description": "Auto-incremented to prevent concurrent updates. First save wins and increments version.",
99
108
  "type":"integer"
100
109
  },
101
110
  "gross_total":{
@@ -114,7 +123,7 @@
114
123
  "type":"number"
115
124
  },
116
125
  "net_total_base":{
117
- "description": "Net total, 6 decimal places. Summmed items net_total_base_raw (incl discount)",
126
+ "description": "Net total, 6 decimal places incl. discount",
118
127
  "readonly":true,
119
128
  "type":"number"
120
129
  }
@@ -222,7 +231,8 @@
222
231
  "properties" : {
223
232
  "source" : {
224
233
  "title" : "Source document id",
225
- "description": "Copies the source document(excl. number,date) and returns a new draft document."
234
+ "description": "Copies the source document(excl. number,date) and returns a new draft document.",
235
+ "type" : "string"
226
236
  }
227
237
  }
228
238
  },
@@ -95,7 +95,7 @@
95
95
  "type":"string"
96
96
  },
97
97
  "lock_version":{
98
- "description": "Auto-incremented to prevent concurrent updateing. First save wins and increments version. ",
98
+ "description": "Auto-incremented to prevent concurrent updates. First save wins and increments version. ",
99
99
  "type":"integer"
100
100
  },
101
101
  "gross_total":{
@@ -101,7 +101,7 @@
101
101
  "type":"string"
102
102
  },
103
103
  "lock_version":{
104
- "description": "Auto-incremented to prevent concurrent updateing. First save wins and increments version. ",
104
+ "description": "Auto-incremented to prevent concurrent updates. First save wins and increments version. ",
105
105
  "type":"integer"
106
106
  },
107
107
  "gross_total":{
@@ -120,7 +120,7 @@
120
120
  "type":"number"
121
121
  },
122
122
  "net_total_base":{
123
- "description": "Net total, 6 decimal places. Summmed items net_total_base_raw (incl discount)",
123
+ "description": "Net total, 6 decimal places incl. discount",
124
124
  "readonly":true,
125
125
  "type":"number"
126
126
  }
@@ -223,12 +223,8 @@
223
223
  "properties" : {
224
224
  "source" : {
225
225
  "title" : "Source document id",
226
- "description": "Copies the source document(excl. number,date) and returns a new draft document."
227
- },
228
- "cancel" : {
229
- "title" : "Cancel an recurring",
230
- "description": "Cancelling a document negates its line item values. A source id must be set.",
231
- "dependencies": ["source"]
226
+ "description": "Copies the source document(excl. number,date) and returns a new draft document.",
227
+ "type" : "string"
232
228
  }
233
229
  }
234
230
  },
@@ -0,0 +1,7 @@
1
+ module SK
2
+ module Api
3
+ class Schema
4
+ VERSION='0.3.3'
5
+ end
6
+ end
7
+ end
data/lib/sk_api_schema.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext/hash/indifferent_access'
4
4
  require 'active_support/core_ext/string/inflections'
5
+
5
6
  module SK
6
7
  module Api
7
8
  class Schema
@@ -1,77 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'sk_api_schema/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = "sk_api_schema"
8
- s.version = "0.3.2"
6
+ s.version = SK::Api::Schema::VERSION
7
+ s.date = %q{2012-06-02}
8
+ s.name = %q{sk_api_schema}
9
+ s.summary = "SalesKing API - JSON Schema"
10
+ s.description = %q{The SalesKing JSON Schema describes our business API in terms of available objects, their fields and links to url endpoints with related objects.
11
+ Besides ruby users can use a small lib with utility methods to load and test the schema files.}
12
+ s.authors = ["Georg Leciejewski"]
13
+ s.email = %q{gl@salesking.eu}
14
+ s.homepage = %q{http://github.com/salesking/sk_api_schema}
15
+ s.extra_rdoc_files = ["README.rdoc"]
16
+ s.executables = nil
17
+ s.files = `git ls-files`.split("\n").reject{|i| i[/^docs\//] }
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
9
19
 
10
20
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Georg Leciejewski"]
12
- s.date = "2012-06-02"
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
- s.email = "gl@salesking.eu"
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- "CHANGELOG.rdoc",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "ci/Gemfile",
24
- "json/v1.0/address.json",
25
- "json/v1.0/attachment.json",
26
- "json/v1.0/auth_permission.json",
27
- "json/v1.0/client.json",
28
- "json/v1.0/comment.json",
29
- "json/v1.0/company.json",
30
- "json/v1.0/credit_note.json",
31
- "json/v1.0/document.json",
32
- "json/v1.0/email.json",
33
- "json/v1.0/email_template.json",
34
- "json/v1.0/estimate.json",
35
- "json/v1.0/export.json",
36
- "json/v1.0/export_template.json",
37
- "json/v1.0/invoice.json",
38
- "json/v1.0/language.json",
39
- "json/v1.0/line_item.json",
40
- "json/v1.0/order.json",
41
- "json/v1.0/payment.json",
42
- "json/v1.0/payment_reminder.json",
43
- "json/v1.0/product.json",
44
- "json/v1.0/recurring.json",
45
- "json/v1.0/sub.json",
46
- "json/v1.0/tag.json",
47
- "json/v1.0/text_template.json",
48
- "json/v1.0/user.json",
49
- "lib/sk_api_schema.rb",
50
- "sk_api_schema.gemspec",
51
- "spec/sk_api_schema_spec.rb",
52
- "spec/spec_helper.rb"
53
- ]
54
- s.homepage = "http://github.com/salesking/sk_api_schema"
55
21
  s.require_paths = ["lib"]
56
22
  s.rubygems_version = "1.8.24"
57
- s.summary = "SalesKing API JSON Schema"
58
-
59
- if s.respond_to? :specification_version then
60
- s.specification_version = 3
61
23
 
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
64
- s.add_development_dependency(%q<rspec>, [">= 0"])
65
- s.add_development_dependency(%q<rcov>, [">= 0"])
66
- else
67
- s.add_dependency(%q<activesupport>, [">= 0"])
68
- s.add_dependency(%q<rspec>, [">= 0"])
69
- s.add_dependency(%q<rcov>, [">= 0"])
70
- end
71
- else
72
- s.add_dependency(%q<activesupport>, [">= 0"])
73
- s.add_dependency(%q<rspec>, [">= 0"])
74
- s.add_dependency(%q<rcov>, [">= 0"])
75
- end
76
- end
24
+ s.add_runtime_dependency 'activesupport'
25
+ s.add_development_dependency 'rdoc'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'simplecov'
28
+ s.add_development_dependency 'rake', '>= 0.9.2'
77
29
 
30
+ end
@@ -1,142 +1,144 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SK::Api::Schema, 'reading' do
3
+ describe SK::Api::Schema do
4
+ context 'reading' do
5
+
6
+ before :each do
7
+ SK::Api::Schema.registry_reset
8
+ end
9
+
10
+ it "should read json schema file" do
11
+ schema = SK::Api::Schema.read(:invoice, 'v1.0')
12
+ schema[:title].should == 'invoice'
13
+ schema[:type].should == 'object'
14
+ schema['properties'].should be_a Hash
15
+ schema['properties']['id']['identity'].should be_true
16
+ end
17
+
18
+ it "should read json schema file with simple version" do
19
+ schema = SK::Api::Schema.read(:invoice, '1.0')
20
+ schema[:title].should == 'invoice'
21
+ schema[:type].should == 'object'
22
+ schema['properties'].should be_a Hash
23
+ schema['properties']['id']['identity'].should be_true
24
+ end
25
+
26
+ it "should read all json schemas" do
27
+ schemas = SK::Api::Schema.read_all('1.0')
28
+
29
+ file_path = File.join(File.dirname(__FILE__), '../json', 'v1.0', '*.json')
30
+ # just check file count
31
+ schemas.length.should == Dir.glob( file_path ).length
32
+ end
33
+
34
+ it "should raise error if version folder does not exist" do
35
+ lambda{
36
+ SK::Api::Schema.read(:invoice, 'v3.0')
37
+ }.should raise_error
38
+ end
39
+
40
+ it "should raise error if schema file does not exist" do
41
+ lambda{
42
+ SK::Api::Schema.read(:nope, 'v1.0')
43
+ }.should raise_error
44
+ end
45
+
46
+ it "should add schema to registry" do
47
+ SK::Api::Schema.read(:credit_note, 'v1.0')
48
+ File.should_not_receive(:open)
49
+ SK::Api::Schema.read(:credit_note, 'v1.0')
50
+ end
4
51
 
5
- before :each do
6
- SK::Api::Schema.registry_reset
7
52
  end
8
53
 
9
- it "should read json schema file" do
10
- schema = SK::Api::Schema.read(:invoice, 'v1.0')
11
- schema[:title].should == 'invoice'
12
- schema[:type].should == 'object'
13
- schema['properties'].should be_a Hash
14
- schema['properties']['id']['identity'].should be_true
54
+ context 'object parsing' do
55
+
56
+ before :each do
57
+ @invoice = Invoice.new
58
+ @invoice.id = 'some-uuid'
59
+ @invoice.title = 'Your Invoice'
60
+ @invoice.number = '911'
61
+
62
+ @client = Client.new
63
+ @client.id = 'some-uuid'
64
+ @client.organisation = 'Dirty Food Inc.'
65
+ @client.number = '911'
66
+
67
+ @item = LineItem.new
68
+ @item.id = 'some-uuid'
69
+ @item.name = 'Pork Chops'
70
+ @item.description = 'Yummi Pork chopped by mexian emigrants'
71
+ @item.position = 1
72
+ @item.price_single = 0.99
73
+ end
74
+
75
+ it "should parse object with empty relations from schema" do
76
+ obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
77
+ # {"invoice"=>{"number"=>"911", "line_items"=>[], "archived_pdf"=>nil, "title"=>"Your Invoice", "date"=>nil, "id"=>"some-uuid", "client"=>nil, "due_date"=>nil}}
78
+ obj_hash.keys.sort.should == ["invoice", "links"]
79
+ obj_hash['invoice'].should include( "number"=>"911","line_items"=>[],"archived_pdf"=>nil,"id"=>"some-uuid", "title"=>"Your Invoice" )
80
+ client_obj_hash = SK::Api::Schema.to_hash_from_schema(@client, 'v1.0')
81
+ client_obj_hash.keys.sort.should == ["client", "links"]
82
+ client_obj_hash['client'].should include("number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil)
83
+ end
84
+
85
+ it "should parse object with relations from schema" do
86
+ @invoice.line_items = [@item]
87
+ @invoice.client = @client
88
+ obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
89
+ obj_hash["invoice"]['client']['client'].should == {"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}
90
+ obj_hash["invoice"]["client"]['links'].should_not be_nil
91
+ obj_hash["invoice"]["line_items"].should == [ {"line_item"=>{"name"=>"Pork Chops", "position"=>1, \
92
+ "id"=>"some-uuid", "description"=>"Yummi Pork chopped by mexian emigrants", "price_single"=>0.99}}]
93
+ end
94
+
95
+ it "should parse object given fields" do
96
+ @invoice.line_items = [@item]
97
+ @invoice.client = @client
98
+ fields = %w(id title client)
99
+ obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0', :fields=>fields)
100
+ obj_hash["invoice"]['client']['client'].should == {"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}
101
+ obj_hash["invoice"]["client"]['links'].should_not be_nil
102
+ obj_hash["invoice"].keys.sort.should == fields.sort
103
+ end
104
+
105
+ it "should use different class name as object hash key" do
106
+ @invoice.line_items = [@item]
107
+ @invoice.client = @client
108
+ obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0', :class_name=>:document)
109
+ schema = SK::Api::Schema.read(:document, 'v1.0')
110
+ # check included fields, which should not be all fields from schema since our dummy invoice object does not responds_to all
111
+ intersect_keys = schema['properties'].keys & obj_hash["document"].keys
112
+ intersect_keys.sort.should == obj_hash["document"].keys.sort
113
+ end
15
114
  end
16
115
 
17
- it "should read json schema file with simple version" do
18
- schema = SK::Api::Schema.read(:invoice, '1.0')
19
- schema[:title].should == 'invoice'
20
- schema[:type].should == 'object'
21
- schema['properties'].should be_a Hash
22
- schema['properties']['id']['identity'].should be_true
23
- end
24
-
25
- it "should read all json schemas" do
26
- schemas = SK::Api::Schema.read_all('1.0')
27
-
28
- file_path = File.join(File.dirname(__FILE__), '../json', 'v1.0', '*.json')
29
- # just check file count
30
- schemas.length.should == Dir.glob( file_path ).length
31
- end
32
-
33
- it "should raise error if version folder does not exist" do
34
- lambda{
35
- SK::Api::Schema.read(:invoice, 'v3.0')
36
- }.should raise_error
37
- end
38
-
39
- it "should raise error if schema file does not exist" do
40
- lambda{
41
- SK::Api::Schema.read(:nope, 'v1.0')
42
- }.should raise_error
43
- end
44
-
45
- it "should add schema to registry" do
46
- SK::Api::Schema.read(:credit_note, 'v1.0')
47
- File.should_not_receive(:open)
48
- SK::Api::Schema.read(:credit_note, 'v1.0')
49
- end
50
-
51
- end
52
-
53
- describe SK::Api::Schema, 'object parsing' do
54
-
55
- before :each do
56
- @invoice = Invoice.new
57
- @invoice.id = 'some-uuid'
58
- @invoice.title = 'Your Invoice'
59
- @invoice.number = '911'
60
-
61
- @client = Client.new
62
- @client.id = 'some-uuid'
63
- @client.organisation = 'Dirty Food Inc.'
64
- @client.number = '911'
65
-
66
- @item = LineItem.new
67
- @item.id = 'some-uuid'
68
- @item.name = 'Pork Chops'
69
- @item.description = 'Yummi Pork chopped by mexian emigrants'
70
- @item.position = 1
71
- @item.price_single = 0.99
72
- end
116
+ context 'hash cleaning' do
73
117
 
74
- it "should parse object with empty relations from schema" do
75
- obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
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.sort.should == ["invoice", "links"]
78
- obj_hash['invoice'].should include( "number"=>"911","line_items"=>[],"archived_pdf"=>nil,"id"=>"some-uuid", "title"=>"Your Invoice" )
79
- client_obj_hash = SK::Api::Schema.to_hash_from_schema(@client, 'v1.0')
80
- client_obj_hash.keys.sort.should == ["client", "links"]
81
- client_obj_hash['client'].should include("number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil)
82
- end
118
+ it "should kick readonly properties" do
119
+ props = {'id'=>'some id', 'archived_pdf'=>'some val', 'number'=>'1234' }
120
+ SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0')
121
+ props.keys.should == ['number']
83
122
 
84
- it "should parse object with relations from schema" do
85
- @invoice.line_items = [@item]
86
- @invoice.client = @client
87
- obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
88
- obj_hash["invoice"]['client']['client'].should == {"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}
89
- obj_hash["invoice"]["client"]['links'].should_not be_nil
90
- obj_hash["invoice"]["line_items"].should == [ {"line_item"=>{"name"=>"Pork Chops", "position"=>1, \
91
- "id"=>"some-uuid", "description"=>"Yummi Pork chopped by mexian emigrants", "price_single"=>0.99}}]
92
- end
123
+ props1 = {:id =>'some id', :archived_pdf =>'some val', :number =>'1234' }
124
+ SK::Api::Schema.clean_hash!(:invoice, props1, 'v1.0')
125
+ props1.keys.should == [:number]
126
+ end
93
127
 
94
- it "should parse object given fields" do
95
- @invoice.line_items = [@item]
96
- @invoice.client = @client
97
- fields = %w(id title client)
98
- obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0', :fields=>fields)
99
- obj_hash["invoice"]['client']['client'].should == {"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}
100
- obj_hash["invoice"]["client"]['links'].should_not be_nil
101
- obj_hash["invoice"].keys.sort.should == fields.sort
102
- end
103
-
104
- it "should use different class name as object hash key" do
105
- @invoice.line_items = [@item]
106
- @invoice.client = @client
107
- obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0', :class_name=>:document)
108
- schema = SK::Api::Schema.read(:document, 'v1.0')
109
- # check included fields, which should not be all fields from schema since our dummy invoice object does not responds_to all
110
- intersect_keys = schema['properties'].keys & obj_hash["document"].keys
111
- intersect_keys.sort.should == obj_hash["document"].keys.sort
112
- end
113
- end
128
+ it "should convert string properties" do
129
+ props = {'title'=>4711, 'number'=>1234 }
130
+ SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0')
131
+ props['title'].should == "4711"
132
+ props['number'].should == "1234"
133
+ end
114
134
 
115
- describe SK::Api::Schema, 'hash cleaning' do
135
+ it "should keep some properties" do
136
+ props = {'id'=>'some id', 'number'=>1234 }
137
+ SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0', :keep=>['id'])
138
+ props['id'].should == "some id"
139
+ end
116
140
 
117
- it "should kick readonly properties" do
118
- props = {'id'=>'some id', 'archived_pdf'=>'some val', 'number'=>'1234' }
119
- SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0')
120
- props.keys.should == ['number']
121
-
122
- props1 = {:id =>'some id', :archived_pdf =>'some val', :number =>'1234' }
123
- SK::Api::Schema.clean_hash!(:invoice, props1, 'v1.0')
124
- props1.keys.should == [:number]
125
- end
126
-
127
- it "should convert string properties" do
128
- props = {'title'=>4711, 'number'=>1234 }
129
- SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0')
130
- props['title'].should == "4711"
131
- props['number'].should == "1234"
132
141
  end
133
-
134
- it "should keep some properties" do
135
- props = {'id'=>'some id', 'number'=>1234 }
136
- SK::Api::Schema.clean_hash!(:invoice, props, 'v1.0', :keep=>['id'])
137
- props['id'].should == "some id"
138
- end
139
-
140
142
  end
141
143
 
142
144
  ################################################################################
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,18 @@
1
+ # encoding: utf-8
2
+ $:.unshift(File.dirname(__FILE__))
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ add_filter "/json/"
8
+ end
9
+ SimpleCov.coverage_dir 'coverage'
10
+
1
11
  require 'rubygems'
2
12
  require 'rspec'
3
- require "#{File.dirname(__FILE__)}/../lib/sk_api_schema"
4
- #require File.dirname(__FILE__) + '/../vendor/jsonschema-1.0.0/lib/jsonschema'
13
+ require "sk_api_schema"
14
+
15
+
16
+
17
+ RSpec.configure do |config|
18
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sk_api_schema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Georg Leciejewski
@@ -18,6 +18,7 @@ cert_chain: []
18
18
  date: 2012-06-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
21
22
  requirement: &id001 !ruby/object:Gem::Requirement
22
23
  none: false
23
24
  requirements:
@@ -27,11 +28,11 @@ dependencies:
27
28
  segments:
28
29
  - 0
29
30
  version: "0"
31
+ version_requirements: *id001
30
32
  prerelease: false
31
33
  name: activesupport
32
- type: :runtime
33
- version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
+ type: :development
35
36
  requirement: &id002 !ruby/object:Gem::Requirement
36
37
  none: false
37
38
  requirements:
@@ -41,11 +42,11 @@ dependencies:
41
42
  segments:
42
43
  - 0
43
44
  version: "0"
44
- prerelease: false
45
- name: rspec
46
- type: :development
47
45
  version_requirements: *id002
46
+ prerelease: false
47
+ name: rdoc
48
48
  - !ruby/object:Gem::Dependency
49
+ type: :development
49
50
  requirement: &id003 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
@@ -55,11 +56,42 @@ dependencies:
55
56
  segments:
56
57
  - 0
57
58
  version: "0"
59
+ version_requirements: *id003
58
60
  prerelease: false
59
- name: rcov
61
+ name: rspec
62
+ - !ruby/object:Gem::Dependency
60
63
  type: :development
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.
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ version_requirements: *id004
74
+ prerelease: false
75
+ name: simplecov
76
+ - !ruby/object:Gem::Dependency
77
+ type: :development
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 63
84
+ segments:
85
+ - 0
86
+ - 9
87
+ - 2
88
+ version: 0.9.2
89
+ version_requirements: *id005
90
+ prerelease: false
91
+ name: rake
92
+ description: |-
93
+ The SalesKing JSON Schema describes our business API in terms of available objects, their fields and links to url endpoints with related objects.
94
+ Besides ruby users can use a small lib with utility methods to load and test the schema files.
63
95
  email: gl@salesking.eu
64
96
  executables: []
65
97
 
@@ -68,11 +100,12 @@ extensions: []
68
100
  extra_rdoc_files:
69
101
  - README.rdoc
70
102
  files:
103
+ - .gitignore
104
+ - .travis.yml
71
105
  - CHANGELOG.rdoc
106
+ - Gemfile
72
107
  - README.rdoc
73
108
  - Rakefile
74
- - VERSION
75
- - ci/Gemfile
76
109
  - json/v1.0/address.json
77
110
  - json/v1.0/attachment.json
78
111
  - json/v1.0/auth_permission.json
@@ -99,6 +132,7 @@ files:
99
132
  - json/v1.0/text_template.json
100
133
  - json/v1.0/user.json
101
134
  - lib/sk_api_schema.rb
135
+ - lib/sk_api_schema/version.rb
102
136
  - sk_api_schema.gemspec
103
137
  - spec/sk_api_schema_spec.rb
104
138
  - spec/spec_helper.rb
@@ -134,6 +168,6 @@ rubyforge_project:
134
168
  rubygems_version: 1.8.24
135
169
  signing_key:
136
170
  specification_version: 3
137
- summary: SalesKing API JSON Schema
171
+ summary: SalesKing API - JSON Schema
138
172
  test_files: []
139
173
 
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.2
data/ci/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source :gemcutter
2
- gem "rake"
3
- gem "rdoc"
4
- gem "rcov"
5
- gem "active_support"
6
- group :test do
7
- gem "rspec"
8
- end