megam_api 0.36 → 0.38

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/lib/megam/api.rb +22 -3
  4. data/lib/megam/api/accounts.rb +15 -1
  5. data/lib/megam/api/availableunits.rb +35 -0
  6. data/lib/megam/api/balances.rb +46 -0
  7. data/lib/megam/api/billinghistories.rb +35 -0
  8. data/lib/megam/api/billings.rb +35 -0
  9. data/lib/megam/api/components.rb +2 -2
  10. data/lib/megam/api/credithistories.rb +35 -0
  11. data/lib/megam/api/discounts.rb +35 -0
  12. data/lib/megam/api/profile.rb +42 -0
  13. data/lib/megam/api/subscriptions.rb +35 -0
  14. data/lib/megam/api/version.rb +1 -1
  15. data/lib/megam/core/account.rb +85 -8
  16. data/lib/megam/core/assembly.rb +5 -9
  17. data/lib/megam/core/availableunits.rb +181 -0
  18. data/lib/megam/core/availableunits_collection.rb +144 -0
  19. data/lib/megam/core/balances.rb +201 -0
  20. data/lib/megam/core/balances_collection.rb +144 -0
  21. data/lib/megam/core/billinghistories.rb +206 -0
  22. data/lib/megam/core/billinghistories_collection.rb +144 -0
  23. data/lib/megam/core/billings.rb +242 -0
  24. data/lib/megam/core/billings_collection.rb +144 -0
  25. data/lib/megam/core/credithistories.rb +191 -0
  26. data/lib/megam/core/credithistories_collection.rb +144 -0
  27. data/lib/megam/core/discounts.rb +191 -0
  28. data/lib/megam/core/discounts_collection.rb +144 -0
  29. data/lib/megam/core/json_compat.rb +57 -15
  30. data/lib/megam/core/subscriptions.rb +191 -0
  31. data/lib/megam/core/subscriptions_collection.rb +144 -0
  32. data/megam_api.gemspec +2 -2
  33. data/test/test_accounts.rb +19 -0
  34. data/test/test_availableunits.rb +29 -0
  35. data/test/test_balances.rb +39 -0
  36. data/test/test_billinghistories.rb +31 -0
  37. data/test/test_billings.rb +34 -0
  38. data/test/test_credithistories.rb +30 -0
  39. data/test/test_discounts.rb +30 -0
  40. data/test/test_helper.rb +2 -2
  41. data/test/test_subscriptions.rb +30 -0
  42. metadata +61 -7
@@ -80,7 +80,7 @@ module Megam
80
80
  @operations
81
81
  end
82
82
  end
83
-
83
+
84
84
  def outputs(arg=[])
85
85
  if arg != []
86
86
  @outputs = arg
@@ -143,7 +143,7 @@ module Megam
143
143
  "status" => status,
144
144
  "created_at" => created_at
145
145
  }
146
-
146
+
147
147
  result
148
148
  end
149
149
 
@@ -180,22 +180,18 @@ module Megam
180
180
  self
181
181
  end
182
182
 
183
-
183
+
184
184
  def self.show(assembly_id, tmp_email=nil, tmp_api_key=nil)
185
185
  asm = self.new(tmp_email, tmp_api_key)
186
- puts "---->>>> "
187
- puts #{assembly_id}
188
- puts "----------->>>"
189
186
  asm.megam_rest.get_one_assembly(assembly_id)
190
187
  end
191
-
188
+
192
189
  def self.update(o,tmp_email=nil, tmp_api_key=nil)
193
190
  asm = from_hash(o, tmp_email, tmp_api_key)
194
191
  asm.update
195
192
  end
196
193
 
197
194
  # Create the node via the REST API
198
-
199
195
  def update
200
196
  megam_rest.update_assembly(to_hash)
201
197
  end
@@ -205,4 +201,4 @@ module Megam
205
201
  end
206
202
 
207
203
  end
