48 Commits

Author SHA1 Message Date
Andrew Yang
e66eac41d1 Warn user if a known opt (such as idempotency_key) is in params 2017-05-26 13:29:36 -07:00
Brandur
2ade248e32 All tests working! 2017-02-14 12:17:37 -08:00
Brandur
de08a9b986 Lots of broken tests, but working implementation! 2017-02-14 12:17:37 -08:00
Brandur
1c780e2b3f Working test suite! 2017-02-14 12:17:37 -08:00
Brandur
1886d9a625 Move to an alternative system based on StripeClient 2017-02-14 12:17:37 -08:00
Brandur
843ea88219 Add a StripeResponse to objects created by API calls 2017-02-14 12:17:37 -08:00
Brandur
11a6eec5f5 Don't allow protected fields in Save.update API operation
As described in #481, adding a protected field like `legal_entity` as
part of an update API operation can cause some issues like a custom
encoding scheme not being considered and special handling around empty
values being ignored.

As a an easy fix for this, let's disallow access to protected fields in
the same way that we disallow them from being set directly on an
instance of a given model.

Helps address (but is not a complete fix for) #481.
2016-11-28 11:42:57 -08:00
Kyle Conroy
732a494ac4 Add update class method to API resources (#426)
* Rename the `Update` operation to `Save`
* Add the `update` class method to all saveable resources
* Add tests for update method
* Add tests for plans, invoice items, and application fees
2016-06-29 14:13:42 -07:00
Edouard CHIN
d288be358a Removed a forgotten line of doc [ci skip]:
- This removes the doc about `req_url` while saving a StripeObject, this options was removed in `e226ef`
2016-06-29 02:11:56 -04:00
Brandur
8f55baa6ea Fix warnings emitted during tests
I'm not sure exactly what changed here (did we change the `$VERBOSE`
setting?), but I'm not seeing a whole lot of warnings when running the
test suites locally and in CI. For example:

```
Started
........................................./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
............../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
......../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
.../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
........./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
...
..../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
....../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
..../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
......./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
........./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
........../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
................./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
.../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
..../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
....../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
..........
........./home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
....../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
......../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
......../home/travis/build/stripe/stripe-ruby/lib/stripe/api_operations/list.rb:6: warning: instance variable @opts not initialized
............./home/travis/build/stripe/stripe-ruby/lib/stripe/stripe_object.rb:35: warning: instance variable @values not initialized
./home/travis/build/stripe/stripe-ruby/lib/stripe/stripe_object.rb:35: warning: instance variable @values not initialized
...................../home/travis/build/stripe/stripe-ruby/lib/stripe/transfer.rb:8: warning: instance variable @api_key not initialized
..............
..
Finished in 0.785621037 seconds.
```

Most of these are due to unused or uninitialized variables. This patch
fixes all warnings by fixing offending code.
2016-04-11 15:20:42 -07:00
Niels Ganser
db3059a3c0 Allow options (headers) to be passed into .save
in the same manner as is already possible for .create.
2016-03-18 13:30:36 +01:00
Joshua Kovach
e226ef2ea1 Change everything from url to resource_url 2016-03-11 02:53:50 -05:00
Brandur
f215827e2f Remove uses and deprecate .serialize_params 2016-03-04 19:18:26 -08:00
Brandur
f723080220 Refactor serialize_params under StripeObject
This pull does two major things:

1. Refactors `serialize_params` to be more concise and readable while
   still complying to our existing test suite. Unfortunately over time
   this method has become a ball of mud that's very difficult to reason
   about, as recently evidenced by #384.
2. Moves `serialize_params` from class method to instance method (while
   still keeping for old class method for backwards compatibility). This
   is to give it a more sane interface.
2016-03-04 19:04:29 -08:00
Brandur
270dfe6052 Fix grammar problem 2016-02-19 10:28:03 -08:00
Brandur
daf2789ad7 Pass through all paging filters to descendent pages
When additional filters were provided for pagination like an expansion
or a predicate, they would not propagate to any call after the first.
This patch addresses that issue by storing all filters and moving them
to any new page objects being created.

Fixes #331.
2015-10-09 13:58:23 -07:00
Brandur
b3912c1712 Merge branch 'brandur-deprecate-refresh-from'
Conflicts:
	lib/stripe/stripe_object.rb
2015-10-08 17:49:27 -07:00
Brandur
11dd870900 Have StripeObject#update_attributes reflect behavior of accessors
This dials down the safety of `StripeObject`'s `#update_attributes`
method so that it allows properties to be assigned that it doesn't yet
know about. We're doing this for a few reasons:

1. To reflect the current behavior of accessors (i.e. `obj.name = ...`)
   through `method_missing`.
2. To allow `#update_attributes` to assign properties on new projects
   that don't yet know their schema from an API call.

Fixes #324.
2015-10-08 14:04:11 -07:00
Brandur
8b255c7005 Deprecate StripeObject#refresh_from
As discussed in #325, this deprecates the public visibility of
`#refresh_from` (by renaming it). It also adds some deprecation
infrastructure to produce warnings when it's used.
2015-10-08 09:57:16 -07:00
Brandur
aa7e559115 Extend Stripe::APIOperations::Create instead of including
Lets not be too shy about just using `extend` instead of `include` here
when it's more appropriate to do so. The advantage to this approach is
that the module can be either extended _or_ included with this change,
but couldn't be without it due to the `ClassMethods` meta-magic.

List has already started doing this as of #314, so we don't have to be
afraid of breaking convention here.
2015-10-05 12:24:53 -07:00
Brandur
42ea34b969 Pagination
Usage on a top-level collection:

