Webhooks & Stripe

What are webhooks A Webhook is a method of altering the behavior of a web page, or web application, with custom callbacks. These callbacks may be maintained, modified, and managed by third-party users and developers who may not necessarily be affiliated with the originating website or application. WebHooks are an HTTP POST callback request sent to URL of a user’s choice in response to some event occurring. They offer simple and effective server to server communication without long running connections How do I implement WebHooks? Simply provide your users with the ability to submit their own URL, and POST

Using OAuth2 gem

oauth2 - A Ruby wrapper for the OAuth 2.0 specification. gem install oauth2 Basics of OAuth2 is well explained here: Oauth2 basics Creating OAuth2::Client instance require 'oauth2' client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org') OAuth2 provides four authentication grant types : Authorization Code Grant Implicit Grant Resource Owner Password Credentials Grant Client Credentials Grant In UN project, we have used Resource Owner Password Credentials Grant type token = client.password.get_token('username', 'password') In case if Credentials are not correct, OAuth2::Error will be raised. With correct credentials, it gives OAuth2::AccessToken instance which

Better Errors in Rails

[better_errors][1] is a Rack middleware that replaces the default standard rails error page with a more useful one. The default Rails error page is also useful, but there is so much output that we don’t usually need and also there is a lot of other things we might need to see. The features of better_errors gem are awesome: Full stack trace Source code inspection for all stack frames (with highlighting) Local and instance variable inspection Live REPL (Read-Eval-Print Loop) on every stack frame In this local and instance variable inspection is so useful. We can immediately

View formatted table columns using table_print gem

table_print Gem It's an efficient way to view a list of structured data, making it easy to scan and compare across large swaths of records. It even lets you nest other tables of related objects, contextualizing data across tables. It’s incredibly flexible, yet simple, making it easy to see exactly the data you care about. INSTALLATION: To install the gem: Add the following to your gemfile- gem "table_print", "~> 1.0.0" Then run: $ bundle install USAGE: Go to rails console: $ rails c Eg. 1) To view the entire table: tp Size.all Will give the output: ID

Attaching images using Attachinary and Cloudinary

A] Cloudinary: Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. It is used to easily upload images to the cloud. It automatically performs smart image resizing, cropping and conversion without installing any complex software. Also, integration of Facebook or Twitter profile image extraction in a snap,that too in any dimension and style to match your website’s graphics requirements. Add following line to your Gemfile: gem 'cloudinary' Add following line to config/cloudinary.yml development: api_key: //enter api key api_secret: //enter api secret cloud_name: //enter cloud name

Recaptcha setup and usage with devise

recaptcha is a gem that uses google's CAPTCHA service. A CAPTCHA is a program that can tell whether its user is a human or a computer. To Setup recaptcha on local machine we need to add the gem, gem "recaptcha", :require => "recaptcha/rails" then we need to obtain private and public key by registering to this url http://www.google.com/recaptcha/whyrecaptcha While registration we can choose if we need public and private keys which work on particular domain or we can choose to use it on any domain. Once we have the public and private key we can

Method / Process to export active record data to excel file, save xls file on S3 and provide download xls feature

In one of our web application, we had a specific requirement wherein the client wanted the data from the app into a specific xls format. Thus we needed to export data from our app in this custom format and save the xls file on S3. Our app will then show a link to "Download" in ActiveAdmin UI clicking which it will start downloading this xls file from S3 on clients local PC. We have broken down the process into numerous steps, hope this will be helpful. The process goes as follows: The data from the app is exported

Stamp gem for Human friendly date and time format

[Stamp Gem(Stamp Gem)][1] Stamp gem is the best gem for converting format of Dates and Times in Human friendly formats. Its very easy to use in our rails application. We can use this gem as: run: gem install stamp or inlude this line in gem file gem 'stamp' then run: bundle install. Example: Suppose, I have a date = 2014-01-15 18:19:07 +0530 then we can convert this date into humans friendly date format like date.stamp('1-Jan-2000') => '15-Jan-2014' date.stamp('1st Jan') => '15th Jan' date.stamp('Jan 1, 2000') => 'Jan 15, 2014' date.stamp(

Reek Gem

Reek gem is a code smell detector for ruby. It examines Ruby classes, modules, methods and reports any code smells it finds. To install this gem, use: gem install reek USAGE: 1/ Scan the current directory: <pre>$ reek .</pre> 2/ scan specific directories like: <pre>$ reek lib/your/files</pre> To read more about reek gem click here(reek doc) To find up to date details of what exactly reek will check in your code check this(reek wiki)

Draw architectural design of the project using "railroady" gem

As a developer no one likes to write a complete documentation for a project. Butsometime we have to give some document which explain at least our architectural design of project. If in future anyone else work on same project then he can easily understand the overview and business logic before look into the code.We should draw a simple architectural design of our project models, controller and their relationship. There is a gem which provides all necessary diagrams - add it into development group. gem 'railroady' System Requirements $ sudo apt-get install graphviz run $ rake diagram:all It generates all diagrams