sk-api 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ nbproject/*
2
2
  coverage/*
3
3
  rdoc/*
4
4
  pkg/*
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -1,241 +1,3 @@
1
- = SalesKing Api
1
+ = This gem is DEPRECATED & OUTDATED
2
2
 
3
- This gem provides an api client using ActiveResource and also provides the API's JSON-Schema
4
- In the near future this will be decoupled and you will find links to the new gems here.
5
-
6
- The SalesKing API client uses JSON and ActiveResource, with some fixes due to json parsing.
7
-
8
- To be able to use the API you must have an SalesKing account and API access.
9
- Than you can start writing your own middelware-stack.
10
-
11
- == Install
12
-
13
- if you try to use it please tell us, so we can provide you a login on our dev system
14
- and support.
15
-
16
- gem install sk-api
17
-
18
- Use with bundler
19
-
20
- gem "sk-api", :require => 'sk_api'
21
-
22
- == Usage
23
-
24
- SalesKing's api interface is RESTful(mostly) and returns & accepts JSON data.
25
- All resources such as clients, invoices, products can be accessed via URL's
26
- through standard HTTP methods GET, POST, PUT and DELETE.
27
-
28
- To give it quick shot, point your browser to my-account.salesking.eu/api/clients.json
29
- (while beeing logged in) and you will see the JSON in the response.
30
- This is an example of a GET-request issued by your browser.
31
-
32
- <b>Request Method overview:</b>
33
- GET => read
34
- POST => create new data
35
- PUT => update data
36
- DELETE => delete data
37
-
38
- Want to know more about REST style webservices?
39
- * http://en.wikipedia.org/wiki/Representational_State_Transfer
40
- * http://www.google.com/search?q=REST+site%3Awww.infoq.com
41
-
42
- === Authentification & Safety
43
-
44
- Authentification is done with HTTP basic using your SalesKing login email and password.
45
- For a production environment it is advisable to create a user, per api
46
- client-software, and restrict his rights with our build in role-system.
47
-
48
- === Toolz
49
-
50
- Since browsers do not support PUT/DELETE methods you can use CURL, a linux
51
- command-line http client, for testing. And of course any http library supporting
52
- http-basic-auth can be used.
53
-
54
- * JSONView FF-Plugin - view json in firefox https://addons.mozilla.org/de/firefox/addon/10869/
55
- * JSONovich FF-Plugin - https://addons.mozilla.org/de/firefox/addon/10122/
56
- * A java GUI REST client http://code.google.com/p/rest-client/
57
-
58
- === GET / Show data
59
-
60
- Get a list of resources:
61
- GET xy.salesking.eu/api/invoices
62
-
63
- Get a single resource
64
- GET xy.salesking.eu/invoices/:id
65
-
66
- Using CURL
67
-
68
- curl -u your@login-mail.com:password \
69
- https://demo.salesking.eu/clients.json
70
-
71
- Returned JSON data for a listings, abbreviated:
72
- {
73
- "clients": [ # array of resources => clients
74
- { "client": { # a single resource
75
- "number": "0800013", ..
76
- "links":{} #links to actions for the resource (comming soon)
77
- }, ...
78
- ],
79
- collection": { # information about the collection
80
- "total_pages": 1,
81
- "total_entries": 3,
82
- "current_page": 1,
83
- "per_page": 30
84
- },
85
- "links": { # links for the collection
86
- "prev": "/api/clients?page=0",
87
- "next": "/api/clients?page=2",
88
- "self": "/api/clients?page=1"
89
- },
90
- }
91
-
92
- ==== Filtering
93
-
94
- Filtering data can be achived by adding a filter parameter to the url.
95
-
96
- All objects which can be tagged(clients, documents, products) can be filter by a tag param, taking one or multiple tags:
97
- GET xy.salesking.eu/api/invoices?filter[tags]=Agentur
98
- GET xy.salesking.eu/api/invoices?filter[tags]=Agentur Grafik
99
- # find all objects without tags
100
- GET xy.salesking.eu/api/invoices?filter[not_tagged]=1
101
-
102
- All objects have a q-search available. The fields to be searched in can be seen inside SalesKing, behind the search field above list.
103
- GET xy.salesking.eu/api/invoices?q=0800013
104
- GET xy.salesking.eu/api/invoices?filter[q]=0800013
105
-
106
- Document specific filters
107
- # find all documents for a client
108
- GET xy.salesking.eu/api/invoices?filter[client]=:client_id
109
-
110
- Client filter:
111
- # find clients organisation or lastname starting with A
112
- GET xy.salesking.eu/api/clients?filter[letter]=A
113
-
114
- === POST / Create data
115
-
116
- To create a resource you can use the gem with its methods or make a POST request containing the json for a single resource.
117
- The JSON format can be seen in each of the resources: http://github.com/salesking/sk-api/tree/master/lib/resources/
118
-
119
- POST https://my-sub.salesking.eu/invoices.json content-type application/json
120
-
121
- This a minimal json to create a draft invoice:
122
-
123
- {"invoice": {
124
- "due_days": 14,
125
- "line_items": [
126
- {
127
- "quantity_unit": "Stuck",
128
- "tax": 19,
129
- "price_single": 0,
130
- "position": 1,
131
- "quantity": 21,
132
- "description": "dep38usabq4Boxen kostenlos"
133
- },
134
- {
135
- "quantity_unit": "Stuck",
136
- "tax": 19,
137
- "price_single": 0.042022,
138
- "position": 2,
139
- "quantity": 21,
140
- "description": "dep38usabq4 Boxen"
141
- }
142
- ],
143
- "title": "Dabei",
144
- "client_id": "c5d5xIwZGr3R56abxfpGMl",
145
- "address_field": "Wurst Bolle\nHalve-Hahn Alle 4711\n50733 Köln-Nippes"
146
- }}
147
-
148
- Some quick hints on document creation:
149
-
150
- * The line items array does not need prefixes .. (sry little inconsistency here)
151
- * Dates are formatted like <tt>yyyy-mm-dd 2010-09-08</tt>
152
- * <tt>"price_total": 0.88, "price_tax": 0.167</tt> can be ommited are calculated by sk => read only
153
- * <tt>due_date</tt> if left out will be auto calculated from due days. If date and due date are given due_days are not taken into consideration.
154
- * <tt>status: draft</tt> is default, so can be omitted
155
- * <tt>client_id</tt> must be given as uuid of the client object
156
- * line items with quantity of 0 are kicked
157
- * If you create the doc as draft you can leave out any dates. When “opened” in salesking the date will be set and due date is calculated from due_days
158
- * If you create the invoice as "open" you must set a number(and date), by now there is no api method to get the next number.
159
- * The proposed workflow is to create the document as draft and continue (open/send/close) in SalesKing.
160
-
161
-
162
- For more information on how to use take a look into the tests/specs:
163
-
164
- http://github.com/salesking/sk-api/tree/master/spec/resources/
165
-
166
- === PUT / Update data
167
-
168
- To Update a client:
169
-
170
- PUT ( application/json ) to ../api/clients/:id
171
- {
172
- 'client':
173
- {
174
- 'gender':'male',
175
- 'first_name': "Andrew"
176
- }
177
- }
178
-
179
- === DELETE / kill data
180
-
181
- To delete a record simply issue a DELETE request to a resource url:
182
-
183
- DELETE https://demo.salesking.eu/clients/:id
184
-
185
- == Ruby Example
186
-
187
- Since the sk-api gem provides a wrapper around the whole url/request stuff its
188
- pretty straight forward to use:
189
-
190
- class SomeMiddleware
191
- include SKApi::Resources
192
-
193
- def initialize()
194
- # init api connection => just an example depending on your code structure do it wherever you want
195
- set_api_connection
196
- end
197
-
198
- def create_client(last_name)
199
- # create a new client object
200
- client = SKApi::Resources::Client.new(:last_name=> last_name)
201
- # set more data
202
- client.first_name = "Meister"
203
- # save it, which also does the remote saving action
204
- client.save
205
- end
206
-
207
- def set_api_connection
208
- SKApi::Resources::Base.set_connection({
209
- :site => 'my_sub.salesking.eu',
210
- :user => 'demo@salesking.eu',
211
- :password => 'password',
212
- :format => :json # symbol expected
213
- })
214
- end
215
- end
216
-
217
- ##### use it
218
- a = SomeMiddleware.new
219
- a.create_client('eder')
220
-
221
-
222
- == Salesking API Resources
223
-
224
- Right now the following resources are available:
225
-
226
- * clients
227
- * invoices
228
- * products
229
- * credit_notes
230
-
231
- See classes here:
232
- http://github.com/salesking/sk-api/tree/master/lib/resources/
233
-
234
- == Tests / Specs
235
-
236
- To run the test you must insert some credentials into the spec helper.
237
- We will gladly provide you with a test account on one of our development
238
- systems.
239
-
240
-
241
- Copyright (c) 2009, 2010 Georg Leciejewski, released under the MIT license
3
+ {Use our new SalesKing-SDK}[https://github.com/salesking/sk_sdk]
data/Rakefile CHANGED
@@ -1,42 +1,21 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
- require 'rake/rdoctask'
4
- require 'spec/rake/spectask'
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
4
+ require 'rdoc/task'
5
+ require 'bundler/gem_helper'
6
+
7
+ Bundler::GemHelper.install_tasks
5
8
 
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "sk-api"
10
- gem.summary = %Q{Interact with SalesKing}
11
- gem.description = %Q{Interact with SalesKing}
12
- gem.email = "gl@salesking.eu"
13
- gem.homepage = "http://github.com/salesking/sk-api"
14
- gem.authors = ["Georg Leciejewski"]
15
- gem.add_development_dependency "rspec", ">= 0"
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
22
9
 
23
10
  desc 'Default: run specs.'
24
11
  task :default => :spec
25
12
 
26
- spec_files = Rake::FileList["spec/**/*_spec.rb"]
27
-
28
13
  desc "Run specs"
