Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for exchange_rates API requests #606

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-10-26 15:43:11 +0200 using RuboCop version 0.50.0.
# on 2017-10-30 14:39:50 +0100 using RuboCop version 0.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -38,7 +38,7 @@ Metrics/MethodLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 303
Max: 304

# Offense count: 5
# Configuration parameters: CountKeywordArgs.
Expand All @@ -55,6 +55,6 @@ Style/ClassVars:
- 'lib/stripe/stripe_object.rb'
- 'test/stripe/api_resource_test.rb'

# Offense count: 51
# Offense count: 52
Style/Documentation:
Enabled: false
1 change: 1 addition & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
require "stripe/dispute"
require "stripe/ephemeral_key"
require "stripe/event"
require "stripe/exchange_rate"
require "stripe/file_upload"
require "stripe/invoice"
require "stripe/invoice_item"
Expand Down
11 changes: 11 additions & 0 deletions lib/stripe/exchange_rate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Stripe
class ExchangeRate < APIResource
extend Stripe::APIOperations::List

OBJECT_NAME = "exchange_rate".freeze

def self.resource_url
"/v1/exchange_rates"
end
end
end
1 change: 1 addition & 0 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.object_classes
Dispute::OBJECT_NAME => Dispute,
EphemeralKey::OBJECT_NAME => EphemeralKey,
Event::OBJECT_NAME => Event,
ExchangeRate::OBJECT_NAME => ExchangeRate,
FileUpload::OBJECT_NAME => FileUpload,
Invoice::OBJECT_NAME => Invoice,
InvoiceItem::OBJECT_NAME => InvoiceItem,
Expand Down
44 changes: 44 additions & 0 deletions test/stripe/exchange_rate_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require File.expand_path("../../test_helper", __FILE__)

module Stripe
class ExchangeRateTest < Test::Unit::TestCase
should "be listable" do
# TODO: remove stub once stripe-mock supports /v1/exchange_rates
stub_request(:get, "#{Stripe.api_base}/v1/exchange_rates")
.to_return(body: JSON.generate(
object: "list",
data: [
{
id: "eur",
object: "exchange_rate",
rates: { "usd" => 1.18221 },
},
{
id: "usd",
object: "exchange_rate",
rates: { "eur" => 0.845876 },
},
]
))

list_rates = Stripe::ExchangeRate.list
assert_requested :get, "#{Stripe.api_base}/v1/exchange_rates"
assert list_rates.data.is_a?(Array)
assert list_rates.data.first.is_a?(Stripe::ExchangeRate)
end

should "be retrievable" do
# TODO: remove stub once stripe-mock supports /v1/exchange_rates
stub_request(:get, "#{Stripe.api_base}/v1/exchange_rates/usd")
.to_return(body: JSON.generate(
id: "usd",
object: "exchange_rate",
rates: { "eur" => 0.845876 }
))

rates = Stripe::ExchangeRate.retrieve("usd")
assert_requested :get, "#{Stripe.api_base}/v1/exchange_rates/usd"
assert rates.is_a?(Stripe::ExchangeRate)
end
end
end