sk_sdk 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,8 @@
1
1
  = SalesKing SDK
2
2
 
3
- A bunch of classes to get a quick start creating SalesKing App's, using oAuth
4
- and the API.
3
+ Automate your workflow's by integrating and connecting your business with SalesKing.
4
+ This Ruby Software-Development-Kit provides solid and handy tools for building
5
+ SalesKing App's(using oAuth2) and API clients.
5
6
 
6
7
 
7
8
  == Install
@@ -11,7 +12,7 @@ and the API.
11
12
  Dependencies (gem's):
12
13
 
13
14
  * activesupport
14
- * activeresource
15
+ * activeresource v2.3.x, v3.1 (v3.0.10 until sk_sdk v0.0.8)
15
16
  * curb
16
17
  * sk_api_schema
17
18
 
@@ -22,26 +23,27 @@ All classes must be explicitly required so each can be used on their own.
22
23
  require 'sk_sdk/signed_request'
23
24
  require 'sk_sdk/oauth'
24
25
  require 'sk_sdk/base'
26
+ require 'sk_sdk/sync'
25
27
 
26
- === API client Base
28
+ === API client
27
29
 
28
- Uses ActiveResource to CRUD SalesKing object's {see usage in README}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/README_Base.rdoc]
30
+ Uses ActiveResource to CRUD SalesKing object's {see usage in README}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/]
29
31
 
30
- === oAuth
32
+ === {oAuth}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/oauth.rb]
31
33
 
32
- Handling oAuth related URL's and getting an access token.
33
- There also is an omniAuth strategy in case you are using it.
34
+ Get an oAuth2 access token and create oAuth related URL's.
35
+ There also is an {omniAuth strategy}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/omni_auth].
34
36
 
35
- === SignedRequest
37
+ === {SignedRequest}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/signed_request.rb]
36
38
 
37
- Helping in de/encoding of signed_request parameter available in canvas pages and
38
- PubSub/Webhook callbacks.
39
+ De/encoding of signed_request parameter on canvas pages and PubSub/Webhook
40
+ callbacks.
39
41
 
40
- === Sync
42
+ === {Sync}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/sync.rb]
41
43
 
42
- Synchronize a local with an remote object. Tackles the problem of normalizing
43
- objects to match internal data structures. Synchronization is done by a
44
- field-mapping which also supports transition methods for each way.
44
+ Map & Synchronize fields of a local with an remote object. Tackles the problem
45
+ of normalizing objects to match internal data structures. Synchronization is
46
+ done by a field-mapping and also sports transition methods for each way.
45
47
 
46
48
  == Usage
47
49
 
@@ -53,6 +55,9 @@ Before you run the tests use bundler to install all required gems:
53
55
  # git clone
54
56
  # cd into dir
55
57
  BUNDLE_GEMFILE=ci/Gemfile bundle install
58
+
59
+ # create /spec/settingsyml from default
60
+ # run specs with most recent version of activeresource
56
61
  BUNDLE_GEMFILE=ci/Gemfile bundle exec rake spec
57
62
 
58
63
  Copyright (c) 2011 Georg Leciejewski, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.1.0
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activeresource (2.3.14)
5
+ activesupport (= 2.3.14)
6
+ activesupport (2.3.14)
7
+ curb (0.7.15)
8
+ diff-lcs (1.1.3)
9
+ rake (0.9.2)
10
+ rcov (0.9.10)
11
+ rdoc (3.9.4)
12
+ rspec (2.6.0)
13
+ rspec-core (~> 2.6.0)
14
+ rspec-expectations (~> 2.6.0)
15
+ rspec-mocks (~> 2.6.0)
16
+ rspec-core (2.6.4)
17
+ rspec-expectations (2.6.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.6.0)
20
+ sk_api_schema (0.2.4)
21
+ activesupport
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ activeresource (= 2.3.14)
28
+ activesupport (= 2.3.14)
29
+ curb
30
+ rake
31
+ rcov
32
+ rdoc
33
+ rspec
34
+ sk_api_schema
@@ -1,4 +1,4 @@
1
- = SalesKing API Client
1
+ = SalesKing API Client - SK::SDK::Base
2
2
 
