balanced 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Balanced::ApiKey do
4
+ describe "attributes" do
5
+ use_vcr_cassette
6
+ before do
7
+ @key = Balanced::ApiKey.new.save
8
+ end
9
+ describe "#secret" do
10
+ subject { @key.secret }
11
+ it { should_not be_nil }
12
+ it { should_not be_empty }
13
+ end
14
+
15
+ describe "#merchant" do
16
+ subject { @key.merchant }
17
+ it { should_not be_nil }
18
+ it { should be_instance_of Balanced::Merchant }
19
+ end
20
+ end
21
+
22
+ describe "new key" do
23
+ use_vcr_cassette
24
+
25
+ describe "before configure" do
26
+ use_vcr_cassette
27
+ before do
28
+ @new_key = Balanced::ApiKey.new.save
29
+ end
30
+ describe "#merchant" do
31
+ use_vcr_cassette
32
+ subject { @new_key.merchant }
33
+ it { should_not be_nil }
34
+ it { should be_instance_of Balanced::Merchant }
35
+ end
36
+ end
37
+
38
+ describe "after configure" do
39
+ use_vcr_cassette
40
+ before do
41
+ @new_key = Balanced::ApiKey.new.save
42
+ Balanced.configure @new_key.secret
43
+ @new_key = Balanced::ApiKey.new.save
44
+ end
45
+
46
+ describe "#merchant" do
47
+ use_vcr_cassette
48
+ subject { @new_key.merchant }
49
+ it { should_not be_nil }
50
+ it { should be_instance_of Balanced::Merchant }
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+
4
+ describe Balanced::Marketplace do
5
+ use_vcr_cassette
6
+ before do
7
+ api_key = Balanced::ApiKey.new.save
8
+ Balanced.configure api_key.secret
9
+ @marketplace = Balanced::Marketplace.new.save
10
+ @bank_account = Balanced::BankAccount.new(
11
+ :account_number => "1234567890",
12
+ :bank_code => "321174851",
13
+ :name => "Jack Q Merchant"
14
+ ).save
15
+ @merchant = @marketplace.create_merchant(
16
+ "merchant@example.org",
17
+ {
18
+ :type => "person",
19
+ :name => "Billy Jones",
20
+ :street_address => "801 High St.",
21
+ :postal_code => "94301",
22
+ :country => "USA",
23
+ :dob => "1842-01",
24
+ :phone_number => "+16505551234",
25
+ },
26
+ @bank_account.uri,
27
+ "Jack Q Merchant",
28
+ )
29
+ end
30
+
31
+ describe "create_merchant" do
32
+ use_vcr_cassette
33
+
34
+ describe "class" do
35
+ subject { @merchant }
36
+ it { should be_instance_of Balanced::Account }
37
+ end
38
+
39
+ describe "attributes" do
40
+ describe "#id" do
41
+ subject { @merchant.id }
42
+ it { should_not be_nil }
43
+ it { should_not be_empty }
44
+ end
45
+ describe "#roles" do
46
+ subject { @merchant.roles }
47
+ it { should include("merchant") }
48
+ end
49
+ describe "#email_address" do
50
+ subject { @merchant.email_address }
51
+ it { should eql "merchant@example.org" }
52
+ end
53
+ describe "#name" do
54
+ subject { @merchant.name }
55
+ it { should eql "Jack Q Merchant" }
56
+ end
57
+ describe "#created_at" do
58
+ subject { @merchant.created_at }
59
+ it { should_not be_nil }
60
+ it { should_not be_empty }
61
+ end
62
+ describe "#uri" do
63
+ subject { @merchant.uri }
64
+ it { should match MERCHANT_URI_REGEX }
65
+ end
66
+ describe "#holds_uri" do
67
+ subject { @merchant.holds_uri }
68
+ it { should match HOLDS_URI_REGEX }
69
+ end
70
+ describe "#bank_accounts_uri" do
71
+ subject { @merchant.bank_accounts_uri }
72
+ it { should match BANK_ACCOUNTS_URI_REGEX }
73
+ end
74
+ describe "#refunds_uri" do
75
+ subject { @merchant.refunds_uri }
76
+ it { should match REFUNDS_URI_REGEX }
77
+ end
78
+ describe "#debits_uri" do
79
+ subject { @merchant.debits_uri }
80
+ it { should match DEBITS_URI_REGEX }
81
+ end
82
+ describe "#transactions_uri" do
83
+ subject { @merchant.transactions_uri }
84
+ it { should match TRANSACTIONS_URI_REGEX }
85
+ end
86
+ describe "#credits_uri" do
87
+ subject { @merchant.credits_uri }
88
+ it { should match CREDITS_URI_REGEX }
89
+ end
90
+ describe "#cards_uri" do
91
+ subject { @merchant.cards_uri }
92
+ it { should match CARDS_URI_REGEX }
93
+ end
94
+ end
95
+ end
96
+ end
97
+
@@ -1,16 +1,77 @@
1
- require "balanced"
1
+ require "spec_helper"
2
2
 
