1130 Commits

Author SHA1 Message Date
Brandur
f6e542e6ab Bump version to 3.12.1 v3.12.1 2018-04-05 16:18:02 -07:00
Brandur
676670c022
Merge pull request #636 from stripe/brandur-initialize-instance-var
Initialize instance variable on the getter too
2018-04-05 16:12:09 -07:00
Brandur
776d45f116 Initialize instance variable on the getter too
The test suite is currently throwing a bunch of warnings from some
recent changes I made -- although we initialize `@additive_params` when
setting one with `self.additive_object_param`, we don't when we check
one with `self.additive_object_param?`. This often isn't a problem
because every API resource sets `metadata`, but it is from the test
suite and probably for vanilla `StripeObject`s too.
2018-04-05 15:42:46 -07:00
Brandur
2f322cadb4 Bump version to 3.12.0 v3.12.0 2018-04-05 07:17:58 -07:00
Brandur
c63081e3c5
Merge pull request #632 from stripe/brandur-only-empty-metadata
Fix replacement of non-`metadata` embedded `StripeObjects`
2018-04-05 07:16:22 -07:00
Brandur
39b80e518b Now that most hashes are non-additive, remove hack on subscription items
See the discussion here: https://github.com/stripe/stripe-ruby/pull/632
2018-04-05 07:10:15 -07:00
Brandur
5cfdf35d20 Introduce additive_object_param for use with metadata 2018-04-05 07:02:36 -07:00
Brandur
256556efa0 Fix replacement of non-metadata embedded StripeObjects
So we have a bit of a problem right now when it comes to replacing a
`StripeObject` that's embedded in an API resource.

Most of the time when someone does this, they want to _replace_ an
object embedded in another object. Take setting a source on a
subscription for example:

``` ruby
subscription.source = {
  object: 'card',
  number: 123,
}
subscription.save
```

In the case above, the serialized parameters should come out as:

```
source[object]=card&source[number]=123
```

That should apply even if the previous source had something else set on
it which we're not going to set this time -- say an optional parameter
like `source[address_state]`. Those should not be present at all in the
final serialized parameters.

(Another example is setting a `payout_schedule` as seen in #631 which is
PR is intended to address.)

There is an exception to this rule in the form of metadata though.
Metadata is a bit of a strange case in that the API will treat it as
additive, so if we send `metadata[foo]`, that will set the `foo` key,
but it won't overwrite any other keys that were already present.

This is a problem because when a user fully sets `metadata` to a new
object in Ruby, what they're probably trying to do is _replace_ it
rather than add to it. For example:

``` ruby
subscription.metadata
=> { old: 'bar' }

subscription.metadata = {
  new: 'baz'
}
subscription.save
```

To accomplish what the user is probably trying to do, we actually need
to send `metadata[old]=&metadata[new]=baz` so that we empty the value of
`old` while simultaneously setting `new` to `baz`.

In summary, metadata behaves different from other embedded objects in a
fairly fundamental way, and because the code is currently only set up to
handle the metadata case, it's not behaving correctly when other types
of objects are being set. A lot of the time emptying values like we do
for `metadata` is benign, but as we've seen in #631, sometimes it's not.

In this patch, I modify serialization to only empty out object values
when we see that parameter is `metadata`.

