From 8415eef5b4ae43210170edae81221f99db3faee0 Mon Sep 17 00:00:00 2001 From: Sarthak Kukreja Date: Thu, 11 Apr 2019 12:14:40 +0530 Subject: [PATCH 1/8] Add Pagination --- lib/client/client.rb | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/client/client.rb b/lib/client/client.rb index 168421e..a46e7c8 100644 --- a/lib/client/client.rb +++ b/lib/client/client.rb @@ -75,11 +75,16 @@ def authenticate(username = nil, password = nil, options = {}, &block) end # GET /links - def links_list - get('links') + def links_list(limit = nil , page = nil ) + if limit != nil && page != nil + get('links', {limit: limit, page: page}) + else + get('links') + end @response.success? ? @response.body[:links].map { |link| Instamojo::Link.new link, self } : @response end + # GET /links/:slug def link_detail(slug) slug = slug.slug if slug.instance_of? Instamojo::Link @@ -125,8 +130,12 @@ def upload_file(filepath) # GET /payments - def payments_list - get('payments') + def payments_list(limit = nil , page = nil ) + if limit != nil && page != nil + get('payments' , {limit: limit, page: page}) + else + get('payments') + end @response.success? ? @response.body[:payments].map { |payment| Instamojo::Payment.new payment, self } : @response end @@ -145,8 +154,12 @@ def payment_request(options, &block) end # GET /payment-requests - def payment_requests_list - get('payment-requests') + def payment_requests_list(limit = nil , page = nil) + if limit != nil && page != nil + get('payment-requests', {limit: limit, page: page} ) + else + get('payment-requests') + end @response.success? ? @response.body[:payment_requests].map { |payment_request| Instamojo::PaymentRequest.new payment_request, self } : @response end @@ -157,8 +170,12 @@ def payment_request_status(payment_request_id) end # GET /refunds - def refunds_list - get('refunds') + def refunds_list(limit = nil , page = nil) + if limit != nil && page != nil + get('refunds' , {limit: limit, page: page}) + else + get('refunds') + end @response.success? ? @response.body[:refunds].map { |refund| Instamojo::Refund.new refund, self } : @response end From 8d936d332346b6437dc0212ca184d65bb2acf27a Mon Sep 17 00:00:00 2001 From: Vijith Date: Fri, 5 Jul 2019 14:49:08 +0530 Subject: [PATCH 2/8] some pagination param refactoring --- lib/client/client.rb | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/client/client.rb b/lib/client/client.rb index a46e7c8..b644454 100644 --- a/lib/client/client.rb +++ b/lib/client/client.rb @@ -75,12 +75,8 @@ def authenticate(username = nil, password = nil, options = {}, &block) end # GET /links - def links_list(limit = nil , page = nil ) - if limit != nil && page != nil - get('links', {limit: limit, page: page}) - else - get('links') - end + def links_list(page = nil, limit = nil) + get('links', get_pagination_params(page, limit)) @response.success? ? @response.body[:links].map { |link| Instamojo::Link.new link, self } : @response end @@ -130,12 +126,8 @@ def upload_file(filepath) # GET /payments - def payments_list(limit = nil , page = nil ) - if limit != nil && page != nil - get('payments' , {limit: limit, page: page}) - else - get('payments') - end + def payments_list(page = nil, limit = nil) + get('payments', get_pagination_params(page, limit)) @response.success? ? @response.body[:payments].map { |payment| Instamojo::Payment.new payment, self } : @response end @@ -154,12 +146,8 @@ def payment_request(options, &block) end # GET /payment-requests - def payment_requests_list(limit = nil , page = nil) - if limit != nil && page != nil - get('payment-requests', {limit: limit, page: page} ) - else - get('payment-requests') - end + def payment_requests_list(page = nil, limit = nil) + get('payment-requests', get_pagination_params(page, limit)) @response.success? ? @response.body[:payment_requests].map { |payment_request| Instamojo::PaymentRequest.new payment_request, self } : @response end @@ -170,12 +158,8 @@ def payment_request_status(payment_request_id) end # GET /refunds - def refunds_list(limit = nil , page = nil) - if limit != nil && page != nil - get('refunds' , {limit: limit, page: page}) - else - get('refunds') - end + def refunds_list(page = nil, limit = nil) + get('refunds', get_pagination_params(page, limit)) @response.success? ? @response.body[:refunds].map { |refund| Instamojo::Refund.new refund, self } : @response end @@ -239,5 +223,17 @@ def get_file_upload_url get('links/get_file_upload_url') @response.success? ? @response.body[:upload_url] : @response end + + def get_pagination_params(page, limit) + params = {} + if page != nil + params.merge!(page: page) + end + + if limit != nil + params.merge!(limit: limit) + end + params + end end end From a03fcb903cae180a4a420b1c026af2e930fa57f9 Mon Sep 17 00:00:00 2001 From: Vijith Date: Fri, 5 Jul 2019 15:32:31 +0530 Subject: [PATCH 3/8] gemspec updates --- Rakefile | 10 +++++----- Instamojo-rb.gemspec => instamojo-ruby.gemspec | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) rename Instamojo-rb.gemspec => instamojo-ruby.gemspec (93%) diff --git a/Rakefile b/Rakefile index 6aa2cbb..9fff47d 100644 --- a/Rakefile +++ b/Rakefile @@ -14,13 +14,13 @@ require 'rake' require 'jeweler' Jeweler::Tasks.new do |gem| # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options - gem.name = "Instamojo-rb" - gem.homepage = "http://github.com/AnkurGel/Instamojo-rb" + gem.name = "instamojo-ruby" + gem.homepage = "http://github.com/Instamojo/Instamojo-rb" gem.license = "MIT" gem.summary = %Q{Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo} gem.description = %Q{Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo. Also supports listing, updation and details of Payments, Payments Requests and Refunds.} - gem.email = "ankurgel@gmail.com" - gem.authors = ["Ankur Goel"] + gem.email = "dev-accounts@instamojo.com" + gem.authors = ["Instamojo Technologies"] # dependencies defined in Gemfile end Jeweler::RubygemsDotOrgTasks.new @@ -38,7 +38,7 @@ Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' - rdoc.title = "Instamojo-rb #{version}" + rdoc.title = "instamojo-ruby #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end diff --git a/Instamojo-rb.gemspec b/instamojo-ruby.gemspec similarity index 93% rename from Instamojo-rb.gemspec rename to instamojo-ruby.gemspec index 06794fa..3fe126a 100644 --- a/Instamojo-rb.gemspec +++ b/instamojo-ruby.gemspec @@ -5,15 +5,15 @@ # stub: Instamojo-rb 1.1.0 ruby lib Gem::Specification.new do |s| - s.name = "Instamojo-rb" + s.name = "instamojo-ruby" s.version = "1.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] - s.authors = ["Ankur Goel"] + s.authors = ["Instamojo Technologies"] s.date = "2015-12-18" s.description = "Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo. Also supports listing, updation and details of Payments, Payments Requests and Refunds." - s.email = "ankurgel@gmail.com" + s.email = "dev-accounts@instamojo.com" s.extra_rdoc_files = [ "LICENSE.txt", "README.md", @@ -44,7 +44,7 @@ Gem::Specification.new do |s| "spec/Instamojo-rb_spec.rb", "spec/spec_helper.rb" ] - s.homepage = "http://github.com/AnkurGel/Instamojo-rb" + s.homepage = "http://github.com/Instamojo/Instamojo-rb" s.licenses = ["MIT"] s.rubygems_version = "2.2.2" s.summary = "Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo" From 74d966c4e58f6d6ba02f474e0dbd68fe810549c1 Mon Sep 17 00:00:00 2001 From: Vijith Date: Fri, 5 Jul 2019 18:21:57 +0530 Subject: [PATCH 4/8] specfile name update --- instamojo-ruby.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instamojo-ruby.gemspec b/instamojo-ruby.gemspec index 3fe126a..e2401ee 100644 --- a/instamojo-ruby.gemspec +++ b/instamojo-ruby.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| ".rspec", "Gemfile", "Gemfile.lock", - "Instamojo-rb.gemspec", + "instamojo-ruby.gemspec", "LICENSE.txt", "README.md", "README.rdoc", From dcc02699b2c4f8d91c053b7e83a53357c1688890 Mon Sep 17 00:00:00 2001 From: Vijith Date: Fri, 5 Jul 2019 18:24:19 +0530 Subject: [PATCH 5/8] version 1.1.1 --- VERSION | 2 +- instamojo-ruby.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 1cc5f65..8cfbc90 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1 \ No newline at end of file diff --git a/instamojo-ruby.gemspec b/instamojo-ruby.gemspec index e2401ee..c8b3f20 100644 --- a/instamojo-ruby.gemspec +++ b/instamojo-ruby.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |s| s.name = "instamojo-ruby" - s.version = "1.1.0" + s.version = "1.1.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] From 45c6007a5184161add96324df884fb1f629f321e Mon Sep 17 00:00:00 2001 From: Vijith Date: Mon, 8 Jul 2019 14:41:26 +0530 Subject: [PATCH 6/8] Read me update --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 564f105..7588d82 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This is the **Ruby** library of [Instamojo REST API](https://www.instamojo.com/d This will assist you to programmatically create, edit and delete links on Instamojo. Also supports [RAP](https://www.instamojo.com/developers/request-a-payment-api/) api for payments request, listing and status. ## Installation -`gem install Instamojo-rb` +`gem install instamojo-ruby` For your Rails/bundler projects: -`gem 'Instamojo-rb'` +`gem 'instamojo-ruby'` ## Usage ### Set API keys @@ -47,6 +47,11 @@ _Helper methods_ for `Link`: client.links_list #=> Array of Instamojo::Link objects ``` +##### Supports optional pagination +```ruby +client.links_list(1, 10) +#=> Array of 10 Link objects (page 1) +``` #### Create a new product ##### Required: @@ -142,6 +147,11 @@ Details are documented [here](https://www.instamojo.com/developers/rest/#toc-pay client.payments_list #=> Returns array of Payment objects ``` +##### Supports optional pagination +```ruby +client.payments_list(1, 10) +#=> Array of 10 Payment objects (page 1) +``` #### Detail or status of a payment ```ruby payment = client.payment_detail('MOJxxx06000F97367750') @@ -161,6 +171,11 @@ payment_request = client.payment_request({amount:100, purpose: 'api', send_email payment_requests = client.payment_requests_list #=> Returns array of PaymentRequest objects ``` +##### Supports optional pagination +```ruby +client.payment_requests_list(1, 10) +#=> Array of 10 PaymentRequest objects (page 1) +``` #### Status of payment request You can get the status of a payment_request from the id you obtained after making payment request. ```ruby @@ -178,7 +193,11 @@ payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b276168 refunds = client.refunds_list #=> Returns array of Refund objects ``` - +##### Supports optional pagination +```ruby +client.refunds_list(1, 10) +#=> Array of 10 Refund objects (page 1) +``` #### Create a new refund ##### Required: * `payment_id` - Payment ID of the payment against which you're initiating the refund. From e2d1c769567fe9e61b4a5f6deffa137710e80de2 Mon Sep 17 00:00:00 2001 From: Vijith Date: Tue, 9 Jul 2019 15:28:05 +0530 Subject: [PATCH 7/8] options as hash + v1.1.2 --- README.md | 8 ++++---- instamojo-ruby.gemspec | 2 +- lib/client/client.rb | 28 ++++++++-------------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 7588d82..cd9c040 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ client.links_list ``` ##### Supports optional pagination ```ruby -client.links_list(1, 10) +client.links_list(page:1, limit:10) #=> Array of 10 Link objects (page 1) ``` @@ -149,7 +149,7 @@ client.payments_list ``` ##### Supports optional pagination ```ruby -client.payments_list(1, 10) +client.payments_list(page:1, limit:10) #=> Array of 10 Payment objects (page 1) ``` #### Detail or status of a payment @@ -173,7 +173,7 @@ payment_requests = client.payment_requests_list ``` ##### Supports optional pagination ```ruby -client.payment_requests_list(1, 10) +client.payment_requests_list(page:1, limit:10) #=> Array of 10 PaymentRequest objects (page 1) ``` #### Status of payment request @@ -195,7 +195,7 @@ refunds = client.refunds_list ``` ##### Supports optional pagination ```ruby -client.refunds_list(1, 10) +client.refunds_list(page:1, limit:10) #=> Array of 10 Refund objects (page 1) ``` #### Create a new refund diff --git a/instamojo-ruby.gemspec b/instamojo-ruby.gemspec index c8b3f20..4e69552 100644 --- a/instamojo-ruby.gemspec +++ b/instamojo-ruby.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |s| s.name = "instamojo-ruby" - s.version = "1.1.1" + s.version = "1.1.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] diff --git a/lib/client/client.rb b/lib/client/client.rb index b644454..90e84e9 100644 --- a/lib/client/client.rb +++ b/lib/client/client.rb @@ -75,8 +75,8 @@ def authenticate(username = nil, password = nil, options = {}, &block) end # GET /links - def links_list(page = nil, limit = nil) - get('links', get_pagination_params(page, limit)) + def links_list(opts = {}) + get('links', opts) @response.success? ? @response.body[:links].map { |link| Instamojo::Link.new link, self } : @response end @@ -126,8 +126,8 @@ def upload_file(filepath) # GET /payments - def payments_list(page = nil, limit = nil) - get('payments', get_pagination_params(page, limit)) + def payments_list(opts = {}) + get('payments', opts) @response.success? ? @response.body[:payments].map { |payment| Instamojo::Payment.new payment, self } : @response end @@ -146,8 +146,8 @@ def payment_request(options, &block) end # GET /payment-requests - def payment_requests_list(page = nil, limit = nil) - get('payment-requests', get_pagination_params(page, limit)) + def payment_requests_list(opts = {}) + get('payment-requests', opts) @response.success? ? @response.body[:payment_requests].map { |payment_request| Instamojo::PaymentRequest.new payment_request, self } : @response end @@ -158,8 +158,8 @@ def payment_request_status(payment_request_id) end # GET /refunds - def refunds_list(page = nil, limit = nil) - get('refunds', get_pagination_params(page, limit)) + def refunds_list(opts = {}) + get('refunds', opts) @response.success? ? @response.body[:refunds].map { |refund| Instamojo::Refund.new refund, self } : @response end @@ -223,17 +223,5 @@ def get_file_upload_url get('links/get_file_upload_url') @response.success? ? @response.body[:upload_url] : @response end - - def get_pagination_params(page, limit) - params = {} - if page != nil - params.merge!(page: page) - end - - if limit != nil - params.merge!(limit: limit) - end - params - end end end From 7f54c9007fbb5e3a4b409e3d4fe8783cc24a0676 Mon Sep 17 00:00:00 2001 From: Vijith Date: Wed, 10 Jul 2019 16:02:46 +0530 Subject: [PATCH 8/8] update to VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 8cfbc90..8428158 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.2 \ No newline at end of file