3
- describe "Balanced module" do
4
- before(:each) do
5
- Balanced.configure "some-secret"
6
- end
3
+ describe Balanced do
4
+ describe "configure" do
5
+ use_vcr_cassette
6
+ before do
7
+ @api_key = Balanced::ApiKey.new.save
7
8
 
8
- it "should have a non-nil client" do
9
- Balanced.client.should_not eq(nil)
10
- end
9
+ Balanced.configure @api_key.secret
10
+ end
11
11
 
12
- its "client should not have a nil conn" do
13
- Balanced.client.conn.should_not eq(nil)
14
- end
12
+ describe "api key" do
13
+ describe "merchant" do
14
+ subject { @api_key.merchant }
15
+ it { should_not be_nil }
16
+ end
17
+ end
18
+
19
+ describe "#client" do
20
+ subject { Balanced.client }
21
+ it { should_not be_nil }
22
+
23
+ describe "#connection" do
24
+ subject { Balanced.client.conn }
25
+ it { should_not be_nil }
26
+ end
27
+
28
+ describe "#api_key" do
29
+ subject { Balanced.client.api_key }
30
+ it { should eql @api_key.secret }
31
+ end
32
+
33
+ describe "#url" do
34
+ subject { Balanced.client.url.to_s }
35
+ it { should eql "https://api.balancedpayments.com" }
36
+ end
37
+ end
15
38
 
16
- end
39
+ describe "reconfigure with new api key" do
40
+ use_vcr_cassette
41
+ before do
42
+ @new_api_key = Balanced::ApiKey.new.save
43
+ Balanced.configure @new_api_key.secret
44
+ end
45
+
46
+ describe "api key" do
47
+ describe "merchant" do
48
+ use_vcr_cassette
49
+ subject { @api_key.merchant }
50
+ it { should_not be_nil }
51
+ end
52
+ end
53
+
54
+ describe "#client" do
55
+ describe "#api_key" do
56
+ subject { Balanced.client.api_key }
57
+ it { should_not eql @api_key.secret }
58
+ it { should eql @new_api_key.secret }
59
+ end
60
+ end
61
+
62
+ describe "new api key" do
63
+ describe "secret" do
64
+ subject { @new_api_key.secret }
65
+ it { should_not be_nil }
66
+
67
+ end
68
+ describe "merchant" do
69
+ use_vcr_cassette
70
+
71
+ subject { @new_api_key.merchant }
72
+ it { should_not be_nil }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,4 +1,4 @@
1
- require "balanced"
1
+ require "spec_helper"
2
2
 
3
3
  describe "balanced client" do
4
4
 
@@ -9,4 +9,4 @@ describe "balanced client" do
9
9
  client.api_key.should eq("foo")
10
10
  end
11
11
 