29
- Spec::Rake::SpecTask.new do |t|
30
- t.spec_files = spec_files
31
- t.spec_opts = ["-c"]
14
+ RSpec::Core::RakeTask.new do |t|
15
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
16
+ # Put spec opts in a file named .rspec in root
32
17
  end
33
18
 
34
- desc "Generate code coverage"
35
- Spec::Rake::SpecTask.new(:coverage) do |t|
36
- t.spec_files = spec_files
37
- t.rcov = true
38
- t.rcov_opts = ['--exclude', 'spec,/var/lib/gems']
39
- end
40
19
 
41
20
  desc 'Generate sk-api documentation.'
42
21
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -1,3 +1,4 @@
1
- Patches for activerecord as long as the 3.0 version is not out
1
+ Patches for activerecord
2
2
 
3
+ * parse nested json responses
3
4
  * parse error from json response
@@ -22,7 +22,9 @@ module ActiveResource
22
22
 
23
23
  # override ARes method to parse only the client part
24
24
  def load_attributes_from_response(response)
25
- if response['Content-Length'] != "0" && response.body.strip.size > 0
25
+ if (response['Transfer-Encoding'] == 'chunked' ||
26
+ (!response['Content-Length'].blank? && response['Content-Length'] != "0")) &&
27
+ !response.body.nil? && response.body.strip.size > 0
26
28
  load( self.class.format.decode(response.body)[self.class.element_name] )
