I'm building an API with Grape on Rails 4.2. Here's a link to the repo on GitHub.
On the frontend, I have a JavaScript application built with EmberJS. Here's the link to the repo on GitHub as well.
I have updated the following gems so that I can format the responses of my API following JSON API standard, which appears to be required to update to Ember 1.13, then to Ember 2.0.
gem "active_model_serializers", '0.10.0.rc2'
gem "grape"
gem "grape-active_model_serializers", :git => 'https://github.com/jrhe/grape-active_model_serializers.git'
After that, I've got the following error when I call the API: IOError: Not opened for reading
According to the information I gathered here and there, I suspect this is a conflict with how I format JSON.
In default.rb, the file that inherit all API controllers, when I comment this line:
formatter :json, Grape::Formatter::ActiveModelSerializers
I don't have any error anymore, but obviously the response isn't serialized.
My questions are:
Do you have any idea how I can solve this?
Do you think it's relevant to use Grape to build the API in my Rails app? With Rails 5 coming, isn't that better to user rails-api and rewrite the whole app? I mean, I'm starting, it's maybe the right time to do that...
Let me know if you need more information.
Thanks in advance for your help.
I ended up rewriting the whole API using jsonapi-resources.
Related
I googled a little bit to find a proper and easy to implement way to generate Swagger documentation for an existing Rails API app. To be short, there are 2 ways of implementation: either via controllers, models or via Rspec controller/request specs. The list is not too long and the choice is not so easy to make:
swagger-docs gem, - the oldest one. Pros: implementation is to be
done in controllers. Cons: does not support Swagger V2 version
and limited to 1.2 only.
swagger-blocks gem, - improved version of swagger-docs, supports Swagger V2 version, implementation is to be done in controllers, models. But I couldn't make it work, Swagger Editor could not parse the generated json file.
rswag gem: extends rspec-rails "request specs" with a Swagger-based DSL. Personally, I found it really difficult to implement in an existing Rails app for 2 reasons:
you will have to modify existing request specs
request specs look really weird and the syntax is not RSpec-ish.
rspec-rails-swagger gem: implementation via request specs. The same cons as above.
Does anybody know other gems to generate Swagger documentation for an existing Rails API app ? Any suggestions are welcome ! Thank you.
The solution I came to is as to use rswag gem and rspec-rails-swagger gem
- install rswag gem by adding the following in your Gemfile:
#Gemfile
gem 'rswag-api'
gem 'rswag-ui'
group :development, :test do
gem 'rspec-rails', '~> 3.8.1'
gem 'rspec-rails-swagger', '~> 0.1.5'
...
end
run `bundle install``
run rails g rswag:install to generate swagger_helper.rb
to create a new request spec with rspec-rails-swagger, run rails generate rspec:swagger PostsController(adapt the name to your won controller you want to write the spec).
write some specs as explained in rspec-rails-swagger README
run bundle exec rake swagger to generate a swagger.json file.
mount RSwag API and RSwag UI engines by adding the following lines to your routes.rb file:
#../config/routes.rb
Rails.application.routes.draw do
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'
...#other routes come here
end
start up your rails server with rails s
navigate to localhost:3000/api-docs to see the generated Swagger documentation.
Note: it works pretty good and replies to the client requirements, i.e.:
generate Swagger 2.0 compatible documentation
be able to execute requests directly from Swagger interface to see the real data
I removed rswag-specs gem from Gemfile because it could not validate response schema returned in JSON API format by active_model_serializers gem I use in my Rails API app. I had always to:
generate the docs
comment out failing tests
then uncomment failing tests in case I need to generate some new documentation, that was really hard to maintain.
Now request specs are validated by RSpec and rspec-rails-swagger at the same time without hassle.
Hope this helps.
Our working solution is to use:
swagger-blocks gem to generate the Swagger JSON
Swagger UI Console Chrome
Extension to provide the Swagger UI
i want to give request and get xml response so i'm using savon gem
i am facing problem with savon gem.
i tried version 3 and 2.2
with version 3 i face this problem https://stackoverflow.com/questions/20331827/savon-gem-not-getting-xml-response
with version 2.2 i face error unable to authenticate account
response = client.call(:get_models, message: {username: "xxx", secret: "xxx"})
followed savon doc version 2
how can i solve this or suggest any similar gem to savon
I have personally used Savon on several scenarios. I started with other gems (to connect to web services via SOAP), but I ended up moving to Savon. Before selecting another one, please bear in mind the way Savon responds.
There are other options you can find in RubyGems. One of them is HANDSOAP. The useful search will lead you to many others you can choose from depending on your specific needs.
Now I remember having started with soap4r, whose newest version you can find in GitHub.
Hope that helps,
I am currently creating a theme on Shopify and found a ruby gem called guard-shopify. I am struggling to use the gem. It is installed and i got to the point of adding the api key and secret password but now I am struggling to find out how to go about editing theme files locally and getting it to work with guard shopify so it pushes the most recent changes to the shopify account via guard.
Does anyone have good experience using this ruby gem?
Thanks,
Mark
try the shopify_theme gem - it has a watch option - https://rubygems.org/gems/shopify_theme
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.
Which gem or plugin should I use for building Myspace applications using Ruby on Rails?
MySpace provides a REST API Ruby Library:
http://developer.myspace.com/community/libs/ruby.aspx
I don't know if it's any good.
There's also a Spacer gem. I wasn't able to get it working, however.
http://www.railslodge.com/ruby_gems/18-spacer-
Here's a snippet of code for the OAUTH gem:
http://developer.myspace.com/Community/forums/p/3626/15947.aspx
I was unable to get it working.
Another snippit of code for the OAUTH gem:
http://developer.myspace.com/Community/forums/p/804/12424.aspx
Also unable to get it working.
A large part of developing on myspace must be done through the REST api that myspace provides, as well as ajax calls to import the response. Unfortunately you're not allowed to use an iFrame until OpenSocial 0.9 which wont be out for a while. Until then become familiar with MySpace's API and ajax.
You can use the myspace-ruby-sdk http://code.google.com/p/myspaceid-ruby-sdk/
There are a sample of Rails application ( 2.2.2 version ) into