Class: Awesm::Project

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/awesm/project.rb

Constant Summary collapse

PATH =
'/projects'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(attributes) ⇒ Object


5
6
7
8
# File 'lib/awesm/project.rb', line 5

def self.create(attributes)
  project = self.new(attributes)
  project.save ? project : nil
end

.listObject


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/awesm/project.rb', line 10

def self.list
  response = Awesm.http_client.post("#{Awesm::HOST}#{PATH}/list", { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key})
  unless response.status == 200
    nil
  else
    projects = []
    json = JSON.parse response.content
    json['response']['projects'].each do |project|
      projects << new(project)
    end
    projects
  end
end

Instance Method Details

#destroyObject


41
42
43
44
# File 'lib/awesm/project.rb', line 41

def destroy
  response = Awesm.http_client.post("#{Awesm::HOST}#{PATH}/#{api_key}/destroy", { :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key })
  response.status == 200
end

#saveObject

Instance Methods #


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/awesm/project.rb', line 28

def save
  response = Awesm.http_client.post("#{Awesm::HOST}#{PATH}/new", :application_key => Awesm.application_key, :subscription_key => Awesm.subscription_key, :json => self.to_hash.to_json)
  json = JSON.parse response.content
  unless response.status.between? 200, 230
    # use mash to update error code and message
    update(json)
    false
  else
    update(json['response']['project'])
    true
  end
end