Class: Megam::API

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/api.rb,
lib/megam/api/disks.rb,
lib/megam/api/addons.rb,
lib/megam/api/errors.rb,
lib/megam/api/promos.rb,
lib/megam/api/domains.rb,
lib/megam/api/license.rb,
lib/megam/api/reports.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/eventsvm.rb,
lib/megam/api/requests.rb,
lib/megam/api/eventsall.rb,
lib/megam/api/snapshots.rb,
lib/megam/api/assemblies.rb,
lib/megam/api/components.rb,
lib/megam/api/marketplaces.rb,
lib/megam/api/eventsbilling.rb,
lib/megam/api/eventsstorage.rb,
lib/megam/api/organizations.rb,
lib/megam/api/subscriptions.rb,
lib/megam/api/billedhistories.rb,
lib/megam/api/eventscontainer.rb,
lib/megam/api/billingtransactions.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
X_Megam_PUTTUSAVI =
'X-Megam-PUTTUSAVI'.freeze
X_Megam_MASTERKEY =
'X-Megam-MASTERKEY'.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: {},
    nonblock: false
}
VERSION =
"1.9.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



135
136
137
138
139
140
141
142
143
# File 'lib/megam/api.rb', line 135

def initialize(options = {})
    @options = OPTIONS.merge(options)

    assign_credentials

    ensure_host_is_flattened

    turn_off_ssl_verify
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



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

def api_url
  @api_url
end

#api_versionObject

Returns the value of attribute api_version.



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

def api_version
  @api_version
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



111
112
113
# File 'lib/megam/api.rb', line 111

def last_response
  @last_response
end

#master_keyObject

Returns the value of attribute master_key.



110
111
112
# File 'lib/megam/api.rb', line 110

def master_key
  @master_key
end

#org_idObject

Returns the value of attribute org_id.



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

def org_id
  @org_id
end

#password_hashObject

Returns the value of attribute password_hash.



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

def password_hash
  @password_hash
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#delete_assemblies(asm_id) ⇒ Object

Yet to be tested DELETE /nodes/:node_id



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

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



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

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

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

#forgot(account) ⇒ Object



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

def forgot()
  @options = { path:  "/accounts/forgot/#{account["email"]}", passthru: true,
               body: ''}.merge(@options)

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

#get_accounts(email) ⇒ Object

GET /accounts



4
5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/accounts.rb', line 4

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

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

#get_addon(name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/addons.rb', line 5

def get_addon(name)
  @options = {:path => "/addons/#{name}",:body => ""}.merge(@options)

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

#get_assembliesObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/assemblies.rb', line 4

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

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

#get_balance(id) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/megam/api/balances.rb', line 13

