balanced 0.7.5 → 0.8.1
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rbenv-version +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -0
- data/balanced.gemspec +2 -2
- data/examples/bank_account_debits.rb +2 -1
- data/examples/customers.rb +8 -4
- data/examples/events_and_callbacks.rb +2 -1
- data/examples/examples.rb +6 -5
- data/examples/exception_handling.rb +2 -1
- data/lib/balanced/client.rb +3 -3
- data/lib/balanced/resources/account.rb +5 -3
- data/lib/balanced/resources/card.rb +3 -1
- data/lib/balanced/resources/credit.rb +12 -13
- data/lib/balanced/resources/customer.rb +1 -1
- data/lib/balanced/resources/debit.rb +1 -1
- data/lib/balanced/resources/resource.rb +83 -93
- data/lib/balanced/utils.rb +13 -4
- data/lib/balanced/version.rb +1 -1
- data/scenario.cache +299 -380
- data/scenarios/account_add_card/ruby.mako +3 -3
- data/scenarios/account_capture_hold/request.rb +1 -1
- data/scenarios/account_capture_hold/ruby.mako +1 -1
- data/scenarios/account_create/ruby.mako +1 -1
- data/scenarios/account_create_buyer/ruby.mako +2 -2
- data/scenarios/account_create_debit/request.rb +1 -1
- data/scenarios/account_create_debit/ruby.mako +1 -1
- data/scenarios/account_create_hold/request.rb +1 -1
- data/scenarios/account_create_hold/ruby.mako +1 -1
- data/scenarios/account_create_merchant/ruby.mako +3 -3
- data/scenarios/account_underwrite_business/ruby.mako +1 -1
- data/scenarios/account_underwrite_person/request.rb +1 -1
- data/scenarios/account_underwrite_person/ruby.mako +7 -7
- data/scenarios/bank_account_create/request.rb +1 -1
- data/scenarios/bank_account_create/ruby.mako +5 -5
- data/scenarios/bank_account_delete/ruby.mako +2 -2
- data/scenarios/bank_account_invalid_routing_number/ruby.mako +2 -8
- data/scenarios/bank_account_list/ruby.mako +1 -1
- data/scenarios/bank_account_show/ruby.mako +2 -2
- data/scenarios/bank_account_verification_create/ruby.mako +2 -2
- data/scenarios/bank_account_verification_show/ruby.mako +2 -2
- data/scenarios/bank_account_verification_update/ruby.mako +2 -2
- data/scenarios/callback_create/definition.rb +1 -1
- data/scenarios/callback_create/request.rb +1 -1
- data/scenarios/callback_create/ruby.mako +0 -11
- data/scenarios/callback_delete/definition.rb +1 -1
- data/scenarios/callback_delete/request.rb +1 -1
- data/scenarios/callback_delete/ruby.mako +0 -10
- data/scenarios/callback_list/definition.rb +1 -1
- data/scenarios/callback_list/ruby.mako +0 -10
- data/scenarios/callback_show/definition.rb +1 -1
- data/scenarios/callback_show/ruby.mako +0 -9
- data/scenarios/card_create/request.rb +2 -1
- data/scenarios/card_create/ruby.mako +6 -5
- data/scenarios/card_delete/ruby.mako +2 -2
- data/scenarios/card_invalidate/ruby.mako +2 -2
- data/scenarios/card_list/ruby.mako +1 -1
- data/scenarios/card_show/ruby.mako +2 -2
- data/scenarios/card_update/ruby.mako +2 -2
- data/scenarios/credit_bank_account_list/ruby.mako +2 -2
- data/scenarios/credit_create_existing_bank_account/ruby.mako +3 -3
- data/scenarios/credit_customer_list/ruby.mako +2 -2
- data/scenarios/credit_failed_state/request.rb +2 -2
- data/scenarios/credit_failed_state/ruby.mako +2 -5
- data/scenarios/credit_list/ruby.mako +1 -1
- data/scenarios/credit_paid_state/request.rb +2 -2
- data/scenarios/credit_paid_state/ruby.mako +2 -5
- data/scenarios/credit_pending_state/request.rb +2 -2
- data/scenarios/credit_pending_state/ruby.mako +2 -5
- data/scenarios/credit_show/ruby.mako +2 -2
- data/scenarios/customer_add_bank_account/ruby.mako +3 -3
- data/scenarios/customer_add_card/ruby.mako +3 -3
- data/scenarios/customer_capture_hold/request.rb +1 -1
- data/scenarios/customer_create/ruby.mako +1 -1
- data/scenarios/customer_create_debit/request.rb +1 -1
- data/scenarios/customer_create_debit/ruby.mako +3 -3
- data/scenarios/customer_create_hold/request.rb +1 -1
- data/scenarios/customer_create_hold/ruby.mako +1 -1
- data/scenarios/customer_credit/request.rb +1 -1
- data/scenarios/customer_credit/ruby.mako +2 -2
- data/scenarios/customer_delete/ruby.mako +1 -1
- data/scenarios/debit_create/ruby.mako +3 -3
- data/scenarios/debit_customer_list/ruby.mako +2 -2
- data/scenarios/debit_list/ruby.mako +1 -1
- data/scenarios/debit_refund/ruby.mako +2 -2
- data/scenarios/debit_show/ruby.mako +2 -2
- data/scenarios/debit_update/ruby.mako +2 -2
- data/scenarios/event_list/ruby.mako +1 -1
- data/scenarios/event_show/ruby.mako +2 -2
- data/scenarios/helpers.rb +1 -5
- data/scenarios/hold_capture/ruby.mako +4 -3
- data/scenarios/hold_create/request.rb +2 -2
- data/scenarios/hold_create/ruby.mako +6 -6
- data/scenarios/hold_customer_list/ruby.mako +2 -2
- data/scenarios/hold_list/ruby.mako +1 -1
- data/scenarios/hold_show/ruby.mako +2 -2
- data/scenarios/hold_update/ruby.mako +2 -2
- data/scenarios/hold_void/ruby.mako +2 -2
- data/scenarios/refund_create/ruby.mako +2 -2
- data/scenarios/refund_customer_list/ruby.mako +2 -2
- data/scenarios/refund_list/ruby.mako +1 -1
- data/scenarios/refund_show/ruby.mako +2 -2
- data/scenarios/refund_update/ruby.mako +2 -2
- data/scenarios/render.rb +1 -1
- data/scenarios/render_mako.rb +0 -1
- data/spec/balanced/error_spec.rb +4 -4
- data/spec/balanced/pager_spec.rb +7 -7
- data/spec/balanced/resources/account_spec.rb +51 -30
- data/spec/balanced/resources/bank_account_spec.rb +2 -2
- data/spec/balanced/resources/card_spec.rb +8 -8
- data/spec/balanced/resources/customer_spec.rb +11 -11
- data/spec/balanced/resources/hold_spec.rb +1 -1
- data/spec/balanced/resources/marketplace_spec.rb +12 -10
- data/spec/balanced/resources/resource_spec.rb +1 -1
- data/spec/scenarios_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +16 -15
- data/examples/customers-with-meta-example.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7186ba853d6660c7502ad3767c186b1df7561a8
|
4
|
+
data.tar.gz: 42fbc557f0911e4a666d9df08ba0eb93122eef72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bba78d1960941223a2fb01eadc1cb73b1f0b617577889b0705dd11e4d04f83cea273e6696d2eea418ed1b68d7d4e33aa26127411a4b1b6a8f882fdb0ba5b9252
|
7
|
+
data.tar.gz: 665f3459a00d622a9d366c4637928f7fed47cf9e73cfaf73d1c0b1ee3e31b6d77415ab632da22a60b69ddaa830d23788113d9734dc0152a950a60243798cfdd1
|
data/.gitignore
CHANGED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.2-p290
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
CHANGED
data/balanced.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.summary = %q{Sign up on https://balancedpayments.com/}
|
14
14
|
gem.homepage = "https://balancedpayments.com"
|
15
15
|
|
16
|
-
gem.add_dependency("faraday", '
|
16
|
+
gem.add_dependency("faraday", '>= 0.8.6')
|
17
17
|
gem.add_dependency("faraday_middleware", '~> 0.9.0')
|
18
18
|
|
19
19
|
gem.files = `git ls-files`.split($\)
|
@@ -22,4 +22,4 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.name = "balanced"
|
23
23
|
gem.require_paths = %w(lib)
|
24
24
|
gem.version = Balanced::VERSION
|
25
|
-
end
|
25
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
"""
|
2
2
|
Learn how to authenticate a bank account so you can debit with it.
|
3
3
|
"""
|
4
|
-
cwd = File.dirname(File.dirname(File.
|
4
|
+
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
5
5
|
$:.unshift(cwd + "/lib")
|
6
|
+
require 'rubygems'
|
6
7
|
require 'balanced'
|
7
8
|
|
8
9
|
host = ENV.fetch('BALANCED_HOST') { nil }
|
data/examples/customers.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
cwd = File.dirname(File.dirname(File.
|
1
|
+
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
2
2
|
$:.unshift(cwd + "/lib")
|
3
|
+
require 'rubygems'
|
3
4
|
require 'balanced'
|
4
5
|
|
5
|
-
|
6
6
|
begin
|
7
7
|
Balanced::Card
|
8
8
|
rescue NameError
|
@@ -45,7 +45,7 @@ customer = marketplace.create_customer(
|
|
45
45
|
:line1 => "1234 1st Street",
|
46
46
|
:city => "San Francisco",
|
47
47
|
:state => "CA"
|
48
|
-
|
48
|
+
}
|
49
49
|
).save
|
50
50
|
|
51
51
|
puts "our customer uri is #{customer.uri}"
|
@@ -61,7 +61,7 @@ bank_account = marketplace.create_bank_account(
|
|
61
61
|
card = marketplace.create_card(
|
62
62
|
:card_number => "4111111111111111",
|
63
63
|
:expiration_month => "12",
|
64
|
-
:expiration_year => "2015"
|
64
|
+
:expiration_year => "2015"
|
65
65
|
).save
|
66
66
|
|
67
67
|
puts "our bank account uri is #{bank_account.uri}"
|
@@ -108,3 +108,7 @@ raise "active card is incorrect" unless customer.active_card.id == card.id
|
|
108
108
|
puts "check to see what is the active bank_account for a customer"
|
109
109
|
|
110
110
|
raise "active bank account is incorrect" unless customer.active_bank_account.id == bank_account.id
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
@@ -3,8 +3,9 @@ Welcome weary traveller. Sick of polling for state changes? Well today have I
|
|
3
3
|
got good news for you. Run this example below to see how to get yourself some
|
4
4
|
callback goodness and to understand how events work.
|
5
5
|
"""
|
6
|
-
cwd = File.dirname(File.dirname(File.
|
6
|
+
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
7
7
|
$:.unshift(cwd + "/lib")
|
8
|
+
require 'rubygems'
|
8
9
|
require 'balanced'
|
9
10
|
require 'net/http'
|
10
11
|
require 'uri'
|
data/examples/examples.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
cwd = File.dirname(File.dirname(File.
|
1
|
+
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
2
2
|
$:.unshift(cwd + "/lib")
|
3
|
+
require 'rubygems'
|
3
4
|
require 'balanced'
|
4
5
|
|
5
6
|
begin
|
@@ -52,7 +53,7 @@ puts "cool! let's create a new card."
|
|
52
53
|
card = Balanced::Card.new(
|
53
54
|
:card_number => "5105105105105100",
|
54
55
|
:expiration_month => "12",
|
55
|
-
:expiration_year => "2015"
|
56
|
+
:expiration_year => "2015"
|
56
57
|
).save
|
57
58
|
puts "Our card uri: #{card.uri}"
|
58
59
|
|
@@ -83,7 +84,7 @@ puts "ok, we have a merchant that's signing up, let's create an account for them
|
|
83
84
|
bank_account = marketplace.create_bank_account(
|
84
85
|
:account_number => "1234567890",
|
85
86
|
:routing_number => "322271627",
|
86
|
-
:name => "Jack Q Merchant"
|
87
|
+
:name => "Jack Q Merchant"
|
87
88
|
)
|
88
89
|
|
89
90
|
merchant = marketplace.create_merchant(
|
@@ -95,10 +96,10 @@ merchant = marketplace.create_merchant(
|
|
95
96
|
:postal_code => "94301",
|
96
97
|
:country => "USA",
|
97
98
|
:dob => "1842-01",
|
98
|
-
:phone_number => "+16505551234"
|
99
|
+
:phone_number => "+16505551234"
|
99
100
|
},
|
100
101
|
:bank_account_uri => bank_account.uri,
|
101
|
-
:name => "Jack Q Merchant"
|
102
|
+
:name => "Jack Q Merchant"
|
102
103
|
)
|
103
104
|
|
104
105
|
puts "oh our buyer is interested in buying something for 530.00$"
|
data/lib/balanced/client.rb
CHANGED
@@ -70,9 +70,9 @@ module Balanced
|
|
70
70
|
def url
|
71
71
|
builder = (config[:scheme] == 'http') ? URI::HTTP : URI::HTTPS
|
72
72
|
|
73
|
-
builder.build
|
74
|
-
|
75
|
-
|
73
|
+
builder.build({:host => config[:host],
|
74
|
+
:port => config[:port],
|
75
|
+
:scheme => config[:scheme]})
|
76
76
|
end
|
77
77
|
|
78
78
|
def method_missing(method, *args, &block)
|
@@ -60,7 +60,7 @@ module Balanced
|
|
60
60
|
:meta => meta,
|
61
61
|
:description => description,
|
62
62
|
:source_uri => source_uri,
|
63
|
-
:on_behalf_of_uri => on_behalf_of
|
63
|
+
:on_behalf_of_uri => on_behalf_of
|
64
64
|
)
|
65
65
|
debit.save
|
66
66
|
end
|
@@ -81,12 +81,14 @@ module Balanced
|
|
81
81
|
amount = args[0] || options.fetch(:amount) { }
|
82
82
|
meta = args[1] || options.fetch(:meta) { nil }
|
83
83
|
source_uri = args[2] || options.fetch(:source_uri) { nil }
|
84
|
+
description = args[3] || options.fetch(:description) { nil }
|
84
85
|
|
85
86
|
hold = Hold.new(
|
86
87
|
:uri => self.holds_uri,
|
87
88
|
:amount => amount,
|
88
89
|
:meta => meta,
|
89
90
|
:source_uri => source_uri,
|
91
|
+
:description => description
|
90
92
|
)
|
91
93
|
hold.save
|
92
94
|
end
|
@@ -102,9 +104,9 @@ module Balanced
|
|
102
104
|
warn_on_positional args
|
103
105
|
|
104
106
|
if args.last.is_a? Hash
|
105
|
-
args.last.merge! uri
|
107
|
+
args.last.merge! :uri => self.credits_uri
|
106
108
|
else
|
107
|
-
args << { uri
|
109
|
+
args << { :uri => self.credits_uri }
|
108
110
|
end
|
109
111
|
Credit.new(*args).save
|
110
112
|
end
|
@@ -56,13 +56,15 @@ module Balanced
|
|
56
56
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
57
57
|
amount = args[0] || options.fetch(:amount) { nil }
|
58
58
|
meta = args[1] || options.fetch(:meta) { nil }
|
59
|
+
description = args[3] || options.fetch(:description) { nil }
|
59
60
|
|
60
61
|
ensure_associated_to_account!
|
61
62
|
|
62
63
|
self.account.hold(
|
63
64
|
:amount => amount,
|
64
65
|
:meta => meta,
|
65
|
-
:source_uri => self.uri
|
66
|
+
:source_uri => self.uri,
|
67
|
+
:description => description
|
66
68
|
)
|
67
69
|
end
|
68
70
|
|
@@ -27,23 +27,23 @@ module Balanced
|
|
27
27
|
unless bank_account.nil?
|
28
28
|
# Accountless bank account
|
29
29
|
attributes = {
|
30
|
-
uri
|
31
|
-
amount
|
32
|
-
description
|
33
|
-
bank_account
|
34
|
-
meta
|
30
|
+
:uri => uri,
|
31
|
+
:amount => amount,
|
32
|
+
:description => description,
|
33
|
+
:bank_account => bank_account,
|
34
|
+
:meta => nil
|
35
35
|
}
|
36
36
|
else
|
37
37
|
meta = args[2] || options.fetch(:meta) { nil }
|
38
38
|
destination_uri = args[3] || options.fetch(:destination_uri) { nil }
|
39
39
|
appears_on_statement_as = args[4] || options.fetch(:appears_on_statement_as) { nil }
|
40
40
|
attributes = {
|
41
|
-
uri
|
42
|
-
amount
|
43
|
-
meta
|
44
|
-
description
|
45
|
-
destination_uri
|
46
|
-
appears_on_statement_as
|
41
|
+
:uri => uri,
|
42
|
+
:amount => amount,
|
43
|
+
:meta => meta,
|
44
|
+
:description => description,
|
45
|
+
:destination_uri => destination_uri,
|
46
|
+
:appears_on_statement_as => appears_on_statement_as
|
47
47
|
}
|
48
48
|
end
|
49
49
|
|
@@ -63,9 +63,8 @@ module Balanced
|
|
63
63
|
:uri => self.reversals_uri,
|
64
64
|
:credit_uri => self.uri,
|
65
65
|
:amount => amount,
|
66
|
-
:description => description
|
66
|
+
:description => description
|
67
67
|
)
|
68
|
-
|
69
68
|
reversal.save
|
70
69
|
end
|
71
70
|
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require File.expand_path('../../pager', __FILE__)
|
3
2
|
|
4
3
|
module Balanced
|
5
4
|
module Resource
|
@@ -89,7 +88,7 @@ module Balanced
|
|
89
88
|
end
|
90
89
|
|
91
90
|
def method_missing(method, *args, &block)
|
92
|
-
case method
|
91
|
+
case method.to_s
|
93
92
|
when /(.+)\=$/
|
94
93
|
attr = method.to_s.chop
|
95
94
|
@attributes[attr] = args[0]
|
@@ -107,16 +106,8 @@ module Balanced
|
|
107
106
|
#
|
108
107
|
# This solves the acute problem, for now.
|
109
108
|
if @attributes.has_key? "#{method}_uri"
|
110
|
-
|
111
109
|
value = @attributes["#{method}_uri"]
|
112
|
-
|
113
|
-
# construct? Welp, we catch that NameError and return to super.
|
114
|
-
begin
|
115
|
-
values_class = Balanced.from_uri(value)
|
116
|
-
rescue NameError
|
117
|
-
super
|
118
|
-
end
|
119
|
-
|
110
|
+
values_class = Balanced.from_uri(value)
|
120
111
|
# if uri is a collection -> this would definitely be if
|
121
112
|
# it ends in a symbol then we should allow a lazy executor of
|
122
113
|
# the query pager
|
@@ -126,112 +117,111 @@ module Balanced
|
|
126
117
|
else
|
127
118
|
return values_class.find(value)
|
128
119
|
end
|
129
|
-
|
130
120
|
else
|
131
121
|
super
|
132
122
|
end
|
133
123
|
end
|
134
124
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
module ClassMethods
|
141
|
-
def resource_name
|
142
|
-
Utils.demodulize name
|
125
|
+
|
126
|
+
def self.included(base)
|
127
|
+
base.extend ClassMethods
|
143
128
|
end
|
144
129
|
|
145
|
-
|
146
|
-
|
147
|
-
|
130
|
+
module ClassMethods
|
131
|
+
def resource_name
|
132
|
+
Utils.demodulize name
|
133
|
+
end
|
148
134
|
|
149
|
-
|
150
|
-
|
151
|
-
|
135
|
+
def collection_name
|
136
|
+
Utils.pluralize Utils.underscore(resource_name)
|
137
|
+
end
|
152
138
|
|
153
|
-
|
154
|
-
|
155
|
-
|
139
|
+
def collection_path
|
140
|
+
["/v#{Balanced.config[:version]}", collection_name].compact.join '/'
|
141
|
+
end
|
156
142
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
# @return [String] the uri of the instance or the class
|
163
|
-
def uri
|
164
|
-
# the uri of a particular resource depends if there's a marketplace
|
165
|
-
# created or not. if there's a marketplace, then all resources have their
|
166
|
-
# own uri from there and the top level ones. if there's not a marketplace
|
143
|
+
def member_name
|
144
|
+
Utils.underscore resource_name
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns the resource URI for a given class.
|
167
148
|
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
149
|
+
# @example A Balanced::Account resource
|
150
|
+
# Balanced::Account.uri # => "/v1/marketplaces/TEST-MP72zVdg2j9IiqRffW9lczRZ/accounts"
|
151
|
+
#
|
152
|
+
# @return [String] the uri of the instance or the class
|
153
|
+
def uri
|
154
|
+
# the uri of a particular resource depends if there's a marketplace
|
155
|
+
# created or not. if there's a marketplace, then all resources have their
|
156
|
+
# own uri from there and the top level ones. if there's not a marketplace
|
157
|
+
#
|
158
|
+
# if there's an api key, then the merchant is available
|
159
|
+
# if there's no api key, the only resources exposed are purely top level
|
160
|
+
if self == Balanced::Merchant || self == Balanced::Marketplace || self == Balanced::ApiKey
|
161
|
+
collection_path
|
162
|
+
else
|
163
|
+
unless Balanced::Marketplace.marketplace_exists?
|
164
|
+
raise Balanced::StandardError, "#{self.name} is nested under a marketplace, which is not created or configured."
|
165
|
+
end
|
176
166
|
|
177
|
-
|
167
|
+
Balanced::Marketplace.marketplace_uri + "/#{collection_name}"
|
168
|
+
end
|
178
169
|
end
|
179
|
-
end
|
180
170
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
171
|
+
def construct_from_response payload
|
172
|
+
payload = Balanced::Utils.hash_with_indifferent_read_access payload
|
173
|
+
return payload if payload[:uri].nil?
|
174
|
+
klass = Balanced.from_uri(payload[:uri])
|
175
|
+
instance = klass.new payload
|
186
176
|
|
187
|
-
|
188
|
-
|
177
|
+
# http://stackoverflow.com/a/2495650/133514
|
178
|
+
instance_eigen = class << instance; self; end
|
189
179
|
|
190
|
-
|
180
|
+
payload.each do |name, value|
|
191
181
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
182
|
+
# here is where our interpretations will begin.
|
183
|
+
# if the value is a sub-resource, lets instantiate the class
|
184
|
+
# and set it correctly
|
185
|
+
if value.instance_of? Hash and value.has_key? 'uri'
|
186
|
+
value = construct_from_response value
|
187
|
+
end
|
198
188
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
189
|
+
# Get attribute
|
190
|
+
instance.class.send(:define_method, name, proc{@attributes[name]})
|
191
|
+
# Set attribute
|
192
|
+
instance.class.send(:define_method, "#{name}=", proc{ |value| @attributes[name] = value })
|
193
|
+
# Is attribute present?
|
194
|
+
instance.class.send(:define_method, "#{name}?", proc{ !!@attributes[name] })
|
205
195
|
|
206
|
-
|
196
|
+
instance.send("#{name}=".to_s, value)
|
197
|
+
end
|
198
|
+
instance
|
207
199
|
end
|
208
|
-
instance
|
209
|
-
end
|
210
200
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
201
|
+
def find *arguments
|
202
|
+
scope = arguments.slice!(0)
|
203
|
+
options = arguments.slice!(0) || {}
|
204
|
+
case scope
|
205
|
+
when :all then all(options)
|
206
|
+
when :first then paginate(options).first
|
207
|
+
else
|
208
|
+
response = Balanced.get scope, options
|
209
|
+
construct_from_response response.body
|
210
|
+
end
|
220
211
|
end
|
221
|
-
end
|
222
212
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
213
|
+
def paginate options = {}
|
214
|
+
Balanced::Pager.new uri, options
|
215
|
+
end
|
216
|
+
alias scoped paginate
|
217
|
+
alias where paginate
|
228
218
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
219
|
+
def all options = {}
|
220
|
+
pager = paginate(options)
|
221
|
+
pager.to_a
|
222
|
+
end
|
233
223
|
|
234
|
-
|
224
|
+
end
|
235
225
|
|
236
226
|
end
|
237
227
|
end
|