Skip to content

Commit ebdda1b

Browse files
committed
Merge pull request #1 from Cielo24/feature/CLC-673
Feature/clc 673
2 parents a3c4639 + 08a65e7 commit ebdda1b

File tree

7 files changed

+59
-9
lines changed

7 files changed

+59
-9
lines changed

cielo24_gem/cielo24-0.0.16.gem

-10 KB
Binary file not shown.

cielo24_gem/cielo24-0.0.17.gem

9 KB
Binary file not shown.

cielo24_gem/lib/cielo24/actions.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Actions
3131
GET_CAPTION_PATH = '/api/job/get_caption'
3232
GET_ELEMENT_LIST_PATH = '/api/job/get_elementlist'
3333
GET_LIST_OF_ELEMENT_LISTS_PATH = '/api/job/list_elementlists'
34+
AGGREGATE_STATISTICS_PATH = '/api/job/aggregate_statistics'
3435

3536
def initialize(base_url='https://api.cielo24.com')
3637
@base_url = base_url
@@ -77,10 +78,10 @@ def update_password(api_token, new_password, sub_account=nil)
7778
WebUtils.http_request(@base_url + UPDATE_PASSWORD_PATH, 'POST', WebUtils::BASIC_TIMEOUT, nil, nil, query_hash)
7879
end
7980

80-
def generate_api_key(api_token, username, force_new=false)
81-
assert_argument(username, 'Username')
81+
def generate_api_key(api_token, sub_account=nil, force_new=false)
8282
query_hash = init_access_req_dict(api_token)
83-
query_hash[:account_id] = username
83+
# account_id parameter named sub_account for clarity
84+
query_hash[:account_id] = sub_account unless sub_account.nil?
8485
query_hash[:force_new] = force_new
8586
response = WebUtils.get_json(@base_url + GENERATE_API_KEY_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
8687
response['ApiKey']
@@ -213,6 +214,18 @@ def get_list_of_element_lists(api_token, job_id)
213214
WebUtils.get_json(@base_url + GET_LIST_OF_ELEMENT_LISTS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
214215
end
215216

217+
def aggregate_statistics(api_token, metrics=nil, group_by=nil, start_date=nil, end_date=nil, sub_account=nil)
218+
query_hash = init_access_req_dict(api_token)
219+
query_hash[:metrics] = metrics.to_json unless metrics.nil?
220+
query_hash[:group_by] = group_by unless group_by.nil?
221+
query_hash[:start_date] = start_date unless start_date.nil?
222+
query_hash[:end_date] = end_date unless end_date.nil?
223+
# account_id parameter named sub_account for clarity
224+
query_hash[:account_id] = sub_account unless sub_account.nil?
225+
response = WebUtils.get_json(@base_url + AGGREGATE_STATISTICS_PATH, 'GET', WebUtils::BASIC_TIMEOUT, query_hash)
226+
return Mash.new(response)
227+
end
228+
216229
##############################
217230
### PRIVATE HELPER METHODS ###
218231
##############################

cielo24_gem/lib/cielo24/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Cielo24
2-
VERSION = '0.0.16'
3-
end
2+
VERSION = '0.0.17'
3+
end

cielo24_gem/test/actions_test.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,33 @@
55

66
class ActionsTest < Test::Unit::TestCase
77

8-
def initialize(test_method_name)
9-
super(test_method_name)
8+
def initialize(opts)
9+
super(opts)
1010
@config = Configuration.new
1111
@actions = Cielo24::Actions.new(@config.server_url)
1212
@api_token = nil
1313
@secure_key = nil
1414
end
1515

16-
# Called before every test method runs. Can be used to set up fixture information.
1716
def setup
1817
# Start with a fresh session each time
1918
@api_token = @actions.login(@config.username, @config.password, nil, true)
2019
@secure_key = @actions.generate_api_key(@api_token, @config.username, false)
2120
end
21+
22+
def teardown
23+
# Remove secure key
24+
unless @api_token.nil? or @secure_key.nil?
25+
begin
26+
@actions.remove_api_key(@api_token, @secure_key)
27+
rescue WebError => e
28+
if e.type == ErrorType::ACCOUNT_UNPRIVILEGED
29+
@api_token = @actions.login(@config.username, @config.password, nil, true)
30+
@actions.remove_api_key(@api_token, @secure_key)
31+
else
32+
# Pass silently
33+
end
34+
end
35+
end
36+
end
2237
end

cielo24_gem/test/job_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ def setup
1515
@job_id = @actions.create_job(@api_token, 'Ruby_test').JobId
1616
end
1717

18+
# Called after every test method runs. Can be used to tear down fixture information.
19+
def teardown
20+
super
21+
# Delete job
22+
begin
23+
@actions.delete_job(@api_token, @job_id)
24+
rescue
25+
# Pass silently
26+
end
27+
end
28+
1829
# Since all option classes extend BaseOptions class (with all of the functionality) we only need to test one class
1930
def test_options
2031
options = CaptionOptions.new
@@ -106,4 +117,16 @@ def test_add_media_to_job_file
106117
@task_id = @actions.add_media_to_job_file(@api_token, @job_id, file)
107118
assert_equal(32, @task_id.length)
108119
end
120+
121+
def test_aggregate_statistics
122+
response = @actions.aggregate_statistics(@api_token,
123+
metrics=%w(billable_minutes_total billable_minutes_professional),
124+
group_by='month',
125+
start_date='2015-06-25T00:00:00.000000',
126+
end_date='2015-07-25T00:00:00.000000',
127+
account_id='*')
128+
assert_equal(response.data.length, 2)
129+
assert(response.data[0].has_key?('billable_minutes_total'))
130+
assert(response.data[0].has_key?('billable_minutes_professional'))
131+
end
109132
end

cielo24_gem/test/sequential_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
class SequentialTest < ActionsTest
1010

11-
# Called before every test method runs. Can be used to set up fixture information.
1211
def setup
1312
# Do nothing - we want to be able to control when we login/logout etc.
1413
end

0 commit comments

Comments
 (0)