Rails currency exchange gem that works? - ruby-on-rails

Just wondering if anyone has used a currency exchange ruby gem that gets exchange rates from an external api and actually works. I have tried the following gems but have not been able to get any of them to function as described:
goog_currency, yahoo_currency, google_currency, yahoo_finance_currency
One of these uses deprecated code and hence does not work correctly.
I am just trying to display a currency exchange rate in a rails view which has been grabbed from an external api.
I have also considered trying to parse the json from yahoo/google finance urls but this seems much harder to do than it should.

I picked google_currency from your list as most popular and it has been recently maintained. It worked fine for me, I ran the code from the synopsis without a problem.
If you saw the message:
You are using an old or stdlib version of json gem
Please upgrade to the recent version by adding this to your Gemfile:
gem 'json', '~> 1.7.7'
Then you may need to update your copy of multi_json to avoid the json deprecation warnings:
gem install json
gem install multi_json
Which should (at the time of writing) install json 1.8.0 and multi_json 1.7.8. Or of course, if this is for a project, you should be able to pick these versions in your Gemfile, provided there is no conflict with other libraries in your project. The message may of caused you concern, but it is not a problem with google_currency.
I didn't notice any conflict or problems with the google_currency gem, using either the deprecated JSON modules or the most recent ones. To do something similar to what you want:
require 'money'
require 'money/bank/google_currency'
bank = Money::Bank::GoogleCurrency.new
bank.get_rate(:GBP, :USD).to_f
=> 1.5513

Related

How i can use Mailchimp API directtly without using Rails Gem

I'm using Rails 3.2.11 and Ruby 1.9.3. I want to subscribe user to
mailchimp. But when i use gems like(gibbon and mailchimp_api).There are
too many dependencies issues. Mailchimp developer guide not help me too
much.I spent many days but not solve these issues.
How can i make direct api calls to mailchimp for subscribe users?
Any help?
Resolving your dependency issues with Gibbon should be a cinch: it only relies on two things:
gem 'faraday', '>= 0.9.1'
gem 'multi_json', '>= 1.11.0'
If you're unable to use a recent version of each of those, you probably have something else awry.
As for working with Mailchimp directly, their developer guides do a great job of walking you through how to obtain API tokens for other users using OAuth2 and explaining the endpoints that are available. You then just need to make HTTP requests (e.g. with Faraday v0.9.1 or greater), parse the responses (e.g. with multi_json 1.11.0 or greater) and write logic to handle errors.
If you want to get started faster, you could look at the source for Gibbon. You can even get away with copy-pasting the entirety of Gibbon into a gem of your own naming and modify the code to not rely on those dependencies.
...when i install gibbon then i need to move my ruby version from 1.9.3 to 2.1.3
You can use an earlier version of Gibbon that supports Ruby 1.9.3. It looks like the last version to support Ruby 1.9.3 is Gibbon 1.2.1.

update gem version that is specified in another gem dependency

In my Gemfile, I'm including a gem that has a .gemspec that uses the pessimistic operator ~> to specify a version of the gem. However, I need to use a newer version of the gem. In my case I'm using spree 3-0-stable that has activemerchant set to '~> 1.47.0' https://github.com/spree/spree/blob/3-0-stable/core/spree_core.gemspec#L22 but I need use active merchant '~> 1.59.0'
I tried to specify version 1.59.0 in my Gemfile but bundle complains with:
You have requested:
activemerchant ~> 1.59.0
The bundle currently has activemerchant locked at 1.47.0. Try running
bundle update activemerchant
If you are updating multiple gems in your Gemfile at once, try passing
them all to bundle update
But the command bundle update activemerchant will only update to 1.47.x.
What's the rails-y way of accomplishing this? Aside from forking spree myself and updating the .gemspec? Obviously updates to the activemerchant gem might break the spree gem. But I can test with my app.
The maintainers of Bundler have recommended forking the relevant gem, then making a PR back onto the gem. Then link directly to the branch in that PR in your Gemfile. This encourages the community to rally around a solution.
I've documented the process in detail here: https://github.com/rubygems/rfcs/pull/13#issuecomment-770416467
You can't do it, the rubygems system doesn't allow that. You have to file an issue for the upstream gem dependency, and ask them to loosen their requirements.
It may be that the version of activemerchant you want actually won't work with the version of spree you want, it will break it. If so, spree code would have to be fixed to work with the new version of activemerchant. Or, it could work fine with the version you want, the restriction in spree is accidentally unneccesarily strict, in which case the spree gemspec would just have to be changed to allow it.
But there's no way for you to override it without changing the spree gemspec.
You could make your own fork of spree in which you change the gemspec -- but without knowing whether or not spree will really work with the version of activemerchant you want, that could be dangerous. And now you're on your own fork, so you won't be able to upgrade to new versions of spree without merging in their changes to your fork, etc.
Another thing is, it's a bit odd to be running off a spree 3-0-stable branch, instead of an actual released version of the gem. But I'm not familiar with spree's release management practices, perhaps this is what they encourage? At any rate, changing this probably won't fix your problem.
If your app is relatively new or simple, you could consider switching from spree to solidus, a fork of spree. Solidus forked off at spree 2.x though, so migration from spree 3.x might not be straightforward, especially if your app is established and somewhat complex. Although the solidus_core gem is also locked to activemerchant ~> 1.48.0, so it also won't allow anything but activemerchant 1.48.x. The solidus team is pretty responsive on their Slack channel, if you wanted to ask them what's up with that, if they know if later versions of activemerchant will work, if the dependency can be loosened. I have found the solidus maintainers to be very responsive, and likely to be interested in allowing later versions of activemerchant if it's feasible to do. I'm not familiar with the current Spree team and how they communicate with users (if they have a slack, or listserv, or are responsive on github issues, or what), but you could of course have the same conversation with them.

