This is the Ruby library of Instamojo API.
This will assist you to programmatically create, edit and delete offers on Instamojo.
gem install Instamojo-rb
For Rails/bundler projects:
gem 'Instamojo-rb'
require 'Instamojo-rb' api = Instamojo::API.new do |app| app.app_id = "app_id-you-received-from-api@instamojo.com" end #or api = Instamojo::API.new("app_id-you-received-from-api@instamojo.com")
client = api.client
client.authenticate('instamojo_username', 'instamojo_password') #or client.authenticate do |user| user.username = "instamojo_username" user.password = "instamojo_password" end #=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
client.get_offers
offer_slug = "my-foo-product" client.get_offer(offer_slug) #=> {"offer"=> {"shorturl"=>nil, "start_date"=>nil, "note"=>"", "description"=>"This is a demo product. Just *claim* it. ", "venue"=>nil, "title"=>"Demo product", "url"=>"https://www.instamojo.com/ankurgel/demo-product/", "slug"=>"demo-product", "base_price"=>"0.00", "quantity"=>nil, "end_date"=>nil, "currency"=>"INR", "cover_image"=>nil, "timezone"=>nil, "redirect_url"=>""},
client.create_offer do |offer| offer.title = "Command line offer" offer.description = "This offer is being created via Instamojo-rb" offer.currency = "INR" offer.base_price = 0 offer.quantity = 0 end #OR client.create_offer({ "title" => "Command line offer", "description" => "This offer is being created via Instamojo-rb", "currency" => "INR", "base_price" => 0, "quantity" => 0 })
offer_slug = "my-foo-product" client.delete_offer(offer_slug)
client.logout
Few things which will be available in next versions:
-
Error handling; with respect to ‘Instamojo` error codes.
-
File Upload support.
-
Offer
andEvent
model with api methods like-
Accessor methods like on
Offer
:#title
,#description
,#quantity
-
Functional setters: +offer.set_title(‘Changed offer title’)+
-
+offer.set_quantity(30)+
-
offer.enable_variants
-
Copyright © 2014 Ankur Goel. See LICENSE.txt for further details.