I'm pretty new, but getting the concepts of Ruby on Rails. I'm trying to get a tournament up and running. I added the gem as a dependency in the Gem file; however, I'm unsure where to add my username and API key. This is the API - https://bitbucket.org/corneldm/challonge-api/wiki/Home - And what about displaying the the filtered list in view "Challonge::Tournament.find(:all)." I'm not sure how to connect the preconfigured ActiveResource classes. Has anyone experienced Challonge API for Ruby? Or Another bracket system I could use?
a file in config/initializers would be the conventional place to put that configuration info, probably in challone.rb so its clear what is getting initialized
If you have environment-specific user names and API keys, then you can consider /environments/.rb
Related
I know I'm going to get downvotes for even asking but I honestly have no clue how to do this and any assistance would be appreciated as I have never done this.
I have a client that migrated their blog to HubSpot and would like to have their blog posts displayed on their website. So how do I connect to HubSpot's API to display the blog in their website that I have in a Rails app?
Do I create MVC just for Blog API? Where do I put the URL to connect to?
If you want to connect to an other API the best way to do this is to create service objects. These are plain old Ruby objects (aka PORO) that represent the API as a Ruby object. You are free to use any location you want, but I would stick them in lib/services or app/services. If the provided API uses the Rails (REST) standards than you might be able to use ActiveResource.
You could also look for gems that provide these service objects. A quick RubyGem search finds multiple (unofficial) gems. From witch hubspot-ruby seems the most used and active.
If the gems don't do what you want you could look through the code to find some inspiration and create you own objects. Another option is to fork a project and add the functionality you want.
Here is a link to answer the broader question you're asking: What is the proper "Rails Way" to consume a RESTful web service on another domain?
When I build an API to handle my classes, if I want to add data, I have to make CURL commands through the terminal. Is there a simple way to do this ? So I'm looking for a gem (or other stuff) to handle my database easily, by myself (with no access for the users)
I've already found this : https://github.com/igorkasyanchuk/rails_db
But it's only to view content, not to add some.
Thanks !
I would suggest reading the Getting Started Guide (again?) closely as this is one of the central functions of the rails framework. If you are building an application with rails, you should be able to use the rails generate command to set up scaffolds, models, controllers, etc. And when you set up models, they will be persisted to whichever database you have set up (sqlite by default) when you call save on them.
I started using mongodb in my application and I'm now looking for an easy way to encrypt some sensitive binary data and store it in the mongodb.
When I do it for my MySql DB I use the attr_encrypted, but I guess that with mongoid, I'll need some other gem or method to do it, especially with a non-string field (BSON::Binary ).
Any suggestions?
Firstly attr_encrypted works with Mongoid/other DataMappers. it is similar to how you use it with SQL.
Otherwise, you can always check out the rails library for basic Encryption.
But, if you're looking for a specific gem that works with mongoid, you can go with either of these two options - (I have not included old/inactive gems but you can check out a complete list here)
symmetric-encryption
Here's a how-to blog.
This one isn't Mongoid specific though.
The second option is mongoid-encrypted-fields
It is mongoid specific, albeit a little less popular. More info here.
Hope this helps! :)
So I've been reading tutorials and trying to understand the differences between a ruby gem, a rails engine and a rails plugin however it is not completely clear which path to take.
Say I wanted to make an extension to rails which needs access only to active record within rails.
Should I do this within a rails engine? It seems overkill since I won't be needing routes, controllers, or views just a way to create models which exist within a database. Or do I make a gem that requires rails be installed? and if I do go that route is it possible to have db migrations within the gem. What happens if I just require ActiveRecord? Will others still easily be able to integrate my gem within their own projects?
It would be nice to know that if I do make a gem it is not required that the users absolutely have to have the full rails stack within the application they are working on.
I am developing a Rails application which will need frequent access to public APIs, and I am not sure what is best way to put external API (SOAP/WSDL) code in Rails application, what about model thingy, how we can manage that? Any ideas, comments?
The current contenders for "best" library for consuming External SOAP services seems to be either Savon or Handsoap. There is a comparison between the two here
I can't comment on handsoap as I haven't used it by I am happy with Savon which is working well for me.
In terms of Application structure then I would create a folder under lib for the interface named after the external entity and then store files under there using the namespacing features of rails.
So an example I have an external interface to a system called Sentinel. So I have RAILS_ROOT/lib/sentinel and then all classes within that folder are declared within a Sentinel module.
The first thing to do would be to see if there are any gems for the API's you want to interface with. Write a small wrapper class for the gem or just include it and use it where needed.
If you're looking to talk to a REST service, I would suggest the rest-client gem. If you want to do something completely custom you could make use of Jon Nunemaker's HTTParty. Nokogiri, an XML parser gem is useful for consuming XML-based services as well.