```
Stripe::Customer.list.auto_paging_each do |customer|
  puts customer
end
```

Usage on a subcollection:

``` ruby
customer.invoices.auto_paging_each do |invoice|
  puts invoice
end
```

We've also renamed `#all` to `#list` to prevent confusion ("all" implies
that all resources are being returned, and in Stripe's paginated API
this was not the case). An alias has been provided for backward API
compatibility.

Fixes #167.

Replaces #211 and #248.
2015-10-05 12:15:09 -07:00
Brandur
b57cd5aca4 Support Ruby 1.8.7 2015-10-01 16:59:56 -07:00
Brandur
e23b57628f Add attribute mass assignment and use it in #save
As detailed in issue #119, we've somewhat unfortunately been allowing
object attributes to be passed in during a #save because we mix any
arguments directly into the serialized hash (it seems that this was
originally intended to be used more for meta parameters that go to the
request).

As also noted in #119, this use causes problems when certain types of
parameters (like subobjects) are used. We're now left in the somewhat
awkward position of either:

1. Removing this functionality on #save and breaking what may be
   behavior that people depend on.
2. Fully support this mass assignment.

This patch takes the second path by extracting a new #update_attributes
method and using it from #save. It's still far from a perfect approach
because keys that have the same name as certain options (e.g. `req_url`)
are not going to work, but it should capture the behavior that most
people want.

Fixes #119.
2015-10-01 16:21:34 -07:00
Brandur
e0354b70f7 Add RDoc for #save 2015-09-29 22:10:51 -07:00
Brandur
ac7d050ecf Create if #save is called on a new object
Modifies the behavior of an update so that it can create an object if it
was new. This allows an "upsert"-like functionality where the SDK will
tend to do the right/expected thing.

This is a tad janky in that it checks for the existence of a class-level
`.create` method which is expected to come from a different module, but
most modules in the project are already fairly deeply intertwined and
co-dependent.

Fixes #165.
2015-09-29 17:39:43 -07:00
Rasmus Rygaard
690fd18cb3 Add SKUs, Products 2015-09-13 18:10:47 -07:00
Brian Krausz
f8d5687040 Fixes as requested 2015-03-05 00:07:13 -08:00
Brian Krausz
a47a754795 Support arrays & add more nested tests 2015-03-03 14:25:10 -08:00
Brian Krausz
03abd88f0c Fix updating for nested hashes 2015-03-02 18:29:59 -08:00
Brian Krausz
3cbc60f35c Rename @@opts_to_persist 2015-02-11 12:31:57 -08:00
Brian Krausz
ff5be97ada TIL Hash#select is different in 1.8 2015-02-10 11:25:24 -08:00
Brian Krausz
4d611c62f7 Support persisted use of Stripe-Account header everywhere
Including implicit use in /v1/accounts/ endpoints
2015-02-09 23:38:34 -08:00
Kyle Conroy
43d591a93e Pass along API key 2015-01-08 10:32:57 -08:00
Kyle Conroy
e3a68bb3b9 Replace api_key with an options hash
For now, only two options are supported: `api_key` and
`idempotency_key`. In the future, we'll be adding support for additional
headers as needed.
2014-12-17 23:23:46 -08:00
Kyle Conroy
bfaaae9336 Add per-request headers 2014-12-15 16:11:45 -08:00
Tim Craft
0fc6ee5e5b Return self from Stripe::StripeObject#refresh_from 2014-08-22 19:43:13 +01:00
Andrew Thorp
11ed3d2d32 Merge pull request #110 from stripe/allow-expanding-on-save
Allow save to take opts
2014-01-29 17:50:06 -08:00
Andrew Thorp
5331e81f54 #save doesn't need an api_key, it's on the object already 2014-01-26 12:13:39 -06:00
Andrew Thorp
88b4afbac0 allow save to take opts, and an api_key
fixes #78
2014-01-25 15:26:51 -08:00
Pat Allan
b0f0c03990 Ensure delete parameters are passed through for subscriptions. 2014-01-22 17:42:37 +11:00
kiran-b
a0f1856cbb refactored update api operation, added ruby 1.9 tests back 2013-10-09 20:56:31 -07:00
kiran-b
b52c98c9c3 added support for setting/deleting individual keys 2013-10-08 17:38:40 -07:00
Brian Collins
b02b557b74 Style tweaks 2013-10-08 13:54:39 -07:00
kiran-b
57656f6e89 update now accounts for metadata={'key' => 'val'} syntax 2013-10-08 13:54:39 -07:00
Andrew Metcalf
88ead09193 support unsetting parameters by passing nil and updating 2013-08-06 11:37:35 -07:00
Jean Boussier
6a57264758 Allow to update a resource without retreiving it first
Rationale:

  Sometime you don't care about the current state of a resource
  you just want to update one of it's attributes.
  It should only require one request.

fixes #52

```ruby
  c = Stripe::Customer.new("cus_1EqKjPaFs4ZwDD")
  c.description = 'Ny new Description'
  c.save
```

Before:

```json
{
  error: {
    type: "invalid_request_error",
    message: "A parameter provided in the URL (id) was repeated as a GET or POST parameter. You can only provide this information as a portion of the URL.",
    param: "id",
  }
}
```

After:

Successfully update the customer and return it's whole state.
2013-03-14 11:04:18 -04:00
Greg Brockman
22907c7046 Fixup whitespace 2012-06-19 23:15:08 -07:00
Akash Manohar J
90ef0971d9 Moves API operations to seperate files
Signed-off-by: Akash Manohar J <akash@akash.im>
2012-05-15 02:56:40 +05:30