Class: Megam::API

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/api.rb,
lib/megam/api/csars.rb,
lib/megam/api/login.rb,
lib/megam/api/errors.rb,
lib/megam/api/promos.rb,
lib/megam/api/domains.rb,
lib/megam/api/sensors.rb,
lib/megam/api/sshkeys.rb,
lib/megam/api/version.rb,
lib/megam/api/accounts.rb,
lib/megam/api/assembly.rb,
lib/megam/api/balances.rb,
lib/megam/api/billings.rb,
lib/megam/api/invoices.rb,
lib/megam/api/requests.rb,
lib/megam/api/discounts.rb,
lib/megam/api/assemblies.rb,
lib/megam/api/components.rb,
lib/megam/api/marketplaces.rb,
lib/megam/api/organizations.rb,
lib/megam/api/subscriptions.rb,
lib/megam/api/availableunits.rb,
lib/megam/api/billedhistories.rb,
lib/megam/api/credithistories.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

API_VERSION2 =
'/v2'.freeze
X_Megam_DATE =
'X-Megam-DATE'.freeze
X_Megam_HMAC =
'X-Megam-HMAC'.freeze
X_Megam_OTTAI =
'X-Megam-OTTAI'.freeze
X_Megam_ORG =
'X-Megam-ORG'.freeze
HEADERS =
{
  'Accept' => 'application/json',
  'Accept-Encoding' => 'gzip',
  'User-Agent' => "megam-api/#{Megam::API::VERSION}",
  'X-Ruby-Version' => RUBY_VERSION,
  'X-Ruby-Platform' => RUBY_PLATFORM
}
OPTIONS =
{
  headers: {},
  host: '127.0.0.1',
  nonblock: false,
  scheme: 'http'
}
VERSION =
"0.100"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

It is assumed that every API call will use an API_KEY/email. This ensures validity of the person really the same guy on who he claims. 3 levels of options exits

  1. The global OPTIONS as available inside the API (OPTIONS)

  2. The options as passed via the instantiation of API will override global options. The ones that are passed are :email and :api_key and will

be merged into a class variable @options

  1. Upon merge of the options, the api_key, email as available in the @options is deleted.



145
146
147
148
149
150
151
152
153
154
# File 'lib/megam/api.rb', line 145

def initialize(options = {})
  @options = OPTIONS.merge(options)
  @api_key = @options.delete(:api_key) || ENV['MEGAM_API_KEY']
  @email = @options.delete(:email)
  @password = @options.delete(:password)
  @org_id = @options.delete(:org_id)
  unless !@options.delete(:reset_flag)
     fail Megam::API::Errors::AuthKeysMissing if (@email.nil? && @api_key.nil?) || (@email.nil? && @password.nil?)
  end
end

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



136
137
138
# File 'lib/megam/api.rb', line 136

def last_response
  @last_response
end

#textObject

text is used to print stuff in the terminal (message, log, info, warn etc.)



108
109
110
# File 'lib/megam/api.rb', line 108

def text
  @text
end

Instance Method Details

#delete_assemblies(asm_id) ⇒ Object

Yet to be tested DELETE /nodes/:node_id



52
53
54
55
56
57
58
59
60
61
# File 'lib/megam/api/assemblies.rb', line 52

def delete_assemblies(asm_id)
  @options = {:path => '/nodes/#{asm_id}',
    :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :delete,
    :body     => @options[:body]
  )
end

#delete_marketplaceapp(catitem_id) ⇒ Object

Yet to be tested DELETE /marketplacess/:node_id



63
64
65
66
67
68
69
70
71
72
# File 'lib/megam/api/csars.rb', line 63

def delete_marketplaceapp(node_id)
  @options = {:path => '/marketplaces/#{node_id}',
    :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :delete,
    :body     => @options[:body]
  )
end

#get_accounts(email) ⇒ Object

GET /accounts Yet to be tested



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/megam/api/accounts.rb', line 20

