megam_api 1.8.16 → 1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad93f5223b09881ca75af18ecf0fdd94db307e57
4
- data.tar.gz: 2603ac05a467a0025b116f0ee76c8b93bbff8402
3
+ metadata.gz: 7b9607ccb526464b608d2c6fee9012ef761c87a9
4
+ data.tar.gz: e00e3813791631deb93a5228e9955632b53a6ade
5
5
  SHA512:
6
- metadata.gz: 351d75d64027503a98cdc9a75454a1b54b69db899c54b9d9898a5fb838daf8f36be153fa9b6992bf134535ca215cdcec52496eaaf426a845242f6a2357b615aa
7
- data.tar.gz: 37c712f610cf32d8943f639208ee38e9f827d62f50fb7a09b0176db65b38c954af33d8747fe1e7a38130f1d90b3e80c48990c15da5682836498562f07d4f669c
6
+ metadata.gz: f70df29812f6e44bcb743a4f05cc47cdc9474dc787547786e86192035696b87c0b64027818ff38de868f1f0a44fc79c0d50079245b0340b44b7ac9b201765ceb
7
+ data.tar.gz: 56611b0ce9100de5f2083b3ea0a6c953a0a512bcbf8ac1501dc0e7df155978462488c584f1800edb026f965cb05e0ad8b8424a5cbad9c5083ec728603470aab3
data/lib/megam/api.rb CHANGED
@@ -210,7 +210,7 @@ module Megam
210
210
 
211
211
  scheme = (uri && uri.scheme) ? uri.scheme : 'http'
212
212
 
213
- host = (uri && uri.host) ? uri.host : '127.0.0.1'
213
+ host = (uri && uri.host) ? uri.host : '192.168.0.118'
214
214
 
215
215
  port = (uri && uri.port) ? uri.port.to_s : '9000'
216
216
 
@@ -31,5 +31,15 @@ module Megam
31
31
  )
32
32
  end
33
33
 
34
+ def list_assembly
35
+ @options = {:path => "/assembly",:body => ""}.merge(@options)
36
+
37
+ request(
38
+ :expects => 200,
39
+ :method => :get,
40
+ :body => @options[:body]
41
+ )
42
+ end
43
+
34
44
  end
35
45
  end
