Class: Basecampeverest::Project
- Inherits:
-
Object
- Object
- Basecampeverest::Project
- Defined in:
- lib/basecampeverest/resources/project.rb
Class Method Summary collapse
- .activate(project_id) ⇒ Object
-
.all ⇒ Basecampeverest::Project
find all projects via the Basecamp API.
-
.archive(project_id) ⇒ Basecampeverest::Project
archive a project via the Basecamp API.
-
.delete(project_id) ⇒ Basecampeverest::Project
delete a project via the Basecamp API.
-
.find(project_id) ⇒ Basecampeverest::Project
find a project via the Basecamp API.
-
.new(options = {}) ⇒ Basecampeverest::Project
create a project via the Basecamp API the options hash must have the name and description element.
-
.update(project_id, options = {}) ⇒ Basecampeverest::Project
update a project via the Basecamp API.
Class Method Details
.activate(project_id) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/basecampeverest/resources/project.rb', line 90 def self.activate(project_id) post_params = { :body => {:archived => false}.to_json, :headers => Basecampeverest::Connect.merge({'Content-Type' => 'application/json'}) } url = "/projects/#{project_id}.json" response = Basecampeverest::Connect.put url post_params # This checks the response code for validity and error checking if response.code == 200 = "Project successfully activated" elsif response.code == 403 = "You do not have permission to activate this project" else = "Invalid project ID or authentication. The project was not activated." end # return the message end |
.all ⇒ Basecampeverest::Project
find all projects via the Basecamp API
5 6 7 8 9 10 |
# File 'lib/basecampeverest/resources/project.rb', line 5 def self.all response = Basecampeverest::Connect.get "/projects.json" # parse the response to remove HTTParty info response.parsed_response end |
.archive(project_id) ⇒ Basecampeverest::Project
archive a project via the Basecamp API
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/basecampeverest/resources/project.rb', line 68 def self.archive(project_id) post_params = { :body => {:archived => true}.to_json, :headers => Basecampeverest::Connect.merge({'Content-Type' => 'application/json'}) } url = "/projects/#{project_id}.json" response = Basecampeverest::Connect.put url post_params # This checks the response code for validity and error checking if response.code == 200 = "Project successfully archived" elsif response.code == 403 = "You do not have permission to archive this project" else = "Invalid project ID or authentication. The project was not archived." end # return the message end |
.delete(project_id) ⇒ Basecampeverest::Project
delete a project via the Basecamp API
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/basecampeverest/resources/project.rb', line 116 def self.delete(project_id) # for some reason ruby won't put in the project ID for a delete method. Solved by setting the url # and then calling delete url = "/projects/#{project_id}.json" response = Basecampeverest::Connect.delete url # This checks the response code for validity and error checking if response.code == 204 = "Project successfully deleted" elsif response.code == 403 = "You do not have permission to delete this project" else = "Invalid project ID or authentication. The project was not deleted." end # return the message end |
.find(project_id) ⇒ Basecampeverest::Project
find a project via the Basecamp API
16 17 18 19 20 21 |
# File 'lib/basecampeverest/resources/project.rb', line 16 def self.find(project_id) response = Basecampeverest::Connect.get "/projects/#{project_id}.json" # parse the response to remove HTTParty info response.parsed_response end |
.new(options = {}) ⇒ Basecampeverest::Project
create a project via the Basecamp API the options hash must have the name and description element.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/basecampeverest/resources/project.rb', line 29 def self.new(={}) # if options[:name].nil? # return "You need a project name" # else # end post_params = { :body => .to_json, :headers => Basecampeverest::Connect.headers.merge({'Content-Type' => 'application/json'}) } # make the http basecamp call response = Basecampeverest::Connect.post "/projects.json", post_params # parse the response to remove HTTParty info response.parsed_response end |
.update(project_id, options = {}) ⇒ Basecampeverest::Project
update a project via the Basecamp API
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/basecampeverest/resources/project.rb', line 51 def self.update(project_id, ={}) post_params = { :body => .to_json, :headers => Basecampeverest::Connect.merge({'Content-Type' => 'application/json'}) } # make the http basecamp call response = Basecampeverest::Connect.put "/projects/#{project_id}.json", post_params # parse the response to remove HTTParty info response.parsed_response end |