megam_api 0.51 → 0.52
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 +4 -4
- data/lib/megam/api.rb +3 -0
- data/lib/megam/api/promos.rb +18 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/json_compat.rb +5 -2
- data/lib/megam/core/promos.rb +161 -0
- data/test/test_helper.rb +2 -2
- data/test/test_promos.rb +12 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efb3b538b59b4202914e5b5258d6116ed2fd3147
|
4
|
+
data.tar.gz: 43a27dd9a928bb3428793c5c0e6dd174352e410e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04259a55304074084b0bbbf5951b184bcefddae9bbf2dd459e403d2a0a6f6f1616b862f91377d67665a67e98d9ed5d22be43609c25b6160ad07b29f6d43f25df
|
7
|
+
data.tar.gz: ce62a8c7dccf35fa9ac8cc0e342c4f352533c0b3ad2825d65799e4824b85c56e7ef349ab482781e36e845324d295eca97b364bd2f938d20bddfafe1d0300a2d8
|
data/lib/megam/api.rb
CHANGED
@@ -37,6 +37,7 @@ require "megam/api/billings"
|
|
37
37
|
require "megam/api/credithistories"
|
38
38
|
require "megam/api/discounts"
|
39
39
|
require "megam/api/subscriptions"
|
40
|
+
require "megam/api/promos"
|
40
41
|
|
41
42
|
require "megam/core/server_api"
|
42
43
|
require "megam/core/config"
|
@@ -75,6 +76,7 @@ require "megam/core/cat_request"
|
|
75
76
|
require "megam/core/cat_request_collection"
|
76
77
|
require "megam/core/event"
|
77
78
|
|
79
|
+
|
78
80
|
require "megam/core/availableunits_collection"
|
79
81
|
require "megam/core/availableunits"
|
80
82
|
require "megam/core/balances_collection"
|
@@ -89,6 +91,7 @@ require "megam/core/discounts_collection"
|
|
89
91
|
require "megam/core/discounts"
|
90
92
|
require "megam/core/subscriptions_collection"
|
91
93
|
require "megam/core/subscriptions"
|
94
|
+
require "megam/core/promos"
|
92
95
|
|
93
96
|
module Megam
|
94
97
|
class API
|
data/lib/megam/api/version.rb
CHANGED
@@ -65,8 +65,9 @@ module Megam
|
|
65
65
|
MEGAM_SSHKEYCOLLECTION = "Megam::SshKeyCollection".freeze
|
66
66
|
MEGAM_SUBSCRIPTIONS = "Megam::Subscriptions".freeze
|
67
67
|
MEGAM_SUBSCRIPTIONSCOLLECTION = "Megam::SubscriptionsCollection".freeze
|
68
|
-
|
69
|
-
|
68
|
+
MEGAM_PROMOS = "Megam::Promos".freeze
|
69
|
+
|
70
|
+
|
70
71
|
class <<self
|
71
72
|
# Increase the max nesting for JSON, which defaults
|
72
73
|
# to 19, and isn't enough for some (for example, a Node within a Node)
|
@@ -225,6 +226,8 @@ module Megam
|
|
225
226
|
Megam::Subscriptions
|
226
227
|
when MEGAM_SUBSCRIPTIONSCOLLECTION
|
227
228
|
Megam::SubscriptionsCollection
|
229
|
+
when MEGAM_PROMOS
|
230
|
+
Megam::Promos
|
228
231
|
else
|
229
232
|
raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
230
233
|
end
|
@@ -0,0 +1,161 @@
|
|
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 Promos < Megam::ServerAPI
|
18
|
+
def initialize(email=nil, api_key=nil)
|
19
|
+
@id = nil
|
20
|
+
@code = nil
|
21
|
+
@amount = nil
|
22
|
+
@created_at = nil
|
23
|
+
@some_msg = {}
|
24
|
+
super(email, api_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
def promos
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def id(arg=nil)
|
32
|
+
if arg != nil
|
33
|
+
@id = arg
|
34
|
+
else
|
35
|
+
@id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def code(arg=nil)
|
40
|
+
if arg != nil
|
41
|
+
@code = arg
|
42
|
+
else
|
43
|
+
@code
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def amount(arg=nil)
|
48
|
+
if arg != nil
|
49
|
+
@amount = arg
|
50
|
+
else
|
51
|
+
@amount
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def created_at(arg=nil)
|
56
|
+
if arg != nil
|
57
|
+
@created_at = arg
|
58
|
+
else
|
59
|
+
@created_at
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
def some_msg(arg=nil)
|
66
|
+
if arg != nil
|
67
|
+
@some_msg = arg
|
68
|
+
else
|
69
|
+
@some_msg
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def error?
|
74
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
75
|
+
end
|
76
|
+
|
77
|
+
# Transform the ruby obj -> to a Hash
|
78
|
+
def to_hash
|
79
|
+
index_hash = Hash.new
|
80
|
+
index_hash["json_claz"] = self.class.name
|
81
|
+
index_hash["id"] = id
|
82
|
+
index_hash["code"] = code
|
83
|
+
index_hash["amount"] = amount
|
84
|
+
index_hash["created_at"] = created_at
|
85
|
+
index_hash
|
86
|
+
end
|
87
|
+
|
88
|
+
# Serialize this object as a hash: called from JsonCompat.
|
89
|
+
# Verify if this called from JsonCompat during testing.
|
90
|
+
def to_json(*a)
|
91
|
+
for_json.to_json(*a)
|
92
|
+
end
|
93
|
+
|
94
|
+
def for_json
|
95
|
+
result = {
|
96
|
+
"id" => id,
|
97
|
+
"code" => code,
|
98
|
+
"amount" => amount,
|
99
|
+
"created_at" => created_at
|
100
|
+
}
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.json_create(o)
|
105
|
+
promos = new
|
106
|
+
promos.id(o["id"]) if o.has_key?("id")
|
107
|
+
promos.code(o["code"]) if o.has_key?("code")
|
108
|
+
promos.amount(o["amount"]) if o.has_key?("amount")
|
109
|
+
promos.created_at(o["created_at"]) if o.has_key?("created_at")
|
110
|
+
#success or error
|
111
|
+
promos.some_msg[:code] = o["code"] if o.has_key?("code")
|
112
|
+
promos.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
113
|
+
promos.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
114
|
+
promos.some_msg[:links] = o["links"] if o.has_key?("links")
|
115
|
+
promos
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
|
119
|
+
promos = self.new(tmp_email, tmp_api_key)
|
120
|
+
promos.from_hash(o)
|
121
|
+
promos
|
122
|
+
end
|
123
|
+
|
124
|
+
def from_hash(o)
|
125
|
+
@id = o[:id] if o.has_key?(:id)
|
126
|
+
@code = o[:name] if o.has_key?(:name)
|
127
|
+
@amount = o[:credit] if o.has_key?(:credit)
|
128
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.create(params)
|
133
|
+
promo = from_hash(params,params["email"], params["api_key"])
|
134
|
+
promo.create
|
135
|
+
end
|
136
|
+
|
137
|
+
# Create the predef via the REST API
|
138
|
+
def create
|
139
|
+
megam_rest.post_promos(to_hash) #WONT BE USED AS OF NOW
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.list(params)
|
143
|
+
promos = self.new(params["email"], params["api_key"])
|
144
|
+
promos.megam_rest.get_promos
|
145
|
+
end
|
146
|
+
|
147
|
+
# Show a particular promo by name,
|
148
|
+
# Megam::Promos
|
149
|
+
def self.show(params)
|
150
|
+
pre = self.new(params["email"], params["api_key"])
|
151
|
+
pre.megam_rest.get_promos(params["email"])
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
def to_s
|
157
|
+
Megam::Stuff.styled_hash(to_hash)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/test_promos.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.52'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar, Subash Sethurajan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/megam/api/marketplaces.rb
|
152
152
|
- lib/megam/api/organizations.rb
|
153
153
|
- lib/megam/api/predef_clouds.rb
|
154
|
+
- lib/megam/api/promos.rb
|
154
155
|
- lib/megam/api/requests.rb
|
155
156
|
- lib/megam/api/sshkeys.rb
|
156
157
|
- lib/megam/api/subscriptions.rb
|
@@ -197,6 +198,7 @@ files:
|
|
197
198
|
- lib/megam/core/organizations_collection.rb
|
198
199
|
- lib/megam/core/predefcloud.rb
|
199
200
|
- lib/megam/core/predefcloud_collection.rb
|
201
|
+
- lib/megam/core/promos.rb
|
200
202
|
- lib/megam/core/request.rb
|
201
203
|
- lib/megam/core/request_collection.rb
|
202
204
|
- lib/megam/core/server_api.rb
|
@@ -231,6 +233,7 @@ files:
|
|
231
233
|
- test/test_marketplaces.rb
|
232
234
|
- test/test_organizations.rb
|
233
235
|
- test/test_predefclouds.rb
|
236
|
+
- test/test_promos.rb
|
234
237
|
- test/test_requests.rb
|
235
238
|
- test/test_sshkeys.rb
|
236
239
|
- test/test_subscriptions.rb
|
@@ -281,6 +284,7 @@ test_files:
|
|
281
284
|
- test/test_marketplaces.rb
|
282
285
|
- test/test_organizations.rb
|
283
286
|
- test/test_predefclouds.rb
|
287
|
+
- test/test_promos.rb
|
284
288
|
- test/test_requests.rb
|
285
289
|
- test/test_sshkeys.rb
|
286
290
|
- test/test_subscriptions.rb
|