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/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/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
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.7.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/megam/api.rb', line 122

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

    ensure_authkeys unless is_passthru?
    
    turn_off_ssl_verify
end

Instance Attribute Details

#api_key ⇒ Object

Returns the value of attribute api_key.



97
98
99
# File 'lib/megam/api.rb', line 97

def api_key
  @api_key
end

#api_url ⇒ Object

Returns the value of attribute api_url.



98
99
100
# File 'lib/megam/api.rb', line 98

def api_url
  @api_url
end

#api_version ⇒ Object

Returns the value of attribute api_version.



98
99
100
# File 'lib/megam/api.rb', line 98

def api_version
  @api_version
end

#email ⇒ Object

Returns the value of attribute email.



97
98
99
# File 'lib/megam/api.rb', line 97

def email
  @email
end

#last_response ⇒ Object (readonly)

Returns the value of attribute last_response.



99
100
101
# File 'lib/megam/api.rb', line 99

def last_response
  @last_response
end

#org_id ⇒ Object

Returns the value of attribute org_id.



97
98
99
# File 'lib/megam/api.rb', line 97

def org_id
  @org_id
end

#password_hash ⇒ Object

Returns the value of attribute password_hash.



97
98
99
# File 'lib/megam/api.rb', line 97

def password_hash
  @password_hash
end

#text ⇒ Object

Returns the value of attribute text.



96
97
98
# File 'lib/megam/api.rb', line 96

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



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

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

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

#get_accounts(email) ⇒ Object

GET /accounts Yet to be tested



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

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_assemblies ⇒ Object

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
21
# File 'lib/megam/api/balances.rb', line 13

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

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

#get_balances ⇒ Object



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_billedhistories ⇒ Object



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_billingtransactions ⇒ Object



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_domains ⇒ Object



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_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_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_marketplaceapps ⇒ Object



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_organizations ⇒ Object



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_requests ⇒ Object

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_sensors ⇒ Object



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_sshkeys ⇒ Object



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_subscription ⇒ Object



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_eventsbilling ⇒ Object



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_eventscontainer ⇒ Object



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_eventsstorage ⇒ Object



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_eventsvm ⇒ Object



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_disks ⇒ Object

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_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_snapshots ⇒ Object

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.



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

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



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

def password_reset()
  @options = {:path => "/accounts/password_reset",
 :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.



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

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



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

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_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_request(new_req) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# 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



139
140
141
142
143
144
145
146
147
148
149
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
# File 'lib/megam/api.rb', line 139

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

    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



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

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



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



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

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