12
- end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'balanced'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/cassettes'
9
+ c.hook_into :faraday
10
+ end
11
+
12
+ RSpec.configure do |c|
13
+ c.extend VCR::RSpec::Macros
14
+ end
15
+
16
+
17
+ MERCHANT_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*/
18
+ HOLDS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/holds/
19
+ BANK_ACCOUNTS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/bank_accounts/
20
+ REFUNDS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/refunds/
21
+ DEBITS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/debits/
22
+ TRANSACTIONS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/transactions/
23
+ CREDITS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/credits/
24
+ CARDS_URI_REGEX = /\/v1\/marketplaces\/TEST-\w*\/accounts\/\w*\/cards/
@@ -1,8 +1,8 @@
1
- require "balanced"
1
+ require "spec_helper"
2
2
 
3
3
  describe "the utils module" do
4
4
  it "should correctly translate underscored names" do
5
5
  result = Balanced::Utils.camelize "api_key"
6
6
  result.should eq("ApiKey")
7
7
  end
8
- end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balanced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '2.0'
53
+ version: '2.10'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,55 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '2.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: vcr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.2.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.2.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.0
62
110
  description: ! "Balanced is the payments platform for marketplaces.\n Integrate
63
111
  a payments experience just like Amazon for your marketplace.\n Forget about dealing
64
112
  with banking systems, compliance, fraud, and security.\n "
@@ -70,21 +118,48 @@ extra_rdoc_files: []
70
118
  files:
71
119
  - .gitignore
72
120
  - .rbenv-version
121
+ - .rspec
122
+ - CONTRIBUTORS
73
123
  - Gemfile
124
+ - Guardfile
74
125
  - LICENSE
75
126
  - README.md
76
127
  - Rakefile
77
128
  - balanced.gemspec
129
+ - doc/balanced_plugin.rb
130
+ - doc/balanced_templates/default/method_details/html/method_signature.erb
131
+ - doc/balanced_templates/default/module/html/children.erb
132
+ - doc/balanced_templates/default/module/html/header.erb
133
+ - doc/balanced_templates/default/module/html/method_details_list.erb
134
+ - doc/balanced_templates/default/module/html/pre_docstring.erb
135
+ - doc/balanced_templates/default/module/setup.rb
136
+ - doc/balanced_templates/default/onefile/html/layout.erb
137
+ - doc/balanced_templates/default/onefile/html/setup.rb
138
+ - doc/balanced_templates/default/tags/html/index.erb
78
139
  - examples/examples.rb
79
140
  - lib/balanced.rb
80
- - lib/balanced/base.rb
81
141
  - lib/balanced/client.rb
82
142
  - lib/balanced/resources.rb
143
+ - lib/balanced/resources/account.rb
144
+ - lib/balanced/resources/api_key.rb
145
+ - lib/balanced/resources/bank_account.rb
146
+ - lib/balanced/resources/card.rb
147
+ - lib/balanced/resources/credit.rb
148
+ - lib/balanced/resources/debit.rb
149
+ - lib/balanced/resources/hold.rb
150
+ - lib/balanced/resources/marketplace.rb
151
+ - lib/balanced/resources/merchant.rb
152
+ - lib/balanced/resources/refund.rb
153
+ - lib/balanced/resources/resource.rb
154
+ - lib/balanced/resources/transaction.rb
83
155
  - lib/balanced/utils.rb
84
156
  - lib/balanced/version.rb
85
- - spec/api_key_spec.rb
157
+ - spec/balanced/resources/account_spec.rb
158
+ - spec/balanced/resources/api_key_spec.rb
159
+ - spec/balanced/resources/marketplace_spec.rb
86
160
  - spec/balanced_spec.rb
87
161
  - spec/client_spec.rb
162
+ - spec/spec_helper.rb
88
163
  - spec/utils_spec.rb
89
164
  homepage: https://balancedpayments.com
90
165
  licenses: []
@@ -111,7 +186,10 @@ signing_key:
111
186
  specification_version: 3
112
187
  summary: Sign up on https://balancedpayments.com/
113
188
  test_files:
114
- - spec/api_key_spec.rb
189
+ - spec/balanced/resources/account_spec.rb
190
+ - spec/balanced/resources/api_key_spec.rb
191
+ - spec/balanced/resources/marketplace_spec.rb
115
192
  - spec/balanced_spec.rb
