zoho_reports 0.0.3
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +79 -0
- data/Rakefile +8 -0
- data/lib/zoho_reports/client.rb +245 -0
- data/lib/zoho_reports/configuration.rb +11 -0
- data/lib/zoho_reports/version.rb +3 -0
- data/lib/zoho_reports/zoho_reportify.rb +53 -0
- data/lib/zoho_reports.rb +16 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/widget.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140418123137_create_widgets.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +45 -0
- data/spec/dummy/log/test.log +3539 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/add_row.json +22 -0
- data/spec/fixtures/import.json +23 -0
- data/spec/fixtures/update.json +16 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/zoho_reports/client_spec.rb +170 -0
- data/spec/zoho_reports/configuration_spec.rb +19 -0
- data/spec/zoho_reports/zoho_reportify_spec.rb +73 -0
- data/spec/zoho_reports_spec.rb +18 -0
- data/zoho_reports.gemspec +31 -0
- metadata +306 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"uri": "/api/user@example.com/test_database/widgets",
|
4
|
+
"action": "ADDROW",
|
5
|
+
"result": {
|
6
|
+
"column_order": [
|
7
|
+
"id",
|
8
|
+
"name",
|
9
|
+
"description",
|
10
|
+
"active"
|
11
|
+
],
|
12
|
+
"rows": [
|
13
|
+
[
|
14
|
+
"1",
|
15
|
+
"Acme Widget",
|
16
|
+
"Widget from Acme for Testing",
|
17
|
+
"t"
|
18
|
+
]
|
19
|
+
]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
" response": {
|
3
|
+
"uri": "/api/abc@zoho.com/EmployeeDB/EmployeeDetails",
|
4
|
+
"action": "IMPORT",
|
5
|
+
"result": {
|
6
|
+
"importSummary": {
|
7
|
+
"totalColumnCount": 3,
|
8
|
+
"selectedColumnCount": 3,
|
9
|
+
"totalRowCount": 50,
|
10
|
+
"successRowCount": 48,
|
11
|
+
"warnings": 0,
|
12
|
+
"importOperation": "created",
|
13
|
+
"importType": "APPEND"
|
14
|
+
},
|
15
|
+
"columnDetails": {
|
16
|
+
"Name": "Plain Text",
|
17
|
+
"Date Of Birth": "Date",
|
18
|
+
"Salary": "Number"
|
19
|
+
},
|
20
|
+
"importErrors": "[Line: 5 Field: 3] a1213 -WARNING: Invalid Number value"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"uri": "/api/user@example.com/test_database/widgets",
|
4
|
+
"action": "UPDATE",
|
5
|
+
"criteria": "(((id = 1)))",
|
6
|
+
"result": {
|
7
|
+
"updatedColumns": [
|
8
|
+
"id",
|
9
|
+
"description",
|
10
|
+
"active",
|
11
|
+
"name"
|
12
|
+
],
|
13
|
+
"updatedRows": "1"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'zoho_reports'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'addressable/uri'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
12
|
+
|
13
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
14
|
+
# in spec/support/ and its subdirectories.
|
15
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
16
|
+
|
17
|
+
# Checks for pending migrations before tests are run.
|
18
|
+
# If you are not using ActiveRecord, you can remove this line.
|
19
|
+
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# ## Mock Framework
|
23
|
+
#
|
24
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
25
|
+
#
|
26
|
+
# config.mock_with :mocha
|
27
|
+
# config.mock_with :flexmock
|
28
|
+
# config.mock_with :rr
|
29
|
+
|
30
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
31
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
32
|
+
|
33
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
34
|
+
# examples within a transaction, remove the following line or assign false
|
35
|
+
# instead of true.
|
36
|
+
config.use_transactional_fixtures = true
|
37
|
+
|
38
|
+
# If true, the base class of anonymous controllers will be inferred
|
39
|
+
# automatically. This will be the default behavior in future versions of
|
40
|
+
# rspec-rails.
|
41
|
+
config.infer_base_class_for_anonymous_controllers = false
|
42
|
+
|
43
|
+
# Run specs in random order to surface order dependencies. If you find an
|
44
|
+
# order dependency and want to debug it, you can fix the order by providing
|
45
|
+
# the seed, which is printed after each run.
|
46
|
+
# --seed 1234
|
47
|
+
config.order = "random"
|
48
|
+
end
|
49
|
+
|
50
|
+
def stub_zoho_request(action, path, zoho_action, options = {})
|
51
|
+
response_filename = options.delete :response_filename
|
52
|
+
status = options.delete(:status) || 200
|
53
|
+
query = options.delete(:query) || {}
|
54
|
+
|
55
|
+
stub_request(action, "https://reportsapi.zoho.com/api/#{ZohoReports.configuration.login_email}/#{path}")
|
56
|
+
.with(options.merge(
|
57
|
+
:query => query.merge({
|
58
|
+
'ZOHO_ACTION' => zoho_action,
|
59
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
60
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
61
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
62
|
+
'ZOHO_API_VERSION' => '1.0'})
|
63
|
+
))
|
64
|
+
.to_return(:body => File.new("spec/fixtures/#{response_filename}"), :status => status)
|
65
|
+
end
|
66
|
+
|
67
|
+
def query_string(values)
|
68
|
+
uri = Addressable::URI.new
|
69
|
+
uri.query_values = values
|
70
|
+
uri.query
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZohoReports::Client do
|
4
|
+
before :each do
|
5
|
+
ZohoReports.configure do |config|
|
6
|
+
config.auth_token = 'token'
|
7
|
+
config.login_email = 'user@example.com'
|
8
|
+
config.zoho_database_name = 'test_database'
|
9
|
+
end
|
10
|
+
|
11
|
+
@client = ZohoReports::Client.new
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#new" do
|
15
|
+
it "should initialize with options" do
|
16
|
+
expect(@client.api_version).to eq('1.0')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#add_row" do
|
21
|
+
before do
|
22
|
+
@stub = stub_zoho_request :post, "test_database/widgets", "ADDROW", response_filename: "add_row.json"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should add a row" do
|
26
|
+
widget = { id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't' }
|
27
|
+
response = @client.add_row("widgets", widget)
|
28
|
+
|
29
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
30
|
+
.with(:query => {
|
31
|
+
'ZOHO_ACTION' => 'ADDROW',
|
32
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
33
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
34
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
35
|
+
'ZOHO_API_VERSION' => '1.0'
|
36
|
+
},
|
37
|
+
:body => query_string({ id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't' }))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "#update_data" do
|
42
|
+
before do
|
43
|
+
@stub = stub_zoho_request :post, "test_database/widgets", "UPDATE", response_filename: "update.json"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should update a row" do
|
47
|
+
widget = { id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't' }
|
48
|
+
criteria = "(id: 1)"
|
49
|
+
response = @client.update_data("widgets", widget, criteria)
|
50
|
+
|
51
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
52
|
+
.with(:query => {
|
53
|
+
'ZOHO_ACTION' => 'UPDATE',
|
54
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
55
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
56
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
57
|
+
'ZOHO_API_VERSION' => '1.0'
|
58
|
+
},
|
59
|
+
:body => query_string({ id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't', :ZOHO_CRITERIA => criteria }))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#import_data" do
|
64
|
+
before do
|
65
|
+
@stub = stub_zoho_request :post, "test_database/widgets", "IMPORT", response_filename: "import.json"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should ADD a single row" do
|
69
|
+
|
70
|
+
widget = [ { id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't' } ]
|
71
|
+
|
72
|
+
response = @client.import_data("widgets", 'APPEND', widget.to_json)
|
73
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
74
|
+
.with(:query => {
|
75
|
+
'ZOHO_ACTION' => 'IMPORT',
|
76
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
77
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
78
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
79
|
+
'ZOHO_API_VERSION' => '1.0',
|
80
|
+
},
|
81
|
+
:body => {
|
82
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
83
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
84
|
+
'ZOHO_CREATE_TABLE' => 'false',
|
85
|
+
'ZOHO_IMPORT_TYPE' => 'APPEND',
|
86
|
+
'ZOHO_IMPORT_DATA' => widget.to_json,
|
87
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
88
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
89
|
+
})
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should UPDATE a single row" do
|
93
|
+
|
94
|
+
widget = [ { id: 1, name: 'Acme Widget Revision', description: 'Widget from Acme for Testing', active: 't' } ]
|
95
|
+
|
96
|
+
response = @client.import_data("widgets", 'UPDATEADD', widget.to_json)
|
97
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
98
|
+
.with(:query => {
|
99
|
+
'ZOHO_ACTION' => 'IMPORT',
|
100
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
101
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
102
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
103
|
+
'ZOHO_API_VERSION' => '1.0',
|
104
|
+
},
|
105
|
+
:body => {
|
106
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
107
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
108
|
+
'ZOHO_CREATE_TABLE' => 'false',
|
109
|
+
'ZOHO_IMPORT_TYPE' => 'UPDATEADD',
|
110
|
+
'ZOHO_IMPORT_DATA' => widget.to_json,
|
111
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
112
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
113
|
+
})
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should ADD multiple rows" do
|
117
|
+
|
118
|
+
widgets =[
|
119
|
+
{ id: 1, name: 'Acme Widget', description: 'Widget from Acme for Testing', active: 't' },
|
120
|
+
{ id: 2, name: 'Acme 2nd Widget', description: '2nd Widget from Acme for Testing', active: 't' }
|
121
|
+
]
|
122
|
+
|
123
|
+
response = @client.import_data("widgets", 'UPDATEADD', widgets.to_json)
|
124
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
125
|
+
.with(:query => {
|
126
|
+
'ZOHO_ACTION' => 'IMPORT',
|
127
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
128
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
129
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
130
|
+
'ZOHO_API_VERSION' => '1.0',
|
131
|
+
},
|
132
|
+
:body => {
|
133
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
134
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
135
|
+
'ZOHO_CREATE_TABLE' => 'false',
|
136
|
+
'ZOHO_IMPORT_TYPE' => 'UPDATEADD',
|
137
|
+
'ZOHO_IMPORT_DATA' => widgets.to_json,
|
138
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
139
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
140
|
+
})
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should UPDATE multiple rows" do
|
144
|
+
|
145
|
+
widgets =[
|
146
|
+
{ id: 1, name: 'Acme Widget Revision', description: 'Widget from Acme for Testing', active: 't' },
|
147
|
+
{ id: 2, name: 'Acme 2nd Widget', description: '2nd Widget from Acme for Testing', active: 't' }
|
148
|
+
]
|
149
|
+
|
150
|
+
response = @client.import_data("widgets", 'UPDATEADD', widgets.to_json, 'ZOHO_MATCHING_COLUMNS' => 'id')
|
151
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api#{@client.get_uri("widgets")}")
|
152
|
+
.with(:query => {
|
153
|
+
'ZOHO_ACTION' => 'IMPORT',
|
154
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
155
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
156
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
157
|
+
'ZOHO_API_VERSION' => '1.0',
|
158
|
+
},
|
159
|
+
:body => {
|
160
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
161
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
162
|
+
'ZOHO_CREATE_TABLE' => 'false',
|
163
|
+
'ZOHO_IMPORT_TYPE' => 'UPDATEADD',
|
164
|
+
'ZOHO_IMPORT_DATA' => widgets.to_json,
|
165
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
166
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
167
|
+
})
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ZohoReports
|
4
|
+
describe Configuration do
|
5
|
+
describe "#auth_token" do
|
6
|
+
it "default value is nil" do
|
7
|
+
expect(Configuration.new.auth_token).to eq('')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#auth_token=" do
|
12
|
+
it "can set value" do
|
13
|
+
config = Configuration.new
|
14
|
+
config.auth_token = 'token'
|
15
|
+
expect(config.auth_token).to eq('token')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ZohoReports
|
4
|
+
describe ZohoReportify do
|
5
|
+
before do
|
6
|
+
ZohoReports.configure do |config|
|
7
|
+
config.auth_token = 'token'
|
8
|
+
config.login_email = 'user@example.com'
|
9
|
+
config.zoho_database_name = 'test_database'
|
10
|
+
end
|
11
|
+
|
12
|
+
@stub = stub_zoho_request :post, "test_database/widgets", "IMPORT", response_filename: "import.json"
|
13
|
+
end
|
14
|
+
describe ".initialize_zoho_table" do
|
15
|
+
|
16
|
+
it "sends a proper request to import records into Zoho Reports" do
|
17
|
+
Widget.create(name: 'Baby-inator', description: 'Turns people into babies')
|
18
|
+
Widget.create(name: 'Deflate-inator Ray', description: 'Deflate every inflatable in the Tri-State Area')
|
19
|
+
|
20
|
+
response = Widget.initialize_zoho_table
|
21
|
+
|
22
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
23
|
+
.with(:query => {
|
24
|
+
'ZOHO_ACTION' => 'IMPORT',
|
25
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
26
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
27
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
28
|
+
'ZOHO_API_VERSION' => '1.0',
|
29
|
+
},
|
30
|
+
:body => query_string({
|
31
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
32
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
33
|
+
'ZOHO_CREATE_TABLE' => 'true',
|
34
|
+
'ZOHO_IMPORT_TYPE' => 'UPDATEADD',
|
35
|
+
'ZOHO_IMPORT_DATA' => Widget.all.to_json,
|
36
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
37
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
38
|
+
}))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when object created" do
|
43
|
+
it "should send an update to Zoho Reports" do
|
44
|
+
# Create an initial widget
|
45
|
+
@widget = Widget.create(name: 'Baby-inator', description: 'Turns people into babies')
|
46
|
+
|
47
|
+
# Update an attribute
|
48
|
+
@widget.description = 'Turns people into whiny babies'
|
49
|
+
|
50
|
+
# Save the update
|
51
|
+
@widget.save
|
52
|
+
|
53
|
+
expect(WebMock).to have_requested(:post, "https://reportsapi.zoho.com/api/user@example.com/test_database/widgets")
|
54
|
+
.with(:query => {
|
55
|
+
'ZOHO_ACTION' => 'IMPORT',
|
56
|
+
'authtoken' => ZohoReports.configuration.auth_token,
|
57
|
+
'ZOHO_OUTPUT_FORMAT' => 'JSON',
|
58
|
+
'ZOHO_ERROR_FORMAT' => 'JSON',
|
59
|
+
'ZOHO_API_VERSION' => '1.0',
|
60
|
+
},
|
61
|
+
:body => query_string({
|
62
|
+
'ZOHO_AUTO_IDENTIFY' => 'true',
|
63
|
+
'ZOHO_ON_IMPORT_ERROR' => 'ABORT',
|
64
|
+
'ZOHO_CREATE_TABLE' => 'false',
|
65
|
+
'ZOHO_IMPORT_TYPE' => 'UPDATEADD',
|
66
|
+
'ZOHO_IMPORT_DATA' => [@widget].to_json,
|
67
|
+
'ZOHO_IMPORT_FILETYPE' => 'JSON',
|
68
|
+
'ZOHO_MATCHING_COLUMNS' => 'id',
|
69
|
+
}))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZohoReports do
|
4
|
+
describe "#configure" do
|
5
|
+
before do
|
6
|
+
ZohoReports.configure do |config|
|
7
|
+
config.auth_token = 'token'
|
8
|
+
config.login_email = 'user@example.com'
|
9
|
+
config.zoho_database_name = 'test_database'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a user_uri with the configuratoin login_email embedded" do
|
14
|
+
user_uri = ZohoReports::Client.new.get_user_uri
|
15
|
+
expect(user_uri).to eq('/user@example.com')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zoho_reports/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zoho_reports"
|
8
|
+
spec.version = ZohoReports::VERSION
|
9
|
+
spec.authors = ["Neil Giarratana"]
|
10
|
+
spec.email = ["neil@scorebrd.com"]
|
11
|
+
spec.summary = ["Wrapper for Zoho Reports API"]
|
12
|
+
spec.description = ["Wraps the raw HTTP based API of Zoho Reports with easy to use methods for the ruby platform. This enables ruby and Rails developers to easily use Zoho Reports API."]
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
spec.add_development_dependency "rspec-rails"
|
26
|
+
spec.add_development_dependency "spring"
|
27
|
+
spec.add_development_dependency "sqlite3"
|
28
|
+
spec.add_dependency "rails"
|
29
|
+
spec.add_dependency "addressable"
|
30
|
+
spec.add_dependency "httmultiparty"
|
31
|
+
end
|