megam_api 1.10 → 1.10.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e91f998c5bb1d48e63a95947fdafbf14bf7d929b
4
- data.tar.gz: 1bab47dcd854ed876737a0c2e24a6abe61c85caf
3
+ metadata.gz: 661f42188a2c36b396c116b89e8a7bcfb3bdb2f2
4
+ data.tar.gz: b2ea92953b575a776a93e10e62c6870befbc4b77
5
5
  SHA512:
6
- metadata.gz: 6ab088c5533e497c41ba66dc7acb1f007ac06736a3704574a4aae045e0ec1dace45e158caa49bfd79e1066605070390b9a3046d2a64e5bc67f01b45c5788775a
7
- data.tar.gz: 0cdd53e1f6d6453d9c90fafc8cfd9b13110d3e4301428e7cb93fe6898855b3d42d2f115d41c92d755e6675023f273bd9f44502683c29962cf5e5cc7bfbba42a7
6
+ metadata.gz: 3d2a669191c45f02ac9357daccc4b54376f076dedb43db5a7592c2821ed408394511a46de4df16ccb208088bde251a6d89f81c252424f2d70779d8428fdac85d
7
+ data.tar.gz: d1774af55a64a11ab6203463b08d5d63e4f1579bb9669b1246145240c02b978f2645a5e92e824f50cec4a9d9c4790eca39102288ecc278f31b693ba9b8063eaf
data/lib/megam/api.rb CHANGED
@@ -12,6 +12,7 @@ require 'megam/api/accounts'
12
12
  require 'megam/api/assemblies'
13
13
  require 'megam/api/assembly'
14
14
  require 'megam/api/balances'
15
+ require 'megam/api/credits'
15
16
  require 'megam/api/billedhistories'
16
17
  require 'megam/api/billingtransactions'
17
18
  require 'megam/api/components'
@@ -95,6 +96,8 @@ require 'megam/core/disks'
95
96
  require 'megam/core/disks_collection'
96
97
  require 'megam/core/balances_collection'
97
98
  require 'megam/core/balances'
99
+ require 'megam/core/credits_collection'
100
+ require 'megam/core/credits'
98
101
  require 'megam/core/billedhistories_collection'
99
102
  require 'megam/core/billedhistories'
100
103
  require 'megam/core/billingtransactions_collection'
@@ -216,7 +219,7 @@ module Megam
216
219
 
217
220
  scheme = (uri && uri.scheme) ? uri.scheme : 'http'
218
221
 
219
- host = (uri && uri.host) ? uri.host : '192.168.0.118'
222
+ host = (uri && uri.host) ? uri.host : 'localhost'
220
223
 
221
224
  port = (uri && uri.port) ? uri.port.to_s : '9000'
222
225
 
