File tree 8 files changed +98
-0
lines changed
8 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Ey::Core::Client < Cistern::Service
21
21
collection :component_actions
22
22
collection :components
23
23
collection :connectors
24
+ collection :costs
24
25
collection :database_server_revisions
25
26
collection :database_server_snapshots
26
27
collection :database_servers
@@ -82,6 +83,7 @@ class Ey::Core::Client < Cistern::Service
82
83
model :component
83
84
model :component_action
84
85
model :connector
86
+ model :cost
85
87
model :database_server
86
88
model :database_server_snapshot
87
89
model :database_server_revision
@@ -220,6 +222,7 @@ class Ey::Core::Client < Cistern::Service
220
222
request :get_connector
221
223
request :get_connectors
222
224
request :get_contacts
225
+ request :get_costs
223
226
request :get_current_user
224
227
request :get_database_server
225
228
request :get_database_server_revisions
@@ -608,6 +611,7 @@ def self.data
608
611
:connectors => { } ,
609
612
:contacts => { } ,
610
613
:contact_assignments => [ ] ,
614
+ :costs => [ ] ,
611
615
:database_server_firewalls => [ ] ,
612
616
:database_server_revisions => { } ,
613
617
:database_server_snapshots => { } ,
Original file line number Diff line number Diff line change
1
+ class Ey ::Core ::Client ::Costs < Ey ::Core ::Collection
2
+ model Ey ::Core ::Client ::Cost
3
+
4
+ self . model_root = "cost"
5
+ self . model_request = :get_cost
6
+ self . collection_root = "costs"
7
+ self . collection_request = :get_costs
8
+ end
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Ey::Core::Client::Account < Ey::Core::Model
21
21
has_many :owners , key : :users
22
22
has_many :ssl_certificates
23
23
has_many :referrals , key : :account_referrals
24
+ has_many :costs
24
25
25
26
has_one :cancellation , assoc_name : 'account_cancellation' , collection : :account_cancellations
26
27
has_one :account_trial
Original file line number Diff line number Diff line change
1
+ class Ey ::Core ::Client ::Cost < Ey ::Core ::Model
2
+ extend Ey ::Core ::Associations
3
+
4
+ attribute :billing_month
5
+ attribute :data_type
6
+ attribute :level
7
+ attribute :finality
8
+ attribute :related_resource_type
9
+ attribute :category
10
+ attribute :units
11
+ attribute :description
12
+ attribute :value
13
+
14
+ has_one :account
15
+ has_one :environment
16
+ end
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class Ey::Core::Client::Environment < Ey::Core::Model
12
12
has_one :project
13
13
14
14
has_many :clusters
15
+ has_many :costs
15
16
has_many :keypairs
16
17
has_many :servers
17
18
has_many :applications
Original file line number Diff line number Diff line change
1
+ class Ey ::Core ::Client
2
+ class Real
3
+ def get_costs ( params = { } )
4
+ request (
5
+ "url" => params [ "url" ] ,
6
+ "path" => "/accounts/#{ params [ "id" ] } /costs"
7
+ )
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def get_costs ( params = { } )
13
+ extract_url_params! ( params )
14
+
15
+ response (
16
+ :body => { "costs" => self . data [ :costs ] } ,
17
+ :status => 200
18
+ )
19
+ end
20
+ end
21
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'Costs' do
4
+ let ( :client ) { create_client }
5
+ let! ( :account ) { create_account ( client : client ) }
6
+
7
+ it 'should return an empty array with no costs' do
8
+ expect ( account . costs . all ) . to be_empty
9
+ end
10
+
11
+ it 'should get costs for an account' do
12
+ create_cost ( client , account : account )
13
+ expect ( account . costs . all ) . not_to be_empty
14
+ end
15
+
16
+ it 'should search costs' do
17
+ create_cost ( client , account : account , level : 'total' )
18
+ create_cost ( client , account : account , level : 'summarized' )
19
+ costs = account . costs . select { |c | c . level == 'total' }
20
+ expect ( costs . first . level ) . to eq 'total'
21
+ end
22
+ end
Original file line number Diff line number Diff line change @@ -40,6 +40,31 @@ def create_server(client, options={})
40
40
)
41
41
end
42
42
43
+ def create_cost ( client , options = { } )
44
+ account = options [ :account ] || create_account ( client : client )
45
+ level = options [ :level ] || "summarized"
46
+ finality = options [ :finality ] || "estimated"
47
+ related_resource_type = options [ :related_resource_type ] || "account"
48
+ category = options [ :category ] || "non-server"
49
+ description = options [ :description ] || "AWS Other Services"
50
+ value = options [ :value ] || "1763"
51
+ environment = options [ :environment ] || nil
52
+
53
+ cost = client . data [ :costs ] << {
54
+ billing_month : "2015-07" ,
55
+ data_type : "cost" ,
56
+ level : level ,
57
+ finality : finality ,
58
+ related_resource_type : related_resource_type ,
59
+ category : category ,
60
+ units : "USD cents" ,
61
+ description : description ,
62
+ value : value ,
63
+ account : client . url_for ( "accounts/#{ account . identity } " ) ,
64
+ environment : environment
65
+ }
66
+ end
67
+
43
68
def create_account_referral ( client , options = { } )
44
69
referred = options . delete ( :referred ) || create_account ( client : client )
45
70
referrer = options . delete ( :referrer ) || create_account ( client : client )
You can’t perform that action at this time.
0 commit comments