sk_sdk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/lib/sk_sdk/signed_request.rb +26 -4
- data/sk_sdk.gemspec +55 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -7,7 +7,6 @@ Still in a very early stage
|
|
7
7
|
|
8
8
|
== Install
|
9
9
|
|
10
|
-
|
11
10
|
gem install sk_sdk
|
12
11
|
|
13
12
|
Dependencies (gem's):
|
@@ -15,4 +14,11 @@ Dependencies (gem's):
|
|
15
14
|
* activeresupport
|
16
15
|
* curb
|
17
16
|
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
The classes must be explicitly required
|
20
|
+
|
21
|
+
require 'sk_sdk/sign_req'
|
22
|
+
require 'sk_sdk/oauth'
|
23
|
+
|
18
24
|
Copyright (c) 2011 Georg Leciejewski, released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require "active_support/json"
|
3
3
|
require 'openssl'
|
4
|
+
|
4
5
|
module SK::SDK
|
5
6
|
# Decode and validate signed requests which Salesking sends to canvas pages
|
6
7
|
# and PubSub subscribers
|
7
8
|
class SignedRequest
|
8
|
-
|
9
9
|
attr_reader :signed_request, :app_secret, :data, :payload, :sign
|
10
10
|
|
11
11
|
def initialize(signed_request, app_secret)
|
@@ -38,13 +38,35 @@ module SK::SDK
|
|
38
38
|
@sign == OpenSSL::HMAC.hexdigest('sha256', @app_secret, @payload)
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
# Base64 url encode a string and sign it using the given secret. The hmac
|
42
|
+
# signature and the encoded string are joined by . and returned
|
43
|
+
#
|
44
|
+
# === Parameter
|
45
|
+
# str<String>:: the string to encode
|
46
|
+
# secret<String>:: the string used to create the signature
|
47
|
+
# === Returns
|
48
|
+
# <String>:: hmac-sign.encoded-string
|
49
|
+
def self.signed_param(str, secret)
|
42
50
|
# base65 url encode the json, remove trailing-padding =
|
43
|
-
enc_str =
|
51
|
+
enc_str = base64_url_encode(str)
|
44
52
|
# create hmac signature
|
45
|
-
hmac_sig = OpenSSL::HMAC.hexdigest('sha256'
|
53
|
+
hmac_sig = OpenSSL::HMAC.hexdigest('sha256',secret, enc_str)
|
46
54
|
# glue together and return
|
47
55
|
[hmac_sig, enc_str].join('.')
|
48
56
|
end
|
57
|
+
|
58
|
+
# Base64 url encode a string:
|
59
|
+
# NO padding = is added
|
60
|
+
# + is replaced by -
|
61
|
+
# / is replaced by _
|
62
|
+
#
|
63
|
+
# === Parameter
|
64
|
+
# str<String>:: the string to encode
|
65
|
+
# === Returns
|
66
|
+
# <String>:: base64url-encoded
|
67
|
+
def self.base64_url_encode(str)
|
68
|
+
[str].pack('m').tr('+/','-_').gsub("\n",'').gsub(/=+$/, '' )
|
69
|
+
end
|
70
|
+
|
49
71
|
end
|
50
72
|
end
|
data/sk_sdk.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sk_sdk}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Georg Leciejewski"]
|
12
|
+
s.date = %q{2011-03-10}
|
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
|
+
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
|
+
"lib/sk_sdk.rb",
|
24
|
+
"lib/sk_sdk/oauth.rb",
|
25
|
+
"lib/sk_sdk/signed_request.rb",
|
26
|
+
"sk_sdk.gemspec",
|
27
|
+
"spec/oauth_spec.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/salesking/sk_sdk}
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.5.2}
|
32
|
+
s.summary = %q{SalesKing SDK Ruby}
|
33
|
+
s.test_files = [
|
34
|
+
"spec/oauth_spec.rb"
|
35
|
+
]
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_runtime_dependency(%q<curb>, [">= 0"])
|
42
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<curb>, [">= 0"])
|
46
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
47
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<curb>, [">= 0"])
|
51
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
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-
|
18
|
+
date: 2011-03-10 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/sk_sdk.rb
|
77
77
|
- lib/sk_sdk/oauth.rb
|
78
78
|
- lib/sk_sdk/signed_request.rb
|
79
|
+
- sk_sdk.gemspec
|
79
80
|
- spec/oauth_spec.rb
|
80
81
|
has_rdoc: true
|
81
82
|
homepage: http://github.com/salesking/sk_sdk
|