megam_api 1.5.rc1 → 1.5.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,136 @@
1
+ ##
2
+ ## Copyright 2013-2016 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 BillingtranscationsCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @billingtranscations = Array.new
23
+ @billingtranscations_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_billingtranscations
28
+ @billingtranscations
29
+ end
30
+
31
+ def [](index)
32
+ @billingtranscations[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_billingtranscations(arg)
37
+ @billingtranscations[index] = arg
38
+ @billingtranscations_by_name[arg.accounts_id] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_billingtranscations(a)
44
+ @billingtranscations << a
45
+ @billingtranscations_by_name[a.accounts_id] =@billingtranscations.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(billingtranscations)
54
+ is_megam_billingtranscations(billingtranscations)
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
+ # billingtranscations
59
+ @billingtranscations.insert(@insert_after_idx + 1, billingtranscations)
60
+ # update name -> location mappings and register new billingtranscations
61
+ @billingtranscations_by_name.each_key do |key|
62
+ @billingtranscations_by_name[key] += 1 if@billingtranscations_by_name[key] > @insert_after_idx
63
+ end
64
+ @billingtranscations_by_name[billingtranscations.accounts_id] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @billingtranscations << billingtranscations
68
+ @billingtranscations_by_name[billingtranscations.accounts_id] =@billingtranscations.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @billingtranscations.each do |billingtranscations|
74
+ yield billingtranscations
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @billingtranscations.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @billingtranscations.empty?
86
+ end
87
+
88
+ def lookup(billingtranscations)
89
+ lookup_by = nil
90
+ if billingtranscations.kind_of?(Megam::billingtranscations)
91
+ lookup_by = billingtranscations.accounts_id
92
+ elsif billingtranscations.kind_of?(String)
93
+ lookup_by = billingtranscations
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::billingtranscations or String to lookup"
96
+ end
97
+ res =@billingtranscations_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a billingtranscations matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @billingtranscations[res]
102
+ end
103
+
104
+ def to_s
105
+ @billingtranscations.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
110
+ end
111
+
112
+ def to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
114
+ end
115
+
116
+ def self.json_create(o)
117
+ collection = self.new()
118
+ o["results"].each do |billingtranscations_list|
119
+ billingtranscations_array = billingtranscations_list.kind_of?(Array) ? billingtranscations_list : [ billingtranscations_list ]
120
+ billingtranscations_array.each do |billingtranscations|
121
+ collection.insert(billingtranscations)
122
+ end
123
+ end
124
+ collection
125
+ end
126
+
127
+ private
128
+
129
+ def is_megam_billingtranscations(arg)
130
+ unless arg.kind_of?(Megam::Billingtranscations)
131
+ raise ArgumentError, "Members must be Megam::billingtranscations's"
132
+ end
133
+ true
134
+ end
135
+ end
136
+ end
@@ -15,20 +15,19 @@
15
15
  #
16
16
 
17
17
  module Megam
18
- class Events < Megam::RestAdapter
18
+ class EventsBilling < Megam::RestAdapter
19
19
  def initialize(o)
20
20
  @account_id = nil
21
21
  @assembly_id = nil
22
22
  @event_type = nil
23
23
  @data = []
24
- @read_status= nil
25
24
  @created_at = nil
26
25
  @limit = nil
27
26
  @some_msg = {}
28
27
  super(o)
29
28
  end
30
29
 
31
- def events
30
+ def eventsbilling
32
31
  self
33
32
  end
34
33
 
@@ -48,14 +47,6 @@ module Megam
48
47
  end
49
48
  end
50
49
 
51
- def read_status(arg=nil)
52
- if arg != nil
53
- @read_status = arg
54
- else
55
- @read_status
56
- end
57
- end
58
-
59
50
  def event_type(arg=nil)
60
51
  if arg != nil
61
52
  @event_type = arg
@@ -110,7 +101,6 @@ module Megam
110
101
  index_hash["assembly_id"] = assembly_id
111
102
  index_hash["event_type"] = event_type
112
103
  index_hash["data"] = data
113
- index_hash["read_status"] = read_status
114
104
  index_hash["limit"] = limit
115
105
  index_hash["created_at"] = created_at
116
106
  index_hash["some_msg"] = some_msg
@@ -129,7 +119,6 @@ module Megam
129
119
  "assembly_id" => assembly_id,
130
120
  "event_type" => event_type,
131
121
  "data" => data,
132
- "read_status" => read_status,
133
122
  "limit" => limit,
134
123
  "created_at" => created_at
135
124
  }
@@ -142,8 +131,7 @@ module Megam
142
131
  evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
143
132
  evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
144
133
  evt.data(o["data"]) if o.has_key?("data")
145
- evt.read_status(o["read_status"]) if o.has_key?("read_status")
146
- evt.read_status(o["limit"]) if o.has_key?("limit")
134
+ evt.limit(o["limit"]) if o.has_key?("limit")
147
135
  evt.created_at(o["created_at"]) if o.has_key?("created_at")
