sk_sdk 0.2.1 → 0.2.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/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ coverage/*
2
+ rdoc/*
3
+ doc/*
4
+ .yardoc/*
5
+ pkg/*
6
+ ci/Gemfile.lock
7
+ ci/Gemfile_ar2
8
+ ci/vendor
9
+ ci/.bundle
10
+ spec/settings.yml
11
+ Gemfile.lock
12
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ # Sorry no travis since you need a private sk login .. too bad
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ gemfile:
6
+ - Gemfile
7
+ - ci/Gemfile_ar2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :gemcutter
2
+ gemspec
data/README.rdoc CHANGED
@@ -51,13 +51,20 @@ Read specs: https://github.com/salesking/sk_sdk/tree/master/spec/sk_sdk
51
51
 
52
52
  == Tests
53
53
 
54
- Before you run the tests use bundler to install all required gems:
55
- # git clone
56
- # cd into dir
57
- BUNDLE_GEMFILE=ci/Gemfile bundle install
58
-
59
- # create /spec/settingsyml from default
60
- # run specs with most recent version of activeresource
61
- BUNDLE_GEMFILE=ci/Gemfile bundle exec rake spec
54
+ Before you run the tests install required gems via bundler. We are providing
55
+ several Gemfiles because of different patches for active_resource v2 vs v3.
56
+ This definitly sucks, but as long as we stay with ARes we need to ensure it is
57
+ working with every version.
58
+
59
+ Before running the specs, add your SalesKing credentials to /spec/settings.yml
60
+ cp spec/settings.yml.default spec/settings.yml
61
+
62
+ # test with most recent ARes version
63
+ bundle install
64
+ rake spec
65
+
66
+ #test with ARes 2
67
+ BUNDLE_GEMFILE=ci/Gemfile_ar2 bundle install
68
+ BUNDLE_GEMFILE=ci/Gemfile_ar2 bundle exec rake spec
62
69
 
63
70
  Copyright (c) 2011 Georg Leciejewski, released under the MIT license
data/Rakefile CHANGED
@@ -1,45 +1,13 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
- require 'rdoc/task'
4
2
  require 'rspec'
5
3
  require 'rspec/core/rake_task'
6
-
7
- begin
8
- require 'jeweler'
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = "sk_sdk"
11
- gem.summary = %Q{SalesKing SDK Ruby}
12
- gem.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 }
13
- gem.email = "gl@salesking.eu"
14
- gem.homepage = "http://github.com/salesking/sk_sdk"
15
- gem.authors = ["Georg Leciejewski"]
16
- gem.add_dependency 'curb'
17
- gem.add_dependency 'activesupport'
18
- gem.add_dependency 'sk_api_schema'
19
- gem.add_dependency 'activeresource'
20
- gem.add_development_dependency "rspec"
21
- gem.add_development_dependency "rcov"
22
- end
23
- Jeweler::GemcutterTasks.new
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
- end
27
-
28
- desc 'Default: run specs.'
29
- task :default => :spec
4
+ require 'rdoc/task'
5
+ require 'bundler/gem_helper'
6
+ Bundler::GemHelper.install_tasks
30
7
 
31
8
  desc "Run specs"
32
- RSpec::Core::RakeTask.new do |t|
33
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
34
- # Put spec opts in a file named .rspec in root
35
- end
36
-
37
- desc "Generate code coverage"
38
- RSpec::Core::RakeTask.new(:coverage) do |t|
39
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
40
- t.rcov = true
41
- t.rcov_opts = ['--exclude', 'spec']
42
- end
9
+ RSpec::Core::RakeTask.new
10
+ task :default => :spec
43
11
 
44
12
  desc 'Generate documentation.'
45
13
  Rake::RDocTask.new(:rdoc) do |rdoc|
data/ci/Gemfile_ar2.lock CHANGED
@@ -6,8 +6,8 @@ GEM
6
6
  activesupport (2.3.14)
7
7
  curb (0.7.15)
8
8
  diff-lcs (1.1.3)
9
+ multi_json (1.3.5)
9
10
  rake (0.9.2)
10
- rcov (0.9.10)
11
11
  rdoc (3.9.4)
12
12
  rspec (2.6.0)
13
13
  rspec-core (~> 2.6.0)
@@ -17,6 +17,10 @@ GEM
17
17
  rspec-expectations (2.6.0)
18
18
  diff-lcs (~> 1.1.2)
19
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)
20
24
  sk_api_schema (0.2.4)
21
25
  activesupport
22
26
 
@@ -28,7 +32,7 @@ DEPENDENCIES
28
32
  activesupport (= 2.3.14)
29
33
  curb
30
34
  rake
31
- rcov
32
35
  rdoc
33
36
  rspec
37
+ simplecov
34
38
  sk_api_schema
data/lib/sk_sdk/base.rb CHANGED
@@ -30,14 +30,13 @@ class SK::SDK::Base < ActiveResource::Base
30
30
  def save; save_with_validation; end
31
31
 
32
32
  # Define the connection to be used when talking to a salesking server
33
- # === Params
34
- # opts<Hash{Symbol=>String}>:: options
35
- # == opts
36
- # :site<String>:: SalesKing Url, required
37
- # :token<String>:: oAuth2 access token, will be added to the request header if
38
- # set user/pass are not needed, so this is what you should be using!
39
- # :user<String>:: if using httpBasic auth set to sk user login email
40
- # :password<String>:: if using httpBasic sk user password
33
+ #
34
+ # @param[Hash{Symbol=>String}] opts
35
+ # @option [String] :site SalesKing Url, required
36
+ # @option [String] :token oAuth2 access token, added to the request header
37
+ # if set user/pass are not needed, so this is what you should be using!
38
+ # @option [String] :user if using httpBasic auth set to sk user login email
39
+ # @option [String] :password if using httpBasic sk user password
41
40
  def self.set_connection(opts)
42
41
  self.site = site_api_url(opts[:site])
43
42
  self.format = :json # f*** xml
data/lib/sk_sdk/oauth.rb CHANGED
@@ -11,17 +11,16 @@ module SK::SDK
11
11
  attr_accessor :sub_domain
12
12
 
13
13
  # Setup a new oAuth connection requires you to set some default:
14
- # === Params
15
- # opts<Hash{String=>String}>:: options for your app
16
- #
17
- # == Options(opts)
18
- # id<String>:: oAuth app id from SalesKing app registration
19
- # secret<String>:: oAuth app secret from SalesKing app registration
20
- # scope<String>:: permission your app requests
21
- # redirect_url<String>:: redirect url inside your app for auth dialog
22
- # sk_url<String>:: SalesKing base url, * is replaced with users subdomain,
14
+ #
15
+ # @param[Hash{String=>String}] opts containing id, secrete, scope, url of
16
+ # your app
17
+ # @option [String] id oAuth app id from SalesKing app registration
18
+ # @option [String] secret oAuth app secret from SalesKing app registration
19
+ # @option [String] scope permission your app requests
20
+ # @option [String] redirect_url inside your app for auth dialog
21
+ # @option [String] sk_url SalesKing base url, * is replaced with users subdomain,
23
22
  # no trailing slash, optional defaults to https://*.salesking.eu
24
- # sub_domain<String>:: optinal, will probably be set later after a users
23
+ # @option [String] sub_domain optional, will probably be set later after a users
25
24
  # provided his subdomain
26
25
  def initialize(opts)
27
26
  @id = opts['id']
@@ -33,10 +32,7 @@ module SK::SDK
33
32
  @sub_domain = opts['sub_domain']
34
33
  end
35
34
 
36
- # URL showing the auth dialog to the user
37
- #
38
- # === Returns
39
- # <String>:: URL with parameter
35
+ # @return [String] URL with parameter to show the auth dialog to the user
40
36
  def auth_dialog
41
37
  params = { :client_id => @id,
42
38
  :redirect_uri=> @redirect_url,
@@ -44,20 +40,17 @@ module SK::SDK
44
40
  "#{sk_url}/oauth/authorize?#{to_url_params(params)}"
45
41
  end
46
42
 
47
- # The app's canvas url inside SalesKing
48
- # === Returns
49
- # <String>:: URL
43
+ # @return [String] app's canvas url inside SalesKing
50
44
  def sk_canvas_url
51
45
  "#{sk_url}/app/#{@canvas_slug}"
52
46
  end
53
47
 
54
48
  # URL to get the access_token, used in the second step after you have
55
49
  # requested the authorization and gotten a code
56
- # The token url is located at /oauth/token
57
- # === Parameter
58
- # code<String>:: code received after auth
59
- # === Returns
60
- # <String>:: Url with parameter
50
+ # The token url is located at /oauth/token
51
+ #
52
+ # @param [String] code received after auth
53
+ # @return [String] Url with parameter
61
54
  def token_url(code)
62
55
  params = { :client_id => @id,
63
56
  :client_secret => @secret,
@@ -68,23 +61,28 @@ module SK::SDK
68
61
 
69
62
  # Makes a GET request to the access_token endpoint in SK and receives the
70
63
  # access token
64
+ # @param [String] code request token
65
+ # @return [Hash{String=>String}] access token
71
66
  def get_token(code)
72
- c = Curl::Easy.perform( token_url( code ) )
73
- # grab token from response body, containing json string
67
+ c = Curl::Easy.new( token_url( code ) )
68
+ if sk_url[/dev\.salesking.eu/] # as long as we are using a self signed cert
69
+ c.ssl_verify_host = false
70
+ c.ssl_verify_peer = false
71
+ end
72
+ c.http_get
73
+ # grab token from response body
74
74
  ActiveSupport::JSON.decode(c.body_str)
75
75
  end
76
76
 
77
- # The API url ist the salesking url of the current company + /api
78
- # === Returns
79
- # <String>:: base api url my-sub.salesking.eu/api
77
+ # @return [String] base api url my-sub.salesking.eu/api
80
78
  def sk_api_url
81
79
  "#{sk_url}/api"
82
80
  end
83
81
 
84
82
  # Each company has it's own subdomain so the url must be dynamic.
85
83
  # This is achieved by replacing the * with the subdomain in the instance
86
- # === Returns
87
- # <String>:: url
84
+ #
85
+ # @return [String] url
88
86
  def sk_url
89
87
  @sk_url.gsub('*', sub_domain).gsub(/\/\z/, '' )
90
88
  end
@@ -7,11 +7,13 @@ module OmniAuth
7
7
  # SalesKing requires a subdomain up front
8
8
  # It needs to be provided in a form and retrieved from the request
9
9
  # The one on init is not used as it is grabbed from the session later
10
- # === Params
11
- # app<Rack Application]>:: app standard middleware application parameter
12
- # client_id<String>:: the application id as registered on SalesKing
13
- # client_secret<String>:: the application secret as registered on SalesKing
14
- # scope<String>:: space separated extended permissions such as `api/invoices` or `api/clients:read,delete`
10
+ #
11
+ # @param [Rack Application] app rack middleware application
12
+ # @param [String] client_id the application id as registered on SalesKing
13
+ # @param [String] client_secret the application secret as registered on SalesKing
14
+ # @param [String] sk_url
15
+ # @param [String] scope space separated extended permissions such as
16
+ # `api/invoices` or `api/clients:read,delete api/orders`
15
17
  def initialize(app, client_id, client_secret, sk_url, scope)
16
18
  @base_url = sk_url
17
19
  @scope = scope
@@ -19,19 +21,20 @@ module OmniAuth
19
21
  super(app, :salesking, client_id, client_secret, client_options)
20
22
  end
21
23
 
22
- #inject salesking url and scope
24
+ # inject salesking url and scope into OmniAuth
23
25
  def request_phase
24
26
  options[:scope] = @scope
25
27
  set_sk_url
26
28
  super
27
29
  end
28
30
 
29
- #Monkey-patching to inject subdomain again
31
+ # Monkey-patching to inject subdomain again into OmniAuth
30
32
  def callback_phase
31
33
  set_sk_url
32
34
  super
33
35
  end
34
36
 
37
+ # @return [Hash] user currently logged in
35
38
  def user_data
36
39
  @data ||= begin
37
40
  ret = MultiJson.decode(@access_token.get('api/users/current'))
@@ -62,8 +65,7 @@ module OmniAuth
62
65
 
63
66
  # Each company has it's own subdomain so the url must be dynamic.
64
67
  # This is achieved by replacing the * with the subdomain from the session
65
- # === Returns
66
- # <String>:: url
68
+ # @return [String] url with subdomain of sk user
67
69
  def set_sk_url
68
70
  client_options[:site] = @base_url.gsub('*', session[:subdomain]).gsub(/\/\z/, '' )
69
71
  end
@@ -1,5 +1,5 @@
1
1
  require 'base64'
2
- require "active_support/json"
2
+ require 'active_support/json'
3
3
  require 'openssl'
4
4
  require 'sk_sdk'
5
5
 
@@ -24,8 +24,7 @@ module SK::SDK
24
24
 
25
25
  # Decode a base64URL encoded string: replace - with + and _ with /
26
26
  # Also add padding so ruby's Base64 can decode it
27
- # === returns
28
- # <String>:: the plain string decoded
27
+ # @return [String] the plain string decoded
29
28
  def base64_url_decode(str)
30
29
  encoded_str = str.tr('-_', '+/')
31
30
  encoded_str += '=' while !(encoded_str.size % 4).zero?
@@ -42,11 +41,9 @@ module SK::SDK
42
41
  # Base64 url encode a string and sign it using the given secret. The hmac
43
42
  # signature and the encoded string are joined by . and returned
44
43
  #
45
- # === Parameter
46
- # str<String>:: the string to encode
47
- # secret<String>:: the string used to create the signature
48
- # === Returns
49
- # <String>:: hmac-sign.encoded-string
44
+ # @param [String] str the string to encode
45
+ # @param [String] secret used to create the signature
46
+ # @return [String] hmac-sign.encoded-string
50
47
  def self.signed_param(str, secret)
51
48
  # base65 url encode the json, remove trailing-padding =
52
49
  enc_str = base64_url_encode(str)
@@ -61,10 +58,8 @@ module SK::SDK
61
58
  # + is replaced by -
62
59
  # / is replaced by _
63
60
  #
64
- # === Parameter
65
- # str<String>:: the string to encode
66
- # === Returns
67
- # <String>:: base64url-encoded
61
+ # @param [String] str the string to encode
62
+ # @return [String] base64url-encoded
68
63
  def self.base64_url_encode(str)
69
64
  [str].pack('m').tr('+/','-_').gsub("\n",'').gsub(/=+$/, '' )
70
65
  end
data/lib/sk_sdk/sync.rb CHANGED
@@ -2,85 +2,82 @@ module SK::SDK
2
2
 
3
3
  # Provide methods for mapping and syncing the fields of a remote to local
4
4
  # object.
5
- # The class gets two objects(local/remote) and a field-map(Array) which
6
- # maps the field-names between those two. Of course your objects MUST respond
7
- # to the method names passed in the mapping.
5
+ # Sync needs a local(left), a remote(right) object and a field-map(Array) to
6
+ # map the field-names between those two. Optionally you can add transition
7
+ # methods to convert the values from on side to the other.
8
8
  #
9
9
  # When syncing the corresponding fields, the names are simply #send to each
10
10
  # object.
11
11
  #
12
- # After an object was updated you can check the #log for changes
13
- #
12
+ # After an object was updated you can check the #log for changes. Sync does
13
+ # not save anything, it only sets the field values on the other object.
14
+ #
15
+ #
14
16
  # == Example
15
17
  #
16
18
  # map =[
17
- # [:name, :full_name, :'someClass.set_local_name', :'SomeClass.set_remote_name'],
19
+ # [:name, :full_name, :'someClass.set_local_name', :'MyClass.set_remote_name'],
18
20
  # [:street, :address1]
19
21
  # ]
20
- # map = SK::SDK::Sync.new(@local_user, @remote_user, map)
21
- # map.update(:r) #Does not save! only sets the field values on the remote object
22
+ # map = SK::SDK::Sync.new(@local_user, @remote_user, map)
23
+ # map.update(:r)
22
24
  #
23
- # == Mapping Explanation
24
- #
25
- # A mapping consist of the local and the remote field name. It can further
26
- # contain transition methods if the value needs to be changed when set from
27
- # one side to the other.
28
- #
29
- # Those methods will be called(eval'ed) and receive the value from the other
30
- # side as param:
25
+ # == Mapping Explained
31
26
  #
32
27
  # Mappings are passed as an array:
33
- # [
34
- # [:local_field_name, :remote_field_name, "SomeClass.left_trans", "SomeClass.rigt_trans"]
35
- # [:firstname, :first_name, :'SomeClass.set_local_name', :'SomeClass.set_remote_name']
36
- # ]
28
+ # [
29
+ # [:local_field_name, :remote_field_name, "MyClass.local_trans", "MyClass.remote_trans"]
30
+ # [:firstname, :first_name, :'MyClass.set_local_name', :'MyClass.set_remote_name']
31
+ # ]
32
+ # A mapping consist of a local and the remote field(method) name. And might
33
+ # contain transition methods, if the value needs to be changed when set from
34
+ # one side to the other. Those methods will be called with the value from
35
+ # the other side.
36
+ # local_obj.field = MyClass.local_trans(remote_obj.field)
37
+ #
37
38
  class Sync
38
39
 
39
- # The local object
40
+ # @return [Object] The local object
40
41
  attr_accessor :l_obj
41
- # The remote object
42
+ # @return [Object] The remote object
42
43
  attr_accessor :r_obj
43
- # <Hash{Symbol=>Symbol, Symbol=>{Hash} }>::the field mapping
44
+ # @return [Array<Field>] mapped fields
44
45
  attr_reader :fields
45
- # the outdated fields
46
+ # @return [Array<Field>] outdated fields
46
47
  attr_reader :outdated
47
- # <Array[String]>::log field changes
48
+ # @return [Array<String>] log of field changes
48
49
  attr_reader :log
49
50
 
50
- # Takes a local and remote object which should respond to function defined
51
- # in the mapping hash
52
- # === Parameter
53
- # l_obj<Object>::
54
- # r_obj<Object>::
55
- # field_map<Hash{Symbol=>Symbol, Symbol=>{Hash} }>::the field mapping
56
- def initialize(l_obj, r_obj, field_map)
57
- @l_obj = l_obj
58
- @r_obj = r_obj
51
+ # @param [Object] local_object
52
+ # @param [Object] remote_object
53
+ # @param [Array<String,Symbol>] field_map assign local to remote field names
54
+ def initialize(local_object, remote_object, field_map)
55
+ @l_obj = local_object
56
+ @r_obj = remote_object
59
57
  self.fields = field_map
60
58
  @log = []
61
59
  end
62
60
 
63
- # === Parameter
64
- # field_map<Array[Hash{}]>::
65
- def fields=(field_map)
61
+ # Create field for given mapping arrays and resets all existing ones
62
+ # @param [Array<Array>] field_maps
63
+ def fields=(field_maps)
66
64
  @fields = []
67
- field_map.each { |fld| @fields << Field.new(fld) }
65
+ field_maps.each { |fld| @fields << Field.new(fld) }
68
66
  @fields
69
67
  end
70
68
 
71
69
  # Find a field by its local name
72
- # === Parameter
73
- # l_name<Symbol>:: local name
74
- # === Return
75
- # <Field>::
70
+ #
71
+ # @param [Symbol] l_name local name
72
+ # @return [Field]
76
73
  def field(l_name)
77
74
  fields.find{|fld| fld.l_name == l_name}
78
75
  end
79
76
 
80
77
  # Check if the any of the fields are outdated
81
- # Populates self.outdated with outdated local field names
82
- # === Returns
83
- # <Boolean>:: false if not outdated
78
+ # Populates #outdated with local field names
79
+ #
80
+ # @return [Boolean] false if not outdated
84
81
  def outdated?
85
82
  @outdated = []
86
83
  fields.each do |fld|
@@ -108,24 +105,26 @@ module SK::SDK
108
105
 
109
106
  # Update a side with the values from the other side.
110
107
  # Populates the log with updated fields and values.
111
- # === Parameter
112
- # side<String|Symbol>:: the side to update l OR r
113
- # flds<Array[Field] | nil>:: fields to update, if nil all fields are updated
108
+ #
109
+ # @param [String|Symbol] side to update l OR r
110
+ # @param [Array<Field>, nil] flds fields to update, default nil update all fields
114
111
  def update(side, flds=nil)
115
112
  raise ArgumentError, 'The side to update must be :l or :r' unless [:l, :r].include?(side)
116
113
  target, source = (side==:l) ? [:l, :r] : [:r, :l]
117
114
  # use set field/s or update all
118
115
  flds ||= fields
119
- target_obj, source_obj = self.send("#{target}_obj"), self.send("#{source}_obj")
116
+ target_obj = self.send("#{target}_obj")
117
+ source_obj = self.send("#{source}_obj")
120
118
  flds.each do |fld|
121
- target_name, source_name = fld.send("#{target}_name"), fld.send("#{source}_name")
119
+ target_name = fld.send("#{target}_name")
120
+ source_name = fld.send("#{source}_name")
122
121
  # remember for log
123
122
  old_val = target_obj.send(target_name) rescue 'empty'
124
123
  # get new value through transfer method or direct
125
- new_val = if fld.transition? #call transfer function
124
+ new_val = if fld.transition?
126
125
  cur_trans = fld.send("#{target}_trans")
127
126
  eval "#{cur_trans} source_obj.send( source_name )"
128
- else # lookup directly on other side object
127
+ else
129
128
  source_obj.send( source_name )
130
129
  end
131
130
  target_obj.send( "#{target_name}=" , new_val )
@@ -134,22 +133,22 @@ module SK::SDK
134
133
  end
135
134
  end
136
135
 
137
- # A Sync::Field holds the local(left) and remote(right) field names and if
136
+ # A Sync::Field holds the local(left) and remote(right) field name and if
138
137
  # available the transfer methods.
139
138
  class Field
140
139
  attr_reader :l_name, :r_name, :l_trans, :r_trans
141
140
 
142
- # Create a new sync field. the local and remote name MUST be set.
141
+ # Create a new sync field. The local and remote name MUST be set.
143
142
  # Transition methods are optional.
144
143
  #
145
- # == Example
146
-
147
- # With options as array:
148
- # opts = [:local_name, :remote_name, "SomeClass.left_trans", "SomeClass.rigt_trans"]
149
- # fld = Field.new opts
144
+ # @example no transition methods:
145
+ # opts = [:local_name, :remote_name]
146
+ # fld = Field.new opts
147
+ # @example with transition method:
148
+ # opts = [:local_name, :remote_name, "AClass.local_transition", "AClass.remote_transition"]
149
+ # fld = Field.new opts
150
150
  #
151
- # == Parameter
152
- # opts<Hash>::
151
+ # @param [Array<String, Symbol>] opts
153
152
  def initialize(opts)
154
153
  if opts.is_a? Array
155
154
  @l_trans, @r_trans = opts[2], opts[3] if opts.length == 4
@@ -161,8 +160,7 @@ module SK::SDK
161
160
  def transition?
162
161
  @l_trans && @r_trans
163
162
  end
164
- end # class Field
165
-
163
+ end
166
164
 
167
165
  end # Sync
168
166
  end
@@ -0,0 +1,5 @@
1
+ module SK
2
+ module SDK
3
+ VERSION = '0.2.2'
4
+ end
5
+ end
data/sk_sdk.gemspec CHANGED
@@ -1,84 +1,31 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'sk_sdk/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{sk_sdk}
8
- s.version = "0.2.1"
6
+ s.name = 'sk_sdk'
7
+ s.date = %q{2012-05-27}
8
+ s.version = SK::SDK::VERSION
9
+ s.authors = ['Georg Leciejewski', 'Mike Poltyn']
10
+ s.email = ['gl@salesking.eu']
11
+ s.homepage = 'http://github.com/salesking/sk_sdk'
12
+ s.summary = %q{SalesKing Ruby SDK - simplify your Business}
13
+ 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}
9
16
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Georg Leciejewski}]
12
- s.date = %q{2012-05-21}
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
- s.email = %q{gl@salesking.eu}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "ci/Gemfile",
24
- "ci/Gemfile_ar2.lock",
25
- "lib/sk_sdk.rb",
26
- "lib/sk_sdk/README.rdoc",
27
- "lib/sk_sdk/ar_patches/ar2/base.rb",
28
- "lib/sk_sdk/ar_patches/ar2/validations.rb",
29
- "lib/sk_sdk/ar_patches/ar3/base.rb",
30
- "lib/sk_sdk/ar_patches/ar3/validations.rb",
31
- "lib/sk_sdk/base.rb",
32
- "lib/sk_sdk/oauth.rb",
33
- "lib/sk_sdk/omni_auth/README.rdoc",
34
- "lib/sk_sdk/omni_auth/salesking.rb",
35
- "lib/sk_sdk/signed_request.rb",
36
- "lib/sk_sdk/sync.rb",
37
- "sk_sdk.gemspec",
38
- "spec/resources_spec_helper.rb",
39
- "spec/settings.yml.default",
40
- "spec/sk_sdk/base_spec.rb",
41
- "spec/sk_sdk/oauth_spec.rb",
42
- "spec/sk_sdk/resources/README.rdoc",
43
- "spec/sk_sdk/resources/clients_spec.rb",
44
- "spec/sk_sdk/resources/credit_note_spec.rb",
45
- "spec/sk_sdk/resources/invoice_spec.rb",
46
- "spec/sk_sdk/resources/product_spec.rb",
47
- "spec/sk_sdk/signed_request_spec.rb",
48
- "spec/sk_sdk/sync_field_spec.rb",
49
- "spec/sk_sdk/sync_spec.rb",
50
- "spec/spec_helper.rb"
51
- ]
52
- s.homepage = %q{http://github.com/salesking/sk_sdk}
53
- s.require_paths = [%q{lib}]
54
- s.rubygems_version = %q{1.8.6}
55
- s.summary = %q{SalesKing SDK Ruby}
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
56
21
 
57
- if s.respond_to? :specification_version then
58
- s.specification_version = 3
59
-
60
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- s.add_runtime_dependency(%q<curb>, [">= 0"])
62
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
63
- s.add_runtime_dependency(%q<sk_api_schema>, [">= 0"])
64
- s.add_runtime_dependency(%q<activeresource>, [">= 0"])
65
- s.add_development_dependency(%q<rspec>, [">= 0"])
66
- s.add_development_dependency(%q<rcov>, [">= 0"])
67
- else
68
- s.add_dependency(%q<curb>, [">= 0"])
69
- s.add_dependency(%q<activesupport>, [">= 0"])
70
- s.add_dependency(%q<sk_api_schema>, [">= 0"])
71
- s.add_dependency(%q<activeresource>, [">= 0"])
72
- s.add_dependency(%q<rspec>, [">= 0"])
73
- s.add_dependency(%q<rcov>, [">= 0"])
74
- end
75
- else
76
- s.add_dependency(%q<curb>, [">= 0"])
77
- s.add_dependency(%q<activesupport>, [">= 0"])
78
- s.add_dependency(%q<sk_api_schema>, [">= 0"])
79
- s.add_dependency(%q<activeresource>, [">= 0"])
80
- s.add_dependency(%q<rspec>, [">= 0"])
81
- s.add_dependency(%q<rcov>, [">= 0"])
82
- end
83
- end
22
+ s.add_runtime_dependency 'curb'
23
+ s.add_runtime_dependency 'activesupport'
24
+ s.add_runtime_dependency 'activeresource'
25
+ s.add_runtime_dependency 'sk_api_schema'
84
26
 
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'simplecov'
29
+ s.add_development_dependency 'rspec'
30
+ s.add_development_dependency 'rdoc'
31
+ end
@@ -4,7 +4,6 @@ require 'spec_helper'
4
4
  eval "class #{model} < SK::SDK::Base;end" unless Object.const_defined?(model)
5
5
  end
6
6
  SK::SDK::Base.set_connection basic_auth_settings
7
-
8
7
  # check if a SalesKing instance is available by calling /users/current.json
9
8
  def sk_available?
10
9
  begin
@@ -12,7 +11,6 @@ def sk_available?
12
11
  rescue Errno::ECONNREFUSED #ActiveResource::ResourceNotFound => e
13
12
  return false
14
13
  end
15
-
16
14
  end
17
15
 
18
16
  # Params
@@ -17,23 +17,11 @@ describe SK::SDK::Base, "make new class" do
17
17
  end
18
18
 
19
19
  it "should set api url" do
20
- opts = {:site => 'https://my.salesking.eu', :token=>'123'}
21
20
  result = 'https://my.salesking.eu/api'
22
21
 
23
- SK::SDK::Base.set_connection(opts)
24
- SK::SDK::Base.site.to_s.should == result
22
+ SK::SDK::Base.send(:site_api_url, 'https://my.salesking.eu').should == result
23
+ SK::SDK::Base.send(:site_api_url, 'https://my.salesking.eu/api').should == result
25
24
 
26
- opts[:site] = 'https://my.salesking.eu/'
27
- SK::SDK::Base.set_connection(opts)
28
- SK::SDK::Base.site.to_s.should == result
29
-
30
- opts[:site] ='https://my.salesking.eu/api'
31
- SK::SDK::Base.set_connection(opts)
32
- SK::SDK::Base.site.to_s.should == result
33
-
34
- opts[:site] = 'https://my.salesking.eu/api/'
35
- SK::SDK::Base.set_connection(opts)
36
- SK::SDK::Base.site.to_s.should == result
37
25
  end
38
26
 
39
27
  it "should have properties as attributes" do
@@ -1,9 +1,9 @@
1
1
  = SalesKing SDK Resources Specs
2
2
 
3
3
  The specs in here serve mainly as an example using the ActiveResource client
4
- with username+password to CRUD objects against a real sk server.
4
+ with username+password to CRUD objects against a real SK server.
5
5
 
6
- Of course we also have internal specs for all api controllers but sometimes a
6
+ Of course we also have internal specs for all api controllers, but sometimes a
7
7
  view from the outside can be revealing.
8
8
 
9
9
  Please be nice and DON'T misuse those tests!
@@ -3,7 +3,7 @@ require 'resources_spec_helper'
3
3
  unless sk_available?
4
4
  puts "Sorry cannot connect to your SalesKing server, skipping real connections tests. Please check connection settings in spec_helper"
5
5
  else
6
-
6
+
7
7
  describe Client, "with real connection" do
8
8
 
9
9
  before :all do
@@ -115,7 +115,7 @@ else
115
115
  end
116
116
 
117
117
  it "should add line item" do
118
- item = LineItem.new :position=>2, :description => 'Goat-Pie',
118
+ item = LineItem.new :position=>2, :description => 'Goat-Pie',
119
119
  :price_single => 10, :quantity=>10
120
120
  @doc.line_items << item
121
121
  @doc.save
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,24 @@
1
+ # encoding: utf-8
2
+ $:.unshift(File.dirname(__FILE__))
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start 'rails'
7
+ SimpleCov.coverage_dir 'coverage'
8
+
9
+ require 'sk_sdk'
10
+ require 'sk_sdk/base'
11
+ require 'sk_sdk/sync'
12
+ require 'sk_sdk/oauth'
13
+ require 'sk_sdk/signed_request'
1
14
  require 'rubygems'
2
15
  require 'yaml'
3
16
  require 'rspec'
4
- require "active_support"
5
- require "active_support/json"
6
- require "#{File.dirname(__FILE__)}/../lib/sk_sdk"
7
- require "#{File.dirname(__FILE__)}/../lib/sk_sdk/base"
8
- require "#{File.dirname(__FILE__)}/../lib/sk_sdk/sync"
9
- require "#{File.dirname(__FILE__)}/../lib/sk_sdk/oauth"
10
- require "#{File.dirname(__FILE__)}/../lib/sk_sdk/signed_request"
11
-
17
+ require 'active_support'
18
+ require 'active_support/json'
12
19
 
13
20
  puts "Testing with ActiveResource v: #{ActiveResource::VERSION::STRING}"
14
21
 
15
-
16
22
  def basic_auth_settings
17
23
  get_settings['basic_auth'].symbolize_keys
18
24
  end
@@ -22,9 +28,9 @@ def oauth_settings
22
28
  end
23
29
 
24
30
  def get_settings
25
- @settings ||= begin
26
- YAML.load_file(File.join(File.dirname(__FILE__), 'settings.yml'))
31
+ @settings ||= begin
32
+ YAML.load_file(File.join(File.dirname(__FILE__), 'settings.yml'))
27
33
  rescue => e
28
- puts "Missing settings.yml in rails_root/spec/settings.yml"
34
+ raise 'Missing settings.yml in spec/settings.yml'
29
35
  end
30
36
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sk_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Georg Leciejewski
9
+ - Mike Poltyn
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-05-21 00:00:00.000000000 Z
13
+ date: 2012-05-27 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: curb
16
- requirement: &70341335516100 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,15 @@ dependencies:
21
22
  version: '0'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70341335516100
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
25
31
  - !ruby/object:Gem::Dependency
26
32
  name: activesupport
27
- requirement: &70341335515380 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
28
34
  none: false
29
35
  requirements:
30
36
  - - ! '>='
@@ -32,10 +38,15 @@ dependencies:
32
38
  version: '0'
33
39
  type: :runtime
34
40
  prerelease: false
35
- version_requirements: *70341335515380
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
36
47
  - !ruby/object:Gem::Dependency
37
- name: sk_api_schema
38
- requirement: &70341335514260 !ruby/object:Gem::Requirement
48
+ name: activeresource
49
+ requirement: !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,15 @@ dependencies:
43
54
  version: '0'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *70341335514260
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
47
63
  - !ruby/object:Gem::Dependency
48
- name: activeresource
49
- requirement: &70341335513260 !ruby/object:Gem::Requirement
64
+ name: sk_api_schema
65
+ requirement: !ruby/object:Gem::Requirement
50
66
  none: false
51
67
  requirements:
52
68
  - - ! '>='
@@ -54,10 +70,47 @@ dependencies:
54
70
  version: '0'
55
71
  type: :runtime
56
72
  prerelease: false
57
- version_requirements: *70341335513260
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rake
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: simplecov
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
58
111
  - !ruby/object:Gem::Dependency
59
112
  name: rspec
60
- requirement: &70341335512600 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
61
114
  none: false
62
115
  requirements:
63
116
  - - ! '>='
@@ -65,10 +118,15 @@ dependencies:
65
118
  version: '0'
66
119
  type: :development
67
120
  prerelease: false
68
- version_requirements: *70341335512600
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
69
127
  - !ruby/object:Gem::Dependency
70
- name: rcov
71
- requirement: &70341335511640 !ruby/object:Gem::Requirement
128
+ name: rdoc
129
+ requirement: !ruby/object:Gem::Requirement
72
130
  none: false
73
131
  requirements:
74
132
  - - ! '>='
@@ -76,21 +134,28 @@ dependencies:
76
134
  version: '0'
77
135
  type: :development
78
136
  prerelease: false
79
- version_requirements: *70341335511640
80
- description: ! 'Connect your business world with SalesKing. This gem gives ruby developers
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ description: ! 'Connect your business with SalesKing. This gem gives ruby developers
81
144
  a jump-start for building SalesKing Business Apps. It provides classes to handle
82
- oAuth, make RESTfull API requests and parses JSON Schema '
83
- email: gl@salesking.eu
145
+ oAuth, make RESTfull API requests and parses JSON Schema '
146
+ email:
147
+ - gl@salesking.eu
84
148
  executables: []
85
149
  extensions: []
86
150
  extra_rdoc_files:
87
151
  - README.rdoc
88
152
  files:
153
+ - .gitignore
154
+ - .travis.yml
155
+ - Gemfile
89
156
  - MIT-LICENSE
90
157
  - README.rdoc
91
158
  - Rakefile
92
- - VERSION
93
- - ci/Gemfile
94
159
  - ci/Gemfile_ar2.lock
95
160
  - lib/sk_sdk.rb
96
161
  - lib/sk_sdk/README.rdoc
@@ -104,6 +169,7 @@ files:
104
169
  - lib/sk_sdk/omni_auth/salesking.rb
105
170
  - lib/sk_sdk/signed_request.rb
106
171
  - lib/sk_sdk/sync.rb
172
+ - lib/sk_sdk/version.rb
107
173
  - sk_sdk.gemspec
108
174
  - spec/resources_spec_helper.rb
109
175
  - spec/settings.yml.default
@@ -130,16 +196,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
196
  - - ! '>='
131
197
  - !ruby/object:Gem::Version
132
198
  version: '0'
199
+ segments:
200
+ - 0
201
+ hash: -3310092520426669956
133
202
  required_rubygems_version: !ruby/object:Gem::Requirement
134
203
  none: false
135
204
  requirements:
136
205
  - - ! '>='
137
206
  - !ruby/object:Gem::Version
138
207
  version: '0'
208
+ segments:
209
+ - 0
210
+ hash: -3310092520426669956
139
211
  requirements: []
140
212
  rubyforge_project:
141
- rubygems_version: 1.8.6
213
+ rubygems_version: 1.8.24
142
214
  signing_key:
143
215
  specification_version: 3
144
- summary: SalesKing SDK Ruby
216
+ summary: SalesKing Ruby SDK - simplify your Business
145
217
  test_files: []
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.1
data/ci/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source :gemcutter
2
- gem "rake"
3
- gem "rdoc"
4
- gem "rcov"
5
- gem "activesupport"
6
- gem "activeresource"
7
- gem "sk_api_schema"
8
- gem "curb"
9
- group :test do
10
- gem "rspec"
11
- end