zoho_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b0afebc24d463ec69d604aad39a205d58f73df247a79bc19fc0d8cf81b0bbfe0
4
+ data.tar.gz: 276372c86e9964d22742f490817034402cfa09b3e6ec901478d5e20b7577c09d
5
+ SHA512:
6
+ metadata.gz: 634c9cb91eb215ae71ca59f0f1aaabd7b11df21a7009ffdb5caf02fcb6e039140e0aa802f5d82c31b17552459c155724d666803e16b9a0058d290a53f208c4b8
7
+ data.tar.gz: 9188400c80661801c3828badd66d8a7efbd7f12a757823a1ac8e35c35d242b7030e246394957bc71f5fbd4c961dfb86fe4ab6be9c164bb747ca0bf3539d7f98c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zoho_tools.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem 'rest-client', '> 2'
9
+ gem 'webmock', '> 3'
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zoho_tools (0.1.0)
5
+ rest-client (> 2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.5)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.5.0)
15
+ domain_name (0.5.20190701)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ hashdiff (1.0.1)
18
+ http-accept (1.7.0)
19
+ http-cookie (1.0.5)
20
+ domain_name (~> 0.5)
21
+ mime-types (3.5.0)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2023.0808)
24
+ netrc (0.11.0)
25
+ public_suffix (5.0.3)
26
+ rake (12.3.3)
27
+ rest-client (2.1.0)
28
+ http-accept (>= 1.7.0, < 2.0)
29
+ http-cookie (>= 1.0.2, < 2.0)
30
+ mime-types (>= 1.16, < 4.0)
31
+ netrc (~> 0.8)
32
+ rexml (3.2.6)
33
+ rspec (3.12.0)
34
+ rspec-core (~> 3.12.0)
35
+ rspec-expectations (~> 3.12.0)
36
+ rspec-mocks (~> 3.12.0)
37
+ rspec-core (3.12.2)
38
+ rspec-support (~> 3.12.0)
39
+ rspec-expectations (3.12.3)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-mocks (3.12.6)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-support (3.12.1)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.8.2)
49
+ webmock (3.18.1)
50
+ addressable (>= 2.8.0)
51
+ crack (>= 0.3.2)
52
+ hashdiff (>= 0.4.0, < 2.0.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ rake (~> 12.0)
59
+ rest-client (> 2)
60
+ rspec (~> 3.0)
61
+ webmock (> 3)
62
+ zoho_tools!
63
+
64
+ BUNDLED WITH
65
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Lubomir Vnenk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # ZohoTools
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zoho_tools`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'zoho_tools'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zoho_tools
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zoho_tools.
36
+
37
+
38
+ ## License
39
+
40
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "zoho_tools"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/changelog.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## 0.1
4
+ Basic api created
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoTools
4
+ class Configuration
5
+ attr_accessor :client_id, :client_secret, :campaigns_api_url, :accounts_api_url, :callback_url
6
+
7
+ def initialize
8
+ @client_secret = ENV['ZOHO_CLIENT_SECRET']
9
+ @client_id = ENV['ZOHO_CLIENT_ID']
10
+ @accounts_api_url = ENV['ZOHO_ACCOUNTS_API_URL']
11
+ @campaigns_api_url = ENV['ZOHO_CAMPAIGNS_API_URL']
12
+ @callback_url = ENV['ZOHO_CALLBACK_URL']
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module ZohoTools
2
+ class ListManagement
3
+ SUBSCRIBE_URL = '/api/v1.1/json/listsubscribe'.freeze
4
+ UNSUBSCRIBE_URL = '/api/v1.1/json/listunsubscribe'.freeze
5
+
6
+ def self.subscribe(access_token:, list_key:, contact_info:, topic_id: nil, source: nil)
7
+ params = { listkey: list_key, resfmt: 'JSON', contactinfo: contact_info.to_json }
8
+ params = params.merge(source: source) if source
9
+ params = params.merge(topic_id: topic_id) if topic_id
10
+
11
+ response = RestClient.post(URI.join(ZohoTools.config.campaigns_api_url, SUBSCRIBE_URL).to_s,
12
+ params,
13
+ { 'Authorization': "Zoho-oauthtoken #{access_token}" })
14
+ ZohoTools::Response.new(response)
15
+
16
+ end
17
+
18
+ def self.unsubscribe(access_token:, list_key:, contact_info:, topic_id: nil)
19
+ params = { listkey: list_key, resfmt: 'JSON', contactinfo: contact_info.to_json }
20
+ params = params.merge(topic_id: topic_id) if topic_id
21
+
22
+ response = RestClient.post(URI.join(ZohoTools.config.campaigns_api_url, UNSUBSCRIBE_URL).to_s,
23
+ params,
24
+ { 'Authorization': "Zoho-oauthtoken #{access_token}" })
25
+ ZohoTools::Response.new(response)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module ZohoTools
2
+ module SpecHelper
3
+ class Interface
4
+ def stub_refresh_access_tokens(refresh_token, access_token:)
5
+ stub_request(:post, URI.join(ZohoTools.config.accounts_api_url, '/oauth/v2/token'))
6
+ .with(body: hash_including(client_id: ZohoTools.config.client_id,
7
+ client_secret: ZohoTools.config.client_secret,
8
+ refresh_token: refresh_token,
9
+ grant_type: 'refresh_token'))
10
+ .to_return(status: 200,
11
+ body: { access_token: access_token,
12
+ scope: 'ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL',
13
+ api_domain: 'https://www.zohoapis.eu',
14
+ token_type: 'Bearer',
15
+ expires_in: 3600 }.to_json)
16
+ end
17
+ end
18
+
19
+ def zoho_tools
20
+ @zoho_tools ||= Interface.new
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ module ZohoTools
2
+ class Oauth
3
+ OAUTH_URL = '/oauth/v2/auth'.freeze
4
+ TOKEN_URL = '/oauth/v2/token'.freeze
5
+
6
+ def self.authorize(access_type: 'offline', scope: %w[ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL])
7
+ uri = URI.join(ZohoTools.config.accounts_api_url, OAUTH_URL)
8
+ uri.query = URI.encode_www_form(self.auth_params.merge({ redirect_uri: ZohoTools.config.callback_url,
9
+ access_type: access_type,
10
+ response_type: 'code',
11
+ scope: scope.join(',') }))
12
+ uri.to_s
13
+ end
14
+
15
+ def self.authorization_code(code)
16
+ response = RestClient.post(URI.join(ZohoTools.config.accounts_api_url, TOKEN_URL).to_s,
17
+ self.auth_params.merge(code: code, grant_type: 'authorization_code', redirect_uri: ZohoTools.config.callback_url),
18
+ { accept: :json })
19
+ ZohoTools::Response.new(response)
20
+ end
21
+
22
+ def self.refresh_access_token(refresh_token)
23
+ response = RestClient.post(URI.join(ZohoTools.config.accounts_api_url, TOKEN_URL).to_s,
24
+ self.auth_params.merge(refresh_token: refresh_token, grant_type: 'refresh_token'),
25
+ { accept: :json })
26
+ ZohoTools::Response.new(response)
27
+ end
28
+
29
+ def self.auth_params
30
+ { client_id: ZohoTools.config.client_id,
31
+ client_secret: ZohoTools.config.client_secret }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZohoTools
4
+ class Response
5
+ attr_accessor :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def success?
12
+ response.code == 200 && (!body['status'] || body['status'] == 'success') && !body['error']
13
+ end
14
+
15
+ def error_message
16
+ return body['error'] if response.code == 200
17
+
18
+ response.message
19
+ end
20
+
21
+ def body
22
+ @body ||= JSON.parse(response.body)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module ZohoTools
2
+ VERSION = '0.1.0'
3
+ end
data/lib/zoho_tools.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rest-client'
2
+
3
+ require 'zoho_tools/configuration'
4
+ require 'zoho_tools/list_management'
5
+ require 'zoho_tools/response'
6
+ require 'zoho_tools/version'
7
+ require 'zoho_tools/oauth'
8
+
9
+ module ZohoTools
10
+ @configuration = Configuration.new
11
+
12
+ def self.config
13
+ @configuration
14
+ end
15
+
16
+ def self.configure
17
+ yield(@configuration)
18
+ end
19
+
20
+ class Error < StandardError
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/zoho_tools/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "zoho_tools"
5
+ spec.version = ZohoTools::VERSION
6
+ spec.authors = ["Lubomir Vnenk"]
7
+ spec.email = ["lubomir.vnenk@zoho.com"]
8
+
9
+ spec.summary = %q{ZOHO auth and subscriptions}
10
+ spec.description = %q{ZOHO auth and subscriptions}
11
+ spec.homepage = "https://github.com/lubosch/zoho_tools"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/lubosch/zoho_tools"
17
+ spec.metadata["changelog_uri"] = "https://github.com/lubosch/zoho_tools"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency 'rest-client', '> 2'
29
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoho_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lubomir Vnenk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ description: ZOHO auth and subscriptions
28
+ email:
29
+ - lubomir.vnenk@zoho.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - changelog.md
45
+ - lib/zoho_tools.rb
46
+ - lib/zoho_tools/configuration.rb
47
+ - lib/zoho_tools/list_management.rb
48
+ - lib/zoho_tools/mock/spec_helper.rb
49
+ - lib/zoho_tools/oauth.rb
50
+ - lib/zoho_tools/response.rb
51
+ - lib/zoho_tools/version.rb
52
+ - zoho_tools.gemspec
53
+ homepage: https://github.com/lubosch/zoho_tools
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/lubosch/zoho_tools
58
+ source_code_uri: https://github.com/lubosch/zoho_tools
59
+ changelog_uri: https://github.com/lubosch/zoho_tools
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: ZOHO auth and subscriptions
79
+ test_files: []