27
29
  end
28
30
  end
@@ -5,8 +5,11 @@ module ActiveResource
5
5
 
6
6
  # override ARes method to parse only the client part
7
7
  def load_attributes_from_response(response)
8
- if response['Content-Length'] != "0" && response.body.strip.size > 0
8
+ if (response['Transfer-Encoding'] == 'chunked' ||
9
+ (!response['Content-Length'].blank? && response['Content-Length'] != "0")) &&
10
+ !response.body.nil? && response.body.strip.size > 0
9
11
  load( self.class.format.decode(response.body)[self.class.element_name] )
12
+ @persisted = true
10
13
  end
11
14
  end
12
15
 
@@ -4,12 +4,19 @@ module SKApi
4
4
  class Base < ActiveResource::Base
5
5
  include SKApi::Utils::Serializer
6
6
  self.format = :json # bug in AR must be set here
7
-
8
- def initialize(attributes = {})
9
- # json comes in nested {client={data}
10
- attr = attributes[self.class.element_name] || attributes
11
- super(attr)
12
- end
7
+ # hook before init in activeresource base because json comes in nested:
8
+ # {client={data}
9
+ if ActiveResource::VERSION::MAJOR == 3 && ActiveResource::VERSION::MINOR > 0
10
+ def initialize(attributes = {}, *args)
11
+ attr = attributes[self.class.element_name] || attributes
12
+ super(attr, *args)
13
+ end
14
+ else
15
+ def initialize(attributes = {})
16
+ attr = attributes[self.class.element_name] || attributes
17
+ super(attr)
18
+ end
19
+ end
13
20
 
14
21
  # Define the connection to be used when talking to a salesking server
15
22
  def self.set_connection(opts)
@@ -6,19 +6,6 @@ module SKApi
6
6
  save_with_validation
7
7
  end
8
8
 
9
- def open
10
- self.put(:open, :id => self.id) # PUT /invoices/:id/open
11
- end
12
-
13
- # rethink
14
- def print(template_id)
15
- self.get(:print, :template_id => template_id) # GET /invoices.pdf?template_id=:ids
16
- end
17
-
18
- def mail(template_id, cc, bcc)
19
- self.get(:print, :template_id => template_id) # GET /invoices.pdf?template_id=:ids
20
- end
21
-
22
9
  ##########################################################################
23
10
  # Class methods
24
11
  ##########################################################################
@@ -54,14 +41,8 @@ module SKApi
54
41
 
55
42
  def self.api_links
