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 currency parameter to #coin method #4

Merged
merged 3 commits into from
Dec 11, 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
4 changes: 2 additions & 2 deletions lib/coinmarketcap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def self.coins(limit = nil)
end
end

def self.coin(id)
HTTParty.get("https://api.coinmarketcap.com/v1/ticker/#{id}/")
def self.coin(id, currency = 'USD')
HTTParty.get("https://api.coinmarketcap.com/v1/ticker/#{id}/?convert=#{currency}")
end

def self.global(currency = 'USD')
Expand Down
12 changes: 12 additions & 0 deletions spec/coinmarketcap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
end
end
end

context 'with valid id and a currency code' do
it "should receive a 200 response with coin details" do
VCR.use_cassette('single_eur_coin_response') do
response = Coinmarketcap.coin('bitcoin', 'EUR')
coin = JSON.parse(response.body)
expect(response.code).to eq(200)
expect(coin.count).to eq(1)
expect(coin.first['market_cap_eur'].to_i).to be > 0
end
end
end
end

describe "#global" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/cassettes/single_coin_response.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/fixtures/cassettes/single_eur_coin_response.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/fixtures/cassettes/wrong_coin_response.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.