Skip to content

Instantly share code, notes, and snippets.

View amitpatelx's full-sized avatar

Amit Patel amitpatelx

View GitHub Profile
@amitpatelx
amitpatelx / access_google_driver.rb
Created June 18, 2018 12:02
Access google drive API
require 'google/apis/drive_v3'
require "googleauth"
credentials =
Google::Auth::UserRefreshCredentials.new(
client_id: "854280762506-lrrj2ajqh9b.apps.googleusercontent.com",
client_secret: "jWiGrijiFCNRmig1s3aQt",
scope: ["https://www.googleapis.com/auth/drive"],
additional_parameters: { "access_type" => "offline" })
@amitpatelx
amitpatelx / google_drive.rb
Created June 18, 2018 11:59
Accessing google drive API
require 'google/apis/drive_v3'
# Create object of the drice service
service = Google::Apis::DriveV3
# Authorize it with the help of credentials generated
service.authorization = credentials
@amitpatelx
amitpatelx / generate_token.rb
Last active June 18, 2018 12:03
Generate Google API token using refresh token
require "googleauth"
redentials =
Google::Auth::UserRefreshCredentials.new(
client_id: "3453463453ghjejfrekjfrekgjher.apps.googleusercontent.com",
client_secret: "dnbddfjfjkffrfrfj",
scope: ["https://www.googleapis.com/auth/drive"], # enter the scope for a service whichever you want to use
additional_parameters: { "access_type" => "offline" }) # DO not forgot to add this
# Set the refresh token
@amitpatelx
amitpatelx / README.md
Created June 5, 2018 11:35
Install Spina and Shop extension
  1. rails new MyShop --database=postgresql
  2. rails active_storage:install
  3. Add spina and spinga shop gems to Gemfile
  4. rails g spina:install
  5. rails g spina:shop:install
  6. rails spina_shop:import_countries
@amitpatelx
amitpatelx / devise.rb
Created October 12, 2017 10:41
How to fix No route matches [GET] “/auth/shopify” after introducing devise with Omniauth?
# Commented the following line, moved it to omniauth.rb
# config.omniauth :google_oauth2, Settings.google.client_id, Settings.google.client_secret, { access_type: "offline", approval_prompt: "" }
@amitpatelx
amitpatelx / routes.rb
Created October 6, 2017 10:44
Devise - Disable Sign in
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' },
path_names: { sign_in: '' }
@amitpatelx
amitpatelx / user.rb
Created October 6, 2017 10:42
Disable Sign Up in Devise
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable
end
@amitpatelx
amitpatelx / user.rb
Created October 6, 2017 10:37
Typical Devise User Model
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
@amitpatelx
amitpatelx / enqueued_job_spec.rb
Created September 27, 2017 10:31
Check if mail is queued for delivery in rspec
mailer_jobs_count = ActionMailer::DeliveryJob.queue_adapter.enqueued_jobs.count{ |x| x[:job] == ActionMailer::DeliveryJob && x[:args].last == feed.id}
expect(mailer_jobs_count).to eq 1
@amitpatelx
amitpatelx / get_all_shopify_products.rb
Last active October 7, 2017 08:39
How to fetch all products using Shopify’s Ruby SDK?
# assumption: configured as per https://github.com/Shopify/shopify_app#managing-api-keys
class Shopify::ProductService
def new
# get valid session to connect with the target store
session = ShopifyAPI::Session.new("your shop shopify_domain", "your shop shopify_token")
ShopifyAPI::Base.activate_session(session)
end
def products