def get_accounts(email)

  @options = {:path => "/accounts/#{email}",
    :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_assembliesObject

GET /nodes



19
20
21
22
23
24
25
26
27
# File 'lib/megam/api/assemblies.rb', line 19

def get_assemblies
  @options = {:path => '/assemblies',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_availableunit(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/availableunits.rb', line 28

def get_availableunit(id)
  @options = {:path => "/availableunits/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_availableunitsObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/availableunits.rb', line 18

def get_availableunits
  @options = {:path => '/availableunits',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_balance(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/balances.rb', line 28

def get_balance(id)
  @options = {:path => "/balances/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_balancesObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/balances.rb', line 18

def get_balances
  @options = {:path => '/balances',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billedhistoriesObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/billedhistories.rb', line 18

def get_billedhistories
  @options = {:path => '/billedhistories',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billedhistory(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/billedhistories.rb', line 28

def get_billedhistory(id)
  @options = {:path => "/billedhistories/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billing(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/billings.rb', line 28

def get_billing(id)
  @options = {:path => "/billings/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billingsObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/billings.rb', line 18

def get_billings
  @options = {:path => '/billings',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_components(comp_id) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/components.rb', line 18

def get_components(comp_id)
  @options = { path: "/components/#{comp_id}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_credithistories(id) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/credithistories.rb', line 18

def get_credithistories
  @options = {:path => '/credithistories',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_csar(id) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/megam/api/csars.rb', line 30

def get_csar(id)
  @options = {:path => "/csars/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_csarsObject

GET /csars



20
21
22
23
24
25
26
27
28
# File 'lib/megam/api/csars.rb', line 20

def get_csars
  @options = {:path => '/csars',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_discountsObject



18
19
20
21
22
23
24
25
# File 'lib/megam/api/discounts.rb', line 18

def get_discounts
  @options = {:path => '/discounts',:body => ""}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_domainsObject



20
21
22
23
24
25
26
27
# File 'lib/megam/api/domains.rb', line 20

def get_domains
  @options = {:path => "/domains", :body => ''}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_invoice(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/invoices.rb', line 28

def get_invoice(id)
  @options = {:path => "/invoices/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_invoicesObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/invoices.rb', line 18

def get_invoices
  @options = {:path => '/invoices',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceapp(id) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/megam/api/marketplaces.rb', line 29

def get_marketplaceapp(id)
  @options = {:path => "/marketplaces/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceappsObject



19
20
21
22
23
24
25
26
27
# File 'lib/megam/api/marketplaces.rb', line 19

def get_marketplaceapps
  @options = {:path => '/marketplaces',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_one_assemblies(asm_id) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/megam/api/assemblies.rb', line 29

def get_one_assemblies(asm_id)
  @options = {:path => "/assemblies/#{asm_id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_one_assembly(asm_id) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/assembly.rb', line 18

def get_one_assembly(asm_id)
  @options = { path: "/assembly/#{asm_id}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_organization(id) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/megam/api/organizations.rb', line 29

def get_organization(id)

  @options = {:path => "/organizations/#{id}",
  :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_organizationsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/megam/api/organizations.rb', line 18

def get_organizations
  @options = {:path => '/organizations',:body => ''}.merge(@options)

  request(
    :expects => 200,
    :method => :get,
    :body => @options[:body]

  )
end

#get_promos(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/megam/api/promos.rb', line 20

def get_promos(id)
  @options = {:path => "/promos/#{id}", :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_request(node_name) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/megam/api/requests.rb', line 30

def get_request(node_name)
  @options = {:path => "/requests/#{node_name}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_requestsObject

GET /requests



20
21
22
23
24
25
26
27
28
# File 'lib/megam/api/requests.rb', line 20

def get_requests
  @options = {:path => '/requests',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sensor(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/sensors.rb', line 28

def get_sensor(id)
  @options = {:path => "/sensors/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sensorsObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/sensors.rb', line 18

def get_sensors
  @options = {:path => '/sensors',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sshkey(sshkey_name) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/sshkeys.rb', line 28

def get_sshkey(sshkey_name)
  @options = {:path => "/sshkeys/#{sshkey_name}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sshkeysObject



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/sshkeys.rb', line 18

def get_sshkeys
  @options = {:path => '/sshkeys',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_subscriptions(id) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/megam/api/subscriptions.rb', line 18

def get_subscriptions
  @options = {:path => '/subscriptions',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#post_accounts(new_account) ⇒ Object

The body content needs to be a json.



33
34
35
36
37
38
39
40
41
42
# File 'lib/megam/api/accounts.rb', line 33

def post_accounts()
  @options = {:path => '/accounts/content',
  :body => Megam::JSONCompat.to_json()}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
    )
end

#post_assemblies(new_asm) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/megam/api/assemblies.rb', line 39

def post_assemblies(new_asm)
  @options = {:path => '/assemblies/content',
    :body => Megam::JSONCompat.to_json(new_asm)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_authObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/megam/api/login.rb', line 18

def post_auth
  @options = {:path => '/auth', :body => ""}.merge(@options)

  request(
    :expects  => 200,
   :method   => :post,
    :body     => @options[:body]

    )
end

#post_availableunits(new_availableunit) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/availableunits.rb', line 38

def post_availableunits(new_availableunit)
  @options = {:path => '/availableunits/content',
    :body => Megam::JSONCompat.to_json(new_availableunit)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_balances(new_balance) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/balances.rb', line 38

def post_balances(new_balance)
  @options = {:path => '/balances/content',
    :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_billedhistories(new_billedhistory) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/billedhistories.rb', line 38

def post_billedhistories(new_billedhistory)
  @options = {:path => '/billedhistories/content',
    :body => Megam::JSONCompat.to_json(new_billedhistory)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_billings(new_billing) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/billings.rb', line 38

def post_billings(new_billing)
  @options = {:path => '/billings/content',
    :body => Megam::JSONCompat.to_json(new_billing)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_credithistories(new_credithistories) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/credithistories.rb', line 38

def post_credithistories(new_credithistories)
  @options = {:path => '/credithistories/content',
    :body => Megam::JSONCompat.to_json(new_credithistories)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_csar(new_csar) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/megam/api/csars.rb', line 40

def post_csar(new_csar)
  @options = {:path => '/csars/content',
    :body => new_csar}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_discounts(new_discount) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/discounts.rb', line 27

def post_discounts(new_discount)
  @options = {:path => '/discounts/content',
  :body => Megam::JSONCompat.to_json(new_discount)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_domains(new_domain) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/megam/api/domains.rb', line 30

def post_domains(new_domain)
  @options = {:path => '/domains/content',
  :body =>  Megam::JSONCompat.to_json(new_domain)}.merge(@options)
  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_invoices(new_invoices) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/invoices.rb', line 38

def post_invoices(new_invoices)
  @options = {:path => '/invoices/content',
    :body => Megam::JSONCompat.to_json(new_invoices)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_marketplaceapp(catitem) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/megam/api/marketplaces.rb', line 39

def post_marketplaceapp(catitem)
  @options = {:path => '/marketplaces/content',
    :body => Megam::JSONCompat.to_json(catitem)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_organization(new_organization) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/megam/api/organizations.rb', line 41

def post_organization(new_organization)

  @options = {:path => '/organizations/content',
  :body =>  Megam::JSONCompat.to_json(new_organization)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_request(new_req) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/megam/api/requests.rb', line 40

def post_request(new_req)
  @options = {:path => '/requests/content',
    :body => Megam::JSONCompat.to_json(new_req)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_sensors(new_sensors) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/sensors.rb', line 38

def post_sensors(new_sensors)
  @options = {:path => '/sensors/content',
    :body => Megam::JSONCompat.to_json(new_sensors)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_sshkey(new_sshkey) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/sshkeys.rb', line 38

def post_sshkey(new_sshkey)
  @options = {:path => '/sshkeys/content',
    :body => Megam::JSONCompat.to_json(new_sshkey)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_subscriptions(new_subscription) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/subscriptions.rb', line 38

def post_subscriptions(new_subscription)
  @options = {:path => '/subscriptions/content',
    :body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#push_csar(id) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/megam/api/csars.rb', line 51

def push_csar(id)
  @options = {:path => "/csars/push/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 201,
    :method   => :get,
    :body     => @options[:body]
  )
end

#repassword_accounts(account) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/megam/api/accounts.rb', line 66

def repassword_accounts()
  @options = {:path => "/accounts/repassword",
 :body => Megam::JSONCompat.to_json()}.merge(@options)

  request(
  :expects => 201,
  :method => :post,
  :body => @options[:body]
  )
end

#request(params, &block) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/megam/api.rb', line 156

def request(params, &block)

  just_color_debug("#{@options[:path]}")
  start = Time.now
  Megam::Log.debug('START')
  params.each do |pkey, pvalue|
    Megam::Log.debug("> #{pkey}: #{pvalue}")
  end

  begin
    response = connection.request(params, &block)
  rescue Excon::Errors::HTTPStatusError => error
    klass = case error.response.status

    when 401 then Megam::API::Errors::Unauthorized
    when 403 then Megam::API::Errors::Forbidden
    when 404 then Megam::API::Errors::NotFound
    when 408 then Megam::API::Errors::Timeout
    when 422 then Megam::API::Errors::RequestFailed
    when 423 then Megam::API::Errors::Locked
    when /50./ then Megam::API::Errors::RequestFailed
    else Megam::API::Errors::ErrorWithResponse
    end
    reerror = klass.new(error.message, error.response)
    reerror.set_backtrace(error.backtrace)
    Megam::Log.debug("#{reerror.response.body}")
    reerror.response.body = Megam::JSONCompat.from_json(reerror.response.body.chomp)
    Megam::Log.debug('RESPONSE ERR: Ruby Object')
    Megam::Log.debug("#{reerror.response.body}")
    raise(reerror)
  end

  @last_response = response
  Megam::Log.debug('RESPONSE: HTTP Status and Header Data')
  Megam::Log.debug("> HTTP #{response.remote_ip} #{response.status}")

  response.headers.each do |header, value|
    Megam::Log.debug("> #{header}: #{value}")
  end
  Megam::Log.debug('End HTTP Status/Header Data.')

  if response.body && !response.body.empty?
    if response.headers['Content-Encoding'] == 'gzip'
      Megam::Log.debug('RESPONSE: Content-Encoding is gzip')
      response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
    end
    Megam::Log.debug('RESPONSE: HTTP Body(JSON)')
    Megam::Log.debug("#{response.body}")

    begin
      unless response.headers[X_Megam_OTTAI]
        response.body = Megam::JSONCompat.from_json(response.body.chomp)
        Megam::Log.debug('RESPONSE: Ruby Object')
      else
        response.body = Megam::KoniPai.new.koni(response.body.chomp)
        Megam::Log.debug('RESPONSE: KoniPai Object ')
      end
      Megam::Log.debug("#{response.body}")
    rescue Exception => jsonerr
      Megam::Log.error(jsonerr)
      raise(jsonerr)
    end
  end
  Megam::Log.debug("END(#{(Time.now - start)}s)")
  # reset (non-persistent) connection
  @connection.reset
  response
end

#reset_accounts(account) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/megam/api/accounts.rb', line 55

def reset_accounts()
  @options = {:path => "/accounts/reset/#{["email"]}",
 :body => ''}.merge(@options)

  request(
  :expects => 201,
  :method => :get,
  :body => @options[:body]
  )
end

#update_accounts(update_account) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/megam/api/accounts.rb', line 44

def update_accounts()
  @options = {:path => '/accounts/update',
 :body => Megam::JSONCompat.to_json()}.merge(@options)

  request(
  :expects => 201,
  :method => :post,
  :body => @options[:body]
  )
end

#update_assembly(new_asm) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/megam/api/assembly.rb', line 28

def update_assembly(new_asm)
   @options = { path: '/assembly/update',
                body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)

   request(
     expects: [200, 201],
     method: :post,
     body: @options[:body]
   )
end

#update_balance(new_balance) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/megam/api/balances.rb', line 49

def update_balance(new_balance)
  @options = {:path => '/balances/update',
    :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#update_component(new_asm) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/megam/api/components.rb', line 28

def update_component(new_asm)
   @options = { path: '/components/update',
                body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)

   request(
     expects: [200, 201],
     method: :post,
     body: @options[:body]
   )
end

#update_discounts(update_discount) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/discounts.rb', line 37

def update_discounts(update_discount)
  @options = {:path => '/discounts/update',
  :body => Megam::JSONCompat.to_json(update_discount)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )

end

#update_organization(new_organization) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/megam/api/organizations.rb', line 53

def update_organization(new_organization)

  @options = {:path => '/organizations/update',
  :body =>  Megam::JSONCompat.to_json(new_organization)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#upgrade_assembly(asm_id) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/megam/api/assembly.rb', line 39

def upgrade_assembly(asm_id)
   @options = { path: "/assembly/upgrade/#{asm_id}", body: '' }.merge(@options)

   request(
     expects: [200, 201],
     method: :get,
     body: @options[:body]
   )
end