3
3
  Easily access SalesKing resources in a RESTfull way with this ActiveResource
4
4
  based SalesKing API client.
@@ -33,9 +33,12 @@ per api client and restrict his rights with our role-system!
33
33
  Getting an access_token or checking is validity is not the scope of this
34
34
  library, it merely sets an AUTHORIZATION header if you added a token in the
35
35
  connection settings.
36
+
36
37
  AUTHORIZATION: Bearer YourAccessToken
37
- See our {oAuth helper class}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/oauth.rb]
38
- and read our {oAuth docs}[http://dev.blog.salesking.eu/docs/authentication/].
38
+
39
+ More on oAuth here:
40
+ * {oAuth helper class}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/oauth.rb]
41
+ * {oAuth docs}[http://dev.blog.salesking.eu/docs/authentication/].
39
42
 
40
43
  == Usage
41
44
 
@@ -43,14 +46,23 @@ SalesKing's api interface is RESTful(mostly) and returns & accepts JSON data.
43
46
  All resources such as clients, invoices, products can be accessed via URL's
44
47
  through standard HTTP methods GET, POST, PUT and DELETE.
45
48
 
46
- The available objects and their endpoints(links) are described in {our json-schema}[https://github.com/salesking/sk_api_schema/tree/master/json].
47
- Take a look into the links-section of each schema to see available
48
- endpoints/routes and their parameter f.ex. to apply search filtering
49
+ == Available resources, properties and links
50
+
51
+ All objects and their endpoints are described in a json schema. You should read
52
+ it and especially take a look at the schema's link section, where you can find
53
+ available endpoints(urls), their nesting and parameters.
54
+
55
+ * {JSON-Schema }[https://github.com/salesking/sk_api_schema/tree/master/json]
56
+ * {API Browser visualized JSON Schema}[http://sk-api-browser.heroku.com/]
49
57
 
50
- Your classes simply descend from SK::SDK::Base and need the connection settings.
58
+ == Class creation
59
+
60
+ Your classes simply descend from SK::SDK::Base and you need to add connection settings(site URL+user+passwd).
51
61
  You MUST provide the full URL using the right protocol in the connection and
52
- remember our production system only supports HTTPS:
62
+ remember we only support HTTPS:
53
63
  https + SUBDomain + salesking url + /api
64
+ =>
65
+ https://my_company.salesking.eu/api
54
66
 
55
67
  Create a single class
56
68
 
@@ -59,7 +71,7 @@ Create a single class
59
71
  class Client < SK::SDK::Base;end
60
72
 
61
73
  # connection using BasicAuth
62
- Client.set_connection {:site => 'https://my_sub.salesking.eu/api',
74
+ Client.set_connection( {:site => 'https://my_sub.salesking.eu/api',
63
75
  :user => 'my-users@login-email.com',
64
76
  :password => 'password' })
65
77
 
@@ -67,7 +79,6 @@ Create a single class
67
79
  client.first_name = "Bill"
68
80
  client.save
69
81
 
70
-
71
82
  Create multiple classes at once
72
83
 
73
84
  require 'sk_sdk/base'
@@ -77,7 +88,7 @@ Create multiple classes at once
77
88
  end
78
89
 
79
90
  # connection using oAuth access token
80
- SK::SDK::Base.set_connection {:site => 'https://my_sub.salesking.eu/api',
91
+ SK::SDK::Base.set_connection( {:site => 'https://my_sub.salesking.eu/api',
81
92
  :token => 'someAccessToken'})
82
93
 
83
94
  invoice = Invoice.new
@@ -90,16 +101,120 @@ Create multiple classes at once
90
101
  invoice.save
91
102
 
92
103
 
104
+ == Quick start - Basic's
105
+
106
+ To give it quick shot, point your browser to my-account.salesking.eu/api/clients.json
107
+ (while beeing logged in) and you will see the JSON in the response.
108
+ This is an example of a GET-request issued by your browser.
109
+
110
+ Or use CURL, if you prefer the command line:
111
+
112
+ curl -u your@login-mail.com:password \
113
+ https://demo.salesking.eu/clients
114
+
115
+ Request Method overview:
116
+ GET => read
117
+ POST => create new data
118
+ PUT => update data
119
+ DELETE => delete data
120
+
93
121
  Want to know more about REST style webservices?
94
122
  * http://en.wikipedia.org/wiki/Representational_State_Transfer
95
123
  * http://www.google.com/search?q=REST+site%3Awww.infoq.com
96
124
 
125
+ === GET / Show
126
+
127
+ A list of resources:
128
+ GET xy.salesking.eu/api/invoices
129
+
130
+ A single resource
131
+ GET xy.salesking.eu/invoices/:id
132
+
133
+ Returned JSON data for a listings, abbreviated:
134
+ {
135
+ "clients": [ # array of resources => clients
136
+ { "client": { # a single resource
137
+ "number": "0800013", ..
138
+ "links":{} #links for the resource
139
+ }, ...
140
+ ],
141
+ collection": { # info on index pages
142
+ "total_pages": 1,
143
+ "total_entries": 3,
144
+ "current_page": 1,
145
+ "per_page": 30
146
+ },
147
+ "links": { # links for the collection
148
+ "prev": "/api/clients?page=0",
149
+ "next": "/api/clients?page=2",
150
+ "self": "/api/clients?page=1"
151
+ },
152
+ }
153
+
154
+ === Filtering
155
+
156
+ Filtering is achieved by using the url filter[xy] param. Following some examples.
157
+ Available filters are defined in each json-schema's instances link ({see invoices}[https://github.com/salesking/sk_api_schema/blob/master/json/v1.0/invoice.json#L156])
158
+
159
+ #Find objects by tags
160
+ GET xy.salesking.eu/api/invoices?filter[tags]=Agentur
161
+
162
+ # find all objects without tags
163
+ GET xy.salesking.eu/api/invoices?filter[exclude_tags]=Agentur Grafik
164
+
165
+ # q-wildcard search in several fields
166
+ GET xy.salesking.eu/api/invoices?filter[q]=0815&per_page=40
167
+
168
+ # find all documents for one or more client
169
+ GET xy.salesking.eu/api/documents?filter[client_ids]=:id,:id
170
+
171
+ === POST / Create
172
+
173
+ To create a resource make a POST request containing the json for a single resource.
174
+
175
+ Header: content-type application/json
176
+ POST https://my-sub.salesking.eu/invoices.json
177
+
178
+ {"invoice": {
179
+ "title": "Your service subscription 2011",
180
+ "line_items": [ {
181
+ "line_item": {
182
+ "quantity_unit": "Month",
183
+ "tax": 19,
184
+ "price_single": 10.23,
185
+ "position": 1,
186
+ "quantity": 12,
187
+ "name": "SalesKing Bronze Account"
188
+ }
189
+ } ]
190
+ }}
191
+
192
+ === PUT / Update
193
+
194
+ Header: content-type application/json
195
+ PUT /api/clients/:id
196
+ {
197
+ 'client':
198
+ {
199
+ 'gender':'male',
200
+ 'first_name': "Andrew"
201
+ }
202
+ }
203
+
204
+ === DELETE
205
+
206
+ A DELETE request to a resource url deletes and returns the deleted object:
207
+
208
+ DELETE https://demo.salesking.eu/clients/:id
209
+
97
210
  == Hints on ActiveResource
98
211
 
99
212
  * Most of the magic is coming from ActiveResource so you should read {its README and code}[https://github.com/rails/rails/tree/master/activeresource]
100
213
  * This client does NOT rely on parsing the JSON Schema, since ActiveResource(AR) creates the Getter/Setter methods.
101
214
  * We added some patches for AR to fix JSON parsing issues, due to our nesting.
102
215
  * non-restful routes can be accessed by custom methods {see examples in AR}[https://github.com/rails/rails/blob/master/activeresource/lib/active_resource/custom_methods.rb]
216
+
217
+ E.g calling the print method a a document:
103
218
  Invoice.find('uuid').post(:print, :template_id => 'pdf-template-uuid')
104
219
 
105
220
  == Tutorials & Tools
@@ -1,19 +1,21 @@
1
1
  module ActiveResource
2
- # Overridden methods to suit SalesKing.
3
- # Some changes might be kicked when AR 3.0 is out
2
+ # Overridden methods to suit SalesKing's nested json format
3
+ # only valid for AR 3.1
4
+ # In the future might add a custom format class, see base.format
4
5
  class Base
5
6
 
6
7
  # override ARes method to parse only the client part
7
8
  def load_attributes_from_response(response)
8
- if response['Content-Length'] != "0" && response.body.strip.size > 0
9
+ if !response['Content-Length'].blank? && response['Content-Length'] != "0" && !response.body.nil? && response.body.strip.size > 0
9
10
  load( self.class.format.decode(response.body)[self.class.element_name] )
11
+ @persisted = true
10
12
  end
11
13
  end
12
14
 
13
15
  # Overridden to grab the data(= clients-collection) from json:
14
16
  # { 'collection'=> will_paginate infos,
15
17
  # 'links' => prev/next links
16
- # 'clients'=> [data], << what we need
18
+ # 'clients'=> [data], << what we need
17
19
  # }
18
20
  def self.instantiate_collection(collection, prefix_options = {})
19
21
  collection = collection[ self.element_name.pluralize ] if collection.is_a?(Hash)
data/lib/sk_sdk/base.rb CHANGED
@@ -15,9 +15,16 @@ class SK::SDK::Base < ActiveResource::Base
15
15
  self.format = :json
16
16
  # hook before init in activeresource base because json comes in nested:
17
17
  # {client={data}
18
- def initialize(attributes = {})
19
- attr = attributes[self.class.element_name] || attributes
20
- super(attr)
18
+ if ActiveResource::VERSION::MAJOR == 3 #TODO Damn this is dirty .. we really need to get rid of backwards compat
19
+ def initialize(attributes = {}, *args)
20
+ attr = attributes[self.class.element_name] || attributes
21
+ super(attr, *args)
22
+ end
23
+ else
24
+ def initialize(attributes = {})
25
+ attr = attributes[self.class.element_name] || attributes
26
+ super(attr)
27
+ end
21
28
  end
22
29
 
23
30
  def save; save_with_validation; end
@@ -21,7 +21,7 @@ If you are using bundler add to Gemfile
21
21
 
22
22
  == Usage
23
23
 
24
- An initializers/omniauth.rb might look somethign like this:
24
+ An initializers/omniauth.rb might look something like this:
25
25
  # if you copied the file into your lib/
26
26
  require File.expand_path('../../../lib/sk_auth', __FILE__)
27
27
  # or from gem
data/sk_sdk.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sk_sdk}
8
- s.version = "0.0.8"
8
+ s.version = "0.1.0"
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{2011-09-02}
12
+ s.date = %q{2011-10-03}
13
13
  s.description = %q{Connect your business world with SalesKing. This gem gives ruby developers a jump-start for building SalesKing Business Apps. It provides classes to handle oAuth, make RESTfull API requests and parses JSON Schema }
14
14
  s.email = %q{gl@salesking.eu}
15
15
  s.extra_rdoc_files = [
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
21
21
  "Rakefile",
22
22
  "VERSION",
23
23
  "ci/Gemfile",
24
+ "ci/Gemfile_ar2.lock",
24
25
  "lib/sk_sdk.rb",
25
- "lib/sk_sdk/README_Base.rdoc",
26
+ "lib/sk_sdk/README.rdoc",
26
27
  "lib/sk_sdk/ar_patches/ar2/base.rb",
27
28
  "lib/sk_sdk/ar_patches/ar2/validations.rb",
28
29
  "lib/sk_sdk/ar_patches/ar3/base.rb",
@@ -35,7 +36,7 @@ Gem::Specification.new do |s|
35
36
  "lib/sk_sdk/sync.rb",
36
37
  "sk_sdk.gemspec",
37
38
  "spec/resources_spec_helper.rb",
38
- "spec/settings.yml",
39
+ "spec/settings.yml.default",
39
40
  "spec/sk_sdk/base_spec.rb",
40
41
  "spec/sk_sdk/oauth_spec.rb",
41
42
  "spec/sk_sdk/resources/README.rdoc",
@@ -1,16 +1,9 @@
1
- CONNECTION = {
2
- :site => "https://demo.dev.salesking.eu/api/",
3
- :password => "demouser",
4
- # :site => "http://demo.salesking.local:3000/api/",
5
- # :password => "demo",
6
- :user => "demo@salesking.eu"
7
- } unless defined?(CONNECTION)
8
-
1
+ require 'spec_helper'
9
2
  # create all classes and set their connection
10
3
  %w[Client Address CreditNote Invoice Product LineItem User].each do |model|
11
4
  eval "class #{model} < SK::SDK::Base;end" unless Object.const_defined?(model)
12
5
  end
13
- SK::SDK::Base.set_connection CONNECTION
6
+ SK::SDK::Base.set_connection basic_auth_settings
14
7
 
15
8
  # check if a SalesKing instance is available by calling /users/current.json
16
9
  def sk_available?
@@ -22,6 +15,14 @@ def sk_available?
22
15
 
23
16
  end
24
17
 
18
+ # Params
19
+ # obj<Class>:: class name
20
+ # number<String>:: the document number the kick
21
+ def kick_existing(obj, number)
22
+ if existing = obj.find(:first, :params =>{ :filter=>{ :number => number } })
23
+ existing.destroy
24
+ end
25
+ end
25
26
 
26
27
  def delete_test_data(doc, client)
27
28
  doc.destroy
@@ -0,0 +1,14 @@
1
+ oauth:
2
+ sk_url: http://*.horsts-lokal.local
3
+ canvas_slug: canvas-page
4
+ id: 2d83d570635ee19c
5
+ secret: eb4005858e4947e4228a12a6b7306ee0
6
+ redirect_url: http://localhorst:4567
7
+ scope: "api/payments:read api/invoices:read"
8
+ session_secret: very_long_random_to_encode_the_session
9
+
10
+ # used in resources spec
11
+ basic_auth:
12
+ site: "https://SUBDOMAIN.dev.salesking.eu/api/"
13
+ password: "your password"
14
+ user: "your login email address"
@@ -35,4 +35,14 @@ describe SK::SDK::Base, "make new class" do
35
35
  p.new_record?.should be_true
36
36
  end
37
37
 
38
- end
38
+ it "should allow multiple parameters in initializer" do
39
+ expect {
40
+ if ActiveResource::VERSION::MAJOR == 3
41
+ Client.new({ :first_name => 'herbert' }, true)
42
+ else
43
+ Client.new({ :first_name => 'herbert' })
44
+ end
45
+ }.should_not raise_error(ArgumentError)
46
+ end
47
+
48
+ end
@@ -4,7 +4,7 @@ describe SK::SDK::Oauth, "in general" do
4
4
 
5
5
  before :each do
6
6
  #setup test oAuth-data to work with
7
- load_settings
7
+ @set = oauth_settings
8
8
  end
9
9
 
10
10
  it "should create a new instance" do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'resources_spec_helper'
3
2
 
4
3
  unless sk_available?
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'resources_spec_helper'
3
2
 
4
3
  unless sk_available?
@@ -37,12 +36,17 @@ else
37
36
  end
38
37
 
39
38
  it "should fail create a doc without unique number" do
39
+ kick_existing(CreditNote, '001')
40
40
  doc = CreditNote.new(:number=>'001')
41
41
  doc.save.should == true
42
42
  doc2 = CreditNote.new(:number=>'001')
43
43
  doc2.save.should == false
44
44
  doc2.errors.count.should == 2
45
- doc2.errors.on(:number).should == "has already been taken"
45
+ if doc2.errors.respond_to? :on # TODO kick with AR 2.3
46
+ doc2.errors.on(:number).should == "has already been taken"
47
+ else
48
+ doc2.errors[:number].should == ["has already been taken"]
49
+ end
46
50
  doc.destroy
47
51
  end
48
52
 
@@ -62,12 +66,17 @@ else
62
66
  end
63
67
 
64
68
  it "should fail edit with wrong number" do
69
+ kick_existing(CreditNote, '002')
65
70
  doc1 = CreditNote.new(:number=>'002')
66
71
  doc1.save.should == true
67
72
  @doc.number = '002'
68
73
  @doc.save.should == false
69
74
  @doc.errors.count.should == 2
70
- @doc.errors.on(:number).should == "has already been taken"
75
+ if @doc.errors.respond_to? :on # TODO kick with AR 2.3
76
+ @doc.errors.on(:number).should == "has already been taken"
77
+ else
78
+ @doc.errors[:number].should == ["has already been taken"]
79
+ end
71
80
  doc1.destroy
72
81
  end
73
82
  end
@@ -116,4 +125,34 @@ else
116
125
  # @doc.line_items.[1].zip.should == '40001'
117
126
  end
118
127
  end
128
+
129
+ describe CreditNote, "with status change" do
130
+
131
+ before :all do
132
+ @doc = CreditNote.new :title => 'Status test'
133
+ end
134
+
135
+ after :all do
136
+ # @doc.destroy
137
+ # lambda {
138
+ # doc = CreditNote.find(@doc.id)
139
+ # }.should raise_error(ActiveResource::ResourceNotFound)
140
+ end
141
+
142
+ it "should update from draft to open and set number with date" do
143
+ @doc.save.should be_true
144
+ @doc.status.should == 'draft'
145
+
146
+ @doc.status = 'open'
147
+ @doc.save
148
+ @doc.status.should == 'open'
149
+ @doc.number.should_not be_empty
150
+ @doc.date.to_s.should_not be_empty
151
+ # make draft to be deleted
152
+ @doc.status = 'draft'
153
+ @doc.save
154
+ @doc.destroy
155
+ end
156
+
157
+ end
119
158
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ #require 'spec_helper'
2
2
  require 'resources_spec_helper'
3
3
 
4
4
  unless sk_available?
@@ -37,12 +37,12 @@ describe Invoice, "a new invoice" do
37
37
  end
38
38
 
39
39
  it "should create a doc" do
40
- doc = Invoice.new()
40
+ doc = Invoice.new
41
41
  doc.title = 'A Document from the API'
42
42
  doc.notes_before = 'Your shiny new invoice [number]'
43
43
  doc.notes_after = 'Please pay me'
44
44
  doc.client_id = @client.id
45
- doc.save
45
+ doc.save.should be_true
46
46
  doc.errors.should be_empty
47
47
  doc.new?.should be_false
48
48
  doc.notes_before.should == 'Your shiny new invoice [number]'
@@ -50,7 +50,7 @@ describe Invoice, "a new invoice" do
50
50
  end
51
51
 
52
52
  it "should create a doc with default before after texts" do
53
- doc = Invoice.new()
53
+ doc = Invoice.new
54
54
  doc.title = 'A Document from the API'
55
55
  doc.client_id = @client.id
56
56
  doc.save
@@ -61,12 +61,18 @@ describe Invoice, "a new invoice" do
61
61
  end
62
62
 
63
63
  it "should fail create a doc without unique number" do
64
+ # if a test failed this invoice might still be present so try to delete
65
+ kick_existing(Invoice, '001')
64
66
  doc = Invoice.new(:number=>'001')
65
67
  doc.save.should == true
66
68
  doc2 = Invoice.new(:number=>'001')
67
69
  doc2.save.should == false
68
70
  doc2.errors.count.should == 2
69
- doc2.errors.on(:number).should == "has already been taken"
71
+ if doc2.errors.respond_to? :on
72
+ doc2.errors.on(:number).should == "has already been taken"
73
+ else
74
+ doc2.errors[:number].should == ["has already been taken"]
75
+ end
70
76
  doc.destroy
71
77
  end
72
78
 
@@ -79,7 +85,7 @@ describe Invoice, "Edit an invoice" do
79
85
  # create client
80
86
  @client = Client.new(:organisation=>'Invoice API-Tester')
81
87
  @client.save.should be_true
82
- @doc = Invoice.new()
88
+ @doc = Invoice.new
83
89
  @doc.title = 'A Document from the API'
84
90
  @doc.notes_before = 'Your invoice [number]'
85
91
  @doc.client_id = @client.id
@@ -103,12 +109,17 @@ describe Invoice, "Edit an invoice" do
103
109
  end
104
110
 
105
111
  it "should fail edit with wrong number" do
112
+ kick_existing(Invoice, '002')
106
113
  doc1 = Invoice.new(:number=>'002')
107
114
  doc1.save.should == true
108
115
  @doc.number = '002'
109
116
  @doc.save.should == false
110
117
  @doc.errors.count.should == 2
111
- @doc.errors.on(:number).should == "has already been taken"
118
+ if @doc.errors.respond_to? :on # TODO kick with AR 2.3
119
+ @doc.errors.on(:number).should == "has already been taken"
120
+ else
121
+ @doc.errors[:number].should == ["has already been taken"]
122
+ end
112
123
  doc1.destroy
113
124
  end
114
125
  end
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'resources_spec_helper'
3
2
 
4
3
  unless sk_available?
@@ -56,7 +55,11 @@ else
56
55
  @product.name = ''
57
56
  @product.save.should == false
58
57
  @product.errors.count.should == 1
59
- @product.errors.on(:name).should == "can't be blank"
58
+ if @product.errors.respond_to? :on # TODO kick with AR 2.3
59
+ @product.errors.on(:name).should == "can't be blank"
60
+ else
61
+ @product.errors[:name].should == ["can't be blank"]
62
+ end
60
63
  end
61
64
 
62
65
  end
@@ -4,7 +4,7 @@ describe SK::SDK::SignedRequest, "in general" do
4
4
 
5
5
  before :each do
6
6
  #setup test oAuth-data to work with
7
- load_settings
7
+ @set = oauth_settings
8
8
  # fake request
9
9
  @param_hash = {'hello' =>'coder', 'algorithm' => 'HMAC-SHA256'}
10
10
  @param = SK::SDK::SignedRequest.signed_param( ActiveSupport::JSON.encode(@param_hash), @set['secret'] )
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe SK::SDK::Sync::Field do
4
4
 
@@ -1,5 +1,4 @@
1
-
2
- require 'spec/spec_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  describe SK::SDK::Sync do
5
4
 
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,18 @@ require "#{File.dirname(__FILE__)}/../lib/sk_sdk/signed_request"
13
13
  puts "Testing with ActiveResource v: #{ActiveResource::VERSION::STRING}"
14
14
 
15
15
 
16
- def load_settings
17
- @set ||= YAML.load_file(File.join(File.dirname(__FILE__), 'settings.yml'))
16
+ def basic_auth_settings
17
+ get_settings['basic_auth'].symbolize_keys
18
+ end
19
+
20
+ def oauth_settings
21
+ get_settings['oauth']
22
+ end
23
+
24
+ def get_settings
25
+ @settings ||= begin
26
+ YAML.load_file(File.join(File.dirname(__FILE__), 'settings.yml'))
27
+ rescue => e
28
+ puts "Missing settings.yml in rails_root/spec/settings.yml"
29
+ end
18
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sk_sdk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 8
10
- version: 0.0.8
10
+ version: 0.1.0
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: 2011-09-02 00:00:00 +02:00
18
+ date: 2011-10-03 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,8 +116,9 @@ files:
116
116
  - Rakefile
117
117
  - VERSION
118
118
  - ci/Gemfile
119
+ - ci/Gemfile_ar2.lock
119
120
  - lib/sk_sdk.rb
120
- - lib/sk_sdk/README_Base.rdoc
121
+ - lib/sk_sdk/README.rdoc
121
122
  - lib/sk_sdk/ar_patches/ar2/base.rb
122
123
  - lib/sk_sdk/ar_patches/ar2/validations.rb
123
124
  - lib/sk_sdk/ar_patches/ar3/base.rb
@@ -130,7 +131,7 @@ files:
130
131
  - lib/sk_sdk/sync.rb
131
132
  - sk_sdk.gemspec
132
133
  - spec/resources_spec_helper.rb
133
- - spec/settings.yml
134
+ - spec/settings.yml.default
134
135
  - spec/sk_sdk/base_spec.rb
135
136
  - spec/sk_sdk/oauth_spec.rb
136
137
  - spec/sk_sdk/resources/README.rdoc
data/spec/settings.yml DELETED
@@ -1,7 +0,0 @@
1
- sk_url: http://*.horsts-lokal.local
2
- canvas_slug: canvas-page
3
- id: 2d83d570635ee19c
4
- secret: eb4005858e4947e4228a12a6b7306ee0
5
- redirect_url: http://localhorst:4567
6
- scope: "api/payments:read api/invoices:read"
7
- session_secret: very_long_random_to_encode_the_session