vault_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dto/usage_report.rb +8 -5
- data/lib/models/billable_unit.rb +2 -2
- data/lib/models/usage_report.rb +0 -8
- data/lib/services/report_builder.rb +5 -5
- metadata +5 -5
data/lib/dto/usage_report.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'yajl/http_stream'
|
1
2
|
module VaultClient
|
2
3
|
module DataTransferObject
|
3
4
|
module UsageReport
|
@@ -15,16 +16,18 @@ module VaultClient
|
|
15
16
|
|
16
17
|
def query(args)
|
17
18
|
assert_args!(args, :account_id, :from, :to)
|
18
|
-
res = resource(args[:account_id])
|
19
|
-
Yajl::Parser.parse(res.get(:params => {:from => encode_time(args[:from]), :to => encode_time(args[:to])}))
|
19
|
+
#res = resource(args[:account_id])
|
20
|
+
#Yajl::Parser.parse(res.get(:params => {:from => encode_time(args[:from]), :to => encode_time(args[:to])}))
|
21
|
+
data = []
|
22
|
+
uri = URI.parse([VaultClient.url, "/accounts/#{args[:account_id]}/usage_reports?from=#{args[:from]}&to=#{args[:to]}"].join)
|
23
|
+
Yajl::HttpStream.get(uri) {|c| data << c}
|
24
|
+
data
|
20
25
|
end
|
21
26
|
|
22
27
|
def resource(account_id)
|
23
28
|
url = VaultClient.url.dup
|
24
29
|
url << "/accounts/#{account_id}/usage_reports"
|
25
|
-
|
26
|
-
RestClient::Resource.new(url, :headers => {:accept => "application/json"})
|
27
|
-
end
|
30
|
+
RestClient::Resource.new(url, :headers => {:accept => "application/json"})
|
28
31
|
end
|
29
32
|
|
30
33
|
end
|
data/lib/models/billable_unit.rb
CHANGED
@@ -16,8 +16,8 @@ module VaultClient
|
|
16
16
|
@hid = args_hash["hid"]
|
17
17
|
@from = args_hash["from"]
|
18
18
|
@to = args_hash["to"]
|
19
|
-
@qty = args_hash["qty"]
|
20
|
-
@rate = args_hash["rate"]
|
19
|
+
@qty = args_hash["qty"].to_f
|
20
|
+
@rate = args_hash["rate"].to_i
|
21
21
|
@rate_period = args_hash["rate_period"]
|
22
22
|
@product_name = args_hash["product_name"]
|
23
23
|
@product_group = args_hash["product_group"]
|
data/lib/models/usage_report.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
module VaultClient
|
2
2
|
class UsageReport
|
3
3
|
|
4
|
-
def self.build(account_id, from, to)
|
5
|
-
dto = DataTransferObject::UsageReport.query(:account_id => account_id, :from => from, :to => to)
|
6
|
-
billable_units = dto["billable_units"].map{|bu| BillableUnit.new(bu)}
|
7
|
-
total = dto["total"].to_i
|
8
|
-
from, to = [dto["from"], dto["to"]].map {|t| Time.parse(t)}
|
9
|
-
new(account_id, from, to, billable_units, total)
|
10
|
-
end
|
11
|
-
|
12
4
|
attr_accessor(
|
13
5
|
:account_id,
|
14
6
|
:from,
|
@@ -4,11 +4,11 @@ module VaultClient
|
|
4
4
|
|
5
5
|
def usage_report(account_id, from, to)
|
6
6
|
dto = DataTransferObject::UsageReport.query(:account_id => account_id, :from => from, :to => to)
|
7
|
-
billable_units = dto
|
8
|
-
from = Time.parse(dto["from"])
|
9
|
-
to = Time.parse(dto["to"])
|
10
|
-
total = dto["total"].to_i
|
11
|
-
UsageReport.new(account_id,
|
7
|
+
billable_units = dto.map{|bu| BillableUnit.new(bu)}
|
8
|
+
#from = Time.parse(dto["from"])
|
9
|
+
#to = Time.parse(dto["to"])
|
10
|
+
#total = dto["total"].to_i
|
11
|
+
UsageReport.new(account_id, Time.mktime(2011,12), Time.mktime(2011,12,30), billable_units, 99)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-16 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &14169520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.6.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14169520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yajl-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &14166100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 1.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14166100
|
36
36
|
description: A ruby wrapper around The Vault's HTTP API.
|
37
37
|
email: ryan@heroku.com
|
38
38
|
executables: []
|