zoho-subscription-api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47027745f4167289e670d14782d6f3127c7c7d93e87a9f530bb2078c2f119816
4
+ data.tar.gz: 0f687ed53e4e464e42f5ffb2244c5e3131a44017b0f173834ae9624e823fb23c
5
+ SHA512:
6
+ metadata.gz: aee4b5cfec6f223bc40db3e4769c38d5e5ca4ddeea276e50832e8545169481860901e4b55ad4628476a761725e3805311a38d373ea45f562dc5db4f1b99195d6
7
+ data.tar.gz: 6b7de7170e490e2a11dfbc2296d170bbe118f26a39ee666e0664beda0630ec0dc5da97ec79bc671cc33883b3ee17b0cbc29f0d4892144cea8cdec2ef4d3fb434
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Saurabh gulati
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Zoho
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'zoho'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install zoho
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Zoho'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :zoho do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,75 @@
1
+ class Zoho::Api::Addon < Zoho::Request
2
+ ATTRS = [
3
+ :addon_code,
4
+ :name,
5
+ :unit_name,
6
+ :pricing_scheme,
7
+ :price_brackets,
8
+ :type,
9
+ :applicable_to_all_plans,
10
+ :product_id,
11
+ :description
12
+ ]
13
+
14
+ ATTRS.each do |attr|
15
+ self.send("attr_accessor", attr)
16
+ end
17
+
18
+ def save
19
+ base_url = Zoho::Api::HOST+"/api/v1/addons"
20
+ response = post(base_url) do |http, request|
21
+ request.body = self.to_json
22
+ response = http.request(request)
23
+ response = JSON.parse(response.body, object_class: OpenStruct)
24
+ end
25
+ return response
26
+ end
27
+
28
+ class << self
29
+ def all
30
+ base_url = Zoho::Api::HOST+"/api/v1/addons"
31
+ response = get(base_url)
32
+ if response.code == 0
33
+ return response.addons
34
+ else
35
+ return response
36
+ end
37
+ end
38
+
39
+ def create(attrs={})
40
+ addon = Zoho::Api::Addon.new(attrs)
41
+ return addon.save
42
+ end
43
+
44
+ def find addon_id
45
+ base_url = Zoho::Api::HOST+"/api/v1/addons/#{addon_id}"
46
+ response = get(base_url)
47
+ if response.code == 0
48
+ return response.addon
49
+ else
50
+ return nil
51
+ end
52
+ end
53
+
54
+ def update addon_id, attrs={}
55
+ addon = Zoho::Api::Addon.new(attrs)
56
+ base_url = Zoho::Api::HOST+"/api/v1/addons/#{addon_id}"
57
+ response = put(base_url) do |http, request|
58
+ request.body = addon.to_json
59
+ response = http.request(request)
60
+ response = JSON.parse(response.body, object_class: OpenStruct)
61
+ end
62
+ if response.code == 0
63
+ return response
64
+ else
65
+ return response
66
+ end
67
+ end
68
+
69
+ def destroy addon_id
70
+ base_url = Zoho::Api::HOST+"/api/v1/addons/#{addon_id}"
71
+ response = Zoho::Request.delete(base_url)
72
+ return response
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,56 @@
1
+ class Zoho::Api::HostedPage < Zoho::Request
2
+ attr_accessor :customer, :plan, :redirect_url, :subscription_id, :addons
3
+
4
+ def save
5
+ base_url = Zoho::Api::HOST+"/api/v1/hostedpages/newsubscription"
6
+ response = post(base_url) do |http, request|
7
+ request.body = self.to_json
8
+ response = http.request(request)
9
+ response = JSON.parse(response.body, object_class: OpenStruct)
10
+ end
11
+
12
+ return response
13
+ end
14
+
15
+ def find hostpage_id
16
+ return Zoho::Api::HostedPage.find(hostpage_id)
17
+ end
18
+
19
+ class << self
20
+ def all
21
+ base_url = Zoho::Api::HOST+"/api/v1/hostedpages"
22
+ response = Zoho::Request.get(base_url)
23
+ if response.code == 0
24
+ return response.hostedpages
25
+ else
26
+ return response
27
+ end
28
+ end
29
+
30
+ def find page_id
31
+ base_url = Zoho::Api::HOST+"/api/v1/hostedpages/#{page_id}"
32
+ response = Zoho::Request.get(base_url)
33
+ if response.code == 0
34
+ return response.data
35
+ else
36
+ return response
37
+ end
38
+ end
39
+
40
+ def create_subscription attrs={}
41
+ hostpage = Zoho::Api::HostedPage.new(attrs)
42
+ return hostpage.save
43
+ end
44
+
45
+ def buy_onetime_addon attrs={}
46
+ hostpage = Zoho::Api::HostedPage.new(attrs)
47
+ base_url = Zoho::Api::HOST+"/api/v1/hostedpages/buyonetimeaddon"
48
+ response = post(base_url) do |http, request|
49
+ request.body = hostpage.to_json
50
+ response = http.request(request)
51
+ response = JSON.parse(response.body, object_class: OpenStruct)
52
+ end
53
+ return response
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,76 @@
1
+ class Zoho::Api::Plan < Zoho::Request
2
+ ATTRS = [
3
+ :plan_code, :name,
4
+ :recurring_price, :interval,
5
+ :interval_unit, :billing_cycles,
6
+ :trial_period, :setup_fee,
7
+ :product_id, :product_type,
8
+ :hsn_or_sac, :item_tax_preferences,
9
+ :tax_id, :is_taxable,
10
+ :tax_exemption_id, :created_time, :updated_time,
11
+ :tax_exemption_code,:description, :status,
12
+ :error_message, :url
13
+ ]
14
+
15
+ ATTRS.each do |attr|
16
+ self.send("attr_accessor", attr)
17
+ end
18
+
19
+ def save
20
+ base_url = Zoho::Api::HOST+"/api/v1/plans"
21
+ response = post(base_url) do |http, request|
22
+ request.body = self.to_json
23
+ response = http.request(request)
24
+ response = JSON.parse(response.body, object_class: OpenStruct)
25
+ end
26
+ return response
27
+ end
28
+
29
+ class << self
30
+ def all
31
+ base_url = Zoho::Api::HOST+"/api/v1/plans"
32
+ response = get(base_url)
33
+ if response.code == 0
34
+ return response.plans
35
+ else
36
+ return response
37
+ end
38
+ end
39
+
40
+ def create(attrs={})
41
+ plan = Zoho::Api::Plan.new(attrs)
42
+ return plan.save
43
+ end
44
+
45
+ def find plan_id
46
+ base_url = Zoho::Api::HOST+"/api/v1/plans/#{plan_id}"
47
+ response = get(base_url)
48
+ if response.code == 0
49
+ return response.plan
50
+ else
51
+ return nil
52
+ end
53
+ end
54
+
55
+ def update plan_id, attrs={}
56
+ plan = Zoho::Api::Plan.new(attrs)
57
+ base_url = Zoho::Api::HOST+"/api/v1/plans/#{plan_id}"
58
+ response = put(base_url) do |http, request|
59
+ request.body = plan.to_json
60
+ response = http.request(request)
61
+ response = JSON.parse(response.body, object_class: OpenStruct)
62
+ end
63
+ if response.code == 0
64
+ return response
65
+ else
66
+ return response
67
+ end
68
+ end
69
+
70
+ def destroy plan_id
71
+ base_url = Zoho::Api::HOST+"/api/v1/plans/#{plan_id}"
72
+ response = Zoho::Request.delete(base_url)
73
+ return response
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,13 @@
1
+ class Zoho::Api::Product < Zoho::Request
2
+ class << self
3
+ def all
4
+ base_url = Zoho::Api::HOST+"/api/v1/products"
5
+ response = get(base_url)
6
+ end
7
+
8
+ def find product_id
9
+ base_url = Zoho::Api::HOST+"/api/v1/products/#{product_id}"
10
+ response = get(base_url)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ class Zoho::Api::Subscription
2
+ class << self
3
+ def all
4
+ base_url = Zoho::Api::HOST+"/api/v1/subscriptions"
5
+ response = Zoho::Request.get(base_url)
6
+ if response.code == 0
7
+ return response.subscriptions
8
+ else
9
+ return response
10
+ end
11
+ end
12
+
13
+ def find subscription_id
14
+ base_url = Zoho::Api::HOST+"/api/v1/subscriptions/#{subscription_id}"
15
+ response = Zoho::Request.get(base_url)
16
+ if response.code == 0
17
+ return response.subscription
18
+ else
19
+ return response
20
+ end
21
+ end
22
+
23
+ def cancel subscription_id
24
+ base_url = Zoho::Api::HOST+"/api/v1/subscriptions/#{subscription_id}/cancel"
25
+ response = Zoho::Request.post(base_url) do |http, request|
26
+ response = http.request(request)
27
+ response = JSON.parse(response.body, object_class: OpenStruct)
28
+ end
29
+ return response
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Zoho
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Zoho
4
+
5
+ initializer :append_migrations do |app|
6
+ unless app.root.to_s.match(root.to_s)
7
+ config.paths["db/migrate"].expanded.each do |p|
8
+ app.config.paths["db/migrate"] << p
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module Zoho
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,92 @@
1
+ class Zoho::Request
2
+ def initialize attrs={}
3
+ attrs.each do |key, val|
4
+ self.send("#{key}=", val)
5
+ end
6
+ end
7
+
8
+ def attributes
9
+ hsh = {}
10
+ self.class.const_get("ATTRS").each do |attr|
11
+ hsh[attr] = self.send(attr)
12
+ end
13
+ return hsh
14
+ end
15
+
16
+ def get url, &blk
17
+ Zoho::Request.get url, &blk
18
+ end
19
+
20
+ def post url, &blk
21
+ Zoho::Request.post url, &blk
22
+ end
23
+
24
+ def put url, &blk
25
+ Zoho::Request.put url, &blk
26
+ end
27
+
28
+ def delete url, &blk
29
+ Zoho::Request.delete url, &blk
30
+ end
31
+
32
+ def self.get url, &blk
33
+ url = URI(url)
34
+ http = Net::HTTP.new(url.host, url.port)
35
+ http.use_ssl = true
36
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
+ request = Net::HTTP::Get.new(url)
38
+ add_request_headers request
39
+ response = http.request(request)
40
+ if block_given?
41
+ yield(response)
42
+ else
43
+ return JSON.parse(
44
+ response.read_body,
45
+ object_class: OpenStruct
46
+ )
47
+ end
48
+ end
49
+
50
+ def self.post url, &blk
51
+ url = URI(url)
52
+ http = Net::HTTP.new(url.host, url.port)
53
+ http.use_ssl = true
54
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
+ request = Net::HTTP::Post.new(url)
56
+ add_request_headers request
57
+ yield(http, request)
58
+ end
59
+
60
+ def self.put url, &blk
61
+ url = URI(url)
62
+ http = Net::HTTP.new(url.host, url.port)
63
+ http.use_ssl = true
64
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
65
+ request = Net::HTTP::Put.new(url)
66
+ add_request_headers request
67
+ yield(http, request)
68
+ end
69
+
70
+ def self.delete url
71
+ url = URI(url)
72
+ http = Net::HTTP.new(url.host, url.port)
73
+ http.use_ssl = true
74
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
+ request = Net::HTTP::Delete.new(url)
76
+ add_request_headers request
77
+ response = http.request(request)
78
+ return JSON.parse(
79
+ response.read_body,
80
+ object_class: OpenStruct
81
+ )
82
+ end
83
+
84
+ private
85
+
86
+ def self.add_request_headers request
87
+ raise "Zoho not configured!" unless Zoho.configuration.present?
88
+ request["Authorization"] = Zoho.configuration.auth_token
89
+ request["X-com-zoho-subscriptions-organizationid"] = Zoho.configuration.organization_id
90
+ request["content-type"] = 'application/json;charset=UTF-8'
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ class Zoho::Response
2
+ attr_accessor :data, :success, :error_message
3
+ end
@@ -0,0 +1,3 @@
1
+ module Zoho
2
+ VERSION = '0.1.0'
3
+ end
data/lib/zoho.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "zoho/railtie"
2
+ require "zoho/engine"
3
+ module Zoho
4
+ class << self
5
+ attr_accessor :configuration
6
+
7
+ def configure &blk
8
+ self.configuration ||= Zoho::Configuration.new.tap(&blk)
9
+ end
10
+ end
11
+
12
+ class Configuration
13
+ attr_accessor :organization_id, :auth_token
14
+ TOKEN_PREFIX = "Zoho-authtoken"
15
+
16
+ def initialize(options={})
17
+ options.each do |key, value|
18
+ if key.to_s == "auth_token"
19
+ self[key] = "#{TOKEN_PREFIX} #{value}"
20
+ else
21
+ self[key] = value
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ module Api
28
+ # attr_accessor :configuration
29
+ HOST = "https://subscriptions.zoho.com"
30
+ end
31
+ require "zoho/request"
32
+ require "zoho/api/hosted_pages"
33
+ require "zoho/api/plan"
34
+ require "zoho/api/product"
35
+ require "zoho/api/addon"
36
+ require "zoho/api/subscription"
37
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoho-subscription-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Saurabh gulati
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of Zoho.
42
+ email:
43
+ - saurabhgulati159@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/tasks/zoho_tasks.rake
52
+ - lib/zoho.rb
53
+ - lib/zoho/api/addon.rb
54
+ - lib/zoho/api/hosted_pages.rb
55
+ - lib/zoho/api/plan.rb
56
+ - lib/zoho/api/product.rb
57
+ - lib/zoho/api/subscription.rb
58
+ - lib/zoho/engine.rb
59
+ - lib/zoho/railtie.rb
60
+ - lib/zoho/request.rb
61
+ - lib/zoho/response.rb
62
+ - lib/zoho/version.rb
63
+ homepage: https://dron-new.herokuapp.com
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Summary of Zoho.
86
+ test_files: []