dwolla 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +74 -0
- data/Rakefile +5 -0
- data/dwolla.gemspec +29 -0
- data/lib/dwolla/client.rb +20 -0
- data/lib/dwolla/connection.rb +45 -0
- data/lib/dwolla/response/parse_json.rb +27 -0
- data/lib/dwolla/transaction.rb +32 -0
- data/lib/dwolla/user.rb +82 -0
- data/lib/dwolla/version.rb +3 -0
- data/lib/dwolla.rb +38 -0
- data/spec/dwolla/client_spec.rb +27 -0
- data/spec/dwolla/transaction_spec.rb +79 -0
- data/spec/dwolla/user_spec.rb +168 -0
- data/spec/dwolla_spec.rb +18 -0
- data/spec/fixtures/account_information.json +13 -0
- data/spec/fixtures/balance.json +5 -0
- data/spec/fixtures/basic_information.json +6 -0
- data/spec/fixtures/contacts.json +18 -0
- data/spec/fixtures/request_transaction.json +3 -0
- data/spec/fixtures/send_transaction.json +3 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/helpers.rb +29 -0
- metadata +164 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Dwolla Ruby Gem
|
2
|
+
|
3
|
+
A Dwolla API wrapper in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install dwolla
|
8
|
+
|
9
|
+
## Resources
|
10
|
+
|
11
|
+
* View Source on GitHub (https://github.com/jeffersongirao/dwolla)
|
12
|
+
* Report Issues on GitHub (https://github.com/jeffersongirao/dwolla/issues)
|
13
|
+
|
14
|
+
#### Users API
|
15
|
+
|
16
|
+
##### With Access Token
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
user = Dwolla::User.me(ACCESS_TOKEN).fetch
|
20
|
+
```
|
21
|
+
|
22
|
+
##### With Client ID and Secret
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
client = Dwolla::Client.new(CLIENT_ID, SECRET)
|
26
|
+
user = client.user(ACCOUNT_ID) # Dwolla account identifier or email address of the Dwolla account.
|
27
|
+
```
|
28
|
+
|
29
|
+
#### Balance API
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
user = Dwolla::User.me(ACCESS_TOKEN)
|
33
|
+
user.balance
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Contacts API
|
37
|
+
|
38
|
+
##### User Contacts
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
user = Dwolla::User.me(ACCESS_TOKEN)
|
42
|
+
|
43
|
+
# limit default is 10
|
44
|
+
# max limit is 200
|
45
|
+
|
46
|
+
# type default is "Dwolla"
|
47
|
+
# valid types are "All", "Twitter", "Facebook", "LinkedIn" and "Dwolla"
|
48
|
+
|
49
|
+
user.contacts(:search => "Bob", :type => "Dwolla", :limit => 5)
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Transactions API
|
53
|
+
|
54
|
+
##### Sending Money
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
user = Dwolla::User.me(ACCESS_TOKEN)
|
58
|
+
other_user_id = 'sample@user.com' # or the Dwolla account id
|
59
|
+
pin = '1234'
|
60
|
+
amount = 200
|
61
|
+
|
62
|
+
user.send_money_to(other_user_id, amount, pin)
|
63
|
+
```
|
64
|
+
|
65
|
+
##### Requesting Money
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
user = Dwolla::User.me(ACCESS_TOKEN)
|
69
|
+
other_user_id = 'sample@user.com' # or the Dwolla account id
|
70
|
+
pin = '1234'
|
71
|
+
amount = 200
|
72
|
+
|
73
|
+
user.request_money_from(other_user_id, amount, pin)
|
74
|
+
```
|
data/Rakefile
ADDED
data/dwolla.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dwolla/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dwolla"
|
7
|
+
s.version = Dwolla::VERSION
|
8
|
+
s.authors = ["Jefferson Girao"]
|
9
|
+
s.email = ["contato@jefferson.eti.br"]
|
10
|
+
s.homepage = "https://github.com/jeffersongirao/dwolla"
|
11
|
+
s.summary = %q{A Ruby wrapper for the Dwolla API.}
|
12
|
+
s.description = %q{A Ruby wrapper for the Dwolla API.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "dwolla"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'jeffersongirao_faraday-stack'
|
22
|
+
s.add_dependency 'multi_json'
|
23
|
+
|
24
|
+
s.add_development_dependency 'bundler'
|
25
|
+
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'rspec'
|
27
|
+
s.add_development_dependency 'webmock'
|
28
|
+
s.add_development_dependency 'simplecov'
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dwolla
|
2
|
+
class Client
|
3
|
+
include Dwolla::Connection
|
4
|
+
|
5
|
+
def initialize(client, secret)
|
6
|
+
@client, @secret = client, secret
|
7
|
+
end
|
8
|
+
|
9
|
+
def user(id)
|
10
|
+
user_attributes_hash = get("users/#{id}")
|
11
|
+
User.new(user_attributes_hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def auth_params
|
17
|
+
{ :client_id => @client, :client_secret => @secret }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Dwolla
|
2
|
+
module Connection
|
3
|
+
private
|
4
|
+
def connection
|
5
|
+
default_options = {
|
6
|
+
:headers => {
|
7
|
+
:accept => 'application/json',
|
8
|
+
:user_agent => Dwolla.user_agent,
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
@connection ||= Faraday.new(Dwolla.endpoint, default_options) do |builder|
|
13
|
+
builder.use FaradayStack::FollowRedirects
|
14
|
+
|
15
|
+
builder.use Dwolla::Response::ParseJson
|
16
|
+
builder.use Faraday::Request::UrlEncoded
|
17
|
+
|
18
|
+
builder.response :logger if Dwolla.debugging?
|
19
|
+
builder.adapter Faraday.default_adapter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(path, params={})
|
24
|
+
request(:get, path, params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(path, params={})
|
28
|
+
request(:post, path, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(method, path, params)
|
32
|
+
response = connection.send(method) do |request|
|
33
|
+
case method.to_sym
|
34
|
+
when :delete, :get
|
35
|
+
request.url(path, params.merge(auth_params))
|
36
|
+
when :post
|
37
|
+
request.path = path
|
38
|
+
params.merge!(auth_params) if auth_params
|
39
|
+
request.body = params unless params.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Dwolla
|
5
|
+
module Response
|
6
|
+
class ParseJson < Faraday::Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
if respond_to? :parse
|
9
|
+
env[:body] = parse(env[:body]) unless [204,302,304,307].index env[:status]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(body)
|
14
|
+
case body
|
15
|
+
when ''
|
16
|
+
nil
|
17
|
+
else
|
18
|
+
response_hash = ::MultiJson.decode(body)
|
19
|
+
response_hash["Response"] ||
|
20
|
+
response_hash["SendResult"] ||
|
21
|
+
response_hash["RequestResult"] ||
|
22
|
+
response_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Dwolla
|
2
|
+
class Transaction
|
3
|
+
include Dwolla::Connection
|
4
|
+
|
5
|
+
ENDPOINTS = { :send => 'transactions/send',
|
6
|
+
:request => 'transactions/request' }
|
7
|
+
|
8
|
+
attr_accessor :origin, :destination, :type, :amount, :pin, :id
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
attrs.each do |key, value|
|
12
|
+
send("#{key}=".to_sym, value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
self.id = post(ENDPOINTS[type], to_payload)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def auth_params
|
23
|
+
{ :oauth_token => origin.oauth_token }
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_payload
|
27
|
+
{ :destinationId => destination.id,
|
28
|
+
:amount => amount.to_s,
|
29
|
+
:pin => pin }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/dwolla/user.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Dwolla
|
2
|
+
class User
|
3
|
+
include Dwolla::Connection
|
4
|
+
|
5
|
+
attr_accessor :id,
|
6
|
+
:name,
|
7
|
+
:latitude,
|
8
|
+
:longitude,
|
9
|
+
:city,
|
10
|
+
:state,
|
11
|
+
:type,
|
12
|
+
:contact_type,
|
13
|
+
:image,
|
14
|
+
:oauth_token
|
15
|
+
|
16
|
+
def initialize(attrs={})
|
17
|
+
update_attributes(attrs)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.me(access_token)
|
21
|
+
User.new(:oauth_token => access_token)
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch
|
25
|
+
user_attributes_hash = get('users')
|
26
|
+
update_attributes(user_attributes_hash)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_attributes(attrs)
|
31
|
+
attrs.each do |key, value|
|
32
|
+
send("#{key.downcase}=".to_sym, value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def balance
|
37
|
+
get('balance')
|
38
|
+
end
|
39
|
+
|
40
|
+
def contacts(options = {})
|
41
|
+
contacts_url = 'contacts'
|
42
|
+
contacts = get(contacts_url, options)
|
43
|
+
|
44
|
+
instances_from_contacts(contacts)
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_money_to(destination, amount, pin)
|
48
|
+
transaction = Transaction.new(:origin => self,
|
49
|
+
:destination => destination,
|
50
|
+
:type => :send,
|
51
|
+
:amount => amount,
|
52
|
+
:pin => pin)
|
53
|
+
|
54
|
+
transaction.execute
|
55
|
+
end
|
56
|
+
|
57
|
+
def request_money_from(destination, amount, pin)
|
58
|
+
transaction = Transaction.new(:origin => self,
|
59
|
+
:destination => destination,
|
60
|
+
:type => :request,
|
61
|
+
:amount => amount,
|
62
|
+
:pin => pin)
|
63
|
+
transaction.execute
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def instances_from_contacts(contacts)
|
69
|
+
user_instances = []
|
70
|
+
contacts.each do |contact|
|
71
|
+
contact["Contact_Type"] = contact["Type"]
|
72
|
+
contact.delete("Type")
|
73
|
+
user_instances << User.new(contact)
|
74
|
+
end
|
75
|
+
user_instances
|
76
|
+
end
|
77
|
+
|
78
|
+
def auth_params
|
79
|
+
{ :oauth_token => self.oauth_token }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/dwolla.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'faraday_stack'
|
2
|
+
|
3
|
+
module Dwolla
|
4
|
+
def self.endpoint=(endpoint)
|
5
|
+
@@endpoint = endpoint
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.endpoint
|
9
|
+
@@endpoint
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.user_agent=(user_agent)
|
13
|
+
@@user_agent = user_agent
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.user_agent
|
17
|
+
@@user_agent
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.debugging?
|
21
|
+
!!@@debug
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.debug=(debug)
|
25
|
+
@@debug = debug
|
26
|
+
end
|
27
|
+
|
28
|
+
self.debug = false
|
29
|
+
self.user_agent = "Dwolla Ruby Wrapper"
|
30
|
+
self.endpoint = "https://www.dwolla.com/oauth/rest"
|
31
|
+
end
|
32
|
+
|
33
|
+
require "dwolla/response/parse_json"
|
34
|
+
require "dwolla/connection"
|
35
|
+
require "dwolla/client"
|
36
|
+
require "dwolla/transaction"
|
37
|
+
require "dwolla/user"
|
38
|
+
require "dwolla/version"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dwolla::Client do
|
4
|
+
subject { Dwolla::Client.new('sample_client_id', 'sample_client_secret') }
|
5
|
+
let(:query_params) { "client_id=sample_client_id&client_secret=sample_client_secret" }
|
6
|
+
|
7
|
+
describe "getting user basic information" do
|
8
|
+
before do
|
9
|
+
stub_get('/users/812-111-1111', query_params).
|
10
|
+
to_return(:body => fixture("basic_information.json"))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should request the correct resource' do
|
14
|
+
subject.user('812-111-1111')
|
15
|
+
a_get('/users/812-111-1111', query_params).should have_been_made
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return extended information of a given user' do
|
19
|
+
user = subject.user('812-111-1111')
|
20
|
+
user.should be_a Dwolla::User
|
21
|
+
user.id.should == '812-111-1111'
|
22
|
+
user.name.should == 'Test User'
|
23
|
+
user.latitude.should == 41.584546
|
24
|
+
user.longitude.should == -93.634167
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dwolla::Transaction do
|
4
|
+
describe "send transaction" do
|
5
|
+
before do
|
6
|
+
@origin = double(:oauth_token => '1')
|
7
|
+
@destination = double(:id => '2')
|
8
|
+
|
9
|
+
@payload = { :oauth_token => '1',
|
10
|
+
:destinationId => '2',
|
11
|
+
:amount => '200',
|
12
|
+
:pin => '1234' }
|
13
|
+
|
14
|
+
stub_post('/transactions/send').with(:body => @payload).to_return(
|
15
|
+
:body => fixture('send_transaction.json'))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should request the correct resource" do
|
19
|
+
transaction = Dwolla::Transaction.new(:origin => @origin,
|
20
|
+
:destination => @destination,
|
21
|
+
:type => :send,
|
22
|
+
:amount => 200,
|
23
|
+
:pin => '1234')
|
24
|
+
transaction.execute
|
25
|
+
|
26
|
+
a_post('/transactions/send').
|
27
|
+
with(:body => @payload).should have_been_made
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should fetch the id if transaction succesfull" do
|
31
|
+
transaction = Dwolla::Transaction.new(:origin => @origin,
|
32
|
+
:destination => @destination,
|
33
|
+
:type => :send,
|
34
|
+
:amount => 200,
|
35
|
+
:pin => '1234')
|
36
|
+
|
37
|
+
transaction.execute.should == 12345
|
38
|
+
transaction.id.should == 12345
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "request transaction" do
|
43
|
+
before do
|
44
|
+
@origin = double(:oauth_token => '1')
|
45
|
+
@destination = double(:id => '2')
|
46
|
+
|
47
|
+
@payload = { :oauth_token => '1',
|
48
|
+
:destinationId => '2',
|
49
|
+
:amount => '200',
|
50
|
+
:pin => '1234' }
|
51
|
+
|
52
|
+
stub_post('/transactions/request').with(:body => @payload).to_return(
|
53
|
+
:body => fixture('request_transaction.json'))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should request the correct resource" do
|
57
|
+
transaction = Dwolla::Transaction.new(:origin => @origin,
|
58
|
+
:destination => @destination,
|
59
|
+
:type => :request,
|
60
|
+
:amount => 200,
|
61
|
+
:pin => '1234')
|
62
|
+
transaction.execute
|
63
|
+
|
64
|
+
a_post('/transactions/request').
|
65
|
+
with(:body => @payload).should have_been_made
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should fetch the id if transaction succesfull" do
|
69
|
+
transaction = Dwolla::Transaction.new(:origin => @origin,
|
70
|
+
:destination => @destination,
|
71
|
+
:type => :request,
|
72
|
+
:amount => 200,
|
73
|
+
:pin => '1234')
|
74
|
+
|
75
|
+
transaction.execute.should == 12345
|
76
|
+
transaction.id.should == 12345
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dwolla::User do
|
4
|
+
let(:oauth_token) { 'valid_token' }
|
5
|
+
let(:token_param) { "oauth_token=#{oauth_token}" }
|
6
|
+
|
7
|
+
describe "fetching your full account information" do
|
8
|
+
before do
|
9
|
+
stub_get('/users', token_param).
|
10
|
+
to_return(:body => fixture("account_information.json"))
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should request the correct resource" do
|
14
|
+
user = Dwolla::User.me(oauth_token).fetch
|
15
|
+
|
16
|
+
a_get('/users', token_param).should have_been_made
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return full information" do
|
20
|
+
user = Dwolla::User.me(oauth_token).fetch
|
21
|
+
|
22
|
+
user.should be_a Dwolla::User
|
23
|
+
user.id.should == '812-111-1111'
|
24
|
+
user.name.should == 'Test User'
|
25
|
+
user.latitude.should == 41.584546
|
26
|
+
user.longitude.should == -93.634167
|
27
|
+
user.city.should == 'Des Moines'
|
28
|
+
user.state.should == 'IA'
|
29
|
+
user.type.should == 'Personal'
|
30
|
+
user.oauth_token.should == oauth_token
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "sending money" do
|
35
|
+
it "should make the correct transaction" do
|
36
|
+
user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
|
37
|
+
destination_user = Dwolla::User.new(:id => '2')
|
38
|
+
amount = 10
|
39
|
+
pin = '2222'
|
40
|
+
|
41
|
+
|
42
|
+
transaction = double('transaction')
|
43
|
+
transaction_id = 123
|
44
|
+
|
45
|
+
Dwolla::Transaction.should_receive(:new).with(:origin => user,
|
46
|
+
:destination => destination_user,
|
47
|
+
:amount => 10,
|
48
|
+
:type => :send,
|
49
|
+
:pin => '2222').and_return(transaction)
|
50
|
+
|
51
|
+
transaction.should_receive(:execute).and_return(transaction_id)
|
52
|
+
|
53
|
+
user.send_money_to(destination_user, amount, pin).should == 123
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "requesting money" do
|
58
|
+
it "should make the correct transaction" do
|
59
|
+
user = Dwolla::User.new(:oauth_token => '12345', :id => '1')
|
60
|
+
destination_user = Dwolla::User.new(:id => '2')
|
61
|
+
amount = 10
|
62
|
+
pin = '2222'
|
63
|
+
|
64
|
+
transaction = double('transaction')
|
65
|
+
transaction_id = 123
|
66
|
+
|
67
|
+
Dwolla::Transaction.should_receive(:new).with(:origin => user,
|
68
|
+
:destination => destination_user,
|
69
|
+
:amount => 10,
|
70
|
+
:type => :request,
|
71
|
+
:pin => '2222').and_return(transaction)
|
72
|
+
|
73
|
+
transaction.should_receive(:execute).and_return(transaction_id)
|
74
|
+
|
75
|
+
user.request_money_from(destination_user, amount, pin).should == 123
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "knows his balance" do
|
80
|
+
stub_get('/balance', token_param).
|
81
|
+
to_return(:body => fixture("balance.json"))
|
82
|
+
|
83
|
+
user = Dwolla::User.me(oauth_token)
|
84
|
+
user.balance.should == 55.76
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "contacts" do
|
88
|
+
it "should request the correct resource when unfiltered" do
|
89
|
+
user = Dwolla::User.me(oauth_token)
|
90
|
+
|
91
|
+
stub_get('/contacts', token_param).
|
92
|
+
to_return(:body => fixture("contacts.json"))
|
93
|
+
|
94
|
+
user.contacts
|
95
|
+
|
96
|
+
a_get('/contacts', token_param).should have_been_made
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should request the correct resource when seaching by name" do
|
100
|
+
user = Dwolla::User.me(oauth_token)
|
101
|
+
|
102
|
+
stub_get("/contacts?search=Bob&#{token_param}").
|
103
|
+
to_return(:body => fixture("contacts.json"))
|
104
|
+
|
105
|
+
user.contacts(:search => 'Bob')
|
106
|
+
|
107
|
+
a_get("/contacts?search=Bob&#{token_param}").should have_been_made
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should request the correct resource when filtering by type" do
|
111
|
+
user = Dwolla::User.me(oauth_token)
|
112
|
+
|
113
|
+
stub_get("/contacts?type=Facebook&#{token_param}").
|
114
|
+
to_return(:body => fixture("contacts.json"))
|
115
|
+
|
116
|
+
user.contacts(:type => 'Facebook')
|
117
|
+
|
118
|
+
a_get("/contacts?type=Facebook&#{token_param}").should have_been_made
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should request the correct resource when limiting" do
|
122
|
+
user = Dwolla::User.me(oauth_token)
|
123
|
+
|
124
|
+
stub_get("/contacts?limit=2&#{token_param}").
|
125
|
+
to_return(:body => fixture("contacts.json"))
|
126
|
+
|
127
|
+
user.contacts(:limit => 2)
|
128
|
+
|
129
|
+
a_get("/contacts?limit=2&#{token_param}").should have_been_made
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should request the correct resource when using all together" do
|
133
|
+
user = Dwolla::User.me(oauth_token)
|
134
|
+
|
135
|
+
stub_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").
|
136
|
+
to_return(:body => fixture("contacts.json"))
|
137
|
+
|
138
|
+
user.contacts(:search => "Bob", :type => "Facebook", :limit => 2)
|
139
|
+
|
140
|
+
a_get("/contacts?search=Bob&type=Facebook&limit=2&#{token_param}").should have_been_made
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return the contact users properly" do
|
144
|
+
user = Dwolla::User.me(oauth_token)
|
145
|
+
|
146
|
+
stub_get("/contacts", token_param).
|
147
|
+
to_return(:body => fixture("contacts.json"))
|
148
|
+
|
149
|
+
contacts = user.contacts
|
150
|
+
|
151
|
+
first_contact = contacts.first
|
152
|
+
|
153
|
+
first_contact.should be_a Dwolla::User
|
154
|
+
first_contact.id.should == "12345"
|
155
|
+
first_contact.name.should == "Ben Facebook Test"
|
156
|
+
first_contact.image.should == "https://graph.facebook.com/12345/picture?type=square"
|
157
|
+
first_contact.contact_type.should == "Facebook"
|
158
|
+
|
159
|
+
second_contact = contacts.last
|
160
|
+
|
161
|
+
second_contact.should be_a Dwolla::User
|
162
|
+
second_contact.id.should == "812-111-1111"
|
163
|
+
second_contact.name.should == "Ben Dwolla Test"
|
164
|
+
second_contact.image.should == "https://www.dwolla.com/avatar.aspx?u=812-111-1111"
|
165
|
+
second_contact.contact_type.should == "Dwolla"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/spec/dwolla_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dwolla do
|
4
|
+
its(:endpoint) { should == "https://www.dwolla.com/oauth/rest" }
|
5
|
+
its(:user_agent) { should == "Dwolla Ruby Wrapper" }
|
6
|
+
|
7
|
+
describe 'debugging' do
|
8
|
+
after do
|
9
|
+
Dwolla.debug = false
|
10
|
+
end
|
11
|
+
|
12
|
+
it { should_not be_debugging }
|
13
|
+
|
14
|
+
it 'should be debugging' do
|
15
|
+
Dwolla.debug = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"Success": true,
|
3
|
+
"Message": "Success",
|
4
|
+
"Response": [
|
5
|
+
{
|
6
|
+
"Name": "Ben Facebook Test",
|
7
|
+
"Id": "12345",
|
8
|
+
"Type": "Facebook",
|
9
|
+
"Image": "https://graph.facebook.com/12345/picture?type=square"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"Name": "Ben Dwolla Test",
|
13
|
+
"Id": "812-111-1111",
|
14
|
+
"Type": "Dwolla",
|
15
|
+
"Image": "https://www.dwolla.com/avatar.aspx?u=812-111-1111"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
def a_get(path, params = nil)
|
2
|
+
url = Dwolla.endpoint + path
|
3
|
+
url += "?#{params}" if params
|
4
|
+
a_request(:get, url)
|
5
|
+
end
|
6
|
+
|
7
|
+
def a_post(path)
|
8
|
+
url = Dwolla.endpoint + path
|
9
|
+
a_request(:post, url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_get(path, params = nil)
|
13
|
+
url = Dwolla.endpoint + path
|
14
|
+
url += "?#{params}" if params
|
15
|
+
stub_request(:get, url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_post(path)
|
19
|
+
url = Dwolla.endpoint + path
|
20
|
+
stub_request(:post, url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fixture_path
|
24
|
+
File.expand_path("../../fixtures", __FILE__)
|
25
|
+
end
|
26
|
+
|
27
|
+
def fixture(file)
|
28
|
+
IO.read(fixture_path + '/' + file)
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dwolla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jefferson Girao
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jeffersongirao_faraday-stack
|
16
|
+
requirement: &2152450200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152450200
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: multi_json
|
27
|
+
requirement: &2152449680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152449680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &2152449040 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152449040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &2152448460 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152448460
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
60
|
+
requirement: &2152447840 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2152447840
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: &2152447240 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2152447240
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: simplecov
|
82
|
+
requirement: &2152446580 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2152446580
|
91
|
+
description: A Ruby wrapper for the Dwolla API.
|
92
|
+
email:
|
93
|
+
- contato@jefferson.eti.br
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- .gitignore
|
99
|
+
- Gemfile
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- dwolla.gemspec
|
103
|
+
- lib/dwolla.rb
|
104
|
+
- lib/dwolla/client.rb
|
105
|
+
- lib/dwolla/connection.rb
|
106
|
+
- lib/dwolla/response/parse_json.rb
|
107
|
+
- lib/dwolla/transaction.rb
|
108
|
+
- lib/dwolla/user.rb
|
109
|
+
- lib/dwolla/version.rb
|
110
|
+
- spec/dwolla/client_spec.rb
|
111
|
+
- spec/dwolla/transaction_spec.rb
|
112
|
+
- spec/dwolla/user_spec.rb
|
113
|
+
- spec/dwolla_spec.rb
|
114
|
+
- spec/fixtures/account_information.json
|
115
|
+
- spec/fixtures/balance.json
|
116
|
+
- spec/fixtures/basic_information.json
|
117
|
+
- spec/fixtures/contacts.json
|
118
|
+
- spec/fixtures/request_transaction.json
|
119
|
+
- spec/fixtures/send_transaction.json
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/support/helpers.rb
|
122
|
+
homepage: https://github.com/jeffersongirao/dwolla
|
123
|
+
licenses: []
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: 3030208524669820078
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: 3030208524669820078
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project: dwolla
|
148
|
+
rubygems_version: 1.8.10
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: A Ruby wrapper for the Dwolla API.
|
152
|
+
test_files:
|
153
|
+
- spec/dwolla/client_spec.rb
|
154
|
+
- spec/dwolla/transaction_spec.rb
|
155
|
+
- spec/dwolla/user_spec.rb
|
156
|
+
- spec/dwolla_spec.rb
|
157
|
+
- spec/fixtures/account_information.json
|
158
|
+
- spec/fixtures/balance.json
|
159
|
+
- spec/fixtures/basic_information.json
|
160
|
+
- spec/fixtures/contacts.json
|
161
|
+
- spec/fixtures/request_transaction.json
|
162
|
+
- spec/fixtures/send_transaction.json
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
- spec/support/helpers.rb
|