116
193
  - spec/client_spec.rb
194
+ - spec/spec_helper.rb
117
195
  - spec/utils_spec.rb
@@ -1,129 +0,0 @@
1
- module Balanced
2
- class Resource
3
-
4
- class << self
5
-
6
- def resource_name
7
- Utils.demodulize name
8
- end
9
-
10
- def collection_name
11
- Utils.pluralize Utils.underscore(resource_name)
12
- end
13
-
14
- def collection_path
15
- ["/v#{Balanced.config[:version]}", collection_name].compact.join '/'
16
- end
17
-
18
- def member_name
19
- Utils.underscore resource_name
20
- end
21
-
22
- def construct_from_response payload
23
- payload = Balanced::Utils.hash_with_indifferent_read_access payload
24
- klass = Balanced.from_uri(payload[:uri])
25
- instance = klass.new payload
26
- payload.each do |name, value|
27
- klass.class_eval {
28
- attr_accessor name.to_s
29
- }
30
- # here is where our interpretations will begin.
31
- # if the value is a sub-resource, lets instantiate the class
32
- # and set it correctly
33
- if value.instance_of? Hash and value.has_key? 'uri'
34
- value = construct_from_response value
35
- elsif name =~ /_uri$/
36
- modified_name = name.sub(/_uri$/, '')
37
- klass.instance_eval {
38
- define_method(modified_name) {
39
- values_class = Balanced.from_uri(value)
40
- # if uri is a collection -> this would definitely be if it ends in a symbol
41
- # then we should allow a lazy executor of the query pager
42
- if Balanced.is_collection(value)
43
- # TODO: return the pager
44
- p "TODO: return the pager for this class: #{values_class}"
45
- values_class.new
46
- else
47
- values_class.find(value)
48
- end
49
- }
50
- }
51
- end
52
-
53
- instance.class.instance_eval {
54
- define_method(name) { self[name] } # Get.
55
- define_method("#{name}=") { |value| self[name] = value } # Set.
56
- define_method("#{name}?") { !!self[name] } # Present.
57
- }
58
- instance.send("#{name}=".to_s, value)
59
- end
60
- instance
61
- end
62
-
63
- end
64
-
65
- attr_reader :attributes
66
-
67
- def initialize attributes = {}
68
- @attributes = attributes
69
- self.attributes = attributes
70
- end
71
-
72
- def attributes= attributes = {}
73
- attributes.each_pair { |k, v|
74
- respond_to?(name = "#{k}=") and send(name, v) or (self[k] = v)
75
- }
76
- end
77
-
78
- def read_attribute key
79
- attributes[key.to_s]
80
- end
81
- alias [] read_attribute
82
-
83
- def write_attribute key, value
84
- attributes[key] = value
85
- end
86
- alias []= write_attribute
87
-
88
- # delegate the query to the pager module
89
-
90
- def find uri, options={}
91
- response = Balanced.get uri
92
- self.class.construct_from_response response.body
93
- end
94
-
95
- def save
96
- uri = self.attributes.delete('uri') { |key| nil }
97
- method = :post
98
- if uri.nil?
99
- uri = self.class.collection_path
100
- elsif !Balanced.is_collection(uri)
101
- method = :put
102
- end
103
- response = Balanced.send(method, uri, self.attributes)
104
- reload response
105
- end
106
-
107
- def destroy
108
- Balanced.delete self.attributes['uri']
109
- end
110
-
111
- def reload response = nil
112
- if response
113
- return if response.body.to_s.length.zero?
114
- fresh = self.class.construct_from_response response.body
115
- else
116
- fresh = self.find(@attributes['uri'])
117
- end
118
- fresh and copy_from fresh
119
- self
120
- end
121
-
122
- def copy_from other
123
- other.instance_variables.each do |ivar|
124
- instance_variable_set ivar, other.instance_variable_get(ivar)
125
- end
126
- end
127
-
128
- end
129
- end