sk_sdk 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -29,12 +29,13 @@ Handling oAuth related URL's and getting an access token
29
29
 
30
30
  === SignedRequest
31
31
 
32
- Helping in de/encoding of signed_request param
32
+ Helping in de/encoding of signed_request parameter available in canvas pages and
33
+ PubSub/Webhook callbacks.
33
34
 
34
35
  === API client
35
36
 
36
37
  Create classes out if thin air to CRUD SalesKing object's using activeresource
37
- README: https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/README_ArCli.rdoc
38
+ {see README}[https://github.com/salesking/sk_sdk/blob/master/lib/sk_sdk/README_ArCli.rdoc]
38
39
 
39
40
  == Usage
40
41
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,10 +1,11 @@
1
1
  = SalesKing API Client
2
2
 
3
- Create classes, descendants of ActiveResource::Base, to CRUD SalesKing objects.
3
+ ActiveResource based SalesKing API client. This client does not uses oAuth2 yet,
4
+ it still uses HTTBasic Auth with username and password.
4
5
 
5
- This does NOT rely on parsing the JSON Schema, since activeresource creates the
6
- getter/Setter methods(less restrict). The client adds some patches to AR to fix
7
- json parsing issues.
6
+ This does NOT rely on parsing the JSON Schema, since ActiveResource creates the
7
+ Getter/Setter methods(less restrict). The client also adds some patches to AR to
8
+ fix json parsing issues.
8
9
 
9
10
  == Install
10
11
 
@@ -20,20 +21,20 @@ Dependencies (gem's):
20
21
  SalesKing's api interface is RESTful(mostly) and returns & accepts JSON data.
21
22
  All resources such as clients, invoices, products can be accessed via URL's
22
23
  through standard HTTP methods GET, POST, PUT and DELETE.
23
- see available methods here:
24
+ see available objects and endpoints here:
24
25
  https://github.com/salesking/sk_api_schema/tree/master/json
25
26
 
26
- ActiveResource provides a wrapper around the whole url/request stuff and makes
27
- usage of the new classes pretty straight forward:
27
+ First create the classes:
28
28
 
29
29
  require "sk_sdk/ar_client"
30
30
  SK::SDK::ArCli.make(:client)
31
- # Create class within any namespace
31
+
32
+ # Create class within namespace
32
33
  module; King; end
33
34
  SK::SDK::ArCli.make(:credit_note, King)
34
35
 
35
- Now the classes are available, but needs some connection settings first. Those Must
36
- be set for each class separate
36
+ Now the classes are available they need connection settings first. Those Must
37
+ be set for each class separate.
37
38
 
38
39
  [Client, CreditNote].each do |i|
39
40
  i.send(:set_connection, {:site => 'my_sub.salesking.eu',
data/lib/sk_sdk/oauth.rb CHANGED
@@ -1,19 +1,28 @@
1
1
  require 'cgi'
2
2
  require 'curb'
3
3
  module SK::SDK
4
- # Authenticate your SalesKing App using oAuth2. This class holds common methods
4
+ # Authenticate your SalesKing App using oAuth2. This class provides helpers
5
+ # to create the token & dialog url and to get an access token
5
6
  class Oauth
6
7
 
7
- attr_reader :app_id, :app_secret, :app_redirect_url
8
+ attr_reader :id, :secret, :redirect_url
8
9
  attr_accessor :sub_domain
9
10
 
11
+ # Setup a new oAuth connection requires you to set some default:
12
+ # === Params
13
+ # opts<Hash{String=>String}>:: options for your app
14
+ # == Options(opts)
15
+ # id:: oAuth app id received after registering your app in SalesKing
16
+ # secret:: oAuth app secret received after registering your app in SalesKing
17
+ # scope:: permission your app requests
18
+ # redirect_url:: permission your app requests
10
19
  def initialize(opts)
11
- @app_id = opts['app_id']
12
- @app_secret = opts['app_secret']
13
- @app_scope = opts['app_scope']
14
- @app_redirect_url = opts['app_redirect_url']
15
- @app_canvas_slug = opts['app_canvas_slug']
16
- @sk_url = opts['sk_url']
20
+ @id = opts['id']
21
+ @secret = opts['secret']
22
+ @scope = opts['scope']
23
+ @redirect_url = opts['redirect_url']
24
+ @canvas_slug = opts['canvas_slug']
25
+ @sk_url = opts['sk_url'] || "https://*.salesking.eu"
17
26
  @sub_domain = opts['sub_domain']
18
27
  end
19
28
 
@@ -22,9 +31,9 @@ module SK::SDK
22
31
  # === Returns
23
32
  # <String>:: URL with parameter
24
33
  def auth_dialog
25
- params = { :client_id => @app_id,
26
- :redirect_uri=> @app_redirect_url,
27
- :scope => @app_scope }
34
+ params = { :client_id => @id,
35
+ :redirect_uri=> @redirect_url,
36
+ :scope => @scope }
28
37
  "#{sk_url}/oauth/authorize?#{to_url_params(params)}"
29
38
  end
30
39
 
@@ -32,7 +41,7 @@ module SK::SDK
32
41
  # === Returns
33
42
  # <String>:: URL
34
43
  def sk_canvas_url
35
- "#{sk_url}/app/#{@app_canvas_slug}"
44
+ "#{sk_url}/app/#{@canvas_slug}"
36
45
  end
37
46
 
38
47
  # URL to get the access_token, used in the second step after you have
@@ -42,9 +51,9 @@ module SK::SDK
42
51
  # === Returns
43
52
  # <String>:: Url with parameter
44
53
  def token_url(code)
45
- params = { :client_id => @app_id,
46
- :client_secret => @app_secret,
47
- :redirect_uri => @app_redirect_url,
54
+ params = { :client_id => @id,
55
+ :client_secret => @secret,
56
+ :redirect_uri => @redirect_url,
48
57
  :code => code }
49
58
  "#{sk_url}/oauth/access_token?#{to_url_params(params)}"
50
59
  end
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.3"
8
+ s.version = "0.0.4"
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-03-14}
12
+ s.date = %q{2011-03-28}
13
13
  s.description = %q{Connect your business world with SalesKing. This gem gives ruby developers a jump-start for building SalesKing Business Apps. Under the hood 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 = [
data/spec/settings.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  sk_url: http://*.horsts-lokal.local
2
- app_canvas_slug: canvas-page
3
- app_id: 2d83d570635ee19c
4
- app_secret: eb4005858e4947e4228a12a6b7306ee0
5
- app_redirect_url: http://localhorst:4567
6
- app_scope: "api/payments:read api/invoices:read"
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
7
  session_secret: very_long_random_to_encode_the_session
@@ -44,18 +44,21 @@ describe SK::SDK::ArCli, "make new class" do
44
44
  end
45
45
  end
46
46
 
47
- describe SK::SDK::ArCli, "with real connection" do
47
+ if sk_available?
48
+ describe SK::SDK::ArCli, "with real connection" do
48
49
 
49
- before :all do
50
- SK::SDK::ArCli.make(:client) unless Object.const_defined?('Client')
51
- Client.set_connection( CONNECTION )
52
- #TODO check if sk is available
53
- end
50
+ before :all do
51
+ SK::SDK::ArCli.make(:client) unless Object.const_defined?('Client')
52
+ Client.set_connection( CONNECTION )
53
+ end
54
54
 
55
- it "should save" do
56
- c = Client.new :organisation=>"Rack'n Roll"
57
- c.save.should be_true
58
- c.id.should_not be_empty
59
- c.number.should_not be_empty
55
+ it "should save" do
56
+ c = Client.new :organisation=>"Rack'n Roll"
57
+ c.save.should be_true
58
+ c.id.should_not be_empty
59
+ c.number.should_not be_empty
60
+ end
60
61
  end
62
+ else
63
+ puts "Sorry your local SalesKing server ain't running, skipping real connections tests"
61
64
  end
@@ -21,9 +21,9 @@ describe SK::SDK::Oauth, "in general" do
21
21
  a = SK::SDK::Oauth.new(@set)
22
22
  a.sub_domain = 'alki'
23
23
  a.auth_dialog.should include "http://alki.horsts-lokal.local/oauth/authorize?"
24
- a.auth_dialog.should include @set['app_id']
25
- a.auth_dialog.should include CGI::escape @set['app_redirect_url']
26
- a.auth_dialog.should include CGI::escape @set['app_scope']
24
+ a.auth_dialog.should include @set['id']
25
+ a.auth_dialog.should include CGI::escape @set['redirect_url']
26
+ a.auth_dialog.should include CGI::escape @set['scope']
27
27
  end
28
28
 
29
29
  it "should get sk_canvas_url" do
@@ -36,9 +36,9 @@ describe SK::SDK::Oauth, "in general" do
36
36
  a = SK::SDK::Oauth.new(@set)
37
37
  a.sub_domain = 'alki'
38
38
  url = a.token_url('some-code')
39
- url.should include @set['app_id']
40
- url.should include @set['app_secret']
41
- url.should include CGI::escape @set['app_redirect_url']
39
+ url.should include @set['id']
40
+ url.should include @set['secret']
41
+ url.should include CGI::escape @set['redirect_url']
42
42
  end
43
43
 
44
44
  end
@@ -7,11 +7,11 @@ describe SK::SDK::SignedRequest, "in general" do
7
7
  load_settings
8
8
  # fake request
9
9
  @param_hash = {'hello' =>'coder', 'algorithm' => 'HMAC-SHA256'}
10
- @param = SK::SDK::SignedRequest.signed_param( ActiveSupport::JSON.encode(@param_hash), @set['app_secret'] )
10
+ @param = SK::SDK::SignedRequest.signed_param( ActiveSupport::JSON.encode(@param_hash), @set['secret'] )
11
11
  end
12
12
 
13
13
  it "should decode payload" do
14
- a = SK::SDK::SignedRequest.new(@param, @set['app_secret'])
14
+ a = SK::SDK::SignedRequest.new(@param, @set['secret'])
15
15
  a.data.should_not be_nil
16
16
  a.payload.should_not be_nil
17
17
  a.sign.should_not be_nil
data/spec/spec_helper.rb CHANGED
@@ -21,4 +21,15 @@ CONNECTION = {
21
21
  :user => "demo@salesking.eu",
22
22
  :password => "demo",
23
23
  :format => :json
24
- } unless defined?(CONNECTION)
24
+ } unless defined?(CONNECTION)
25
+
26
+ def sk_available?
27
+ SK::SDK::ArCli.make(:user) unless Object.const_defined?('User')
28
+ User.set_connection( CONNECTION )
29
+ begin
30
+ User.get(:current)
31
+ rescue Errno::ECONNREFUSED #ActiveResource::ResourceNotFound => e
32
+ return false
33
+ end
34
+
35
+ 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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
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-03-14 00:00:00 +01:00
18
+ date: 2011-03-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency