sk-api 1.0.1 → 1.0.2

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
- 1.0.1
1
+ 1.0.2
@@ -19,5 +19,26 @@ module ActiveResource
19
19
  load( self.class.format.decode(response.body)[self.class.element_name] )
20
20
  end
21
21
  end
22
+
23
+ # Ooverridden to grab the data(clients- collection) from json:
24
+ # { 'collection'=> will_paginate infos,
25
+ # 'links' => prev/next links
26
+ # >> 'clients'=> [data], <<
27
+ # }
28
+ def self.instantiate_collection(collection, prefix_options = {})
29
+ collection = collection[ self.element_name.pluralize ] if collection.is_a?(Hash)
30
+ collection.collect! { |record| instantiate_record(record, prefix_options) }
31
+ end
22
32
  end
23
33
  end
34
+
35
+ # Force json decoding using Rufus
36
+ module ActiveResource
37
+ module Formats
38
+ module JsonFormat
39
+ def decode(json)
40
+ Rufus::Json.decode(json)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,7 +3,6 @@ module SKApi
3
3
  class Client < SKApi::Resources::Base
4
4
 
5
5
  def save
6
- # validate_schema
7
6
  save_with_validation
8
7
  end
9
8
 
@@ -3,26 +3,16 @@ module SKApi
3
3
  class Product < SKApi::Resources::Base
4
4
 
5
5
  def save
6
- # validate_schema
7
6
  save_with_validation
8
7
  end
9
8
 
10
- # not realy stable yet
11
- def validate_schema
12
- json = self.to_json
13
- obj = Rufus::Json.decode(json)
14
- JSON::Schema.validate(obj, SKApi::Resources::Product.schema)
15
- end
16
-
17
9
  def self.schema
18
10
  { "type" => "object",
19
11
  "properties" => SKApi::Resources::Product.schema_props}
20
12
  end
21
13
 
22
14
  def self.schema_props
23
- {
24
- # category
25
- # template_id
15
+ {
26
16
  "id" => {"type" => "string", "identity" => true , "readonly" => true},
27
17
  "number" => {"type" => "string", "optional" => true},
28
18
  "name" => {"type" => "string"},
data/lib/sk_api.rb CHANGED
@@ -1,16 +1,15 @@
1
1
  require 'rubygems'
2
+ require 'active_resource'
2
3
  # patches are for specific AR version
3
- gem 'activeresource' , '=2.3.4'
4
+ #gem 'activeresource' , '=2.3.4'
4
5
 
5
6
  unless RUBY_PLATFORM =~ /java/
6
7
  require 'yajl'
7
8
  require 'rufus-json'
8
-
9
9
  Rufus::Json.backend = :yajl
10
10
  else
11
11
  require 'json'
12
12
  require 'rufus-json'
13
-
14
13
  Rufus::Json.backend = :json
15
14
  end
16
15
 
@@ -29,11 +29,16 @@ describe SKApi::Resources::Client, "in general" do
29
29
  client.errors.full_messages.should == ["Bank iban is invalid"]
30
30
  end
31
31
 
32
- it "should find a client" do
32
+ it "should find a single client" do
33
33
  client = SKApi::Resources::Client.find(@client.id)
34
34
  client.organisation.should == @client.organisation
35
35
  end
36
36
 
37
+ it "should find clients" do
38
+ clients = SKApi::Resources::Client.find(:all)
39
+ clients.should_not be_empty
40
+ end
41
+
37
42
  it "should edit a client" do
38
43
  @client.first_name = 'Theodore'
39
44
  @client.gender = 'male'
@@ -47,7 +52,7 @@ describe SKApi::Resources::Client, "in general" do
47
52
  @client.organisation = ''
48
53
  @client.save.should == false
49
54
  @client.errors.count.should == 1
50
- @client.errors.on_base.should == "<p>clients.errors.fill_name_or_organisation</p>"
55
+ @client.errors.on_base.should == "Organisation or lastname must be present."
51
56
  end
52
57
 
53
58
  it "should validate raw json object with schema" do
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ SKApi::CONNECTION = {
8
8
  :user => "demo@salesking.eu",
9
9
  :password => "demo",
10
10
  :format => :json
11
- }
11
+ } unless defined?(SKApi::CONNECTION)
12
12
  SKApi::Resources::Base.set_connection(SKApi::CONNECTION)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Georg Leciejewski
@@ -57,7 +57,6 @@ files:
57
57
  - lib/sk_api.rb
58
58
  - lib/utils/field_map.rb
59
59
  - lib/utils/serializer.rb
60
- - lib/version.rb
61
60
  - spec/resources/client_spec.rb
62
61
  - spec/resources/credit_note_spec.rb
63
62
  - spec/resources/product_spec.rb
data/lib/version.rb DELETED
@@ -1,9 +0,0 @@
1
- module SKApi
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 0
5
- TINY = 1
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end