208
- end
204
+ end
@@ -0,0 +1,181 @@
1
+ ##
2
+ ## Copyright [2013-2015] [Megam Systems]
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ module Megam
17
+ class Availableunits < Megam::ServerAPI
18
+ def initialize(email=nil, api_key=nil)
19
+ @id = nil
20
+ @name = nil
21
+ @duration = nil
22
+ @charges_per_duration = nil
23
+ @created_at = nil
24
+ @some_msg = {}
25
+ super(email, api_key)
26
+ end
27
+
28
+ def availableunits
29
+ self
30
+ end
31
+
32
+
33
+ def id(arg=nil)
34
+ if arg != nil
35
+ @id = arg
36
+ else
37
+ @id
38
+ end
39
+ end
40
+
41
+ def name(arg=nil)
42
+ if arg != nil
43
+ @name = arg
44
+ else
45
+ @name
46
+ end
47
+ end
48
+
49
+ def duration(arg=nil)
50
+ if arg != nil
51
+ @duration= arg
52
+ else
53
+ @duration
54
+ end
55
+ end
56
+
57
+ def charges_per_duration(arg=nil)
58
+ if arg != nil
59
+ @charges_per_duration = arg
60
+ else
61
+ @charges_per_duration
62
+ end
63
+ end
64
+
65
+ def created_at(arg=nil)
66
+ if arg != nil
67
+ @created_at = arg
68
+ else
69
+ @created_at
70
+ end
71
+ end
72
+
73
+ def some_msg(arg=nil)
74
+ if arg != nil
75
+ @some_msg = arg
76
+ else
77
+ @some_msg
78
+ end
79
+ end
80
+
81
+ def error?
82
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
83
+ end
84
+
85
+ # Transform the ruby obj -> to a Hash
86
+ def to_hash
87
+ index_hash = Hash.new
88
+ index_hash["json_claz"] = self.class.name
89
+ index_hash["id"] = id
90
+ index_hash["name"] = name
91
+ index_hash["duration"] = duration
92
+ index_hash["charges_per_duration"] = charges_per_duration
93
+ index_hash["created_at"] = created_at
94
+ index_hash
95
+ end
96
+
97
+ # Serialize this object as a hash: called from JsonCompat.
98
+ # Verify if this called from JsonCompat during testing.
99
+ def to_json(*a)
100
+ for_json.to_json(*a)
101
+ end
102
+
103
+ def for_json
104
+ result = {
105
+ "id" => id,
106
+ "name" => name,
107
+ "duration" => duration,
108
+ "charges_per_duration" => charges_per_duration,
109
+ "created_at" => created_at
110
+ }
111
+ result
112
+ end
113
+
114
+ #
115
+ def self.json_create(o)
116
+ aunit = new
117
+ aunit.id(o["id"]) if o.has_key?("id")
118
+ aunit.name(o["name"]) if o.has_key?("name")
119
+ aunit.duration(o["duration"]) if o.has_key?("duration")
120
+ aunit.charges_per_duration(o["charges_per_duration"]) if o.has_key?("charges_per_duration")
121
+ aunit.created_at(o["created_at"]) if o.has_key?("created_at")
122
+ #success or error
123
+ aunit.some_msg[:code] = o["code"] if o.has_key?("code")
124
+ aunit.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
125
+ aunit.some_msg[:msg]= o["msg"] if o.has_key?("msg")
126
+ aunit.some_msg[:links] = o["links"] if o.has_key?("links")
127
+ aunit
128
+ end
129
+
130
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
131
+ aunit = self.new(tmp_email, tmp_api_key)
132
+ aunit.from_hash(o)
133
+ aunit
134
+ end
135
+
136
+ def from_hash(o)
137
+ @id = o[:id] if o.has_key?(:id)
138
+ @name = o[:name] if o.has_key?(:name)
139
+ @duration = o[:duration] if o.has_key?(:duration)
140
+ @charges_per_duration = o[:charges_per_duration] if o.has_key?(:charges_per_duration)
141
+ @created_at = o[:created_at] if o.has_key?(:created_at)
142
+ self
143
+ end
144
+
145
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
146
+ acct = from_hash(o,tmp_email, tmp_api_key)
147
+ acct.create
148
+ end
149
+
150
+ # Create the predef via the REST API
151
+ def create
152
+ megam_rest.post_availableunits(to_hash)
153
+ end
154
+
155
+ # Load all available units -
156
+ # returns a AvailableUnitsCollection
157
+ # don't return self. check if the Megam::AvailableUnitsCollection is returned.
158
+ def self.list(tmp_email=nil, tmp_api_key=nil)
159
+ aunit = self.new(tmp_email,tmp_api_key)
160
+ aunit.megam_rest.get_availableunits
161
+ end
162
+
163
+ # Show a particular available units by name,
164
+ # Megam::Availables
165
+ def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
166
+ pre = self.new(tmp_email,tmp_api_key)
167
+ pre.megam_rest.get_availableunit(p_name)
168
+ end
169
+
170
+ def self.delete(p_name,tmp_email=nil, tmp_api_key=nil)
171
+ pre = self.new(tmp_email,tmp_api_key)
172
+ pre.megam_rest.delete_availableunit(p_name)
173
+ end
174
+
175
+ def to_s
176
+ Megam::Stuff.styled_hash(to_hash)
177
+ #"---> Megam::Account:[error=#{error?}]\n"+
178
+ end
179
+
180
+ end
181
+ end
@@ -0,0 +1,144 @@
1
+ ##
2
+ ## Copyright [2013-2015] [Megam Systems]
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ module Megam
17
+ class AvailableunitsCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @availableunits = Array.new
23
+ @availableunits_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_availableunits
28
+ @availableunits
29
+ end
30
+
31
+ def [](index)
32
+ @availableunits[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_availableunits(arg)
37
+ @availableunits[index] = arg
38
+ @availableunits_by_name[arg.name] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_availableunits(a)
44
+ @availableunits << a
45
+ @availableunits_by_name[a.name] =@availableunits.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(availableunits)
54
+ is_megam_availableunits(availableunits)
55
+ if @insert_after_idx
56
+ # in the middle of executing a run, so any predefs inserted now should
57
+ # be placed after the most recent addition done by the currently executing
58
+ # availableunits
59
+ @availableunits.insert(@insert_after_idx + 1, availableunits)
60
+ # update name -> location mappings and register new availableunits
61
+ @availableunits_by_name.each_key do |key|
62
+ @availableunits_by_name[key] += 1 if@availableunits_by_name[key] > @insert_after_idx
63
+ end
64
+ @availableunits_by_name[availableunits.name] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @availableunits << availableunits
68
+ @availableunits_by_name[availableunits.name] =@availableunits.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @availableunits.each do |availableunits|
74
+ yield availableunits
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @availableunits.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @availableunits.empty?
86
+ end
87
+
88
+ def lookup(availableunits)
89
+ lookup_by = nil
90
+ if availableunits.kind_of?(Megam::Availableunits)
91
+ lookup_by = availableunits.name
92
+ elsif availableunits.kind_of?(String)
93
+ lookup_by = availableunits
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::Availableunits or String to lookup"
96
+ end
97
+ res =@availableunits_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a availableunits matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @availableunits[res]
102
+ end
103
+
104
+ # Transform the ruby obj -> to a Hash
105
+ def to_hash
106
+ index_hash = Hash.new
107
+ self.each do |availableunits|
108
+ index_hash[availableunits.name] = availableunits.to_s
109
+ end
110
+ index_hash
111
+ end
112
+
113
+ # Serialize this object as a hash: called from JsonCompat.
114
+ # Verify if this called from JsonCompat during testing.
115
+ def to_json(*a)
116
+ for_json.to_json(*a)
117
+ end
118
+
119
+ def self.json_create(o)
120
+ collection = self.new()
121
+ o["results"].each do |availableunits_list|
122
+ availableunits_array = availableunits_list.kind_of?(Array) ? availableunits_list : [ availableunits_list ]
123
+ availableunits_array.each do |availableunits|
124
+ collection.insert(availableunits)
125
+ end
126
+ end
127
+ collection
128
+ end
129
+
130
+ private
131
+
132
+ def is_megam_availableunits(arg)
133
+ unless arg.kind_of?(Megam::Availableunits)
134
+ raise ArgumentError, "Members must be Megam::availableunits's"
135
+ end
136
+ true
137
+ end
138
+
139
+ def to_s
140
+ Megam::Stuff.styled_hash(to_hash)
141
+ end
142
+
143
+ end
144
+ end
@@ -0,0 +1,201 @@
1
+ ##
2
+ ## Copyright [2013-2015] [Megam Systems]
3
+ ##
4
+ ## Licensed under the Apache License, Version 2.0 (the "License");
5
+ ## you may not use this file except in compliance with the License.
6
+ ## You may obtain a copy of the License at
7
+ ##
8
+ ## http://www.apache.org/licenses/LICENSE-2.0
9
+ ##
10
+ ## Unless required by applicable law or agreed to in writing, software
11
+ ## distributed under the License is distributed on an "AS IS" BASIS,
12
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ ## See the License for the specific language governing permissions and
14
+ ## limitations under the License.
15
+ ##
16
+ module Megam
17
+ class Balances < Megam::ServerAPI
18
+ def initialize(email=nil, api_key=nil)
19
+ @id = nil
20
+ @accounts_id = nil
21
+ @name = nil
22
+ @credit = nil
23
+ @created_at = nil
24
+ @updated_at = nil
25
+ @some_msg = {}
26
+ super(email, api_key)
27
+ end
28
+
29
+ def balances
30
+ self
31
+ end
32
+
33
+ def id(arg=nil)
34
+ if arg != nil
35
+ @id = arg
36
+ else
37
+ @id
38
+ end
39
+ end
40
+
41
+ def accounts_id(arg=nil)
42
+ if arg != nil
43
+ @accounts_id= arg
44
+ else
45
+ @accounts_id
46
+ end
47
+ end
48
+
49
+ def name(arg=nil)
50
+ if arg != nil
51
+ @name = arg
52
+ else
53
+ @name
54
+ end
55
+ end
56
+
57
+ def credit(arg=nil)
58
+ if arg != nil
59
+ @credit = arg
60
+ else
61
+ @credit
62
+ end
63
+ end
64
+
65
+ def created_at(arg=nil)
66
+ if arg != nil
67
+ @created_at = arg
68
+ else
69
+ @created_at
70
+ end
71
+ end
72
+
73
+ def updated_at(arg=nil)
74
+ if arg != nil
75
+ @updated_at = arg
76
+ else
77
+ @updated_at
78
+ end
79
+ end
80
+
81
+ def some_msg(arg=nil)
82
+ if arg != nil
83
+ @some_msg = arg
84
+ else
85
+ @some_msg
86
+ end
87
+ end
88
+
89
+ def error?
90
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
91
+ end
92
+
93
+ # Transform the ruby obj -> to a Hash
94
+ def to_hash
95
+ index_hash = Hash.new
96
+ index_hash["json_claz"] = self.class.name
97
+ index_hash["id"] = id
98
+ index_hash["accounts_id"] = accounts_id
99
+ index_hash["name"] = name
100
+ index_hash["credit"] = credit
101
+ index_hash["created_at"] = created_at
102
+ index_hash["updated_at"] = updated_at
103
+ index_hash
104
+ end
105
+
106
+ # Serialize this object as a hash: called from JsonCompat.
107
+ # Verify if this called from JsonCompat during testing.
108
+ def to_json(*a)
109
+ for_json.to_json(*a)
110
+ end
111
+
112
+ def for_json
113
+ result = {
114
+ "id" => id,
115
+ "accounts_id" => accounts_id,
116
+ "name" => name,
117
+ "credit" => credit,
118
+ "created_at" => created_at,
119
+ "updated_at" => updated_at
120
+ }
121
+ result
122
+ end
123
+
124
+ def self.json_create(o)
125
+ balances = new
126
+ balances.id(o["id"]) if o.has_key?("id")
127
+ balances.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
128
+ balances.name(o["name"]) if o.has_key?("name")
129
+ balances.credit(o["credit"]) if o.has_key?("credit")
130
+ balances.created_at(o["created_at"]) if o.has_key?("created_at")
131
+ balances.updated_at(o["updated_at"]) if o.has_key?("updated_at")
132
+ #success or error
133
+ balances.some_msg[:code] = o["code"] if o.has_key?("code")
134
+ balances.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
135
+ balances.some_msg[:msg]= o["msg"] if o.has_key?("msg")
136
+ balances.some_msg[:links] = o["links"] if o.has_key?("links")
137
+ balances
138
+ end
139
+
140
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
141
+ balances = self.new(tmp_email, tmp_api_key)
142
+ balances.from_hash(o)
143
+ balances
144
+ end
145
+
146
+ def from_hash(o)
147
+ @id = o[:id] if o.has_key?(:id)
148
+ @accounts_id = o[:accounts_id] if o.has_key?(:accounts_id)
149
+ @name = o[:name] if o.has_key?(:name)
150
+ @credit = o[:credit] if o.has_key?(:credit)
151
+ @created_at = o[:created_at] if o.has_key?(:created_at)
152
+ @updated_at = o[:updated_at] if o.has_key?(:updated_at)
153
+ self
154
+ end
155
+
156
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
157
+ acct = from_hash(o,tmp_email, tmp_api_key)
158
+ acct.create
159
+ end
160
+
161
+ # Create the predef via the REST API
162
+ def create
163
+ megam_rest.post_balances(to_hash)
164
+ end
165
+
166
+ # Load all balances -
167
+ # returns a BalanceCollection
168
+ # don't return self. check if the Megam::BalanceCollection is returned.
169
+ def self.list(tmp_email=nil, tmp_api_key=nil)
170
+ balance = self.new(tmp_email,tmp_api_key)
171
+ balance.megam_rest.get_balances
172
+ end
173
+
174
+ # Show a particular balance by name,
175
+ # Megam::Balance
176
+ def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
177
+ pre = self.new(tmp_email,tmp_api_key)
178
+ pre.megam_rest.get_balance(p_name)
179
+ end
180
+
181
+ def self.delete(p_name,tmp_email=nil, tmp_api_key=nil)
182
+ pre = self.new(tmp_email,tmp_api_key)
183
+ pre.megam_rest.delete_balance(p_name)
184
+ end
185
+
186
+ def self.update(o,tmp_email=nil, tmp_api_key=nil)
187
+ asm = from_hash(o, tmp_email, tmp_api_key)
188
+ asm.update
189
+ end
190
+
191
+ # Create the node via the REST API
192
+ def update
193
+ megam_rest.update_balance(to_hash)
194
+ end
195
+
196
+ def to_s
197
+ Megam::Stuff.styled_hash(to_hash)
198
+ end
199
+
200
+ end
201
+ end