How to install ember activemodel-adapter

I'm using ember-rails with ember-source and ember-data-source. But somehow the activemodel-adapter is not included in either of the gems. Or I'm missing something. I also searched bower, and can't find any. The code seems to be at: https://github.com/emberjs/data/tree/master/packages/activemodel-adapter
But it also needs compile. I'm wondering if there is an easier way to use it.
You must explicitly load a recent version of Ember Data. For example, add a version to the ember-data-source gem in your Gemfile:
gem 'ember-data-source', '~> 1.0.0.beta.7'
The active model adapter is included with Ember Data. Assuming everything in your project is global you could use it for your entire application like so:
App.ApplicationAdapter = DS.ActiveModelAdapter;

Is there an updated rails_sql_views gem for rails 3.2?

I need the functionality provided by the rails_sql_views gem. However it looks like the last commit for this gem was made in 2010. Has this project been outdated by a new project? I'd like to find an active gem to use to get this functionality.
http://activewarehouse.rubyforge.org/rails_sql_views/
http://rubygems.org/gems/rails_sql_views
After further research here is a Rails 3 candidate for similar functionality:
https://github.com/bradphelan/Active-Illusion
This is a gem of this blog post:
http://xtargets.com/2011/08/02/tableless-views-with-active-record/
However this solution doesn't seem to be very popular.
schema_plus gem has create_view method that seems compatible (although I'm not familiar with rails_sql_views).
barancw, I needed this gem for our product using Rails 3.2.5, so I forked the repo and updated the necessary pieces. This gem is great for improving the performance of our large database queries, as it reduces the need to load objects into memory. I combined this gem with another optimization: Rails - given an array of Users - how to get a output of just emails?
https://github.com/ryanlitalien/rails_sql_views
Original documentation: http://rubydoc.info/gems/rails_sql_views/0.8.0/frames/index
Please keep in mind the docs are a bit outdated ("require_gem" has been replaced with "gem" and add the gem to your Gemfile as well).

What is the easiest way to work with Google Docs API in Ruby on Rails?

What is the easiest way to work with the Google Docs API in a Ruby on Rails application? Is there a gem available?
I did find this page: Google Data on Rails, is it the most up to date resource?
The google data rails on page is really out of date, at least in a ruby 1.9.3 environment its non useful.
Having a play with the google_drive gem now....
https://github.com/gimite/google-drive-ruby#readme
I was able to get it to work by simply installing it and pasting the readme code into a file. What more can you ask for!?
You can also Bearer universal API client available in Ruby.
This way you can query Google Docs API very easily and don't even have to worry about OAuth or refresh tokens: https://www.bearer.sh/integrations/33/google-docs-api
The Google Docs developers have now released their own gem to work with the API. Here's a guide to getting started: https://developers.google.com/sheets/api/quickstart/ruby
And the gem itself can be downloaded in the normal way from Rubygems: gem install google-api-client
There's more information in the Readme for the gem's source code repository: https://github.com/google/google-api-ruby-client
you can use this gem omniauth-google-oauth2. Make configuration with consumer-key and secret-key. Add gem in Gemfile. Follow github.

Resources