@@ -0,0 +1,34 @@
1
+ module Megam
2
+ class API
3
+ def list_credits
4
+ @options = {:path => '/credits',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_credits(account_id)
14
+ @options = {:path => "/credits/#{account_id}",:body => Megam::JSONCompat.to_json(account_id)}.merge(@options)
15
+ request(
16
+ :expects => 200,
17
+ :method => :get,
18
+ :body => @options[:body]
19
+ )
20
+ end
21
+
22
+ def post_credits(new_credits)
23
+ @options = {:path => '/credits/content',
24
+ :body => Megam::JSONCompat.to_json(new_credits)}.merge(@options)
25
+
26
+ request(
27
+ :expects => 201,
28
+ :method => :post,
29
+ :body => @options[:body]
30
+ )
31
+ end
32
+
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "1.10"
3
+ VERSION = "1.10.1"
4
4
  end
5
5
  end
@@ -0,0 +1,146 @@
1
+ module Megam
2
+ class Credits < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @account_id = nil
6
+ @credit = nil
7
+ @created_at = nil
8
+ @some_msg = {}
9
+ super(o)
10
+ end
11
+
12
+ def credit
13
+ self
14
+ end
15
+
16
+ def id(arg=nil)
17
+ if arg != nil
18
+ @id = arg
19
+ else
20
+ @id
21
+ end
22
+ end
23
+
24
+ def account_id(arg=nil)
25
+ if arg != nil
26
+ @account_id= arg
27
+ else
28
+ @account_id
29
+ end
30
+ end
31
+
32
+
33
+ def credit(arg=nil)
34
+ if arg != nil
35
+ @credit = arg
36
+ else
37
+ @credit
38
+ end
39
+ end
40
+
41
+ def created_at(arg=nil)
42
+ if arg != nil
43
+ @created_at = arg
44
+ else
45
+ @created_at
46
+ end
47
+ end
48
+
49
+ def some_msg(arg=nil)
50
+ if arg != nil
51
+ @some_msg = arg
52
+ else
53
+ @some_msg
54
+ end
55
+ end
56
+
57
+ def error?
58
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
59
+ end
60
+
61
+ # Transform the ruby obj -> to a Hash
62
+ def to_hash
63
+ index_hash = Hash.new
64
+ index_hash["json_claz"] = self.class.name
65
+ index_hash["id"] = id
66
+ index_hash["account_id"] = account_id
67
+ index_hash["credit"] = credit
68
+ index_hash["created_at"] = created_at
69
+ index_hash
70
+ end
71
+
72
+ # Serialize this object as a hash: called from JsonCompat.
73
+ # Verify if this called from JsonCompat during testing.
74
+ def to_json(*a)
75
+ for_json.to_json(*a)
76
+ end
77
+
78
+ def for_json
79
+ result = {
80
+ "id" => id,
81
+ "account_id" => account_id,
82
+ "credit" => credit,
83
+ "created_at" => created_at,
84
+ }
85
+ result
86
+ end
87
+
88
+ def self.json_create(o)
89
+ cr = new({})
90
+ cr.id(o["id"]) if o.has_key?("id")
91
+ cr.account_id(o["account_id"]) if o.has_key?("account_id")
92
+ cr.credit(o["credit"]) if o.has_key?("credit")
93
+ cr.created_at(o["created_at"]) if o.has_key?("created_at")
94
+ #success or error
95
+ cr.some_msg[:code] = o["code"] if o.has_key?("code")
96
+ cr.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
97
+ cr.some_msg[:msg]= o["msg"] if o.has_key?("msg")
98
+ cr.some_msg[:links] = o["links"] if o.has_key?("links")
99
+ cr
100
+ end
101
+
102
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil, tmp_host=nil)
103
+ cr = self.new(tmp_email, tmp_api_key, tmp_host)
104
+ cr.from_hash(o)
105
+ cr
106
+ end
107
+
108
+ def from_hash(o)
109
+ @id = o[:id] if o.has_key?(:id)
110
+ @account_id = o[:account_id] if o.has_key?(:account_id)
111
+ @credit = o[:credit] if o.has_key?(:credit)
112
+ @created_at = o[:created_at] if o.has_key?(:created_at)
113
+ self
114
+ end
115
+
116
+ def self.create(params)
117
+ acct = from_hash(params,params["email"], params["api_key"], params["host"])
118
+ acct.create
119
+ end
120
+
121
+ # Create the predef via the REST API
122
+ def create
123
+ megam_rest.post_credits(to_hash)
124
+ end
125
+
126
+ # Load all credit -
127
+ # returns a creditCollection
128
+ # don't return self. check if the Megam::CreditCollection is returned.
129
+ def self.list(params)
130
+ cr = self.new(params)
131
+ cr.megam_rest.list_credits
132
+ end
133
+
134
+ # Show a particular balance by name,
135
+ # Megam::Balance
136
+ def self.show(params)
137
+ pre = self.new(params)
138
+ pre.megam_rest.get_credits(params["account_id"])
139
+ end
140
+
141
+ def to_s
142
+ Megam::Stuff.styled_hash(to_hash)
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,121 @@
1
+ module Megam
2
+ class CreditsCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @credits = Array.new
8
+ @credits_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_credits
13
+ @credits
14
+ end
15
+
16
+ def [](index)
17
+ @credits[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_credits(arg)
22
+ @credits[index] = arg
23
+ @credits_by_name[arg.id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_credits(a)
29
+ @credits << a
30
+ @credits_by_name[a.id] =@credits.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(credits)
39
+ is_megam_credits(credits)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any predefs inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # credit
44
+ @credits.insert(@insert_after_idx + 1, credits)
45
+ # update id -> location mappings and register new credit
46
+ @credits_by_name.each_key do |key|
47
+ @credits_by_name[key] += 1 if@credits_by_name[key] > @insert_after_idx
48
+ end
49
+ @credits_by_name[credits.account_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @credits << credits
53
+ @credits_by_name[credits.account_id] =@credits.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @credits.each do |credits|
59
+ yield credits
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @credits.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @credits.empty?
71
+ end
72
+
73
+ def lookup(credits)
74
+ lookup_by = nil
75
+ if credits.kind_of?(Megam::Credits)
76
+ lookup_by = credits.account_id
77
+ elsif credits.kind_of?(String)
78
+ lookup_by = credits
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Credits or String to lookup"
81
+ end
82
+ res =@credits_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a credits matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @credits[res]
87
+ end
88
+
89
+ def to_s
90
+ @credits.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 |credits_list|
104
+ credits_array = credits_list.kind_of?(Array) ? credits_list : [ credits_list ]
105
+ credits_array.each do |credits|
106
+ collection.insert(credits)
107
+ end
108
+ end
109
+ collection
110
+ end
111
+
112
+ private
113
+
114
+ def is_megam_credits(arg)
115
+ unless arg.kind_of?(Megam::Credits)
116
+ raise ArgumentError, "Members must be Megam::credits's"
117
+ end
118
+ true
119
+ end
120
+ end
121
+ end
@@ -19,6 +19,8 @@ module Megam
19
19
  MEGAM_ASSEMBLYCOLLECTION = 'Megam::AssemblyCollection'.freeze
20
20
  MEGAM_BALANCES = 'Megam::Balances'.freeze
21
21
  MEGAM_BALANCESCOLLECTION = 'Megam::BalancesCollection'.freeze
22
+ MEGAM_CREDITS = 'Megam::Credits'.freeze
23
+ MEGAM_CREDITSCOLLECTION = 'Megam::CreditsCollection'.freeze
22
24
  MEGAM_BILLEDHISTORIES = 'Megam::Billedhistories'.freeze
23
25
  MEGAM_BILLEDHISTORIESCOLLECTION = 'Megam::BilledhistoriesCollection'.freeze
24
26
  MEGAM_BILLINGTRANSACTIONS = 'Megam::BillingTransactions'.freeze
@@ -220,6 +222,10 @@ module Megam
220
222
  Megam::Balances
221
223
  when MEGAM_BALANCESCOLLECTION
222
224
  Megam::BalancesCollection
225
+ when MEGAM_CREDITS
226
+ Megam::Credits
227
+ when MEGAM_CREDITSCOLLECTION
228
+ Megam::CreditsCollection
223
229
  when MEGAM_BILLEDHISTORIES
224
230
  Megam::Billedhistories
225
231
  when MEGAM_BILLEDHISTORIESCOLLECTION
@@ -0,0 +1,28 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ #=begin
5
+
6
+ def test_post_credits
7
+ tmp_hash = { :account_id => "rrr",
8
+ :credit => "50"
9
+ }
10
+
11
+ response = megams.post_credits(tmp_hash)
12
+ assert_equal(201, response.status)
13
+ end
14
+ #=end
15
+
16
+ #=begin
17
+ def test_list_credits
18
+ response = megams.list_credits
19
+ assert_equal(200, response.status)
20
+ end
21
+ #=end
22
+ #=begin
23
+ def test_get_credits
24
+ response = megams.get_credits("rrr")
25
+ assert_equal(200, response.status)
26
+ end
27
+ #=end
28
+ end
data/test/test_helper.rb CHANGED
@@ -30,9 +30,9 @@ end
30
30
 
31
31
  def megams(options={})
32
32
  s_options = SANDBOX_HOST_OPTIONS.merge({
33
- :email => "rajeshr@megam.io",
34
- :api_key => "e6c0a7f564c498b2621393957c85394dc01eb779",
35
- :org_id => "ORG123",
33
+ :email => "rajeshr@virtengine.com",
34
+ :api_key => "5e08ad5a1a3c89910a2e51fb522812fee4560baa",
35
+ :org_id => "ORG6974933279242510669",
36
36
  #:password => "bWVnYW0="
37
37
  })
38
38
 
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.10'
4
+ version: 1.10.1
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-12-30 00:00:00.000000000 Z
12
+ date: 2017-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -144,6 +144,7 @@ files:
144
144
  - lib/megam/api/billedhistories.rb
145
145
  - lib/megam/api/billingtransactions.rb
146
146
  - lib/megam/api/components.rb
147
+ - lib/megam/api/credits.rb
147
148
  - lib/megam/api/disks.rb
148
149
  - lib/megam/api/domains.rb
149
150
  - lib/megam/api/errors.rb
@@ -180,6 +181,8 @@ files:
180
181
  - lib/megam/core/billingtransactions_collection.rb
181
182
  - lib/megam/core/components.rb
182
183
  - lib/megam/core/components_collection.rb
184
+ - lib/megam/core/credits.rb
185
+ - lib/megam/core/credits_collection.rb
183
186
  - lib/megam/core/disks.rb
184
187
  - lib/megam/core/disks_collection.rb
185
188
  - lib/megam/core/domain_collection.rb
@@ -244,6 +247,7 @@ files:
244
247
  - test/test_billedhistories.rb
245
248
  - test/test_billingtranscations.rb
246
249
  - test/test_components.rb
250
+ - test/test_credits.rb
247
251
  - test/test_disks.rb
248
252
  - test/test_domains.rb
249
253
  - test/test_eventsbilling.rb