def get_balance(id)
  @options = {:path => "/balances/#{id}",:body => Megam::JSONCompat.to_json(id)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_balancesObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/balances.rb', line 3

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

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

#get_billedhistoriesObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/billedhistories.rb', line 3

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

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

#get_billedhistory(id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/billedhistories.rb', line 13

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

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

#get_billingtransactionsObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/billingtransactions.rb', line 3

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

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

#get_components(comp_id) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/components.rb', line 3

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

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

#get_disks(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/disks.rb', line 14

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

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

#get_domainsObject



5
6
7
8
9
10
11
12
# File 'lib/megam/api/domains.rb', line 5

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

#get_eventsall(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsall.rb', line 15

def get_eventsall(limit, new_events)
  @options = {:path => "/eventsall/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventsbilling(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsbilling.rb', line 15

def get_eventsbilling(limit, new_events)
  @options = {:path => "/eventsbilling/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventscontainer(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventscontainer.rb', line 15

def get_eventscontainer(limit, new_events)
  @options = {:path => "/eventscontainer/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventsvm(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsvm.rb', line 15

def get_eventsvm(limit, new_events)
  @options = {:path => "/eventsvm/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_license(license_id) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/license.rb', line 4

def get_license(license_id)
  @options = {:path => "/admin/licenses/#{license_id}",:body => ""}.merge(@options)

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

#get_marketplaceapp(id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/marketplaces.rb', line 14

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

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

#get_marketplaceappsObject



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/marketplaces.rb', line 4

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

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

#get_one_assemblies(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/assemblies.rb', line 14

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



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/assembly.rb', line 3

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



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/megam/api/organizations.rb', line 14

def get_organization(id)

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

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

#get_organizationsObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/organizations.rb', line 3

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

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

  )
end

#get_promos(id) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/promos.rb', line 5

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



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/requests.rb', line 15

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



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/requests.rb', line 5

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

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

#get_sensor(id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/sensors.rb', line 13

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

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

#get_sensorsObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/sensors.rb', line 3

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

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

#get_snapshots(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/snapshots.rb', line 14

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

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

#get_sshkey(sshkey_name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/sshkeys.rb', line 13

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

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

#get_sshkeysObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/sshkeys.rb', line 3

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

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

#get_subscriptionObject



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/subscriptions.rb', line 4

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

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

#index_eventsallObject



26
27
28
29
30
31
32
33
34
# File 'lib/megam/api/eventsall.rb', line 26

def index_eventsall
  @options = {:path => "/eventsall",:body => ""}.merge(@options)

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

#index_eventsbillingObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventsbilling.rb', line 25

def index_eventsbilling
  @options = {:path => "/eventsbilling",:body => ""}.merge(@options)

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

#index_eventscontainerObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventscontainer.rb', line 25

def index_eventscontainer
  @options = {:path => "/eventscontainer",:body => ""}.merge(@options)

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

#index_eventsstorageObject



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/eventsstorage.rb', line 14

def index_eventsstorage
  @options = {:path => "/eventsstorage",:body => ""}.merge(@options)

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

#index_eventsvmObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventsvm.rb', line 25

def index_eventsvm
  @options = {:path => "/eventsvm",:body => ""}.merge(@options)

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

#list_accountsObject

ADMIN: LIST /accounts



73
74
75
76
77
78
79
80
81
82
# File 'lib/megam/api/accounts.rb', line 73

def list_accounts
  @options = {:path => "/admin/accounts",
    :body => ''}.merge(@options)

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

#list_assemblyObject



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

def list_assembly
  @options = {:path => "/assembly",:body => ""}.merge(@options)

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

#list_disksObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/disks.rb', line 4

def list_disks
  @options = {:path => "/disks",:body => ""}.merge(@options)

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

#list_eventsall(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsall.rb', line 4

def list_eventsall(limit)
  @options = {:path => "/eventsvm/#{limit}",:body => ""}.merge(@options)

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

#list_eventsbilling(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsbilling.rb', line 4

def list_eventsbilling(limit)
  @options = {:path => "/eventsbilling/#{limit}",:body => ""}.merge(@options)

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

#list_eventscontainer(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventscontainer.rb', line 4

def list_eventscontainer(limit)
  @options = {:path => "/eventscontainer/#{limit}",:body => ""}.merge(@options)

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

#list_eventsstorage(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsstorage.rb', line 4

def list_eventsstorage(limit)
  @options = {:path => "/eventsstorage/#{limit}",:body => ""}.merge(@options)

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

#list_eventsvm(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsvm.rb', line 4

def list_eventsvm(limit)
  @options = {:path => "/eventsvm/#{limit}",:body => ""}.merge(@options)

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

#list_snapshotsObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/snapshots.rb', line 4

def list_snapshots
  @options = {:path => "/snapshots",:body => ""}.merge(@options)

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

#login(new_account) ⇒ Object

The body content needs to be a json.



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

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

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

#password_reset(account) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/megam/api/accounts.rb', line 61

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

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

#post_accounts(new_account) ⇒ Object

The body content needs to be a json.



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

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

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

#post_addons(new_addon) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/megam/api/addons.rb', line 15

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

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

#post_assemblies(new_asm) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/assemblies.rb', line 24

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_balances(new_balance) ⇒ Object



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

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/billedhistories.rb', line 23

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_billingtransactions(new_billtransaction) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/billingtransactions.rb', line 13

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

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

#post_disks(new_dsk) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/megam/api/disks.rb', line 23

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

#post_domains(new_domain) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/domains.rb', line 15

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_license(new_license) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/license.rb', line 14

def post_license(new_license)
  @options = {:path => '/admin/licenses/content',
    :body => Megam::JSONCompat.to_json(new_license)}.merge(@options)

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

#post_marketplaceapp(catitem) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/marketplaces.rb', line 24

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



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

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_reports(new_sps) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/reports.rb', line 4

def post_reports(new_sps)
  @options = {:path => '/admin/reports/content',
      :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)

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

#post_request(new_req) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/requests.rb', line 25

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/sensors.rb', line 23

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_snapshots(new_sps) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/snapshots.rb', line 23

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

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

#post_sshkey(new_sshkey) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/sshkeys.rb', line 23

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



14
15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/subscriptions.rb', line 14

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

#request(params, &block) ⇒ Object



150
151
152
153
154
155
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
# File 'lib/megam/api.rb', line 150

def request(params, &block)
    just_color_debug("#{@options[:path]}")
    start = Time.now
    Megam::Log.debug('START')

    ensure_authkeys unless is_passthru?

    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)
        reerror.response.body = Megam::JSONCompat.from_json(reerror.response.body.chomp)
        raise(reerror)
    end

    @last_response = response

    if response.body && !response.body.empty?
        if response.headers['Content-Encoding'] == 'gzip'
            response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
        end

        begin
            unless response.headers[X_Megam_OTTAI]
                response.body = Megam::JSONCompat.from_json(response.body.chomp)
            else
                response.body = Megam::KoniPai.new.koni(response.body.chomp)
            end
        rescue Exception => jsonerr
            raise(jsonerr)
        end
    end

    Megam::Log.debug("END(#{(Time.now - start)}s)")

    @connection.reset
    response
end

#update_accounts(update_account) ⇒ Object



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

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

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

#update_assembly(new_asm) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/assembly.rb', line 13

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



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

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



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/components.rb', line 13

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_organization(new_organization) ⇒ Object



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

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



24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/assembly.rb', line 24

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

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