Skip to content

Commit d807572

Browse files
committed
Update to support API list methods refactor
Enable Scala 2.9.1 support
1 parent a8a10c9 commit d807572

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ organization := "com.stripe"
66

77
scalaVersion := "2.9.0-1"
88

9-
crossScalaVersions := Seq("2.9.0", "2.9.0-1")
9+
crossScalaVersions := Seq("2.9.0", "2.9.0-1", "2.9.1")
1010

1111
scalacOptions ++= Seq("-unchecked", "-deprecation")
1212

src/main/scala/com/stripe/Stripe.scala

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,23 @@ case class Charge(
186186
def refund(): Charge = request("POST", "%s/refund".format(instanceURL(this.id))).extract[Charge]
187187
}
188188

189+
case class ChargeCollection(data: List[Charge])
190+
189191
object Charge extends APIResource {
190192
def create(params: Map[String,_]): Charge = {
191193
return request("POST", classURL, params).extract[Charge]
192194
}
193195

194-
def all(params: Map[String,_] = Map.empty): List[Charge] = {
195-
return request("GET", classURL, params).extract[List[Charge]]
196-
}
197-
198196
def retrieve(id: String): Charge = {
199197
return request("GET", instanceURL(id)).extract[Charge]
200198
}
199+
200+
def all(params: Map[String,_] = Map.empty): ChargeCollection = {
201+
return request("GET", classURL, params).extract[ChargeCollection]
202+
}
203+
201204
}
205+
202206
case class Customer(
203207
id: String,
204208
created: Long,
@@ -232,6 +236,8 @@ case class Customer(
232236

233237
case class DeletedCustomer(id: String, deleted: Boolean)
234238

239+
case class CustomerCollection(data: List[Customer])
240+
235241
object Customer extends APIResource {
236242
def create(params: Map[String,_]): Customer = {
237243
return request("POST", classURL, params).extract[Customer]
@@ -241,8 +247,8 @@ object Customer extends APIResource {
241247
return request("GET", instanceURL(id)).extract[Customer]
242248
}
243249

244-
def all(params: Map[String,_] = Map.empty): List[Customer] = {
245-
return request("GET", classURL, params).extract[List[Customer]]
250+
def all(params: Map[String,_] = Map.empty): CustomerCollection = {
251+
return request("GET", classURL, params).extract[CustomerCollection]
246252
}
247253
}
248254

@@ -259,6 +265,8 @@ case class Plan(
259265
}
260266
}
261267

268+
case class PlanCollection(data: List[Plan])
269+
262270
case class DeletedPlan(id: String, deleted: Boolean)
263271

264272
object Plan extends APIResource {
@@ -270,8 +278,8 @@ object Plan extends APIResource {
270278
return request("GET", instanceURL(id)).extract[Plan]
271279
}
272280

273-
def all(params: Map[String,_] = Map.empty): List[Plan] = {
274-
return request("GET", classURL, params).extract[List[Plan]]
281+
def all(params: Map[String,_] = Map.empty): PlanCollection = {
282+
return request("GET", classURL, params).extract[PlanCollection]
275283
}
276284
}
277285

@@ -317,6 +325,8 @@ extends APIResource {
317325

318326
case class DeletedInvoiceItem(id: String, deleted: Boolean)
319327

328+
case class InvoiceItemCollection(data: List[InvoiceItem])
329+
320330
object InvoiceItem extends APIResource {
321331
def create(params: Map[String,_]): InvoiceItem = {
322332
return request("POST", classURL, params).extract[InvoiceItem]
@@ -326,8 +336,8 @@ object InvoiceItem extends APIResource {
326336
return request("GET", instanceURL(id)).extract[InvoiceItem]
327337
}
328338

329-
def all(params: Map[String,_] = Map.empty): List[InvoiceItem] = {
330-
return request("GET", classURL, params).extract[List[InvoiceItem]]
339+
def all(params: Map[String,_] = Map.empty): InvoiceItemCollection = {
340+
return request("GET", classURL, params).extract[InvoiceItemCollection]
331341
}
332342
}
333343

@@ -356,13 +366,15 @@ case class Invoice(
356366
lines: InvoiceLines) {
357367
}
358368

369+
case class InvoiceCollection(data: List[Invoice])
370+
359371
object Invoice extends APIResource {
360372
def retrieve(id: String): Invoice = {
361373
return request("GET", instanceURL(id)).extract[Invoice]
362374
}
363375

364-
def all(params: Map[String,_] = Map.empty): List[Invoice] = {
365-
return request("GET", classURL, params).extract[List[Invoice]]
376+
def all(params: Map[String,_] = Map.empty): InvoiceCollection = {
377+
return request("GET", classURL, params).extract[InvoiceCollection]
366378
}
367379

368380
def upcoming(params: Map[String, _]): Invoice = {

src/test/scala/com/stripe/StripeSuite.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ChargeSuite extends FunSuite with StripeSuite {
5151

5252
test("Charges can be listed") {
5353
val charge = Charge.create(DefaultChargeMap)
54-
val charges = Charge.all()
54+
val charges = Charge.all().data
5555
charges.head.isInstanceOf[Charge] should be (true)
5656
}
5757

@@ -95,7 +95,7 @@ class CustomerSuite extends FunSuite with StripeSuite {
9595

9696
test("Customers can be listed") {
9797
val customer = Customer.create(DefaultCustomerMap)
98-
val customers = Customer.all()
98+
val customers = Customer.all().data
9999
customers.head.isInstanceOf[Customer] should be (true)
100100
}
101101
}
@@ -121,7 +121,7 @@ class PlanSuite extends FunSuite with StripeSuite {
121121

122122
test("Plans can be listed") {
123123
val plan = Plan.create(getUniquePlanMap)
124-
val plans = Plan.all()
124+
val plans = Plan.all().data
125125
plans.head.isInstanceOf[Plan] should be (true)
126126
}
127127

@@ -194,7 +194,7 @@ class InvoiceItemSuite extends FunSuite with StripeSuite {
194194

195195
test("InvoiceItems can be listed") {
196196
val invoiceItem = createDefaultInvoiceItem()
197-
val invoiceItems = InvoiceItem.all()
197+
val invoiceItems = InvoiceItem.all().data
198198
invoiceItems.head.isInstanceOf[InvoiceItem] should be (true)
199199
}
200200
}
@@ -203,7 +203,7 @@ class InvoiceSuite extends FunSuite with StripeSuite {
203203
test("Invoices can be retrieved individually") {
204204
val plan = Plan.create(getUniquePlanMap)
205205
val customer = Customer.create(DefaultCustomerMap + ("plan" -> plan.id))
206-
val invoices = Invoice.all(Map("customer" -> customer.id))
206+
val invoices = Invoice.all(Map("customer" -> customer.id)).data
207207
val createdInvoice = invoices.head
208208
val retrievedInvoice = Invoice.retrieve(createdInvoice.id.get)
209209
retrievedInvoice.id.get should equal (createdInvoice.id.get)
@@ -212,14 +212,14 @@ class InvoiceSuite extends FunSuite with StripeSuite {
212212
test("Invoices can be listed") {
213213
val plan = Plan.create(getUniquePlanMap)
214214
val customer = Customer.create(DefaultCustomerMap + ("plan" -> plan.id))
215-
val invoices = Invoice.all()
215+
val invoices = Invoice.all().data
216216
invoices.head.isInstanceOf[Invoice] should be (true)
217217
}
218218

219219
test("Invoices can be retrieved for a customer") {
220220
val plan = Plan.create(getUniquePlanMap)
221221
val customer = Customer.create(DefaultCustomerMap + ("plan" -> plan.id))
222-
val invoices = Invoice.all(Map("customer" -> customer.id))
222+
val invoices = Invoice.all(Map("customer" -> customer.id)).data
223223
val invoice = invoices.head
224224
invoice.customer.get should equal (customer.id)
225225
val invoiceLineSubscription = invoice.lines.subscriptions.get.head

0 commit comments

Comments
 (0)