I'm really not crazy about the implementation here _at all_, but I'm
having trouble thinking of a better way to do it. One possibility is to
introduce a new class annotation like `empty_embedded_object :metadata`,
but that will have to go everywhere and might be error-prone in case
someone forgets it on a new resource type. If anyone has a suggestion
for an alternative (or can let me know if I'm missing something), I'd
love to hear it.

This PR is an alternate to #631.
2018-04-03 16:52:14 -07:00
Olivier Bellone
3bc4256e25
Bump version to 3.11.0 v3.11.0 2018-02-26 13:30:29 +01:00
Olivier Bellone
4d965ac5d7
Merge pull request #628 from stripe/ob-error-code
Add support for code attribute on all Stripe exceptions
2018-02-26 13:29:23 +01:00
Olivier Bellone
3805968741
Add support for code attribute on all Stripe exceptions 2018-02-23 19:02:26 +01:00
Brandur
a7ea9cf1e9 Bump version to 3.10.0 v3.10.0 2018-02-21 11:36:26 -08:00
Brandur
529b9ec417
Merge pull request #627 from stripe/jkakar/topup-client
Add support for /v1/topups endpoints
2018-02-21 11:35:16 -08:00
Jamu Kakar
0be22683a3 Add support for /v1/topups endpoints. 2018-02-16 15:03:46 -08:00
Jamu Kakar
16704d9563
Merge pull request #626 from stripe/jkakar/fix-product-issues
Upgrade to stripe-mock 0.8.0.
2018-02-15 16:44:29 -08:00
Jamu Kakar
74dfbe57d6 Apply review feedback from @ob-stripe. 2018-02-15 16:10:10 -08:00
Jamu Kakar
0b6a45af2e Fix broken test. 2018-02-15 16:05:02 -08:00
Olivier Bellone
fafd449c5f
Bump version to 3.9.2 v3.9.2 2018-02-12 11:32:24 -08:00
Olivier Bellone
1abb8a574b
Merge pull request #625 from stripe/ob-skip-to-hash-for-nil
Skip calling to_hash for nil
2018-02-12 11:31:06 -08:00
Olivier Bellone
5f1ddf2a96
Skip calling to_hash for nil 2018-02-12 11:20:19 -08:00
Brandur
f6484e3240 Bump version to 3.9.1 v3.9.1 2017-12-15 00:47:53 -08:00
Brandur
659025c7e7
Merge pull request #616 from stripe/ob-file-duck-typing
Use duck typing to detect File-like objects
2017-12-14 12:11:31 -08:00
Olivier Bellone
b83a0e5583
Use duck typing to detect File-like objects 2017-12-14 19:54:47 +01:00
Brandur
be8e4ff5f4
Merge pull request #614 from stripe/ob-coveralls
Add support for coveralls.io
2017-12-11 17:55:17 -08:00
Olivier Bellone
56430ad405
Add support for coveralls.io 2017-12-08 17:48:40 -08:00
Brandur
bfbc4b7862 Bump version to 3.9.0 v3.9.0 2017-12-08 10:48:47 -08:00
Brandur
cf810019d6
Merge pull request #613 from stripe/brandur-idempotency-error
Introduce new `IdempotencyError` type
2017-12-08 10:47:51 -08:00
Brandur
8b73853b6b A block and a class got longer so extend the exceptions for Rubocop 2017-12-07 17:42:39 -08:00
Brandur
3fc5e5b351 Introduce new IdempotencyError type
A few weeks back a new error type `idempotency_error` was introduced in
the API. I put it in to respond to #503, but then forgot to add support
for it in this library. This patch introduces a new exception class that
represents it.
2017-12-07 17:39:14 -08:00
Brandur
c36bf00151 Bump version to 3.8.2 v3.8.2 2017-12-07 12:56:27 -08:00
Brandur
e149379b83
Merge pull request #612 from stripe/brandur-fix-array-encoding-in-non-post
Fix encoding of arrays that are sent in query strings
2017-12-07 12:54:54 -08:00
Brandur
2bc471d501 Fix encoding of arrays that are sent in query strings
As discussed in #608, we currently have a problem where Faraday
deconstructs a query string that we encode and strips out any of the
array index numbers that we added. It's not too clear on why it does
this, but it appears to be built in at a pretty low level and hard to
change.

I spent a little time on this and it turns out that we can avoid the bad
code by depending on Faraday's `params` accessor on a request instead of
trying to do the encoding ourselves. Webmock has a pretty hard time
detecting the difference, but you can see some before and after encoding
here.

Before:

```
I, [2017-12-06T17:41:23.083942 #36737]  INFO -- : get
http://localhost:12111/v1/invoices/upcoming?customer=cus_123&subscription_items%5B%5D%5Bplan%5D=gold&subscription_items%5B%5D%5Bquantity%5D=2
```

After:

```
I, [2017-12-06T17:42:12.727752 #37158]  INFO -- : get
http://localhost:12111/v1/invoices/upcoming?customer=cus_123&subscription_items%5B0%5D%5Bplan%5D=gold&subscription_items%5B0%5D%5Bquantity%5D=2
```

Honestly, some of this can still use a lot of cleanup: it's weird that
we manually encode parameters ourselves for bodies, but not for queries;
but I think this'll fix the problem for now.

Fixes #608.
2017-12-07 10:51:07 -08:00
Brandur
ea426108f0 Bump version to 3.8.1 v3.8.1 2017-12-06 10:16:11 -08:00
Brandur
ee30b1f915
Merge pull request #611 from stripe/ob-fix-610
Support Tempfiles in file_upload creation requests
2017-12-06 10:14:59 -08:00
Olivier Bellone
949efb017d
Support Tempfiles in file_upload creation requests 2017-12-05 16:52:37 -08:00
Brandur
ffb6ea4a31
Merge pull request #607 from stripe/brandur-remove-manual-stubs
Remove manual exchange rate stubbing
2017-10-31 09:49:39 -07:00
Brandur
85c811a18f Remove manual exchange rate stubbing
stripe-mock 0.4.0 comes with the up-to-date exchange rates API. Here we
bump the required version and remove the manual exchange rate stubbing
in stripe-ruby's test suite.
2017-10-31 09:17:51 -07:00
Brandur
44e590fdb8 Bump version to 3.8.0 v3.8.0 2017-10-31 08:49:33 -07:00
Brandur
665af07f52
Merge pull request #606 from stripe/ob-exchange-rate
Add support for exchange_rates API requests
2017-10-31 08:48:45 -07:00
Olivier Bellone
b153b39203
Add support for exchange_rates API requests 2017-10-31 10:25:18 +01:00
Brandur
36e6c16cc8 Bump version to 3.7.0 v3.7.0 2017-10-26 07:53:09 -07:00
Brandur
c974c0b904 Merge pull request #603 from stripe/ob-source-transactions
Add support for listing source_transactions
2017-10-26 07:51:54 -07:00
Olivier Bellone
c455be74d4
Add support for listing source_transactions 2017-10-26 15:43:34 +02:00
Brandur
265d064f91 Fix links in the CHANGELOG 2017-10-20 12:16:15 -07:00
Brandur
987bbd09c0 Merge pull request #600 from stripe/brandur-explicit-operations
Add explicit operations list everywhere
2017-10-18 12:05:25 -07:00
Brandur
2a087595a9 Add explicit operations list everywhere
Makes the `operations` argument to `nested_resource_class_methods`
required and adds explicit lists to any invocations that were missing
one.

The impetus here is that I think it's more easily digestible if each
call site is explicit about what operations it supports and therefore
which methods it's about to create on the class.
2017-10-17 18:02:36 -07:00
Brandur
9ade60b082 Remove trailing whitespace 2017-10-17 18:01:56 -07:00
Brandur
53c2f1a760 Bump version to 3.6.0 v3.6.0 2017-10-17 17:56:07 -07:00
Brandur
af51af2577 Add some documentation to NestedResource module 2017-10-17 17:52:35 -07:00
Brandur
cf5354cc27 Alphabetize inclusion order 2017-10-17 17:50:20 -07:00