sk_sdk 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -64,6 +64,8 @@ remember we only support HTTPS:
64
64
  =>
65
65
  https://my_company.salesking.eu/api
66
66
 
67
+ For convenience we check if your url ends in /api and add if you forgot it!
68
+
67
69
  Create a single class
68
70
 
69
71
  require 'sk_sdk/base'
data/lib/sk_sdk/base.rb CHANGED
@@ -39,8 +39,8 @@ class SK::SDK::Base < ActiveResource::Base
39
39
  # :user<String>:: if using httpBasic auth set to sk user login email
40
40
  # :password<String>:: if using httpBasic sk user password
41
41
  def self.set_connection(opts)
42
- self.site = opts[:site]
43
- self.format = :json # f*** xml
42
+ self.site = site_api_url(opts[:site])
43
+ self.format = :json # f*** xml
44
44
  if opts[:token] #oAuth access token in header
45
45
  self.headers['Authorization'] = "Bearer #{opts[:token]}"
46
46
  else
@@ -60,4 +60,11 @@ class SK::SDK::Base < ActiveResource::Base
60
60
  @headers ||= {}
61
61
  end
62
62
  end
63
+
64
+ private
65
+
66
+ def self.site_api_url(site)
67
+ site = site.gsub(/\/$/, '')
68
+ site =~ /\/api$/ ? site : "#{site}/api"
69
+ end
63
70
  end
data/lib/sk_sdk/oauth.rb CHANGED
@@ -19,8 +19,8 @@ module SK::SDK
19
19
  # secret<String>:: oAuth app secret from SalesKing app registration
20
20
  # scope<String>:: permission your app requests
21
21
  # redirect_url<String>:: redirect url inside your app for auth dialog
22
- # sk_url<String>:: SalesKing base url, * is replaced with users subdomain,
23
- # default https://*.salesking.eu, optional
22
+ # sk_url<String>:: SalesKing base url, * is replaced with users subdomain,
23
+ # no trailing slash, optional defaults to https://*.salesking.eu
24
24
  # sub_domain<String>:: optinal, will probably be set later after a users
25
25
  # provided his subdomain
26
26
  def initialize(opts)
@@ -74,6 +74,13 @@ module SK::SDK
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
80
+ def sk_api_url
81
+ "#{sk_url}/api"
82
+ end
83
+
77
84
  # Each company has it's own subdomain so the url must be dynamic.
78
85
  # This is achieved by replacing the * with the subdomain in the instance
79
86
  # === Returns
data/lib/sk_sdk/sync.rb CHANGED
@@ -64,9 +64,7 @@ module SK::SDK
64
64
  # field_map<Array[Hash{}]>::
65
65
  def fields=(field_map)
66
66
  @fields = []
67
- field_map.each do |fld|
68
- @fields << Field.new(fld)
69
- end
67
+ field_map.each { |fld| @fields << Field.new(fld) }
70
68
  @fields
71
69
  end
72
70
 
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.1.0"
8
+ s.version = "0.1.1"
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-10-03}
12
+ s.date = %q{2011-12-21}
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 = [
@@ -16,6 +16,26 @@ describe SK::SDK::Base, "make new class" do
16
16
  c.first_name.should == 'herbert' # implicit getter
17
17
  end
18
18
 
19
+ it "should set api url" do
20
+ opts = {:site => 'https://my.salesking.eu', :token=>'123'}
21
+ result = 'https://my.salesking.eu/api'
22
+
23
+ SK::SDK::Base.set_connection(opts)
24
+ SK::SDK::Base.site.to_s.should == result
25
+
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
+ end
38
+
19
39
  it "should have properties as attributes" do
20
40
  c = Client.new :some_field => ''
21
41
  c.attributes.should == {"some_field"=>""}
@@ -16,6 +16,12 @@ 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
+
20
+ it "should get salesking api url" do
21
+ a = SK::SDK::Oauth.new(@set)
22
+ a.sub_domain = 'alki'
23
+ a.sk_api_url.should == "http://alki.horsts-lokal.local/api"
24
+ end
19
25
 
20
26
  it "should get auth_dialog url" do
21
27
  a = SK::SDK::Oauth.new(@set)
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
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-10-03 00:00:00 +02:00
18
+ date: 2011-12-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency