sk_api_schema 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,6 +1,6 @@
1
- {"type":"object",
1
+ { "type":"object",
2
2
  "title": "address",
3
- "description":"An address",
3
+ "description":"An address in SK must always be related to an object.",
4
4
  "properties": {
5
5
  "id": {
6
6
  "description": "uuid of the adress.",
@@ -10,40 +10,35 @@
10
10
  },
11
11
  "city": {
12
12
  "description": "City for the address. Must at least be present for an address.",
13
+ "required":true,
13
14
  "type":"string"
14
15
  },
15
16
  "address1": {
16
17
  "description": "Should contain the street or otherwise primary address information.",
17
- "optional":true,
18
18
  "type":"string"
19
19
  },
20
20
  "address2": {
21
21
  "description": "Additional address information, like floor number",
22
- "optional":true,
23
22
  "type":"string"
24
23
  },
25
24
  "pobox": {
26
25
  "description": "Post office box number",
27
- "optional":true,
28
26
  "type":"string"
29
27
  },
30
28
  "zip": {
31
29
  "description": "Zip number of the city. Length must be between 4..10",
32
- "optional":true,
33
30
  "type":"string"
34
31
  },
35
32
  "state": {
36
33
  "description": "Country state of address",
37
- "optional":true,
38
34
  "type":"string"
39
35
  },
40
36
  "country": {
41
37
  "description": "Country of the address.",
42
- "optional":true,
43
38
  "type":"string"
44
39
  },
45
40
  "created_at": {
46
- "description": "Date the object was created in SK. Never changes aftwerwards",
41
+ "description": "Date the object was created in SK. Never changes afterwards",
47
42
  "format":"date-time",
48
43
  "readonly":true, "type":"string"
49
44
  },
@@ -56,17 +51,14 @@
56
51
  "address_type": {
57
52
  "description": "Type of the address, as seen by vCard definition.",
58
53
  "enum":["work","home"],
59
- "optional":true,
60
54
  "type":"string"
61
55
  },
62
56
  "lat": {
63
- "description": "Geolocation latitude",
64
- "optional":true,
57
+ "description": "Geolocation latitude",
65
58
  "type":"string"
66
59
  },
67
60
  "long": {
68
61
  "description": "Geolocation longitude",
69
- "optional":true,
70
62
  "type":"string"
71
63
  }
72
64
  }
@@ -10,43 +10,38 @@
10
10
  },
11
11
  "filename": {
12
12
  "description": "The filename as set when uploaded",
13
- "optional":true,
14
13
  "readonly":true,
15
14
  "type":"string"
16
15
  },
17
16
  "disk_filename": {
18
- "description": "The filename as set by SK",
19
- "optional":true,
17
+ "description": "Unique filename set by SK",
20
18
  "readonly":true,
21
19
  "type":"string"
22
20
  },
23
21
  "url": {
24
22
  "description": "File download url. Unique and valid for 15 minutes, public accessible.",
25
- "optional":true,
26
23
  "readonly":true,
27
24
  "type":"string"
28
25
  },
29
26
  "content_type": {
30
27
  "description": "Auto detected on upload. Might not always reflect the real content type",
31
- "optional":true,
32
28
  "readonly":true,
33
29
  "type":"string"
34
30
  },
35
31
  "size": {
36
32
  "description": "Filesize in kb. Auto detected on upload.",
37
- "optional":true,
38
33
  "readonly":true,
39
34
  "type":"integer"
40
35
  },
41
36
  "is_signed": {
42
37
  "description": "True if the file(pdf) has been digitally signed.",
43
- "optional":true,
44
38
  "type":"boolean"
45
39
  },
46
40
  "created_at": {
47
- "description": "Date the object was created in SK. Never changes aftwerwards",
41
+ "description": "Date the object was created in SK. Never changes afterwards",
48
42
  "format":"date-time",
49
- "readonly":true, "type":"string"
43
+ "readonly":true,
44
+ "type":"string"
50
45
  },
51
46
  "updated_at": {
52
47
  "description": "Date the object was edited in SK.",
@@ -4,164 +4,134 @@
4
4
  "properties": {
5
5
  "id": {
6
6
  "identity":true,
7
- "optional":true,
8
7
  "readonly":true,
9
8
  "type":"string"
10
9
  },
11
10
  "number": {
12
- "description": "Unique number, assigned from SK numbering scheme.",
13
- "optional":true,
11
+ "description": "Unique number, auto-created by SK for new client without number.",
14
12
  "type":"string"
15
13
  },
16
14
  "organisation": {
17
15
  "description": "Name of a company. At least this or the lastname field must be filled for new records",
16
+ "required" : true,
18
17
  "type":"string"
19
18
  },
20
19
  "last_name": {
21
20
  "description": "Last name of a person. At least this or the organisation field must be filled for new records",
22
- "optional":true,
23
21
  "type":"string"
24
22
  },
25
23
  "first_name": {
26
24
  "description": "First name of a person.",
27
- "optional":true,
28
25
  "type":"string"
29
26
  },
30
27
  "gender": {
31
28
  "description": "Can be empty for a company. Is used in salutation",
32
- "optional":true,
33
29
  "enum":["male", "female"],
34
30
  "type":"string"
35
31
  },
36
32
  "position": {
37
33
  "description": "Position of a person in a company.",
38
- "optional":true,
39
34
  "type":"string"
40
35
  },
41
36
  "title": {
42
37
  "description": "Academical title of a person e.g. Dr., Prof",
43
- "optional":true,
44
38
  "type":"string"
45
39
  },
46
40
  "tax_number": {
47
41
  "description": "Tax number, normaly applies to a private person",
48
- "optional":true,
49
42
  "type":"string"
50
43
  },
51
44
  "vat_number": {
52
45
  "description": "VAT number, for a company or person paying value added taxes.",
53
- "optional":true,
54
46
  "type":"string"
55
47
  },
56
48
  "email": {
57
49
  "description": "Email address of the contact.",
58
- "optional":true,
59
50
  "type":"string"
60
51
  },
61
52
  "url": {
62
53
  "description": "An url associated with the person, e.g its company website.",
63
- "optional":true,
64
54
  "type":"string"
65
55
  },
66
56
  "birthday": {
67
57
  "format":"date",
68
- "optional":true,
69
58
  "type":"string"
70
59
  },
71
60
  "tag_list": {
72
61
  "description": "Space seperated list of tags.",
73
- "optional":true,
74
62
  "type":"string"
75
63
  },
76
64
  "created_at": {
77
65
  "description": "Date the record was created in SK. Never changes afterwards.",
78
66
  "format":"date-time",
79
- "optional":true,
80
67
  "readonly":true,
81
68
  "type":"string"
82
69
  },
83
70
  "updated_at": {
84
71
  "description": "Last date when the record was edited.",
85
72
  "format":"date-time",
86
- "optional":true,
87
73
  "readonly":true,
88
74
  "type":"string"
89
75
  },
90
76
  "bank_number": {
91
77
  "description": "Number of the bank",
92
- "optional":true,
93
78
  "type":"string"
94
79
  },
95
80
  "bank_name": {
96
81
  "description": "Name of the bank.",
97
- "optional":true,
98
82
  "type":"string"
99
83
  },
100
84
  "bank_account_number": {
101
85
  "description": "Number of the bank account.",
102
- "optional":true,
103
86
  "type":"string"
104
87
  },
105
88
  "bank_iban": {
106
89
  "description": "IBAN Number of the bank account. Is validated",
107
- "optional":true,
108
90
  "type":"string"
109
91
  },
110
92
  "bank_swift": {
111
93
  "description": "SWIFT BIC- Bank Identifier Code",
112
- "optional":true,
113
94
  "type":"string"
114
95
  },
115
96
  "bank_owner": {
116
97
  "description": "Owner of the bank account.",
117
- "optional":true,
118
98
  "type":"string"
119
99
  },
120
100
  "phone_fax": {
121
101
  "description": "Fax number",
122
- "optional":true,
123
102
  "type":"string"
124
103
  },
125
104
  "phone_office": {
126
105
  "description": "Office phone number",
127
- "optional":true,
128
106
  "type":"string"
129
107
  },
130
108
  "phone_home": {
131
109
  "description": "Private phone number.",
132
- "optional":true,
133
110
  "type":"string"
134
111
  },
135
112
  "phone_mobile": {
136
113
  "description": "Mobile phone number",
137
- "optional":true,
138
114
  "type":"string"
139
115
  },
140
116
  "lock_version": {
141
117
  "description": "Increased on every edit, so SK can detect/prevent a concurrent edit by another user. First save wins.",
142
- "optional":true,
143
- "readonly":true,
144
118
  "type":"integer"
145
119
  },
146
120
  "cash_discount": {
147
121
  "description": "Default cash discount for new invoices.",
148
- "optional":true,
149
122
  "type":"number"
150
123
  },
151
124
  "due_days": {
152
125
  "description": "Default due days for new invoices.",
153
- "optional":true,
154
126
  "type":"integer"
155
127
  },
156
128
  "address_field": {
157
129
  "description": "Returns the address field used on new docs. Consist of Organisation name and default(first) address",
158
- "optional":true,
159
130
  "readonly":true,
160
131
  "type":"string"
161
132
  },
162
133
  "addresses": {
163
134
  "description": "A client can have many addresses, sorted by date descending(new first). Default address is the most recent one.",
164
- "optional":true,
165
135
  "type":"array",
166
136
  "properties" : {"$ref":"./addresses.json#properties"}
167
137
  }
@@ -1,77 +1,64 @@
1
1
  { "type":"object",
2
- "title": "credit note",
2
+ "title": "credit_note",
3
3
  "description": "A credit note",
4
4
  "properties":{
5
5
  "id":{
6
6
  "description": "UUID assigned by SK",
7
7
  "identity":true,
8
- "optional":true,
9
8
  "readonly":true,
10
9
  "type":"string"
11
10
  },
12
11
  "number":{
13
12
  "description": "Unique number assigned by SK credit note number schema. Auto-assigned when document is opened. Required unless doc status is draft.",
14
- "optional":true,
15
13
  "type":"string"
16
14
  },
17
15
  "address_field":{
18
16
  "description": "Address field with the receiver. Shown in envelope window.",
19
- "optional":true,
20
17
  "type":"string"
21
18
  },
22
19
  "date":{
23
20
  "description": "Date the credit note is issued. Automatically set when document is opened. Required unless doc status is draft.",
24
21
  "format":"date",
25
- "optional":true,
26
22
  "type":"string"
27
23
  },
28
24
  "due_days":{
29
25
  "description": "Used to calculate the due date of the credit note. Useless if date and due date are present.",
30
- "optional":true,
31
26
  "type":"integer"
32
27
  },
33
28
  "due_date":{
34
29
  "description": "Auto-calculated from date + due days if empty and the document is opened.",
35
30
  "format":"date",
36
- "optional":true,
37
31
  "type":"string"
38
32
  },
39
33
  "status":{
40
- "description": "A new document is always a draft unless otherwise stated. Only draft documents can be deleted. When a doc is opened it's number, date and due date are auto-set",
41
- "optional":true,
34
+ "description": "Defaults to draft for new documents, unless otherwise stated. For new documents with status 'open', following fields are set if empty: number(next in number schema), date(today), due date(due_days must be given). Only draft invoices can be deleted.",
42
35
  "default":"draft",
43
36
  "enum":["draft","open","closed"],
44
37
  "type":"string"
45
38
  },
46
39
  "payment_method":{
47
40
  "description": "How the document is beeing payed. Used in new payments.",
48
- "optional":true,
49
41
  "enum":["cash","bank_transfer","credit_card","paypal","direct_debit","cheque"],
50
42
  "type":"string"
51
43
  },
52
44
  "title":{
53
45
  "description": "The headline of a document. Use SK placeholders to prevent exessive typing e.g. 'Your credit note [number]'",
54
- "optional":true,
55
46
  "type":"string"
56
47
  },
57
48
  "notes_before":{
58
49
  "description": "Notes shown before the line items. Normaly contains salutation and other introductional information. SK placeholders can be used.",
59
- "optional":true,
60
50
  "type":"string"
61
51
  },
62
52
  "notes_after":{
63
53
  "description": "Notes shown after the line items. Can contain information about payments, bank account or a thank-you message. SK placeholders can be used.",
64
- "optional":true,
65
54
  "type":"string"
66
55
  },
67
56
  "tag_list": {
68
57
  "description": "Space seperated list of tags.",
69
- "optional":true,
70
58
  "type":"string"
71
59
  },
72
60
  "client":{
73
61
  "description": "The client for the document. New documents cannot create a client, use client_id field to set it.",
74
- "optional":true,
75
62
  "readonly":true,
76
63
  "type":"object",
77
64
  "properties":{"$ref":"./client.json#properties"}
@@ -82,39 +69,32 @@
82
69
  },
83
70
  "line_items":{
84
71
  "description": "Line items for the document",
85
- "optional":true,
86
72
  "type":"array",
87
73
  "properties":{"$ref":"./address.json#properties"}
88
74
  },
89
75
  "created_at":{
90
- "description": "Date the object was created in SK. Never changes aftwerwards.",
76
+ "description": "Date the object was created in SK. Never changes afterwards.",
91
77
  "format":"date-time",
92
- "optional":true,
93
78
  "readonly":true,
94
79
  "type":"string"
95
80
  },
96
81
  "updated_at":{
97
82
  "description": "Date the object was edited in SK.",
98
83
  "format":"date-time",
99
- "optional":true,
100
84
  "readonly":true,
101
85
  "type":"string"
102
86
  },
103
87
  "lock_version":{
104
88
  "description": "Auto-incremented by SK to prevent concurrent updateing. First save wins.",
105
- "optional":true,
106
- "readonly":true,
107
89
  "type":"integer"
108
90
  },
109
91
  "price_total":{
110
92
  "description": "Net total sum of all line items, 6 decimals places",
111
- "optional":true,
112
93
  "readonly":true,
113
94
  "type":"number"
114
95
  },
115
96
  "price_tax":{
116
97
  "description": "Summed up tax total of all line items, 2 decimals places",
117
- "optional":true,
118
98
  "readonly":true,
119
99
  "type":"number"
120
100
  }
@@ -1,129 +1,180 @@
1
1
  { "type":"object",
2
2
  "title": "invoice",
3
3
  "description": "An invoice",
4
+
4
5
  "properties":{
5
6
  "id":{
6
7
  "description": "UUID assigned by SK",
7
8
  "identity":true,
8
- "optional":true,
9
9
  "readonly":true,
10
10
  "type":"string"
11
11
  },
12
12
  "number":{
13
13
  "description": "Unique number assigned by SK invoice number schema. Auto-assigned when invoice is opened. Required unless doc status is draft.",
14
- "optional":true,
15
14
  "type":"string"
16
15
  },
17
16
  "address_field":{
18
17
  "description": "Address field with the receiver. Shown in envelope window.",
19
- "optional":true,
20
18
  "type":"string"
21
19
  },
22
20
  "date":{
23
- "description": "Date the invoice is issued. Automatically set when invoice is opened. Required unless doc status is draft.",
21
+ "description": "Date the invoice is issued. Automatically set when invoice is opened. Required for non-draft documents.",
24
22
  "format":"date",
25
- "optional":true,
26
23
  "type":"string"
27
24
  },
28
25
  "due_days":{
29
26
  "description": "Used to calculate the due date of the invoice. Useless if date and due date are present.",
30
- "optional":true,
31
27
  "type":"integer"
32
28
  },
33
29
  "due_date":{
34
30
  "description": "Auto-calculated from date + due days if empty and the invoice is opened.",
35
31
  "format":"date",
36
- "optional":true,
37
32
  "type":"string"
38
33
  },
39
34
  "status":{
40
- "description": "A new document is always a draft unless otherwise stated. Only draft invoices can be deleted. When a doc is opened it's number, date and due date are auto-set",
41
- "optional":true,
35
+ "description": "Defaults to draft for new documents, if empty. For new documents with status 'open',the following fields are set if empty: number(next in number schema), date(today), due date(today unless due_days given). Only draft invoices can be deleted.",
42
36
  "default":"draft",
43
37
  "enum":["draft","open","closed"],
44
38
  "type":"string"
45
39
  },
46
40
  "payment_method":{
47
41
  "description": "How the invoce is beeing payed. Used in new payments.",
48
- "optional":true,
49
42
  "enum":["cash","bank_transfer","credit_card","paypal","direct_debit","cheque"],
50
43
  "type":"string"
51
44
  },
52
45
  "title":{
53
46
  "description": "The headline of a document. Use SK placeholders to prevent exessive typing e.g. 'Your invoice [number]'",
54
- "optional":true,
55
47
  "type":"string"
56
48
  },
57
49
  "notes_before":{
58
50
  "description": "Notes shown before the line items. Normaly contains salutation and other introductional information. SK placeholders can be used.",
59
- "optional":true,
60
51
  "type":"string"
61
52
  },
62
53
  "notes_after":{
63
54
  "description": "Notes shown after the line items. Can contain information about payments, bank account or a thank-you message. SK placeholders can be used.",
64
- "optional":true,
65
55
  "type":"string"
66
56
  },
67
57
  "tag_list": {
68
58
  "description": "Space seperated list of tags.",
69
- "optional":true,
70
59
  "type":"string"
71
60
  },
72
61
  "client":{
73
62
  "description": "The client for the document. New documents cannot create a client, use client_id field to set it.",
74
- "optional":true,
75
63
  "readonly":true,
76
64
  "type":"object",
77
65
  "properties":{"$ref":"./client.json#properties"}
78
66
  },
79
67
  "archived_pdf":{
80
68
  "description": "Archived PDF version of the document. Is created when an document is printed and archived. A document can have multiple archived versions. This only returns the most recent one. ",
81
- "optional":true,
82
69
  "readonly":true,
83
70
  "type":"object",
84
71
  "properties":{"$ref":"./attachment.json#properties"}
85
72
  },
86
73
  "client_id":{
87
74
  "description": "The clients uuid, must be set for a new document. New invoices take the clients address field, due days and cash discount if those fields are not set.",
88
- "type":"string"
75
+ "type":"string",
76
+ "required":true
89
77
  },
90
78
  "line_items":{
91
79
  "description": "Line items for the document",
92
- "optional":true,
93
80
  "type":"array",
94
81
  "properties":{"$ref":"./address.json#properties"}
95
82
  },
96
83
  "created_at":{
97
- "description": "Date the object was created in SK. Never changes aftwerwards.",
84
+ "description": "Date the object was created in SK. Never changes afterwards.",
98
85
  "format":"date-time",
99
- "optional":true,
100
86
  "readonly":true,
101
87
  "type":"string"
102
88
  },
103
89
  "updated_at":{
104
90
  "description": "Date the object was edited in SK.",
105
91
  "format":"date-time",
106
- "optional":true,
107
92
  "readonly":true,
108
93
  "type":"string"
109
94
  },
110
95
  "lock_version":{
111
96
  "description": "Auto-incremented by SK to prevent concurrent updateing. First save wins.",
112
97
  "optional":true,
113
- "readonly":true,
114
98
  "type":"integer"
115
99
  },
116
100
  "price_total":{
117
101
  "description": "Net total sum of all line items, 6 decimals places",
118
- "optional":true,
119
102
  "readonly":true,
120
103
  "type":"number"
121
104
  },
122
105
  "price_tax":{
123
106
  "description": "Summed up tax total of all line items, 2 decimals places",
124
- "optional":true,
125
107
  "readonly":true,
126
108
  "type":"number"
127
109
  }
128
- }
110
+ },
111
+ "links":[
112
+ { "rel": "self",
113
+ "href": "invoices/{id}"
114
+ },
115
+ { "rel": "instances",
116
+ "href": "invoices",
117
+ // Params /invoices?page=1&sort_by
118
+ "properties" : {
119
+ "q":{
120
+ "title" : "Search",
121
+ "description": "Search parameter."
122
+ },
123
+ "page":{
124
+ "title" : "Page",
125
+ "description": "In paginated results set the page to look for"
126
+ },
127
+ "filter[tags]":{
128
+ "title" : "Tags",
129
+ "description": "Filter by a space delimited list of tags"
130
+ },
131
+ "filter[from]":{
132
+ "title" : "From date",
133
+ "description": "All objects with a date after the date"
134
+ },
135
+ "filter[to]":{
136
+ "title" : "To date",
137
+ "description": "All objects with date before the date"
138
+ },
139
+ "sort_by":{
140
+ "title" : "Sort by",
141
+ "description": "Sort the results by the given field => invoice.number"
142
+ },
143
+ "sort":{
144
+ "title" : "Sort",
145
+ "description": "Sort the results in ASC or DESC"
146
+ }
147
+ }
148
+ },
149
+ { "rel": "destroy",
150
+ "href": "invoices/{id}",
151
+ "method": "DELETE"
152
+ },
153
+ { "rel": "update",
154
+ "href": "invoices/{id}",
155
+ "method": "PUT",
156
+ "properties" : {
157
+ "invoice" : {"$ref":"./invoice.json#properties"}
158
+ }
159
+ },
160
+ { "rel": "create",
161
+ "href": "invoices",
162
+ "method": "POST"
163
+ },
164
+ { "rel": "print",
165
+ "href": "invoices/{id}/print",
166
+ "method": "POST",
167
+ "properties" : {
168
+ "template_id" : {
169
+ "title" : "PDF template used for printing",
170
+ "description": "UUID of a pdf template used to print the document. MUST be present",
171
+ "required":true
172
+ },
173
+ "base64" : {
174
+ "title" : "Return the created pdf base64 encoded",
175
+ "description": "If set the new pdf is returned inside the attachment JSON within 'base64' key. Leave empty to save traffic."
176
+ }
177
+ }
178
+ }
179
+ ]
129
180
  }
@@ -1,5 +1,5 @@
1
1
  { "type":"object",
2
- "title": "line item",
2
+ "title": "line_item",
3
3
  "description": "A line item for a document",
4
4
  "properties":{
5
5
  "id":{
@@ -10,16 +10,15 @@
10
10
  },
11
11
  "position":{
12
12
  "description": "Required since items are sorted by position.",
13
- "type":"integer"
13
+ "type":"integer",
14
+ "required":true
14
15
  },
15
16
  "name":{
16
17
  "description": "The name of an item",
17
- "optional":true,
18
18
  "type":"string"
19
19
  },
20
20
  "description":{
21
21
  "description": "Item description",
22
- "optional":true,
23
22
  "type":"string"
24
23
  },
25
24
  "price_single":{
@@ -28,44 +27,39 @@
28
27
  },
29
28
  "tax":{
30
29
  "description": "Tax percent for a single item.",
31
- "optional":true,
32
30
  "type":"number"
33
31
  },
34
32
  "discount":{
35
33
  "description": "Discount in percent applied to the items net total",
36
- "optional":true,
37
34
  "type":"number"
38
35
  },
39
36
  "quantity_unit":{
40
- "description": "Unit like kg, days, month.",
41
- "optional":true,
37
+ "description": "Quantity unit: kg, days, month.",
42
38
  "type":"string"
43
39
  },
44
40
  "quantity":{
45
- "description": "Quantity of the item.",
46
- "type":"number"
41
+ "description": "Quantity of the item. Must be > 0",
42
+ "type":"number",
43
+ "exclusiveMinimum":0,
44
+ "required":true
47
45
  },
48
46
  "product_id":{
49
47
  "description": "An item can reference a product by its uuid. See use_product",
50
- "optional":true,
51
48
  "type":"string"
52
49
  },
53
50
  "use_product":{
54
51
  "description": "If set and product_id is present, the products name, description, quantity, unit, price are copied if the according item fields are missing.",
55
- "optional":true,
56
- "type":"integer"
52
+ "type":"boolean"
57
53
  },
58
54
  "created_at":{
59
- "description": "Date the object was created in SK. Never changes aftwerwards",
55
+ "description": "Date the object was created in SK. Never changes afterwards",
60
56
  "format":"date-time",
61
- "optional":true,
62
57
  "readonly":true,
63
58
  "type":"string"
64
59
  },
65
60
  "updated_at":{
66
61
  "description": "Date the object was edited in SK.",
67
62
  "format":"date-time",
68
- "optional":true,
69
63
  "readonly":true,
70
64
  "type":"string"
71
65
  }
@@ -0,0 +1,49 @@
1
+ { "type":"object",
2
+ "title": "product",
3
+ "description": "A product in SK",
4
+ "properties":{
5
+ "id":{
6
+ "description": "uuid of the product.",
7
+ "identity":true,
8
+ "readonly":true,
9
+ "type":"string"
10
+ },
11
+ "number":{
12
+ "description": "Unique number assigned by you or if emtpy SK product number schema.",
13
+ "type":"string"
14
+ },
15
+ "name":{
16
+ "description": "The name of the product",
17
+ "type":"string",
18
+ "required":true
19
+ },
20
+ "description":{
21
+ "description": "Product description",
22
+ "type":"string"
23
+ },
24
+ "price":{
25
+ "description": "Net price of a single product",
26
+ "type":"number"
27
+ },
28
+ "tax":{
29
+ "description": "Tax percentage for this product.",
30
+ "type":"number"
31
+ },
32
+ "quantity_unit":{
33
+ "description": "Unit like kg, days, month.",
34
+ "type":"string"
35
+ },
36
+ "created_at":{
37
+ "description": "Date the object was created in SK. Never changes afterwards",
38
+ "format":"date-time",
39
+ "readonly":true,
40
+ "type":"string"
41
+ },
42
+ "updated_at":{
43
+ "description": "Date the object was edited in SK.",
44
+ "format":"date-time",
45
+ "readonly":true,
46
+ "type":"string"
47
+ }
48
+ }
49
+ }
data/json/v1.0/user.json CHANGED
@@ -4,34 +4,28 @@
4
4
  "properties": {
5
5
  "id": {
6
6
  "identity":true,
7
- "optional":true,
8
7
  "readonly":true,
9
8
  "type":"string"
10
9
  },
11
10
  "last_name": {
12
11
  "description": "Last name of a person. At least this or the organisation field must be filled for new records",
13
- "optional":true,
14
12
  "type":"string"
15
13
  },
16
14
  "first_name": {
17
- "description": "First name of a person.",
18
- "optional":true,
15
+ "description": "First name of a person.",
19
16
  "type":"string"
20
17
  },
21
18
  "gender": {
22
19
  "description": "Can be empty for a company. Is used in salutation",
23
- "optional":true,
24
20
  "enum":["male", "female"],
25
21
  "type":"string"
26
22
  },
27
23
  "position": {
28
24
  "description": "Position of a person in a company.",
29
- "optional":true,
30
25
  "type":"string"
31
26
  },
32
27
  "title": {
33
28
  "description": "Academical title of a person e.g. Dr., Prof",
34
- "optional":true,
35
29
  "type":"string"
36
30
  },
37
31
  "language": {
@@ -41,42 +35,23 @@
41
35
  },
42
36
  "time_zone": {
43
37
  "description": "the users time zone inside SK",
44
- "optional":true,
45
38
  "type":"string"
46
39
  },
47
40
  "email": {
48
- "description": "Email address of the contact.",
49
- "optional":true,
41
+ "description": "Email address of the user. Unique in SK",
42
+ "required":true,
50
43
  "type":"string"
51
44
  },
52
45
  "url": {
53
46
  "description": "An url associated with the person, e.g its company website.",
54
- "optional":true,
55
47
  "type":"string"
56
48
  },
57
49
  "birthday": {
58
50
  "format":"date",
59
- "optional":true,
60
51
  "type":"string"
61
52
  },
62
- "created_at": {
63
- "description": "Date the record was created in SK. Never changes afterwards.",
64
- "format":"date-time",
65
- "optional":true,
66
- "readonly":true,
67
- "type":"string"
68
- },
69
- "updated_at": {
70
- "description": "Last date when the record was edited.",
71
- "format":"date-time",
72
- "optional":true,
73
- "readonly":true,
74
- "type":"string"
75
- },
76
-
77
53
  "phone_fax": {
78
54
  "description": "Fax number",
79
- "optional":true,
80
55
  "type":"string"
81
56
  },
82
57
  "phone_office": {
@@ -94,18 +69,23 @@
94
69
  "optional":true,
95
70
  "type":"string"
96
71
  },
97
- "lock_version": {
98
- "description": "Increased on every edit, so SK can detect/prevent a concurrent edit by another user. First save wins.",
99
- "optional":true,
72
+ "created_at": {
73
+ "description": "Date the record was created in SK. Never changes afterwards.",
74
+ "format":"date-time",
100
75
  "readonly":true,
101
- "type":"integer"
102
- },
103
- "address_field": {
104
- "description": "Returns the address field used on new docs. Consist of Organisation name and default(first) address",
105
- "optional":true,
76
+ "type":"string"
77
+ },
78
+ "updated_at": {
79
+ "description": "Last date when the record was edited.",
80
+ "format":"date-time",
106
81
  "readonly":true,
107
82
  "type":"string"
108
83
  }
84
+ },
109
85
 
110
- }
86
+ "links":[
87
+ { "rel": "self",
88
+ "href": "users/current"
89
+ }
90
+ ]
111
91
  }
data/lib/sk_api_schema.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'activesupport'
2
-
1
+ require 'active_support'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
3
  module SK
4
4
  module Api
5
5
  class Schema
@@ -9,10 +9,12 @@ module SK
9
9
  # === Parameter
10
10
  # schema<String|Symbol>::name of the schema, available ones are in json directory
11
11
  # version<String>:: version to read, this is the folder name where the schema is in.
12
+ # === Return
13
+ # <HashWithIndifferentAccess>:: schema as hash
12
14
  def self.read(schema, version)
13
15
  file_path = File.join(File.dirname(__FILE__), '../json', version, "#{schema}.json")
14
16
  plain_data = File.open(file_path, 'r'){|f| f.read}
15
- ActiveSupport::JSON.decode(plain_data)
17
+ ActiveSupport::JSON.decode(plain_data).with_indifferent_access
16
18
  end
17
19
 
18
20
  # Create a Hash with the available (api)object attributes defined in
@@ -40,16 +42,16 @@ module SK
40
42
  # iterate over the defined schema fields
41
43
  schema['properties'].each do |field, prop|
42
44
  if prop['type'] == 'array'
43
- # always set an empty array
44
- data[field] = []
45
+ data[field] = [] # always set an empty array
45
46
  if rel_objects = obj.send( field )
46
47
  rel_objects.each do |rel_obj|
47
- # call related objects to_hash_from_schema method ex: data[:client][:addresses] << SKApi::Models::Address.to_hash_from_schema(object)
48
+ # call related objects to_hash_from_schema method ex:
49
+ # data[:client][:addresses] << SKApi::Models::Address.to_hash_from_schema(object)
48
50
  data[field] << self.to_hash_from_schema(rel_obj, version)
49
51
  end
50
52
  end
51
53
  elsif prop['type'] == 'object' # a singular related object
52
- data[field] = nil
54
+ data[field] = nil # always set empty val
53
55
  if rel_obj = obj.send( field )
54
56
  data[field] = self.to_hash_from_schema(rel_obj, version)
55
57
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sk_api_schema}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
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 = %q{2010-11-11}
12
+ s.date = %q{2010-12-03}
13
13
  s.description = %q{SalesKing API JSON schema and utility methods}
14
14
  s.email = %q{gl@salesking.eu}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "json/v1.0/credit_note.json",
27
27
  "json/v1.0/invoice.json",
28
28
  "json/v1.0/line_item.json",
29
+ "json/v1.0/product.json",
29
30
  "json/v1.0/user.json",
30
31
  "lib/sk_api_schema.rb",
31
32
  "sk_api_schema.gemspec",
@@ -4,8 +4,8 @@ describe SK::Api::Schema do
4
4
 
5
5
  it "should read json schema file" do
6
6
  schema = SK::Api::Schema.read(:invoice, 'v1.0')
7
- schema['title'].should == 'invoice'
8
- schema['type'].should == 'object'
7
+ schema[:title].should == 'invoice'
8
+ schema[:type].should == 'object'
9
9
  schema['properties'].should be_a Hash
10
10
  schema['properties']['id']['identity'].should be_true
11
11
  end
@@ -45,10 +45,9 @@ describe SK::Api::Schema, 'object parsing' do
45
45
  @item.price_single = 0.99
46
46
  end
47
47
 
48
-
49
48
  it "should parse object without relations from schema" do
50
49
  obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
51
- obj_hash.should == {"invoice"=>{"number"=>"911", "line_items"=>[], "title"=>"Your Invoice", "id"=>"some-uuid", "date"=>nil, "client"=>nil, "due_date"=>nil}}
50
+ obj_hash.should == {"invoice"=>{"number"=>"911", "line_items"=>[], "archived_pdf"=>nil, "title"=>"Your Invoice", "date"=>nil, "id"=>"some-uuid", "client"=>nil, "due_date"=>nil}}
52
51
  client_obj_hash = SK::Api::Schema.to_hash_from_schema(@client, 'v1.0')
53
52
  client_obj_hash.should == {"client"=>{"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}}
54
53
  end
@@ -57,7 +56,7 @@ describe SK::Api::Schema, 'object parsing' do
57
56
  @invoice.line_items = [@item]
58
57
  @invoice.client = @client
59
58
  obj_hash = SK::Api::Schema.to_hash_from_schema(@invoice, 'v1.0')
60
- obj_hash.should == {"invoice"=>{"number"=>"911", "line_items"=>[{"line_item"=>{"position"=>1, "name"=>"Pork Chops", "id"=>"some-uuid", "description"=>"Yummi Pork chopped by mexian emigrants", "price_single"=>0.99}}], "title"=>"Your Invoice", "id"=>"some-uuid", "date"=>nil, "client"=>{"client"=>{"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}}, "due_date"=>nil}}
59
+ obj_hash.should == {"invoice"=>{"number"=>"911", "line_items"=>[{"line_item"=>{"name"=>"Pork Chops", "position"=>1, "id"=>"some-uuid", "description"=>"Yummi Pork chopped by mexian emigrants", "price_single"=>0.99}}], "archived_pdf"=>nil, "title"=>"Your Invoice", "date"=>nil, "id"=>"some-uuid", "client"=>{"client"=>{"number"=>"911", "addresses"=>[], "id"=>"some-uuid", "organisation"=>"Dirty Food Inc.", "last_name"=>nil}}, "due_date"=>nil}}
61
60
  end
62
61
 
63
62
  end
@@ -65,7 +64,7 @@ end
65
64
  ################################################################################
66
65
  # virtual classes used in test
67
66
  class Invoice
68
- attr_accessor :id, :title, :description, :number, :date, :due_date, :line_items, :client
67
+ attr_accessor :id, :title, :description, :number, :date, :due_date, :line_items, :client, :archived_pdf
69
68
  end
70
69
 
71
70
  class LineItem
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Georg Leciejewski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-11 00:00:00 +01:00
18
+ date: 2010-12-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ files:
65
65
  - json/v1.0/credit_note.json
66
66
  - json/v1.0/invoice.json
67
67
  - json/v1.0/line_item.json
68
+ - json/v1.0/product.json
68
69
  - json/v1.0/user.json
69
70
  - lib/sk_api_schema.rb
70
71
  - sk_api_schema.gemspec