148
136
  evt.some_msg[:code] = o["code"] if o.has_key?("code")
149
137
  evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
@@ -163,7 +151,6 @@ module Megam
163
151
  @assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
164
152
  @event_type = o[:event_type] if o.has_key?(:event_type)
165
153
  @data = o[:data] if o.has_key?(:data)
166
- @read_status = o[:read_status] if o.has_key?(:read_status)
167
154
  @limit = o[:limit] if o.has_key?(:limit)
168
155
  @created_at = o[:created_at] if o.has_key?(:created_at)
169
156
  self
@@ -182,12 +169,17 @@ module Megam
182
169
  # Load a account by email_p
183
170
  def self.show(o)
184
171
  evt = self.new(o)
185
- evt.megam_rest.get_events(o[:assembly_id])
172
+ evt.megam_rest.get_eventsbilling(o[:limit], to_hash)
186
173
  end
187
174
 
188
175
  def self.list(params)
189
176
  asm = self.new(params)
190
- asm.megam_rest.list_events(params[:limit])
177
+ asm.megam_rest.list_eventsbilling(params[:limit])
178
+ end
179
+
180
+ def self.index(params)
181
+ asm = self.new(params)
182
+ asm.megam_rest.index_eventsbilling
191
183
  end
192
184
 
193
185
  def to_s
