opentransact 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile.lock +7 -1
- data/README.rdoc +65 -1
- data/lib/opentransact/asset.rb +35 -5
- data/lib/opentransact/client.rb +82 -12
- data/lib/opentransact/server.rb +45 -0
- data/lib/opentransact/version.rb +1 -1
- data/lib/opentransact.rb +1 -0
- data/opentransact.gemspec +3 -0
- data/spec/fixtures/host-meta.xml +38 -0
- data/spec/fixtures/wallet_with_balances.json +9 -0
- data/spec/fixtures/webfinger.xml +22 -0
- data/spec/opentransact/asset_spec.rb +19 -18
- data/spec/opentransact/client_spec.rb +93 -26
- data/spec/opentransact/server_spec.rb +59 -4
- data/spec/spec_helper.rb +6 -1
- metadata +35 -3
data/.rspec
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
opentransact (0.0
|
4
|
+
opentransact (0.1.0)
|
5
|
+
multi_json
|
6
|
+
multi_xml
|
5
7
|
oauth (~> 0.4.4)
|
6
8
|
|
7
9
|
GEM
|
@@ -23,6 +25,8 @@ GEM
|
|
23
25
|
launchy (0.3.7)
|
24
26
|
configuration (>= 0.0.5)
|
25
27
|
rake (>= 0.8.1)
|
28
|
+
multi_json (0.0.5)
|
29
|
+
multi_xml (0.2.0)
|
26
30
|
oauth (0.4.4)
|
27
31
|
open_gem (1.4.2)
|
28
32
|
launchy (~> 0.3.5)
|
@@ -47,6 +51,8 @@ DEPENDENCIES
|
|
47
51
|
fuubar
|
48
52
|
growl
|
49
53
|
guard-rspec
|
54
|
+
multi_json
|
55
|
+
multi_xml
|
50
56
|
oauth (~> 0.4.4)
|
51
57
|
opentransact!
|
52
58
|
rspec (~> 2.1.0)
|
data/README.rdoc
CHANGED
@@ -1,6 +1,70 @@
|
|
1
1
|
= OpenTransact Ruby Client
|
2
2
|
|
3
|
-
This library provides an easy to use client for interacting with OpenTransact financial service providers.
|
3
|
+
This library provides an easy to use client for interacting with OpenTransact[http://opentransact.org] financial service providers.
|
4
|
+
|
5
|
+
This is currently a work in progress and we need to add better error checking, exceptions etc.
|
6
|
+
|
7
|
+
== Quick start
|
8
|
+
|
9
|
+
An OpenTransact asset is a server that accepts either a http POST or GET request containing a to and an amount field.
|
10
|
+
|
11
|
+
There are 2 major ways of performing a transfer/payment with OpenTransact.
|
12
|
+
|
13
|
+
* Simple Web Payments - Simplest to get started
|
14
|
+
* Pre authorized payments - Uses OAuth
|
15
|
+
|
16
|
+
See [http://www.opentransact.org/usecases.html]
|
17
|
+
|
18
|
+
=== Simple Web Payments
|
19
|
+
|
20
|
+
In your controller create a Asset object and redirect to url:
|
21
|
+
|
22
|
+
@asset = OpenTransact::Asset.new "http://picomoney.com/pelle-hours"
|
23
|
+
redirect_to @asset.transfer_url 12, "bob@test.com", "For implementing shopping cart"
|
24
|
+
|
25
|
+
TODO. Work out web callback method, based on http://nubux.heroku.com.
|
26
|
+
|
27
|
+
=== Pre authorized Payments
|
28
|
+
|
29
|
+
OpenTransact delegates all of this to OAuth. This library only supports OAuth 1.0a at the moment. OAuth 2.0 is easy to implement so it will be added shortly.
|
30
|
+
|
31
|
+
==== OAuth Authorization
|
32
|
+
|
33
|
+
You need to register your application eg. https://picomoney.com/client_applications/new
|
34
|
+
|
35
|
+
This whole section can be handled transparently by the OAuth Plugin http://github.com/pelle/oauth-plugin
|
36
|
+
|
37
|
+
Now request authorization:
|
38
|
+
|
39
|
+
def request_authorization
|
40
|
+
@consumer = OAuth::Consumer.new "my key", "my secret", :site=>"http://picomoney.com/pelle-hours"
|
41
|
+
#callback_url is a url on your site
|
42
|
+
@request_token = @consumer.get_request_token(:oauth_callback=>callback_url)
|
43
|
+
session[@request_token.token]=@request_token.secret
|
44
|
+
redirect_to @request_token.authorize_url
|
45
|
+
end
|
46
|
+
|
47
|
+
The user will authorize your app and get redirected back to your callback url
|
48
|
+
|
49
|
+
def callback
|
50
|
+
@consumer = OAuth::Consumer.new "my key", "my secret", :site=>"http://picomoney.com/pelle-hours"
|
51
|
+
|
52
|
+
# build up request_token
|
53
|
+
@request_token = OAuth::RequestToken.new @consumer, params[:oauth_token], session[params[:oauth_token]]
|
54
|
+
|
55
|
+
# exchange request_token for permanent access_token
|
56
|
+
@access_token = @request_token.get_access_token
|
57
|
+
# associate this with your user in your database
|
58
|
+
end
|
59
|
+
|
60
|
+
Performing payments. This could be subscription payments etc.
|
61
|
+
|
62
|
+
@asset = OpenTransact::Asset.new "http://picomoney.com/pelle-hours",
|
63
|
+
:token=>@access_token.token, :secret=>@access_token.secret,
|
64
|
+
:consumer_key=>"my key", :consumer_secret=>"my secret"
|
65
|
+
|
66
|
+
@asset.transfer 12, "bob@test.com", "For implementing shopping cart"
|
67
|
+
|
4
68
|
|
5
69
|
== Note on Patches/Pull Requests
|
6
70
|
|
data/lib/opentransact/asset.rb
CHANGED
@@ -1,20 +1,50 @@
|
|
1
1
|
module OpenTransact
|
2
|
+
# The Asset is the most important concept in OpenTransact. It represents an asset type.
|
2
3
|
class Asset
|
3
|
-
attr_accessor :url, :transaction_url, :options
|
4
|
+
attr_accessor :url, :transaction_url, :client, :options
|
4
5
|
|
5
6
|
def initialize(url,options={})
|
6
7
|
@url = url
|
7
8
|
@transaction_url = options[:transaction_url]||@url
|
9
|
+
@client = options[:client]
|
8
10
|
@options = options||{}
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
# Create a redirect url for a simple web payment
|
14
|
+
#
|
15
|
+
# redirect_to @asset.transfer_url 12, "bob@test.com", "For implementing shopping cart"
|
16
|
+
#
|
17
|
+
def transfer_url(amount,to,memo,options={})
|
18
|
+
uri = URI.parse(transaction_url)
|
19
|
+
uri.query = URI.escape("amount=#{amount}&to=#{to}&memo=#{memo}")
|
20
|
+
uri.to_s
|
13
21
|
end
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
# Perform a transfer (payment)
|
24
|
+
#
|
25
|
+
# @asset.transfer 12, "bob@test.com", "For implementing shopping cart"
|
26
|
+
#
|
27
|
+
def transfer(amount,to,memo=nil)
|
28
|
+
client.access_token.post(transaction_url,{:amount=>amount,:to=>to,:memo=>memo}) if client
|
17
29
|
end
|
18
30
|
|
31
|
+
def name
|
32
|
+
@options["name"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def balance
|
36
|
+
@options["balance"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def [](key)
|
40
|
+
@options[key] if @options
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def uri
|
47
|
+
@uri ||= URI.parse(url)
|
48
|
+
end
|
19
49
|
end
|
20
50
|
end
|
data/lib/opentransact/client.rb
CHANGED
@@ -1,27 +1,97 @@
|
|
1
|
+
require 'oauth'
|
1
2
|
require 'oauth/tokens/access_token'
|
3
|
+
require 'multi_json'
|
2
4
|
module OpenTransact
|
5
|
+
# The main OpenTransact client access point. It wraps around an OAuth Token.
|
3
6
|
class Client
|
4
|
-
attr_accessor :
|
7
|
+
attr_accessor :server, :token, :secret, :options, :site
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# Create a client:
|
10
|
+
#
|
11
|
+
# # no oauth
|
12
|
+
# @client = OpenTransact::Client.new "http://picomoney.com"
|
13
|
+
#
|
14
|
+
# # with oauth credentials
|
15
|
+
# @client = OpenTransact::Client.new "https://picomoney.com",
|
16
|
+
# :token => "my token", :secret => "my secret",
|
17
|
+
# :consumer_key => "consumer key", :consumer_secret => "consumer secret"
|
18
|
+
#
|
19
|
+
# # with pre initialized server
|
20
|
+
# @client = OpenTransact::Client.new "https://picomoney.com",
|
21
|
+
# => :server => @server,
|
22
|
+
# :token => "my token", :secret => "my secret"
|
23
|
+
#
|
24
|
+
def initialize(*params)
|
25
|
+
@options = params.pop if params.last.is_a?(Hash)
|
26
|
+
@options ||= {}
|
27
|
+
@site = params.first || options[:site]
|
12
28
|
end
|
13
29
|
|
14
|
-
|
15
|
-
|
30
|
+
# returns an oauth access token
|
31
|
+
def access_token
|
32
|
+
@access_token ||= OAuth::AccessToken.new server.consumer, token, secret if server
|
16
33
|
end
|
17
34
|
|
18
|
-
|
19
|
-
|
35
|
+
# returns the assets on a particular server
|
36
|
+
def assets
|
37
|
+
[]
|
38
|
+
end
|
39
|
+
|
40
|
+
# returns the assets on the server for a particular client
|
41
|
+
def wallet
|
42
|
+
@wallet ||= wallet_list.collect do |a|
|
43
|
+
OpenTransact::Asset.new(a.delete("url"),a.merge({:client=>self}))
|
44
|
+
end
|
20
45
|
end
|
21
46
|
|
47
|
+
def wallet_list
|
48
|
+
@wallet_list ||= get(server.rel_link("http://opentransact.org/rel/wallet"))["assets"] ||[]
|
49
|
+
end
|
50
|
+
|
22
51
|
def server
|
23
|
-
@server ||=
|
52
|
+
@server ||= options[:server] || OpenTransact::Server.new( :url=>site, :key=>options[:consumer_key], :secret=>options[:consumer_secret])
|
53
|
+
end
|
54
|
+
|
55
|
+
def put(path,params={})
|
56
|
+
parse(access_token.put(path,params, {'Accept' => 'application/json'}))
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(path)
|
60
|
+
parse(access_token.delete(path, {'Accept' => 'application/json'}))
|
24
61
|
end
|
62
|
+
|
63
|
+
def post(path,params={})
|
64
|
+
parse(access_token.post(path,params, {'Accept' => 'application/json'}))
|
65
|
+
end
|
66
|
+
|
67
|
+
def get(path)
|
68
|
+
parse(access_token.get(path, {'Accept' => 'application/json'}))
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
def parse(response)
|
75
|
+
return false unless response
|
76
|
+
if ["200","201"].include? response.code
|
77
|
+
unless response.body.nil?
|
78
|
+
MultiJson.decode(response.body)
|
79
|
+
else
|
80
|
+
true
|
81
|
+
end
|
82
|
+
else
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def token
|
89
|
+
options[:token]
|
90
|
+
end
|
25
91
|
|
92
|
+
def secret
|
93
|
+
options[:secret]
|
94
|
+
end
|
95
|
+
|
26
96
|
end
|
27
97
|
end
|
data/lib/opentransact/server.rb
CHANGED
@@ -1,15 +1,60 @@
|
|
1
1
|
require 'oauth/consumer'
|
2
|
+
require 'net/https'
|
3
|
+
require 'multi_xml'
|
2
4
|
module OpenTransact
|
5
|
+
|
6
|
+
# This class initially maintains and creates the OAuth Consumer for a particular OAuth site. The idea though is for it to
|
7
|
+
# handle various other discovery related features
|
3
8
|
class Server
|
4
9
|
attr_accessor :url, :options
|
5
10
|
|
11
|
+
# Create a server with the url option and optional key and secret
|
12
|
+
|
6
13
|
def initialize(options={})
|
7
14
|
@options=options||{}
|
8
15
|
@url=options[:url]
|
9
16
|
end
|
10
17
|
|
18
|
+
# returns the wellknown url for host-meta
|
19
|
+
def host_meta_url
|
20
|
+
host_meta_uri.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns host_meta xml document
|
24
|
+
def host_meta
|
25
|
+
@host_meta ||= begin
|
26
|
+
request = Net::HTTP::Get.new(host_meta_uri.path)
|
27
|
+
http = Net::HTTP.new(host_meta_uri.host, host_meta_uri.port)
|
28
|
+
http.use_ssl = (host_meta_uri.port==443)
|
29
|
+
response = http.start {|http| http.request(request) }
|
30
|
+
raise OpenTransact::UndiscoverableResource unless response.code=="200"
|
31
|
+
MultiXml.parse(response.body)["XRD"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# returns a rel link from host meta
|
36
|
+
def rel_link(rel)
|
37
|
+
host_meta["Link"].detect{|l| l["rel"]==rel}["href"] if host_meta && host_meta["Link"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def [](key)
|
41
|
+
@options[key] if @options
|
42
|
+
end
|
43
|
+
|
11
44
|
def consumer
|
12
45
|
@consumer ||= OAuth::Consumer.new @options[:key], @options[:secret], :site=>@url
|
13
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def host_meta_uri
|
51
|
+
@uri ||= begin
|
52
|
+
uri = URI.parse(@url)
|
53
|
+
uri.path="/.well-known/host-meta"
|
54
|
+
uri.query=nil
|
55
|
+
uri
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
14
59
|
end
|
15
60
|
end
|
data/lib/opentransact/version.rb
CHANGED
data/lib/opentransact.rb
CHANGED
data/opentransact.gemspec
CHANGED
@@ -24,5 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "fuubar"
|
25
25
|
s.add_development_dependency "guard-rspec"
|
26
26
|
s.add_development_dependency "growl"
|
27
|
+
# s.add_development_dependency "nokogiri"
|
27
28
|
s.add_dependency "oauth", "~> 0.4.4"
|
29
|
+
s.add_dependency "multi_json"
|
30
|
+
s.add_dependency "multi_xml"
|
28
31
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
3
|
+
xmlns:hm='http://host-meta.net/ns/1.0'>
|
4
|
+
<hm:Host>picomoney.com</hm:Host>
|
5
|
+
<Link rel='lrdd'
|
6
|
+
template='https://picomoney.com/webfinger?uri={uri}'>
|
7
|
+
<Title>Resource Descriptor</Title>
|
8
|
+
</Link>
|
9
|
+
<Link rel="http://opentransact.org/rel/assets"
|
10
|
+
href="https://picomoney.com/.well-known/opentransact">
|
11
|
+
<Title>OpenTransact Assets</Title>
|
12
|
+
</Link>
|
13
|
+
<Link rel="http://opentransact.org/rel/wallet"
|
14
|
+
href="https://picomoney.com/wallet">
|
15
|
+
<Title>Authenticated OpenTransact Wallet</Title>
|
16
|
+
</Link>
|
17
|
+
<Link rel="http://opentransact.org/rel/history"
|
18
|
+
href="https://picomoney.com/picos/all">
|
19
|
+
<Title>OpenTransact Transactions</Title>
|
20
|
+
</Link>
|
21
|
+
<Link rel="http://oauth.net/core/1.0/endpoint/requests"
|
22
|
+
href="https://picomoney.com/oauth/request_token">
|
23
|
+
<Title>OAuth 1.0 Request Token</Title>
|
24
|
+
</Link>
|
25
|
+
<Link rel="http://oauth.net/core/1.0/endpoint/access"
|
26
|
+
href="https://picomoney.com/oauth/access_token">
|
27
|
+
<Title>OAuth 1.0 Access Token</Title>
|
28
|
+
</Link>
|
29
|
+
<Link rel="http://oauth.net/core/1.0/endpoint/authorize"
|
30
|
+
href="https://picomoney.com/oauth/authorize">
|
31
|
+
<Title>OAuth 1.0 User Authorization</Title>
|
32
|
+
</Link>
|
33
|
+
<Link rel="http://oauth.net/discovery/1.0/consumer-identity/oob"
|
34
|
+
href="https://picomoney.com/client_applications/new">
|
35
|
+
<Title>OAuth 1.0 Register Client Application</Title>
|
36
|
+
</Link>
|
37
|
+
|
38
|
+
</XRD>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"encoding":"UTF8",
|
3
|
+
"total":3,"version":1.0,"start":1,
|
4
|
+
"assets":[
|
5
|
+
{"name":"PicoPoints","url":"https://picomoney.com/picopoints", "balance":123},
|
6
|
+
{"name":"Bob Smith hours","url":"https://picomoney.com/bob-smith-hours", "balance":3},
|
7
|
+
{"name":"OpenTransact Karma","url":"https://picomoney.com/opentransact-karma"}
|
8
|
+
]
|
9
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
|
3
|
+
|
4
|
+
<Subject>acct:pelle@picomoney.com</Subject>
|
5
|
+
|
6
|
+
<Alias>https://picomoney.com/profiles/pelle</Alias>
|
7
|
+
|
8
|
+
<Link rel='http://webfinger.net/rel/profile-page'
|
9
|
+
type='text/html'
|
10
|
+
href='https://picomoney.com/profiles/pelle' />
|
11
|
+
<Link rel='http://microformats.org/profile/hcard'
|
12
|
+
type='text/html'
|
13
|
+
href='https://picomoney.com/profiles/pelle' />
|
14
|
+
<Link rel='describedby'
|
15
|
+
type='text/html'
|
16
|
+
href='https://picomoney.com/profiles/pelle' />
|
17
|
+
<Link rel='http://webfinger.net/rel/avatar'
|
18
|
+
href='http://s3.amazonaws.com/picomoney.com/avatars/1/thumb/pelle_gravatar_320.jpg?1288973770'/>
|
19
|
+
<Link rel='http://opentransact.org/rel/wallet'
|
20
|
+
href='https://picomoney.com/wallets/pelle' />
|
21
|
+
|
22
|
+
</XRD>
|
@@ -4,37 +4,38 @@ describe OpenTransact::Asset do
|
|
4
4
|
describe "defaults" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@asset = OpenTransact::Asset.new "
|
7
|
+
@asset = OpenTransact::Asset.new "https://picomoney.com"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should have url" do
|
11
|
-
@asset.url.should == "
|
11
|
+
@asset.url.should == "https://picomoney.com"
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have transaction url" do
|
15
|
-
@asset.transaction_url.should == "
|
15
|
+
@asset.transaction_url.should == "https://picomoney.com"
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "should create payment_url" do
|
19
|
+
@asset.transfer_url(1123, "bob@test.com", "2 cows").should == "https://picomoney.com?amount=1123&to=bob@test.com&memo=2%20cows"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "direct transfer" do
|
19
23
|
before(:each) do
|
20
|
-
@
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have site" do
|
24
|
-
@server.url.should=="http://nubux.heroku.com"
|
24
|
+
@asset.client = OpenTransact::Client.new :site => "https://picomoney.com", :token=>"my token", :secret=>"my secret"
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
describe "transfer" do
|
28
|
+
before(:each) do
|
29
|
+
@access_token = @asset.client.access_token
|
30
|
+
@access_token.should_receive(:post).with("https://picomoney.com",{:amount=>1123,:to=>"bob",:memo=>"2 cows"})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should perform transfer" do
|
34
|
+
@asset.transfer 1123, "bob", "2 cows"
|
35
|
+
end
|
29
36
|
end
|
30
37
|
|
31
|
-
it "should have secret" do
|
32
|
-
@server.consumer.secret.should be_nil
|
33
|
-
end
|
34
38
|
|
35
|
-
it "should have a consumer" do
|
36
|
-
@asset.consumer.should == @server.consumer
|
37
|
-
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
end
|
41
|
+
end
|
@@ -1,43 +1,117 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe OpenTransact::Client do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
describe "no credentials" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@client = OpenTransact::Client.new "https://picomoney.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not have assets" do
|
12
|
+
@client.assets.should == []
|
13
|
+
end
|
14
|
+
|
15
|
+
it "have site" do
|
16
|
+
@client.site.should == "https://picomoney.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "server" do
|
20
|
+
subject { @client.server }
|
21
|
+
it { should_not be_nil }
|
22
|
+
it { subject.url.should == "https://picomoney.com" }
|
23
|
+
it { subject[:key].should be_nil }
|
24
|
+
it { subject[:secret].should be_nil }
|
25
|
+
|
26
|
+
end
|
7
27
|
end
|
8
28
|
|
9
|
-
describe "
|
29
|
+
describe "no credentials site in options" do
|
10
30
|
|
11
31
|
before(:each) do
|
12
|
-
@client = OpenTransact::Client.new
|
32
|
+
@client = OpenTransact::Client.new :site => "https://picomoney.com"
|
13
33
|
end
|
14
34
|
|
15
|
-
it "should not have
|
16
|
-
@client.
|
35
|
+
it "should not have assets" do
|
36
|
+
@client.assets.should == []
|
17
37
|
end
|
18
38
|
|
39
|
+
it "have site" do
|
40
|
+
@client.site.should == "https://picomoney.com"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe "server" do
|
45
|
+
subject { @client.server }
|
46
|
+
it { should_not be_nil }
|
47
|
+
it { subject.url.should == "https://picomoney.com" }
|
48
|
+
end
|
19
49
|
end
|
20
50
|
|
21
51
|
describe "with token" do
|
22
52
|
|
23
53
|
before(:each) do
|
24
|
-
@client = OpenTransact::Client.new
|
54
|
+
@client = OpenTransact::Client.new "https://picomoney.com",
|
55
|
+
:token => "my token", :secret => "my secret",
|
56
|
+
:consumer_key => "consumer key", :consumer_secret => "consumer secret"
|
57
|
+
|
25
58
|
end
|
26
59
|
|
27
60
|
it "should have token" do
|
28
|
-
@client.token.should=="my token"
|
61
|
+
@client.send(:token).should=="my token"
|
29
62
|
end
|
30
63
|
|
31
64
|
it "should have secret" do
|
32
|
-
@client.secret.should=="my secret"
|
65
|
+
@client.send(:secret).should=="my secret"
|
33
66
|
end
|
34
67
|
|
35
|
-
|
36
|
-
@client.
|
68
|
+
describe "server" do
|
69
|
+
subject { @client.server }
|
70
|
+
it { should_not be_nil }
|
71
|
+
it { subject.url.should == "https://picomoney.com" }
|
72
|
+
|
73
|
+
it { subject[:key].should == "consumer key" }
|
74
|
+
it { subject[:secret].should == "consumer secret" }
|
37
75
|
end
|
38
76
|
|
39
|
-
|
40
|
-
|
77
|
+
describe "wallet" do
|
78
|
+
before(:each) do
|
79
|
+
FakeWeb.register_uri(:get, "https://picomoney.com/.well-known/host-meta", :body => read_fixture("host-meta.xml"))
|
80
|
+
FakeWeb.register_uri(:get, "https://picomoney.com/wallet", :body => read_fixture("wallet_with_balances.json"))
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should have wallet list" do
|
84
|
+
@client.wallet_list.should == [
|
85
|
+
{"name"=>"PicoPoints", "url"=>"https://picomoney.com/picopoints", "balance"=>123},
|
86
|
+
{"name"=>"Bob Smith hours", "url"=>"https://picomoney.com/bob-smith-hours", "balance"=>3},
|
87
|
+
{"name"=>"OpenTransact Karma", "url"=>"https://picomoney.com/opentransact-karma"}]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have 3 assets wallet" do
|
91
|
+
@client.should have(3).wallet
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "asset" do
|
95
|
+
before(:each) do
|
96
|
+
@asset = @client.wallet.first
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have name" do
|
100
|
+
@asset.name.should == "PicoPoints"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should have url" do
|
104
|
+
@asset.url.should == "https://picomoney.com/picopoints"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should have balance" do
|
108
|
+
@asset.balance.should == 123
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should have client" do
|
112
|
+
@asset.client.should == @client
|
113
|
+
end
|
114
|
+
end
|
41
115
|
end
|
42
116
|
|
43
117
|
describe "access token" do
|
@@ -45,8 +119,12 @@ describe OpenTransact::Client do
|
|
45
119
|
@access_token = @client.access_token
|
46
120
|
end
|
47
121
|
|
122
|
+
it "have be created" do
|
123
|
+
@access_token.should_not be_nil
|
124
|
+
end
|
125
|
+
|
48
126
|
it "should have assets consumer" do
|
49
|
-
@access_token.consumer.should == @
|
127
|
+
@access_token.consumer.should == @client.server.consumer
|
50
128
|
end
|
51
129
|
|
52
130
|
it "should have token" do
|
@@ -56,17 +134,6 @@ describe OpenTransact::Client do
|
|
56
134
|
it "should have secret" do
|
57
135
|
@access_token.secret.should=="my secret"
|
58
136
|
end
|
59
|
-
|
60
|
-
|
61
|
-
describe "transfer" do
|
62
|
-
before(:each) do
|
63
|
-
@access_token.should_receive(:post).with("http://nubux.heroku.com",{:amount=>1123,:to=>"bob",:memo=>"2 cows"})
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should perform transfer" do
|
67
|
-
@client.transfer 1123, "bob", "2 cows"
|
68
|
-
end
|
69
|
-
end
|
70
137
|
end
|
71
138
|
end
|
72
139
|
|
@@ -1,14 +1,69 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe OpenTransact::Server do
|
4
|
-
describe "
|
4
|
+
describe "without credentials" do
|
5
|
+
before(:each) do
|
6
|
+
@server = OpenTransact::Server.new :url => "https://picomoney.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have host-meta url" do
|
10
|
+
@server.host_meta_url.should == "https://picomoney.com/.well-known/host-meta"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have url" do
|
14
|
+
@server.url.should == "https://picomoney.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "check host-meta" do
|
18
|
+
before(:each) do
|
19
|
+
FakeWeb.register_uri(:get, "https://picomoney.com/.well-known/host-meta", :body => read_fixture("host-meta.xml"))
|
20
|
+
end
|
21
|
+
|
22
|
+
{
|
23
|
+
"http://opentransact.org/rel/wallet" => "https://picomoney.com/wallet",
|
24
|
+
"http://opentransact.org/rel/assets" => "https://picomoney.com/.well-known/opentransact",
|
25
|
+
"http://opentransact.org/rel/history" => "https://picomoney.com/picos/all"
|
26
|
+
}.each do |rel|
|
27
|
+
|
28
|
+
it "should have #{rel[0]} link" do
|
29
|
+
@server.rel_link(rel[0]).should == rel[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "no host-meta" do
|
37
|
+
before(:each) do
|
38
|
+
FakeWeb.register_uri(:get, "https://picomoney.com/.well-known/host-meta", :status => ["404", "Not Found"])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise Undiscoverable Resource" do
|
42
|
+
lambda { @server.host_meta }.should raise_error(OpenTransact::UndiscoverableResource)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "with consumer credentials" do
|
5
48
|
|
6
49
|
before(:each) do
|
7
|
-
@server = OpenTransact::Server.new :url => "
|
50
|
+
@server = OpenTransact::Server.new :url => "https://picomoney.com", :key=>"consumer_key", :secret=>"consumer_secret"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have host-meta url" do
|
54
|
+
@server.host_meta_url.should == "https://picomoney.com/.well-known/host-meta"
|
8
55
|
end
|
9
56
|
|
10
57
|
it "should have url" do
|
11
|
-
@server.url.should == "
|
58
|
+
@server.url.should == "https://picomoney.com"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "have key" do
|
62
|
+
@server[:key].should == "consumer_key"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "have secret" do
|
66
|
+
@server[:secret].should == "consumer_secret"
|
12
67
|
end
|
13
68
|
|
14
69
|
describe "Consumer" do
|
@@ -17,7 +72,7 @@ describe OpenTransact::Server do
|
|
17
72
|
end
|
18
73
|
|
19
74
|
it "should have site" do
|
20
|
-
@consumer.site.should=="
|
75
|
+
@consumer.site.should=="https://picomoney.com"
|
21
76
|
end
|
22
77
|
|
23
78
|
it "should have key" do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,11 @@ require 'opentransact'
|
|
4
4
|
require 'fakeweb'
|
5
5
|
require 'rspec'
|
6
6
|
|
7
|
-
RSpec::
|
7
|
+
RSpec::configure do |config|
|
8
8
|
FakeWeb.allow_net_connect = false
|
9
9
|
end
|
10
|
+
|
11
|
+
|
12
|
+
def read_fixture(name)
|
13
|
+
File.read(File.join(File.dirname(__FILE__),'fixtures',name))
|
14
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.2
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pelle Braendgaard
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-29 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,32 @@ dependencies:
|
|
99
99
|
version: 0.4.4
|
100
100
|
type: :runtime
|
101
101
|
version_requirements: *id006
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: multi_json
|
104
|
+
prerelease: false
|
105
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
type: :runtime
|
114
|
+
version_requirements: *id007
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: multi_xml
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
type: :runtime
|
127
|
+
version_requirements: *id008
|
102
128
|
description: OpenTransact client for Ruby
|
103
129
|
email:
|
104
130
|
- pelle@stakeventures.com
|
@@ -124,6 +150,9 @@ files:
|
|
124
150
|
- lib/opentransact/server.rb
|
125
151
|
- lib/opentransact/version.rb
|
126
152
|
- opentransact.gemspec
|
153
|
+
- spec/fixtures/host-meta.xml
|
154
|
+
- spec/fixtures/wallet_with_balances.json
|
155
|
+
- spec/fixtures/webfinger.xml
|
127
156
|
- spec/opentransact/asset_spec.rb
|
128
157
|
- spec/opentransact/client_spec.rb
|
129
158
|
- spec/opentransact/server_spec.rb
|
@@ -161,6 +190,9 @@ signing_key:
|
|
161
190
|
specification_version: 3
|
162
191
|
summary: OpenTransact client for Ruby
|
163
192
|
test_files:
|
193
|
+
- spec/fixtures/host-meta.xml
|
194
|
+
- spec/fixtures/wallet_with_balances.json
|
195
|
+
- spec/fixtures/webfinger.xml
|
164
196
|
- spec/opentransact/asset_spec.rb
|
165
197
|
- spec/opentransact/client_spec.rb
|
166
198
|
- spec/opentransact/server_spec.rb
|