zoho_tools 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0afebc24d463ec69d604aad39a205d58f73df247a79bc19fc0d8cf81b0bbfe0
4
- data.tar.gz: 276372c86e9964d22742f490817034402cfa09b3e6ec901478d5e20b7577c09d
3
+ metadata.gz: d280f463100cf8c240ab86eb6e54868bae66e91c2c5bd8b1588feb4fe616a89b
4
+ data.tar.gz: 8924fa85c00149171acb824f8284671872a279df816416b43f4ae974da9ebf49
5
5
  SHA512:
6
- metadata.gz: 634c9cb91eb215ae71ca59f0f1aaabd7b11df21a7009ffdb5caf02fcb6e039140e0aa802f5d82c31b17552459c155724d666803e16b9a0058d290a53f208c4b8
7
- data.tar.gz: 9188400c80661801c3828badd66d8a7efbd7f12a757823a1ac8e35c35d242b7030e246394957bc71f5fbd4c961dfb86fe4ab6be9c164bb747ca0bf3539d7f98c
6
+ metadata.gz: 17754b8ee90114efb551eef5b77e6471c6831efd59aa319a9c1fc362b0c0f5f6ab0aaf2803969ff01fb4fd3b863ae032576849beb5326bc1acc770253cd66161
7
+ data.tar.gz: 5507afc6b38702d4329327a4b14ca2a1bfc74701985c4530cf5c85250d2f037c3261e20c8755008aad9e6febb7005490a86c176f23f4e132b997c1118618f904
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zoho_tools (0.1.0)
4
+ zoho_tools (1.0.0)
5
5
  rest-client (> 2)
6
6
 
7
7
  GEM
data/changelog.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1
4
+
5
+ Authentication, subscription list subscribe, unsubscribe, stubs
6
+
3
7
  ## 0.1
8
+
4
9
  Basic api created
@@ -1,18 +1,79 @@
1
+ require 'webmock/rspec'
2
+
1
3
  module ZohoTools
2
4
  module SpecHelper
3
5
  class Interface
4
- def stub_refresh_access_tokens(refresh_token, access_token:)
6
+ include RSpec::Mocks::ExampleMethods
7
+ include WebMock::API
8
+
9
+ def stub_authorize_code(code, access_token:, refresh_token:, success: true)
10
+ response_body = if success
11
+ { access_token: access_token,
12
+ refresh_token: refresh_token,
13
+ scope: 'ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL',
14
+ api_domain: 'https://www.zohoapis.eu',
15
+ token_type: 'Bearer',
16
+ expires_in: 3600 }
17
+ else
18
+ { error: 'Invalid code' }
19
+ end
20
+ stub_request(:post, URI.join(ZohoTools.config.accounts_api_url, '/oauth/v2/token'))
21
+ .with(body: hash_including(client_id: ZohoTools.config.client_id,
22
+ client_secret: ZohoTools.config.client_secret,
23
+ code: code,
24
+ grant_type: 'authorization_code',
25
+ redirect_uri: ZohoTools.config.callback_url))
26
+ .to_return(status: 200, body: response_body.to_json)
27
+ end
28
+
29
+ def stub_refresh_access_tokens(refresh_token, access_token:, success: true)
30
+ response_body = if success
31
+ { access_token: access_token,
32
+ scope: 'ZohoCampaigns.campaign.ALL ZohoCampaigns.contact.ALL',
33
+ api_domain: 'https://www.zohoapis.eu',
34
+ token_type: 'Bearer',
35
+ expires_in: 3600 }
36
+ else
37
+ { error: 'Invalid refresh token' }
38
+ end
5
39
  stub_request(:post, URI.join(ZohoTools.config.accounts_api_url, '/oauth/v2/token'))
6
40
  .with(body: hash_including(client_id: ZohoTools.config.client_id,
7
41
  client_secret: ZohoTools.config.client_secret,
8
42
  refresh_token: refresh_token,
9
43
  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)
44
+ .to_return(status: 200, body: response_body.to_json)
45
+ end
46
+
47
+ def stub_list_subscribe(access_token:, list_key:, contact_info:, source:, success: true)
48
+ response_body = if success
49
+ { status: 'success',
50
+ message: 'A confirmation email is sent to the user. User needs to confirm to successfully subscribe.' }
51
+ else
52
+ { error: 'Invalid code' }
53
+ end
54
+
55
+ stub_request(:post, URI.join(ZohoTools.config.campaigns_api_url, '/api/v1.1/json/listsubscribe'))
56
+ .with(body: hash_including(listkey: list_key,
57
+ resfmt: 'JSON',
58
+ contactinfo: contact_info.is_a?(RSpec::Mocks::ArgumentMatchers::SingletonMatcher) ? contact_info : contact_info.to_json,
59
+ source: source),
60
+ headers: { 'Authorization' => "Zoho-oauthtoken #{access_token}" })
61
+ .to_return(status: 200, body: response_body.to_json)
62
+ end
63
+
64
+ def stub_list_unsubscribe(access_token:, list_key:, contact_info:, success: true)
65
+ response_body = if success
66
+ { status: 'success', message: 'User successfully unsubscribed.' }
67
+ else
68
+ { error: 'Invalid code' }
69
+ end
70
+
71
+ stub_request(:post, URI.join(ZohoTools.config.campaigns_api_url, '/api/v1.1/json/listunsubscribe'))
72
+ .with(body: hash_including(listkey: list_key,
73
+ resfmt: 'JSON',
74
+ contactinfo: contact_info.to_json),
75
+ headers: { 'Authorization' => "Zoho-oauthtoken #{access_token}" })
76
+ .to_return(status: 200, body: response_body.to_json)
16
77
  end
17
78
  end
18
79
 
@@ -1,3 +1,3 @@
1
1
  module ZohoTools
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoho_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lubomir Vnenk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2023-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client