56
43
  #internal links on fields=> id => salesking.eu/clients/4567.json
44
+ #external links to actions and related objects => invoeis => salesking.eu/clients/4567/invoices.json
57
45
  [:edit, :destroy, :copy, :print, :show, :payments, :payment_new]
58
- # [ :edit,
59
- # :destroy,
60
- # { :copy =>"invoices/new?source=#{self.id}" },
61
- # :open => "PUT invoices/#{self.id}/open",
62
- # :print,
63
- # :show, ]
64
-
65
46
  end
66
47
  end
67
48
  end
@@ -23,6 +23,4 @@ require 'resources/client'
23
23
  require 'resources/address'
24
24
  require 'resources/invoice'
25
25
  require 'resources/credit_note'
26
- require 'resources/line_item'
27
-
28
- # TODO before post kick empty fields and readonly's
26
+ require 'resources/line_item'
@@ -0,0 +1,3 @@
1
+ module SKApi
2
+ VERSION = "1.1.1"
3
+ end
@@ -1,12 +1,9 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'version'
6
4
  Gem::Specification.new do |s|
7
5
  s.name = %q{sk-api}
8
- s.version = "1.1.0"
9
-
6
+ s.version = SKApi::VERSION
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Georg Leciejewski"]
12
9
  s.date = %q{2010-11-07}
@@ -15,68 +12,23 @@ Gem::Specification.new do |s|
15
12
  s.extra_rdoc_files = [
16
13
  "README.rdoc"
17
14
  ]
18
- s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "Manifest",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "init.rb",
26
- "lib/patches/README",
27
- "lib/patches/ar2/base.rb",
28
- "lib/patches/ar2/validations.rb",
29
- "lib/patches/ar3/base.rb",
30
- "lib/patches/ar3/validations.rb",
31
- "lib/resources/address.rb",
32
- "lib/resources/base.rb",
33
- "lib/resources/client.rb",
34
- "lib/resources/credit_note.rb",
35
- "lib/resources/invoice.rb",
36
- "lib/resources/line_item.rb",
37
- "lib/resources/product.rb",
38
- "lib/sk_api.rb",
39
- "lib/utils/field_map.rb",
40
- "lib/utils/serializer.rb",
41
- "sk-api.gemspec",
42
- "spec/resources/client_spec.rb",
43
- "spec/resources/credit_note_spec.rb",
44
- "spec/resources/invoice_spec.rb",
45
- "spec/resources/product_spec.rb",
46
- "spec/spec_helper.rb",
47
- "spec/utils/field_map_spec.rb",
48
- "tasks/sk_api_tasks.rake",
49
- "vendor/jsonschema-1.0.0/README.rdoc",
50
- "vendor/jsonschema-1.0.0/Rakefile",
51
- "vendor/jsonschema-1.0.0/lib/jsonschema.rb",
52
- "vendor/jsonschema-1.0.0/ruby-jsonschema.gemspec",
53
- "vendor/jsonschema-1.0.0/test/jsonschema_test.rb"
54
- ]
15
+
55
16
  s.homepage = %q{http://github.com/salesking/sk-api}
56
- s.rdoc_options = ["--charset=UTF-8"]
57
17
  s.require_paths = ["lib"]
58
18
  s.rubygems_version = %q{1.3.7}
59
19
  s.summary = %q{Interact with SalesKing}
60
- s.test_files = [
61
- "spec/resources/client_spec.rb",
62
- "spec/resources/credit_note_spec.rb",
63
- "spec/resources/invoice_spec.rb",
64
- "spec/resources/product_spec.rb",
65
- "spec/spec_helper.rb",
66
- "spec/utils/field_map_spec.rb"
67
- ]
20
+ s.executables = nil
21
+ s.files = `git ls-files`.split("\n").reject{|i| i[/^docs\//] }
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
68
23
 
69
- if s.respond_to? :specification_version then
70
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
- s.specification_version = 3
24
+ s.require_paths = ["lib"]
25
+ s.rubygems_version = %q{1.6.2}
72
26
 
73
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
- s.add_development_dependency(%q<rspec>, [">= 0"])
75
- else
76
- s.add_dependency(%q<rspec>, [">= 0"])
77
- end
78
- else
79
- s.add_dependency(%q<rspec>, [">= 0"])
80
- end
81
- end
27
+ s.add_runtime_dependency 'activeresource', '< 3'
82
28
 
29
+ s.add_development_dependency 'rdoc'
30
+ s.add_development_dependency 'rspec'
31
+ s.add_development_dependency 'simplecov'
32
+ s.add_development_dependency 'xml-simple'
33
+ s.add_development_dependency 'rake', '>= 0.9.2'
34
+ end