@@ -0,0 +1,137 @@
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
+ # License:: Apache License, Version 2.0
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 EventsBillingCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @eventsbilling = Array.new
23
+ @eventsbilling_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_eventsbilling
28
+ @eventsbilling
29
+ end
30
+
31
+ def [](index)
32
+ @eventsbilling[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_eventsbilling(arg)
37
+ @eventsbilling[index] = arg
38
+ @eventsbilling_by_name[arg.account_id] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_events(a)
44
+ @eventsbilling << a
45
+ @eventsbilling_by_name[a.account_id] = @eventsbilling.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(eventsbilling)
54
+ is_megam_eventsbilling(eventsbilling)
55
+ if @insert_after_idx
56
+ # in the middle of executing a run, so any nodes inserted now should
57
+ # be placed after the most recent addition done by the currently executing
58
+ # node
59
+ @eventsbilling.insert(@insert_after_idx + 1, eventsbilling)
60
+ # update name -> location mappings and register new node
61
+ @eventsbilling_by_name.each_key do |key|
62
+ @eventsbilling_by_name[key] += 1 if @eventsbilling_by_name[key] > @insert_after_idx
63
+ end
64
+ @eventsbilling_by_name[eventsbilling.account_id] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @eventsbilling << eventsbilling
68
+ @eventsbilling_by_name[eventsbilling.account_id] = @eventsbilling.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @eventsbilling.each do |eventsbilling|
74
+ yield eventsbilling
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @eventsbilling.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @eventsbilling.empty?
86
+ end
87
+
88
+ def lookup(eventsbilling)
89
+ lookup_by = nil
90
+ if events.kind_of?(Megam::EventsBilling)
91
+ lookup_by = eventsbilling.account_id
92
+ elsif events.kind_of?(String)
93
+ lookup_by = eventsbilling
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::EventsBilling or String to lookup"
96
+ end
97
+ res = @eventsbilling_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @eventsbilling[res]
102
+ end
103
+
104
+ def to_s
105
+ @eventsbilling.join(", ")
106
+ end
107
+
108
+ def for_json
109
+ to_a.map { |item| item.to_s }
110
+ end
111
+
112
+ def to_json(*a)
113
+ Megam::JSONCompat.to_json(for_json, *a)
114
+ end
115
+
116
+ def self.json_create(o)
117
+ collection = self.new()
118
+ o["results"].each do |eventsbilling_list|
119
+ eventsbilling_array = eventsbilling_list.kind_of?(Array) ? eventsbilling_list : [ eventsbilling_list ]
120
+ eventsbilling_array.each do |eventsbilling|
121
+ collection.insert(eventsbilling)
122
+
123
+ end
124
+ end
125
+ collection
126
+ end
127
+
128
+ private
129
+
130
+ def is_megam_eventsbilling(arg)
131
+ unless arg.kind_of?(Megam::EventsBilling)
132
+ raise ArgumentError, "Members must be Megam::EventsBilling's"
133
+ end
134
+ true
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,190 @@
1
+ # Copyright:: Copyright (c) 2013-2016 Megam Systems
2
+ # License:: Apache License, Version 2.0
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
+
17
+ module Megam
18
+ class EventsContainer < Megam::RestAdapter
19
+ def initialize(o)
20
+ @account_id = nil
21
+ @assembly_id = nil
22
+ @event_type = nil
23
+ @data = []
24
+ @created_at = nil
25
+ @limit = nil
26
+ @some_msg = {}
27
+ super(o)
28
+ end
29
+
30
+ def eventscontainer
31
+ self
32
+ end
33
+
34
+ def account_id(arg=nil)
35
+ if arg != nil
36
+ @account_id = arg
37
+ else
38
+ @account_id
39
+ end
40
+ end
41
+
42
+ def assembly_id(arg=nil)
43
+ if arg != nil
44
+ @assembly_id = arg
45
+ else
46
+ @assembly_id
47
+ end
48
+ end
49
+
50
+ def event_type(arg=nil)
51
+ if arg != nil
52
+ @event_type = arg
53
+ else
54
+ @event_type
55
+ end
56
+ end
57
+
58
+
59
+ def data(arg=[])
60
+ if arg != []
61
+ @data = arg
62
+ else
63
+ @data
64
+ end
65
+ end
66
+
67
+ def limit(arg=[])
68
+ if arg != []
69
+ @limit = arg
70
+ else
71
+ @limit
72
+ end
73
+ end
74
+ def created_at(arg=nil)
75
+ if arg != nil
76
+ @created_at = arg
77
+ else
78
+ @created_at
79
+ end
80
+ end
81
+
82
+ def error?
83
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
84
+ end
85
+
86
+
87
+ def some_msg(arg=nil)
88
+ if arg != nil
89
+ @some_msg = arg
90
+ else
91
+ @some_msg
92
+ end
93
+ end
94
+
95
+
96
+ # Transform the ruby obj -> to a Hash
97
+ def to_hash
98
+ index_hash = Hash.new
99
+ index_hash["json_claz"] = self.class.name
100
+ index_hash["account_id"] = account_id
101
+ index_hash["assembly_id"] = assembly_id
102
+ index_hash["event_type"] = event_type
103
+ index_hash["data"] = data
104
+ index_hash["limit"] = limit
105
+ index_hash["created_at"] = created_at
106
+ index_hash["some_msg"] = some_msg
107
+ index_hash
108
+ end
109
+
110
+ # Serialize this object as a hash: called from JsonCompat.
111
+ # Verify if this called from JsonCompat during testing.
112
+ def to_json(*a)
113
+ for_json.to_json(*a)
114
+ end
115
+
116
+ def for_json
117
+ result = {
118
+ "account_id" => account_id,
119
+ "assembly_id" => assembly_id,
120
+ "event_type" => event_type,
121
+ "data" => data,
122
+ "limit" => limit,
123
+ "created_at" => created_at
124
+ }
125
+ result
126
+ end
127
+
128
+ def self.json_create(o)
129
+ evt = new({})
130
+ evt.account_id(o["account_id"]) if o.has_key?("account_id")
131
+ evt.assembly_id(o["assembly_id"]) if o.has_key?("assembly_id")
132
+ evt.event_type(o["event_type"]) if o.has_key?("event_type") #this will be an array? can hash store array?
133
+ evt.data(o["data"]) if o.has_key?("data")
134
+ evt.limit(o["limit"]) if o.has_key?("limit")
135
+ evt.created_at(o["created_at"]) if o.has_key?("created_at")
136
+ evt.some_msg[:code] = o["code"] if o.has_key?("code")
137
+ evt.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
138
+ evt.some_msg[:msg]= o["msg"] if o.has_key?("msg")
139
+ evt.some_msg[:links] = o["links"] if o.has_key?("links")
140
+ evt
141
+ end
142
+
143
+ def self.from_hash(o)
144
+ evt = self.new(o)
145
+ evt.from_hash(o)
146
+ evt
147
+ end
148
+
149
+ def from_hash(o)
150
+ @account_id = o[:account_id] if o.has_key?(:account_id)
151
+ @assembly_id = o[:assembly_id] if o.has_key?(:assembly_id)
152
+ @event_type = o[:event_type] if o.has_key?(:event_type)
153
+ @data = o[:data] if o.has_key?(:data)
154
+ @limit = o[:limit] if o.has_key?(:limit)
155
+ @created_at = o[:created_at] if o.has_key?(:created_at)
156
+ self
157
+ end
158
+
159
+ def self.create(params)
160
+ evt = from_hash(params)
161
+ evt.create
162
+ end
163
+
164
+ # Create the node via the REST API
165
+ def create
166
+ megam_rest.post_events(to_hash)
167
+ end
168
+
169
+ # Load a account by email_p
170
+ def self.show(o)
171
+ evt = self.new(o)
172
+ evt.megam_rest.get_eventscontainer(o[:limit], to_hash)
173
+ end
174
+
175
+ def self.list(params)
176
+ asm = self.new(params)
177
+ asm.megam_rest.list_eventscontainer(params[:limit])
178
+ end
179
+
180
+ def self.index(params)
181
+ asm = self.new(params)
182
+ asm.megam_rest.index_eventscontainer
183
+ end
184
+
185
+ def to_s
186
+ Megam::Stuff.styled_hash(to_hash)
187
+ end
188
+
189
+ end
190
+ end