Skip to content

Commit

Permalink
Add support for Radar List and ListItem resources
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Oct 31, 2018
1 parent d62f12f commit 08a8d2b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sudo: false
env:
global:
# If changing this number, please also change it in `test/test_helper.rb`.
- STRIPE_MOCK_VERSION=0.35.0
- STRIPE_MOCK_VERSION=0.36.0

cache:
directories:
Expand Down
2 changes: 2 additions & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
require "stripe/person"
require "stripe/plan"
require "stripe/product"
require "stripe/radar/list"
require "stripe/radar/list_item"
require "stripe/recipient"
require "stripe/recipient_transfer"
require "stripe/refund"
Expand Down
14 changes: 14 additions & 0 deletions lib/stripe/radar/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Stripe
module Radar
class List < Stripe::APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "radar.list".freeze
end
end
end
13 changes: 13 additions & 0 deletions lib/stripe/radar/list_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Stripe
module Radar
class ListItem < Stripe::APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List

OBJECT_NAME = "radar.list_item".freeze
end
end
end
2 changes: 2 additions & 0 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def self.object_classes # rubocop:disable Metrics/MethodLength
Person::OBJECT_NAME => Person,
Plan::OBJECT_NAME => Plan,
Product::OBJECT_NAME => Product,
Radar::List::OBJECT_NAME => Radar::List,
Radar::ListItem::OBJECT_NAME => Radar::ListItem,
Recipient::OBJECT_NAME => Recipient,
RecipientTransfer::OBJECT_NAME => RecipientTransfer,
Refund::OBJECT_NAME => Refund,
Expand Down
38 changes: 38 additions & 0 deletions test/stripe/radar/list_item_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require ::File.expand_path("../../../test_helper", __FILE__)

module Stripe
module Radar
class ListItemTest < Test::Unit::TestCase
should "be listable" do
items = Stripe::Radar::ListItem.list(list: "rsl_123")
assert_requested :get, "#{Stripe.api_base}/v1/radar/list_items?list=rsl_123"
assert items.data.is_a?(Array)
assert items.first.is_a?(Stripe::Radar::ListItem)
end

should "be retrievable" do
item = Stripe::Radar::ListItem.retrieve("rsli_123")
assert_requested :get, "#{Stripe.api_base}/v1/radar/list_items/rsli_123"
assert item.is_a?(Stripe::Radar::ListItem)
end

should "be creatable" do
item = Stripe::Radar::ListItem.create(
list: "rsl_123",
value: "value"
)
assert_requested :post, "#{Stripe.api_base}/v1/radar/list_items"
assert item.is_a?(Stripe::Radar::ListItem)
end

should "be deletable" do
list = Stripe::Radar::ListItem.retrieve("rsli_123")
list = list.delete
assert_requested :delete, "#{Stripe.api_base}/v1//v1/radar/list_items/rsli_123"
assert list.is_a?(Stripe::Radar::ListItem)
end
end
end
end
51 changes: 51 additions & 0 deletions test/stripe/radar/list_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require ::File.expand_path("../../../test_helper", __FILE__)

module Stripe
module Radar
class ListTest < Test::Unit::TestCase
should "be listable" do
lists = Stripe::Radar::List.list
assert_requested :get, "#{Stripe.api_base}/v1/radar/lists"
assert lists.data.is_a?(Array)
assert lists.first.is_a?(Stripe::Radar::List)
end

should "be retrievable" do
list = Stripe::Radar::List.retrieve("rsl_123")
assert_requested :get, "#{Stripe.api_base}/v1/radar/lists/rsl_123"
assert list.is_a?(Stripe::Radar::List)
end

should "be creatable" do
list = Stripe::Radar::List.create(
alias: "list_alias",
name: "list_name"
)
assert_requested :post, "#{Stripe.api_base}/v1/radar/lists"
assert list.is_a?(Stripe::Radar::List)
end

should "be saveable" do
list = Stripe::Radar::List.retrieve("rsl_123")
list.metadata["key"] = "value"
list.save
assert_requested :post, "#{Stripe.api_base}/v1/radar/lists/rsl_123"
end

should "be updateable" do
list = Stripe::Radar::List.update("rsl_123", metadata: { key: "value" })
assert_requested :post, "#{Stripe.api_base}/v1/radar/lists/rsl_123"
assert list.is_a?(Stripe::Radar::List)
end

should "be deletable" do
list = Stripe::Radar::List.retrieve("rsl_123")
list = list.delete
assert_requested :delete, "#{Stripe.api_base}/v1//v1/radar/lists/rsl_123"
assert list.is_a?(Stripe::Radar::List)
end
end
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require ::File.expand_path("../test_data", __FILE__)

# If changing this number, please also change it in `.travis.yml`.
MOCK_MINIMUM_VERSION = "0.35.0".freeze
MOCK_MINIMUM_VERSION = "0.36.0".freeze
MOCK_PORT = ENV["STRIPE_MOCK_PORT"] || 12_111

# Disable all real network connections except those that are outgoing to
Expand Down

0 comments on commit 08a8d2b

Please sign in to comment.