@@ -0,0 +1,15 @@
1
+ module Megam
2
+ class API
3
+ def post_reports(new_sps)
4
+ @options = {:path => '/reports/content',
5
+ :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
6
+
7
+ request(
8
+ :expects => 201,
9
+ :method => :post,
10
+ :body => @options[:body]
11
+ )
12
+ end
13
+
14
+ end
15
+ end
@@ -1,7 +1,8 @@
1
1
  module Megam
2
2
  class API
3
3
  # GET /nodes
4
- def list_snapshots
4
+ def list_s
5
+ puts "jhhdsudsaguysgduyasgduyasguydgasgduysgauysgdas"
5
6
  @options = {:path => "/snapshots",:body => ""}.merge(@options)
6
7
 
7
8
  request(
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.8.16"
3
+ VERSION = "1.9"
4
4
  end
5
5
  end
@@ -204,6 +204,11 @@ module Megam
204
204
  asm.megam_rest.upgrade_assembly(params['id'])
205
205
  end
206
206
 
207
+ def self.list(params)
208
+ asm = self.new(params)
209
+ asm.megam_rest.list_assembly
210
+ end
211
+
207
212
  # Create the node via the REST API
208
213
  def update
209
214
  megam_rest.update_assembly(to_hash)
@@ -59,6 +59,7 @@ module Megam
59
59
  MEGAM_ADDONS = 'Megam::Addons'.freeze
60
60
  MEGAM_ADDONSCOLLECTION = 'Megam::AddonsCollection'.freeze
61
61
  MEGAM_PROMOS = 'Megam::Promos'.freeze
62
+ MEGAM_REPORTS = 'Megam::Reports'.freeze
62
63
 
63
64
  class << self
64
65
  # API to use to avoid create_addtions
@@ -237,6 +238,8 @@ module Megam
237
238
  Megam::AddonsCollection
238
239
  when MEGAM_PROMOS
239
240
  Megam::Promos
241
+ when MEGAM_REPORTS
242
+ Megam::Reports
240
243
  else
241
244
  fail JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
242
245
  end
@@ -0,0 +1,211 @@
1
+ module Megam
2
+ class Reports < Megam::RestAdapter
3
+ def initialize(o)
4
+ @start_date = nil
5
+ @end_date = nil
6
+ @type = nil
7
+ @title = nil
8
+ @xaxis = nil
9
+ @yaxis = nil
10
+ @ytitles = {}
11
+ @data = []
12
+ @total = nil
13
+ @category_id = nil
14
+ @group_id = nil
15
+ @prev30Days = nil
16
+ @some_msg = {}
17
+ super(o)
18
+ end
19
+
20
+ def reports
21
+ self
22
+ end
23
+ def start_date(arg=nil)
24
+ if arg != nil
25
+ @start_date = arg
26
+ else
27
+ @start_date
28
+ end
29
+ end
30
+
31
+ def end_date(arg=nil)
32
+ if arg != nil
33
+ @end_date = arg
34
+ else
35
+ @end_date
36
+ end
37
+ end
38
+
39
+ def type(arg=nil)
40
+ if arg != nil
41
+ @type = arg
42
+ else
43
+ @type
44
+ end
45
+ end
46
+
47
+ def title(arg=nil)
48
+ if arg !=nil
49
+ @title = arg
50
+ else
51
+ @title
52
+ end
53
+ end
54
+
55
+ def xaxis(arg=nil)
56
+ if arg !=nil
57
+ @xaxis = arg
58
+ else
59
+ @xaxis
60
+ end
61
+ end
62
+
63
+ def yaxis(arg=nil)
64
+ if arg !=nil
65
+ @yaxis = arg
66
+ else
67
+ @yaxis
68
+ end
69
+ end
70
+
71
+ def ytitles(arg=nil)
72
+ if arg !=nil
73
+ @ytitles = arg
74
+ else
75
+ @ytitles
76
+ end
77
+ end
78
+
79
+ def data(arg = [])
80
+ if arg != []
81
+ @data = arg
82
+ else
83
+ @data
84
+ end
85
+ end
86
+
87
+ def total(arg=nil)
88
+ if arg !=nil
89
+ @total = arg
90
+ else
91
+ @total
92
+ end
93
+ end
94
+
95
+ def category_id(arg=nil)
96
+ if arg !=nil
97
+ @category_id = arg
98
+ else
99
+ @category_id
100
+ end
101
+ end
102
+
103
+ def group_id(arg=nil)
104
+ if arg !=nil
105
+ @group_id = arg
106
+ else
107
+ @group_id
108
+ end
109
+ end
110
+
111
+ def prev30Days(arg=nil)
112
+ if arg !=nil
113
+ @prev30Days = arg
114
+ else
115
+ @prev30Days
116
+ end
117
+ end
118
+
119
+ def some_msg(arg=nil)
120
+ if arg != nil
121
+ @some_msg = arg
122
+ else
123
+ @some_msg
124
+ end
125
+ end
126
+
127
+ def error?
128
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
129
+ end
130
+
131
+ # Transform the ruby obj -> to a Hash
132
+ def to_hash
133
+ index_hash = Hash.new
134
+ index_hash["json_claz"] = self.class.name
135
+ index_hash["start_date"] = start_date
136
+ index_hash["end_date"] = end_date
137
+ index_hash["type"] = type
138
+ index_hash
139
+ end
140
+
141
+ # Serialize this object as a hash: called from JsonCompat.
142
+ # Verify if this called from JsonCompat during testing.
143
+ def to_json(*a)
144
+ for_json.to_json(*a)
145
+ end
146
+
147
+
148
+ def for_json
149
+ result = {
150
+ "start_date" => start_date,
151
+ "end_date" => end_date,
152
+ "type" => type,
153
+ "title" => title,
154
+ "yaxis" => yaxis,
155
+ "xaxis" => xaxis,
156
+ "ytitles" => ytitles,
157
+ "data" => data,
158
+ "total" => total,
159
+ "category_id" => category_id,
160
+ "group_id" => group_id,
161
+ "prev30Days" => prev30Days
162
+ }
163
+ result
164
+ end
165
+
166
+ def self.json_create(o)
167
+ sps = new({})
168
+ sps.start_date(o["start_date"]) if o.has_key?("start_date")
169
+ sps.end_date(o["end_date"]) if o.has_key?("end_date")
170
+ sps.type(o["type"]) if o.has_key?("type")
171
+ sps.type(o["title"]) if o.has_key?("title")
172
+ sps.type(o["yaxis"]) if o.has_key?("yaxis")
173
+ sps.type(o["xaxis"]) if o.has_key?("xaxis")
174
+ sps.type(o["ytitles"]) if o.has_key?("ytitles")
175
+ sps.type(o["data"]) if o.has_key?("data")
176
+ sps.type(o["total"]) if o.has_key?("total")
177
+ sps.type(o["category_id"]) if o.has_key?("category_id")
178
+ sps.type(o["group_id"]) if o.has_key?("group_id")
179
+ sps.type(o["prev30Days"]) if o.has_key?("prev30Days")
180
+ sps
181
+ end
182
+
183
+ def self.from_hash(o)
184
+ sps = self.new(o)
185
+ sps.from_hash(o)
186
+ sps
187
+ end
188
+
189
+ def from_hash(o)
190
+ @start_date = o[:start_date] if o.has_key?(:start_date)
191
+ @end_date = o[:end_date] if o.has_key?(:end_date)
192
+ @type = o[:type] if o.has_key?(:type)
193
+ self
194
+ end
195
+
196
+ def self.create(params)
197
+ sps = from_hash(params)
198
+ sps.create
199
+ end
200
+
201
+ # Create the node via the REST API
202
+ def create
203
+ megam_rest.post_reports(to_hash)
204
+ end
205
+
206
+ def to_s
207
+ Megam::Stuff.styled_hash(to_hash)
208
+ end
209
+
210
+ end
211
+ end
@@ -0,0 +1,122 @@
1
+ module Megam
2
+ class ReportsCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @reports = Array.new
8
+ @reports_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_reports
13
+ @reports
14
+ end
15
+
16
+ def [](index)
17
+ @reports[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_reports(arg)
22
+ @reports[index] = arg
23
+ @reports_by_name[arg.account_id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_events(a)
29
+ @reports << a
30
+ @reports_by_name[a.account_id] = @reports.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(reports)
39
+ is_megam_reports(reports)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any nodes inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # node
44
+ @reports.insert(@insert_after_idx + 1, reports)
45
+ # update name -> location mappings and register new node
46
+ @reports_by_name.each_key do |key|
47
+ @reports_by_name[key] += 1 if @reports_by_name[key] > @insert_after_idx
48
+ end
49
+ @reports_by_name[reports.account_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @reports << reports
53
+ @reports_by_name[reports.account_id] = @reports.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @reports.each do |reports|
59
+ yield reports
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @reports.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @reports.empty?
71
+ end
72
+
73
+ def lookup(reports)
74
+ lookup_by = nil
75
+ if events.kind_of?(Megam::Reports)
76
+ lookup_by = reports.account_id
77
+ elsif reports.kind_of?(String)
78
+ lookup_by = reports
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Reports or String to lookup"
81
+ end
82
+ res = @reports_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @reports[res]
87
+ end
88
+
89
+ def to_s
90
+ @reports.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |reports_list|
104
+ reports_array = reports_list.kind_of?(Array) ? reports_list : [ reports_list ]
105
+ reports_array.each do |reports|
106
+ collection.insert(reports)
107
+
108
+ end
109
+ end
110
+ collection
111
+ end
112
+
113
+ private
114
+
115
+ def is_megam_reports(arg)
116
+ unless arg.kind_of?(Megam::Reports)
117
+ raise ArgumentError, "Members must be Megam::Reports's"
118
+ end
119
+ true
120
+ end
121
+ end
122
+ end
@@ -4,11 +4,12 @@ class TestApps < MiniTest::Unit::TestCase
4
4
 
5
5
  #=begin
6
6
  def test_get_assembly
7
- response = megams.get_one_assembly("ASM6175632897198829431")
7
+ response = megams.get_one_assembly("ASM5405446528593826612")
8
+ puts response.inspect
8
9
  assert_equal(200, response.status)
9
10
  end
10
11
  #=end
11
- #=begin
12
+ =begin
12
13
  def test_update_assembly
13
14
  tmp_hash = {
14
15
 
@@ -32,5 +33,5 @@ class TestApps < MiniTest::Unit::TestCase
32
33
  response = megams.update_assembly(tmp_hash)
33
34
  assert_equal(201, response.status)
34
35
  end
35
- #=end
36
+ =end
36
37
  end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+
5
+ def test_post_snapshots
6
+ tmp_hash = {
7
+ :account_id => "test@megam.io",
8
+ :asm_id => "ASM535576423764486230",
9
+ :org_id => "ORG7879663326321337888",
10
+ :name => "pop.megambox.com",
11
+ :status => "progress",
12
+ :start_date => "progress",
13
+ :end_date => "progress",
14
+ :type => "progress",
15
+
16
+ }
17
+
18
+ response = megams.post_reports(tmp_hash)
19
+ assert_equal(201, response.status)
20
+ end
21
+
22
+ # def test_get_snapshots
23
+ # response = megams.post_reports("ASM535576423764486230")
24
+ # assert_equal(200, response.status)
25
+ # end
26
+ =begin
27
+ def test_list_snapshots
28
+ response = megams.list_snapshots
29
+ assert_equal(200, response.status)
30
+ end
31
+ =end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.16
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-24 00:00:00.000000000 Z
12
+ date: 2016-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -157,6 +157,7 @@ files:
157
157
  - lib/megam/api/marketplaces.rb
158
158
  - lib/megam/api/organizations.rb
159
159
  - lib/megam/api/promos.rb
160
+ - lib/megam/api/reports.rb
160
161
  - lib/megam/api/requests.rb
161
162
  - lib/megam/api/sensors.rb
162
163
  - lib/megam/api/snapshots.rb
@@ -205,6 +206,8 @@ files:
205
206
  - lib/megam/core/organizations.rb
206
207
  - lib/megam/core/organizations_collection.rb
207
208
  - lib/megam/core/promos.rb
209
+ - lib/megam/core/reports.rb
210
+ - lib/megam/core/reports_collection.rb
208
211
  - lib/megam/core/request.rb
209
212
  - lib/megam/core/request_collection.rb
210
213
  - lib/megam/core/rest_adapter.rb
@@ -249,6 +252,7 @@ files:
249
252
  - test/test_marketplaces.rb
250
253
  - test/test_organizations.rb
251
254
  - test/test_promos.rb
255
+ - test/test_reports.rb
252
256
  - test/test_requests.rb
253
257
  - test/test_sensors.rb
254
258
  - test/test_snapshots.rb