sk_sdk 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +6 -6
- data/Rakefile +0 -10
- data/ci/Gemfile_ar3 +1 -1
- data/ci/Gemfile_ar3.lock +29 -21
- data/lib/sk_sdk/base.rb +2 -5
- data/lib/sk_sdk/oauth.rb +33 -26
- data/lib/sk_sdk/version.rb +1 -1
- data/sk_sdk.gemspec +4 -9
- data/spec/sk_sdk/base_spec.rb +5 -5
- data/spec/sk_sdk/oauth_spec.rb +12 -6
- data/spec/sk_sdk/resources/contacts_spec.rb +1 -4
- data/spec/sk_sdk/resources/credit_note_spec.rb +7 -7
- data/spec/sk_sdk/resources/invoice_spec.rb +20 -20
- data/spec/sk_sdk/resources/payment_spec.rb +3 -3
- data/spec/sk_sdk/resources/product_spec.rb +3 -3
- data/spec/sk_sdk/sync_spec.rb +2 -2
- metadata +20 -41
- data/.travis.yml +0 -7
- data/ci/Gemfile_ar2 +0 -11
- data/ci/Gemfile_ar2.lock +0 -38
- data/lib/sk_sdk/ar_patches/ar2/base.rb +0 -46
- data/lib/sk_sdk/ar_patches/ar2/validations.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77ef87bd3a416159a37c8a613e0c6ac38cf439c0
|
4
|
+
data.tar.gz: 10517502170896710800a0391550bbaf0bc6c1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5980bc0f780904a60a22f30b8b86049d5850f972f32fce402bde776da122fb12143e82c1c880f0f9d140c8aedee493d4e2bf491abe938e4ac898b131c378322
|
7
|
+
data.tar.gz: 6c3ec2afb4b0b59efb00444c3f98bc400bb5ef226829782e7c4b6e41f5436b496436e2c6dc91ff084506c9d90a481901ceda0e71cf57e103942267e60c5d98b2
|
data/README.rdoc
CHANGED
@@ -12,8 +12,8 @@ SalesKing App's(using oAuth2) and API clients.
|
|
12
12
|
Dependencies (gem's):
|
13
13
|
|
14
14
|
* activesupport
|
15
|
-
* activeresource
|
16
|
-
*
|
15
|
+
* activeresource v3.1+ (v3.0.10 until sk_sdk v0.0.8)
|
16
|
+
* httparty
|
17
17
|
* sk_api_schema
|
18
18
|
|
19
19
|
== Classes
|
@@ -63,8 +63,8 @@ Before running the specs, add your SalesKing credentials to /spec/settings.yml
|
|
63
63
|
bundle install
|
64
64
|
rake spec
|
65
65
|
|
66
|
-
#test with
|
67
|
-
BUNDLE_GEMFILE=ci/
|
68
|
-
BUNDLE_GEMFILE=ci/
|
66
|
+
#test with ActiveResource 3
|
67
|
+
BUNDLE_GEMFILE=ci/Gemfile_ar3 bundle install
|
68
|
+
BUNDLE_GEMFILE=ci/Gemfile_ar3 bundle exec rake spec
|
69
69
|
|
70
|
-
Copyright (c) 2011 Georg Leciejewski, released under the MIT license
|
70
|
+
Copyright (c) 2011-2016 Georg Leciejewski, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,19 +1,9 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rspec'
|
3
3
|
require 'rspec/core/rake_task'
|
4
|
-
require 'rdoc/task'
|
5
4
|
require 'bundler/gem_helper'
|
6
5
|
Bundler::GemHelper.install_tasks
|
7
6
|
|
8
7
|
desc "Run specs"
|
9
8
|
RSpec::Core::RakeTask.new
|
10
9
|
task :default => :spec
|
11
|
-
|
12
|
-
desc 'Generate documentation.'
|
13
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
14
|
-
rdoc.rdoc_dir = 'rdoc'
|
15
|
-
rdoc.title = 'SalesKing SDK'
|
16
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
17
|
-
rdoc.rdoc_files.include('README')
|
18
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
-
end
|
data/ci/Gemfile_ar3
CHANGED
data/ci/Gemfile_ar3.lock
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM
|
2
|
-
remote:
|
2
|
+
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
activemodel (3.2.0)
|
5
5
|
activesupport (= 3.2.0)
|
@@ -11,29 +11,34 @@ GEM
|
|
11
11
|
i18n (~> 0.6)
|
12
12
|
multi_json (~> 1.0)
|
13
13
|
builder (3.0.4)
|
14
|
-
curb (0.
|
14
|
+
curb (0.9.3)
|
15
15
|
diff-lcs (1.2.5)
|
16
|
-
docile (1.1.
|
17
|
-
i18n (0.
|
18
|
-
json (1.8.
|
19
|
-
multi_json (1.
|
20
|
-
rake (
|
21
|
-
rdoc (4.
|
16
|
+
docile (1.1.5)
|
17
|
+
i18n (0.7.0)
|
18
|
+
json (1.8.3)
|
19
|
+
multi_json (1.11.3)
|
20
|
+
rake (11.1.2)
|
21
|
+
rdoc (4.2.2)
|
22
22
|
json (~> 1.4)
|
23
|
-
rspec (
|
24
|
-
rspec-core (~>
|
25
|
-
rspec-expectations (~>
|
26
|
-
rspec-mocks (~>
|
27
|
-
rspec-core (
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
rspec (3.4.0)
|
24
|
+
rspec-core (~> 3.4.0)
|
25
|
+
rspec-expectations (~> 3.4.0)
|
26
|
+
rspec-mocks (~> 3.4.0)
|
27
|
+
rspec-core (3.4.4)
|
28
|
+
rspec-support (~> 3.4.0)
|
29
|
+
rspec-expectations (3.4.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.4.0)
|
32
|
+
rspec-mocks (3.4.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.4.0)
|
35
|
+
rspec-support (3.4.1)
|
36
|
+
simplecov (0.11.2)
|
32
37
|
docile (~> 1.1.0)
|
33
|
-
|
34
|
-
simplecov-html (~> 0.
|
35
|
-
simplecov-html (0.
|
36
|
-
sk_api_schema (0.
|
38
|
+
json (~> 1.8)
|
39
|
+
simplecov-html (~> 0.10.0)
|
40
|
+
simplecov-html (0.10.0)
|
41
|
+
sk_api_schema (0.10.6)
|
37
42
|
activesupport
|
38
43
|
|
39
44
|
PLATFORMS
|
@@ -48,3 +53,6 @@ DEPENDENCIES
|
|
48
53
|
rspec
|
49
54
|
simplecov
|
50
55
|
sk_api_schema
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
1.11.2
|
data/lib/sk_sdk/base.rb
CHANGED
@@ -4,13 +4,10 @@ require 'active_resource'
|
|
4
4
|
require 'active_resource/version'
|
5
5
|
# patches are for specific AR version
|
6
6
|
case ActiveResource::VERSION::MAJOR
|
7
|
-
when 2
|
8
|
-
require 'sk_sdk/ar_patches/ar2/validations'
|
9
|
-
require 'sk_sdk/ar_patches/ar2/base'
|
10
7
|
when 3
|
11
8
|
require 'sk_sdk/ar_patches/ar3/base'
|
12
9
|
require 'sk_sdk/ar_patches/ar3/validations'
|
13
|
-
when 4
|
10
|
+
when 4,5
|
14
11
|
require 'sk_sdk/ar_patches/ar4/validations'
|
15
12
|
require 'sk_sdk/ar_patches/ar4/base'
|
16
13
|
end
|
@@ -44,7 +41,7 @@ class SK::SDK::Base < ActiveResource::Base
|
|
44
41
|
# @option [String] :password if using httpBasic sk user password
|
45
42
|
def self.set_connection(opts)
|
46
43
|
self.site = site_api_url(opts[:site])
|
47
|
-
self.format = :json
|
44
|
+
self.format = :json
|
48
45
|
if opts[:token] #oAuth access token in header
|
49
46
|
self.headers['Authorization'] = "Bearer #{opts[:token]}"
|
50
47
|
else
|
data/lib/sk_sdk/oauth.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'cgi'
|
2
|
-
require 'curb'
|
3
2
|
require 'sk_sdk'
|
4
3
|
|
5
4
|
module SK::SDK
|
6
5
|
# Authenticate your SalesKing App using oAuth2. This class provides helpers
|
7
|
-
# to create the token & dialog url and to get an access token
|
6
|
+
# to create the token & dialog url and build the params to get an access token.
|
7
|
+
# ==Example
|
8
|
+
# Using httparty gem:
|
9
|
+
#
|
10
|
+
# require 'sk_sdk/oauth'
|
11
|
+
# require 'httparty'
|
12
|
+
#
|
13
|
+
# auth = SK::SDK::Oauth.new(sk_app_settings)
|
14
|
+
# resp = HTTParty.post( auth.token_url,
|
15
|
+
# body: auth.token_params(code),
|
16
|
+
# basic_auth: auth.basic_params )
|
17
|
+
# Of course you can use curb or any other http lib. Just make sure to read
|
18
|
+
# their docs about POST params, HTTP BASIC Auth and https handling
|
8
19
|
class Oauth
|
9
20
|
|
10
21
|
attr_reader :id, :secret, :redirect_url
|
@@ -49,30 +60,25 @@ module SK::SDK
|
|
49
60
|
# URL to get the access_token, used in the second step after you have
|
50
61
|
# requested the authorization and gotten a code
|
51
62
|
# The token url is located at /oauth/token
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
def token_url
|
64
|
+
"#{sk_url}/oauth/token"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Params used in the POST request to /token e.g see httparty example on top.
|
68
|
+
# Using the client_secret in the params is DEPRECATED. Instead use HTTP Basic
|
69
|
+
# Auth header with client_id:client_secret like provided by #basic_params
|
70
|
+
# @returns[Hash] params used to get the real access-token
|
71
|
+
# @param [String] code to exchange for the access token
|
72
|
+
def token_params(code)
|
73
|
+
{ client_id: @id,
|
74
|
+
grant_type: 'authorization_code',
|
75
|
+
redirect_uri: CGI::escape(@redirect_url),
|
76
|
+
code: code }
|
61
77
|
end
|
62
78
|
|
63
|
-
#
|
64
|
-
|
65
|
-
|
66
|
-
# @return [Hash{String=>String}] access token
|
67
|
-
def get_token(code)
|
68
|
-
c = Curl::Easy.new( token_url( code ) )
|
69
|
-
if sk_url[/dev\.salesking.eu/] # as long as we are using a self signed cert
|
70
|
-
c.ssl_verify_host = false
|
71
|
-
c.ssl_verify_peer = false
|
72
|
-
end
|
73
|
-
c.http_get
|
74
|
-
# grab token from response body
|
75
|
-
ActiveSupport::JSON.decode(c.body_str)
|
79
|
+
# HTTP BASIC Auth Params used in the POST request to /token e.g with httparty
|
80
|
+
def basic_params
|
81
|
+
{ username: @id, password: @secret }
|
76
82
|
end
|
77
83
|
|
78
84
|
# @return [String] base api url my-sub.salesking.eu/api
|
@@ -81,10 +87,11 @@ module SK::SDK
|
|
81
87
|
end
|
82
88
|
|
83
89
|
# Each company has it's own subdomain so the url must be dynamic.
|
84
|
-
# This is achieved by replacing the * with the subdomain in the instance
|
85
|
-
#
|
90
|
+
# This is achieved by replacing the * with the subdomain in the instance if
|
91
|
+
# a sub_domain was given. Else the SalesKing domain MUST include the subdomain
|
86
92
|
# @return [String] url
|
87
93
|
def sk_url
|
94
|
+
return @sk_url unless sub_domain
|
88
95
|
@sk_url.gsub('*', sub_domain).gsub(/\/\z/, '' )
|
89
96
|
end
|
90
97
|
|
data/lib/sk_sdk/version.rb
CHANGED
data/sk_sdk.gemspec
CHANGED
@@ -4,23 +4,19 @@ require 'sk_sdk/version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'sk_sdk'
|
7
|
-
s.date = %q{2012-05-27}
|
8
7
|
s.version = SK::SDK::VERSION
|
9
8
|
s.authors = ['Georg Leciejewski', 'Mike Poltyn']
|
10
|
-
s.email =
|
9
|
+
s.email = 'gl@salesking.eu'
|
11
10
|
s.homepage = 'http://github.com/salesking/sk_sdk'
|
12
11
|
s.summary = %q{SalesKing Ruby SDK - simplify your Business}
|
13
12
|
s.description = %q{Connect your business 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
|
-
s.extra_rdoc_files = ['README.rdoc']
|
15
|
-
s.rubygems_version = %q{1.6.2}
|
16
13
|
s.license = 'MIT'
|
17
14
|
|
18
|
-
s.files = `git ls-files`.split("\
|
19
|
-
s.
|
20
|
-
s.
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject{|i| i[/^docs\//] }
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
21
18
|
s.require_paths = ['lib']
|
22
19
|
|
23
|
-
s.add_runtime_dependency 'curb'
|
24
20
|
s.add_runtime_dependency 'activesupport'
|
25
21
|
s.add_runtime_dependency 'activeresource'
|
26
22
|
s.add_runtime_dependency 'sk_api_schema'
|
@@ -28,5 +24,4 @@ Gem::Specification.new do |s|
|
|
28
24
|
s.add_development_dependency 'rake'
|
29
25
|
s.add_development_dependency 'simplecov'
|
30
26
|
s.add_development_dependency 'rspec'
|
31
|
-
s.add_development_dependency 'rdoc'
|
32
27
|
end
|
data/spec/sk_sdk/base_spec.rb
CHANGED
@@ -31,16 +31,16 @@ describe SK::SDK::Base, "make new class" do
|
|
31
31
|
|
32
32
|
it "should create save method" do
|
33
33
|
c = Contact.new
|
34
|
-
c.respond_to?(:save).should
|
34
|
+
c.respond_to?(:save).should be true
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should have new_record?" do
|
38
38
|
c = Contact.new
|
39
|
-
c.new_record?.should
|
39
|
+
c.new_record?.should be true
|
40
40
|
i = KingTester::Invoice.new
|
41
|
-
i.new_record?.should
|
41
|
+
i.new_record?.should be true
|
42
42
|
p = KingTester::Product.new
|
43
|
-
p.new_record?.should
|
43
|
+
p.new_record?.should be true
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should allow multiple parameters in initializer" do
|
@@ -50,7 +50,7 @@ describe SK::SDK::Base, "make new class" do
|
|
50
50
|
else
|
51
51
|
Contact.new({ :first_name => 'herbert' })
|
52
52
|
end
|
53
|
-
}.
|
53
|
+
}.to_not raise_error(ArgumentError)
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
data/spec/sk_sdk/oauth_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe SK::SDK::Oauth, "in general" do
|
|
16
16
|
a.sub_domain = 'alki'
|
17
17
|
a.sk_url.should == "http://alki.horsts-lokal.local"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should get salesking api url" do
|
21
21
|
a = SK::SDK::Oauth.new(@set)
|
22
22
|
a.sub_domain = 'alki'
|
@@ -38,13 +38,19 @@ describe SK::SDK::Oauth, "in general" do
|
|
38
38
|
a.sk_canvas_url.should == "http://alki.horsts-lokal.local/app/canvas-page"
|
39
39
|
end
|
40
40
|
|
41
|
-
it "
|
41
|
+
it "has token_url" do
|
42
42
|
a = SK::SDK::Oauth.new(@set)
|
43
43
|
a.sub_domain = 'alki'
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
a.token_url.should == "http://alki.horsts-lokal.local/oauth/token"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has token_params" do
|
48
|
+
a = SK::SDK::Oauth.new(@set)
|
49
|
+
res = a.token_params('123')
|
50
|
+
res[:code].should == '123'
|
51
|
+
res[:client_id].should == @set['id']
|
52
|
+
res[:grant_type].should == 'authorization_code'
|
53
|
+
res[:redirect_uri].should == CGI::escape(@set['redirect_url'])
|
48
54
|
end
|
49
55
|
|
50
56
|
end
|
@@ -21,7 +21,7 @@ else
|
|
21
21
|
|
22
22
|
it "should save" do
|
23
23
|
c = Contact.new :organisation=>"Rack'n Roll", :type => 'Client'
|
24
|
-
c.save.should
|
24
|
+
c.save.should be true
|
25
25
|
c.id.should_not be_empty
|
26
26
|
c.number.should_not be_empty
|
27
27
|
c.destroy
|
@@ -42,7 +42,6 @@ else
|
|
42
42
|
|
43
43
|
it "should find contacts" do
|
44
44
|
contacts = Contact.find(:all)
|
45
|
-
ActiveResource::Collection
|
46
45
|
contacts.length.should > 0
|
47
46
|
end
|
48
47
|
end
|
@@ -96,6 +95,4 @@ else
|
|
96
95
|
@contact.addresses.length.should == cnt_before-1
|
97
96
|
end
|
98
97
|
end
|
99
|
-
|
100
|
-
|
101
98
|
end
|
@@ -9,11 +9,11 @@ else
|
|
9
9
|
before :all do
|
10
10
|
#setup test doc to work with
|
11
11
|
@contact = Contact.new(:type=>'Supplier', :organisation=>'Credit Note API-Tester')
|
12
|
-
@contact.save.should
|
12
|
+
@contact.save.should be true
|
13
13
|
@doc = CreditNote.new()
|
14
14
|
@doc.title = 'A Document from the API'
|
15
15
|
@doc.contact_id = @contact.id
|
16
|
-
@doc.save.should
|
16
|
+
@doc.save.should be true
|
17
17
|
end
|
18
18
|
|
19
19
|
after :all do
|
@@ -23,7 +23,7 @@ else
|
|
23
23
|
it "should create a doc and use default before after text" do
|
24
24
|
@doc.errors.should be_empty
|
25
25
|
@doc.notes_before.should_not be_empty
|
26
|
-
@doc.new?.should
|
26
|
+
@doc.new?.should be false
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should fail create a doc without unique number" do
|
@@ -52,7 +52,7 @@ else
|
|
52
52
|
@doc.notes_before = 'Payment made to you bank Account'
|
53
53
|
@doc.title = 'Changed doc title'
|
54
54
|
|
55
|
-
@doc.save.should
|
55
|
+
@doc.save.should be true
|
56
56
|
@doc.lock_version.should > old_lock_version # because save returns the data
|
57
57
|
end
|
58
58
|
|
@@ -76,12 +76,12 @@ else
|
|
76
76
|
|
77
77
|
before :all do
|
78
78
|
@contact =Contact.new(:type=>'Supplier', :organisation=>'Credit Note API-Tester')
|
79
|
-
@contact.save.should
|
79
|
+
@contact.save.should be true
|
80
80
|
#setup test doc to work with
|
81
81
|
@doc = CreditNote.new :contact_id => @contact.id,
|
82
82
|
:line_items =>[{ :position=>1, :description => 'Pork Chops',
|
83
83
|
:quantity => 12, :price_single =>'10.00'}]
|
84
|
-
@doc.save.should
|
84
|
+
@doc.save.should be true
|
85
85
|
end
|
86
86
|
|
87
87
|
after :all do
|
@@ -127,7 +127,7 @@ else
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should update from draft to open and set number with date" do
|
130
|
-
@doc.save.should
|
130
|
+
@doc.save.should be true
|
131
131
|
@doc.status.should == 'draft'
|
132
132
|
|
133
133
|
@doc.status = 'open'
|
@@ -10,11 +10,11 @@ describe Invoice do
|
|
10
10
|
|
11
11
|
before :all do
|
12
12
|
@contact = Contact.new(:type=>'Client', :organisation=>'Invoice API-Tester')
|
13
|
-
@contact.save.should
|
13
|
+
@contact.save.should be true
|
14
14
|
@doc = Invoice.new()
|
15
15
|
@doc.title = 'A Document from the API'
|
16
16
|
@doc.contact_id = @contact.id
|
17
|
-
@doc.save.should
|
17
|
+
@doc.save.should be true
|
18
18
|
end
|
19
19
|
|
20
20
|
after :all do
|
@@ -31,7 +31,7 @@ describe Invoice do
|
|
31
31
|
|
32
32
|
before :all do
|
33
33
|
@contact = Contact.new(:type=>'Client', :organisation=>'Invoice API-Tester')
|
34
|
-
@contact.save.should
|
34
|
+
@contact.save.should be true
|
35
35
|
end
|
36
36
|
after :all do
|
37
37
|
@contact.destroy
|
@@ -43,9 +43,9 @@ describe Invoice do
|
|
43
43
|
doc.notes_before = 'Your shiny new invoice [number]'
|
44
44
|
doc.notes_after = 'Please pay me'
|
45
45
|
doc.contact_id = @contact.id
|
46
|
-
doc.save.should
|
46
|
+
doc.save.should be true
|
47
47
|
doc.errors.should be_empty
|
48
|
-
doc.new?.should
|
48
|
+
doc.new?.should be false
|
49
49
|
doc.notes_before.should == 'Your shiny new invoice [number]'
|
50
50
|
doc.destroy
|
51
51
|
end
|
@@ -56,7 +56,7 @@ describe Invoice do
|
|
56
56
|
doc.contact_id = @contact.id
|
57
57
|
doc.save
|
58
58
|
doc.errors.should be_empty
|
59
|
-
doc.new?.should
|
59
|
+
doc.new?.should be false
|
60
60
|
doc.notes_before.should_not be_empty
|
61
61
|
doc.destroy
|
62
62
|
end
|
@@ -85,12 +85,12 @@ describe Invoice do
|
|
85
85
|
#setup test doc to work with
|
86
86
|
# create client
|
87
87
|
@contact = Contact.new(:type=>'Client', :organisation=>'Invoice API-Tester')
|
88
|
-
@contact.save.should
|
88
|
+
@contact.save.should be true
|
89
89
|
@doc = Invoice.new
|
90
90
|
@doc.title = 'A Document from the API'
|
91
91
|
@doc.notes_before = 'Your invoice [number]'
|
92
92
|
@doc.contact_id = @contact.id
|
93
|
-
@doc.save.should
|
93
|
+
@doc.save.should be true
|
94
94
|
end
|
95
95
|
|
96
96
|
after :all do
|
@@ -104,7 +104,7 @@ describe Invoice do
|
|
104
104
|
@doc.notes_after = 'Payment made to you bank Account'
|
105
105
|
@doc.title = 'Changed doc title'
|
106
106
|
|
107
|
-
@doc.save.should
|
107
|
+
@doc.save.should be true
|
108
108
|
@doc.lock_version.should > old_lock_version # because save returns the data
|
109
109
|
@doc.notes_before.should == 'You will recieve the amout of:'
|
110
110
|
end
|
@@ -129,12 +129,12 @@ describe Invoice do
|
|
129
129
|
|
130
130
|
before :all do
|
131
131
|
@contact = Contact.new(:type=>'Client', :organisation=>'Credit Note API-Tester')
|
132
|
-
@contact.save.should
|
132
|
+
@contact.save.should be true
|
133
133
|
#setup test doc to work with
|
134
134
|
@doc = Invoice.new(:contact_id => @contact.id,
|
135
135
|
:line_items => [{ :position=>1, :description => 'Pork Chops',
|
136
136
|
:quantity => 12, :price_single =>'10.00' }] )
|
137
|
-
@doc.save.should
|
137
|
+
@doc.save.should be true
|
138
138
|
end
|
139
139
|
|
140
140
|
after :all do
|
@@ -157,7 +157,7 @@ describe Invoice do
|
|
157
157
|
it 'should add line item' do
|
158
158
|
item = LineItem.new( { :position=>2, :description => 'Goat-Pie', :price_single => 10, :quantity=>10} )
|
159
159
|
product = Product.new(:name=>'Eis am Stiel', :price => 1.50, :tax=>19, :description => 'Mmmhh lecker Eis')
|
160
|
-
product.save.should
|
160
|
+
product.save.should be true
|
161
161
|
item1 = LineItem.new( { :position=>3, :use_product => 1, :product_id=> product.id, :quantity => 10 } )
|
162
162
|
@doc.line_items << item
|
163
163
|
@doc.line_items << item1
|
@@ -172,7 +172,7 @@ describe Invoice do
|
|
172
172
|
describe 'with items of different type' do
|
173
173
|
before :each do
|
174
174
|
@contact = Contact.new(:type=>'Client', :organisation=>'Credit Note API-Tester')
|
175
|
-
@contact.save.should
|
175
|
+
@contact.save.should be true
|
176
176
|
@doc = Invoice.new(:contact_id => @contact.id)
|
177
177
|
end
|
178
178
|
|
@@ -189,7 +189,7 @@ describe Invoice do
|
|
189
189
|
{ :position=>4, :name => 'Pork Chops', :price_single =>0, :type=>'LineItem' },
|
190
190
|
{ :position=>5, :name => 'Pork Chops', :price_single =>0.0, :type=>'LineItem' },
|
191
191
|
]
|
192
|
-
@doc.save.should
|
192
|
+
@doc.save.should be true
|
193
193
|
@doc.items.length.should == 5
|
194
194
|
@doc.gross_total.should == 0.0
|
195
195
|
end
|
@@ -201,7 +201,7 @@ describe Invoice do
|
|
201
201
|
{ :position=>2, :name => 'Yummi Beef', :type=>'DividerItem' },
|
202
202
|
{ :position=>3, :name => 'Beef Jerky', :description=> 'Jaw Breaker',:quantity => 1, :price_single =>'10.00', :type=>'LineItem' }
|
203
203
|
]
|
204
|
-
@doc.save.should
|
204
|
+
@doc.save.should be true
|
205
205
|
@doc.items.length.should == 4
|
206
206
|
@doc.gross_total.should == 130.0
|
207
207
|
end
|
@@ -214,7 +214,7 @@ describe Invoice do
|
|
214
214
|
{ :divider_item => { :position=>2, :name => 'Yummi Beef', :type=>'DividerItem' }},
|
215
215
|
{ :line_item => { :position=>3, :name => 'Beef Jerky', :description=> 'Jaw Breaker',:quantity => 1, :price_single =>'10.00' }}
|
216
216
|
]
|
217
|
-
@doc.save.should
|
217
|
+
@doc.save.should be true
|
218
218
|
@doc.items.length.should == 4
|
219
219
|
@doc.gross_total.should == 130.0
|
220
220
|
end
|
@@ -223,7 +223,7 @@ describe Invoice do
|
|
223
223
|
describe 'with items and line_items' do
|
224
224
|
before :all do
|
225
225
|
@contact = Contact.new(:type=>'Client', :organisation=>'Credit Note API-Tester')
|
226
|
-
@contact.save.should
|
226
|
+
@contact.save.should be true
|
227
227
|
@doc = Invoice.new(:contact_id => @contact.id)
|
228
228
|
end
|
229
229
|
|
@@ -234,7 +234,7 @@ describe Invoice do
|
|
234
234
|
it 'should prefer line_items over items when both are present' do
|
235
235
|
@doc.items = [LineItem.new( :position=>12, :name => 'dropped', :quantity => 1, :price_single =>1, :type=>'LineItem' )]
|
236
236
|
@doc.line_items = [LineItem.new( :position=>12, :name => 'added', :quantity => 1, :price_single =>10, :type=>'LineItem' )]
|
237
|
-
@doc.save.should
|
237
|
+
@doc.save.should be true
|
238
238
|
@doc.items.length.should == 1
|
239
239
|
@doc.gross_total.should == 10.0
|
240
240
|
end
|
@@ -242,13 +242,13 @@ describe Invoice do
|
|
242
242
|
it 'should manually remove line_items so items are used on update' do
|
243
243
|
# first save so AR loads both(items/line_items) from response
|
244
244
|
@doc.items = [ { :position=>1, :name => 'Pork Chops', :quantity => 1, :price_single =>'10.00', :type=>'LineItem' }]
|
245
|
-
@doc.save.should
|
245
|
+
@doc.save.should be true
|
246
246
|
@doc.gross_total.should == 10.0
|
247
247
|
# edit
|
248
248
|
@doc.items << LineItem.new( :position=>2, :name => 'Puppy Seeds', :quantity => 1, :price_single =>1, :type=>'LineItem' )
|
249
249
|
@doc.line_items = nil # <= IMPORTANT part
|
250
250
|
|
251
|
-
@doc.save.should
|
251
|
+
@doc.save.should be true
|
252
252
|
@doc.items.length.should == 2
|
253
253
|
@doc.gross_total.should == 11.0
|
254
254
|
end
|
@@ -8,11 +8,11 @@ describe Payment do
|
|
8
8
|
|
9
9
|
before :all do
|
10
10
|
@contact = Contact.new(:type=>'Client', :organisation=>'Payment API-Tester')
|
11
|
-
@contact.save.should
|
11
|
+
@contact.save.should be true
|
12
12
|
@doc = Invoice.new
|
13
13
|
@doc.title = 'A Document from the API for payment testing'
|
14
14
|
@doc.contact_id = @contact.id
|
15
|
-
@doc.save.should
|
15
|
+
@doc.save.should be true
|
16
16
|
end
|
17
17
|
|
18
18
|
after :all do
|
@@ -67,7 +67,7 @@ describe Payment do
|
|
67
67
|
it "should create" do
|
68
68
|
# relation MUST be set
|
69
69
|
p = Payment.new :amount => 12.34, :related_object_id=>@doc.id
|
70
|
-
p.save.should
|
70
|
+
p.save.should be true
|
71
71
|
|
72
72
|
payments = Payment.send( :instantiate_collection, @doc.get(:payments))
|
73
73
|
payments.map(&:amount).should include 12.34
|
@@ -9,7 +9,7 @@ else
|
|
9
9
|
before :all do
|
10
10
|
#setup test product to work with
|
11
11
|
@product = Product.new(:name=>'Eis am Stiel', :price => 1.50)
|
12
|
-
@product.save.should
|
12
|
+
@product.save.should be true
|
13
13
|
end
|
14
14
|
|
15
15
|
after :all do
|
@@ -23,7 +23,7 @@ else
|
|
23
23
|
it "should create a product" do
|
24
24
|
@product.number.should_not be_nil
|
25
25
|
@product.price.should == 1.50
|
26
|
-
@product.new?.should
|
26
|
+
@product.new?.should be false
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should fail create a product without name" do
|
@@ -35,7 +35,7 @@ else
|
|
35
35
|
|
36
36
|
it "should fail create a product with empty price" do
|
37
37
|
product = Product.new(:name => 'No brain', :price =>' ')
|
38
|
-
product.save.should
|
38
|
+
product.save.should be false
|
39
39
|
product.errors.full_messages.should == ["Price can't be blank", "Price is not a number"]
|
40
40
|
end
|
41
41
|
|
data/spec/sk_sdk/sync_spec.rb
CHANGED
@@ -20,12 +20,12 @@ describe SK::SDK::Sync do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not be outdated" do
|
23
|
-
@sync.outdated?.should
|
23
|
+
@sync.outdated?.should be false # both objects are empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should find outdated fields" do
|
27
27
|
@l_obj.firstname = 'theo'
|
28
|
-
@sync.outdated?.should
|
28
|
+
@sync.outdated?.should be true
|
29
29
|
@sync.outdated.first.should == @sync.field(:firstname)
|
30
30
|
end
|
31
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sk_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Leciejewski
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: curb
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: activesupport
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,44 +95,23 @@ dependencies:
|
|
109
95
|
- - ">="
|
110
96
|
- !ruby/object:Gem::Version
|
111
97
|
version: '0'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: rdoc
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '0'
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - ">="
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
98
|
description: 'Connect your business with SalesKing. This gem gives ruby developers
|
127
99
|
a jump-start for building SalesKing Business Apps. It provides classes to handle
|
128
100
|
oAuth, make RESTfull API requests and parses JSON Schema '
|
129
|
-
email:
|
130
|
-
- gl@salesking.eu
|
101
|
+
email: gl@salesking.eu
|
131
102
|
executables: []
|
132
103
|
extensions: []
|
133
|
-
extra_rdoc_files:
|
134
|
-
- README.rdoc
|
104
|
+
extra_rdoc_files: []
|
135
105
|
files:
|
136
106
|
- ".gitignore"
|
137
|
-
- ".travis.yml"
|
138
107
|
- Gemfile
|
139
108
|
- MIT-LICENSE
|
140
109
|
- README.rdoc
|
141
110
|
- Rakefile
|
142
|
-
- ci/Gemfile_ar2
|
143
|
-
- ci/Gemfile_ar2.lock
|
144
111
|
- ci/Gemfile_ar3
|
145
112
|
- ci/Gemfile_ar3.lock
|
146
113
|
- lib/sk_sdk.rb
|
147
114
|
- lib/sk_sdk/README.rdoc
|
148
|
-
- lib/sk_sdk/ar_patches/ar2/base.rb
|
149
|
-
- lib/sk_sdk/ar_patches/ar2/validations.rb
|
150
115
|
- lib/sk_sdk/ar_patches/ar3/base.rb
|
151
116
|
- lib/sk_sdk/ar_patches/ar3/validations.rb
|
152
117
|
- lib/sk_sdk/ar_patches/ar4/base.rb
|
@@ -193,8 +158,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
158
|
version: '0'
|
194
159
|
requirements: []
|
195
160
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.4.8
|
197
162
|
signing_key:
|
198
163
|
specification_version: 4
|
199
164
|
summary: SalesKing Ruby SDK - simplify your Business
|
200
|
-
test_files:
|
165
|
+
test_files:
|
166
|
+
- spec/resources_spec_helper.rb
|
167
|
+
- spec/settings.yml.default
|
168
|
+
- spec/sk_sdk/base_spec.rb
|
169
|
+
- spec/sk_sdk/oauth_spec.rb
|
170
|
+
- spec/sk_sdk/resources/README.rdoc
|
171
|
+
- spec/sk_sdk/resources/contacts_spec.rb
|
172
|
+
- spec/sk_sdk/resources/credit_note_spec.rb
|
173
|
+
- spec/sk_sdk/resources/invoice_spec.rb
|
174
|
+
- spec/sk_sdk/resources/payment_spec.rb
|
175
|
+
- spec/sk_sdk/resources/product_spec.rb
|
176
|
+
- spec/sk_sdk/signed_request_spec.rb
|
177
|
+
- spec/sk_sdk/sync_field_spec.rb
|
178
|
+
- spec/sk_sdk/sync_spec.rb
|
179
|
+
- spec/spec_helper.rb
|
data/.travis.yml
DELETED
data/ci/Gemfile_ar2
DELETED
data/ci/Gemfile_ar2.lock
DELETED
@@ -1,38 +0,0 @@
|
|
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
|
-
multi_json (1.3.5)
|
10
|
-
rake (0.9.2)
|
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
|
-
simplecov (0.6.4)
|
21
|
-
multi_json (~> 1.0)
|
22
|
-
simplecov-html (~> 0.5.3)
|
23
|
-
simplecov-html (0.5.3)
|
24
|
-
sk_api_schema (0.2.4)
|
25
|
-
activesupport
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
activeresource (= 2.3.14)
|
32
|
-
activesupport (= 2.3.14)
|
33
|
-
curb
|
34
|
-
rake
|
35
|
-
rdoc
|
36
|
-
rspec
|
37
|
-
simplecov
|
38
|
-
sk_api_schema
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#temp patch as_json on decimals introduced by rails. which collpases with ruby-yail
|
2
|
-
class BigDecimal
|
3
|
-
def as_json
|
4
|
-
self.to_f
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
module ActiveResource
|
9
|
-
# Overridden methods to suit SalesKing.
|
10
|
-
# Some changes might be kicked when AR 3.0 is out
|
11
|
-
class Base
|
12
|
-
|
13
|
-
# override encode because json is also returned nested by SalesKing
|
14
|
-
def encode(options={})
|
15
|
-
case self.class.format
|
16
|
-
when ActiveResource::Formats[:xml]
|
17
|
-
self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
|
18
|
-
else # json also nested
|
19
|
-
self.class.format.encode( {self.class.element_name => attributes}, options)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# override ARes method to parse only the object part
|
24
|
-
def load_attributes_from_response(response)
|
25
|
-
if response['Content-Length'] != "0" && response.body.strip.size > 0
|
26
|
-
load( self.class.format.decode(response.body)[self.class.element_name] )
|
27
|
-
if self.respond_to?(:items)
|
28
|
-
# move double nested items up
|
29
|
-
new_items = []
|
30
|
-
self.items.each { |item| new_items << item.attributes.first[1] }
|
31
|
-
self.items = new_items
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Overridden to grab the data(= clients-collection) from json:
|
37
|
-
# { 'collection'=> will_paginate infos,
|
38
|
-
# 'links' => prev/next links
|
39
|
-
# 'clients'=> [data], << what we need
|
40
|
-
# }
|
41
|
-
def self.instantiate_collection(collection, prefix_options = {})
|
42
|
-
collection = collection[ self.element_name.pluralize ] if collection.is_a?(Hash)
|
43
|
-
collection.collect! { |record| instantiate_record(record, prefix_options) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ActiveResource
|
2
|
-
|
3
|
-
module Validations
|
4
|
-
# Validate a resource and save (POST) it to the remote web service.
|
5
|
-
def save_with_validation
|
6
|
-
save_without_validation
|
7
|
-
true
|
8
|
-
rescue ResourceInvalid => error
|
9
|
-
case error.response['Content-Type']
|
10
|
-
when /xml/ #PATCH
|
11
|
-
errors.from_xml(error.response.body)
|
12
|
-
when /json/ #PATCH
|
13
|
-
errors.from_json(error.response.body)
|
14
|
-
end
|
15
|
-
false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Errors
|
20
|
-
|
21
|
-
# Patched cause we dont need no attribute name magic .. and its just simpler
|
22
|
-
def from_array(messages)
|
23
|
-
clear
|
24
|
-
messages.each do |msg|
|
25
|
-
add msg[0], msg[1]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end #Errors
|
29
|
-
|
30
|
-
end
|