preposterous 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 4
5
5
  :build:
data/lib/preposterous.rb CHANGED
@@ -4,13 +4,53 @@ require 'cgi'
4
4
  require 'mime/types'
5
5
 
6
6
  module Preposterous
7
-
8
- # TODO: Add exceptions based on errors listed at: http://posterous.com/api/posting
7
+
8
+ class InvalidEmailOrPassword < StandardError; end
9
+ class InvalidSiteId < StandardError; end
10
+ class UserDoesNotHaveAccess < StandardError; end
11
+ class UnableToSave < StandardError; end
12
+ class UnableToFindObject < StandardError; end
13
+ class InvalidDate < StandardError; end
14
+ class InvalidPostId < StandardError; end
15
+ class CommentsDisabled < StandardError; end
16
+ class UnableToSaveComment < StandardError; end
17
+ class ApiRateLimitReached < StandardError; end
9
18
 
10
19
  def self.make_friendly(response)
20
+ raise_errors(response)
11
21
  Crack::XML.parse(response.body)["rsp"] if not response.nil?
12
22
  end
13
23
 
24
+ def self.raise_errors(response)
25
+ response.body =~ /code="(\d+)" msg="(.*)"/
26
+ code = $1.to_i
27
+ # going to pass this to the exception at some point... maybe
28
+ msg = $2
29
+
30
+ case code
31
+ when 3001
32
+ raise InvalidEmailOrPassword, msg
33
+ when 3002
34
+ raise InvalidSiteId, msg
35
+ when 3003
36
+ raise UserDoesNotHaveAccess, msg
37
+ when 3004
38
+ raise UnableToSave, msg
39
+ when 3005
40
+ raise UnableToFindObject, msg
41
+ when 3006
42
+ raise InvalidDate, msg
43
+ when 3007
44
+ raise InvalidPostId, msg
45
+ when 3008
46
+ raise CommentsDisabled, msg
47
+ when 3009
48
+ raise UnableToSaveComment, msg
49
+ when 3010
50
+ raise ApiRateLimitReached, msg
51
+ end
52
+ end
53
+
14
54
  end
15
55
 
16
56
  # bring in all of the files in the lib dir
data/preposterous.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{preposterous}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ray Hernandez"]
12
- s.date = %q{2010-05-07}
12
+ s.date = %q{2010-05-08}
13
13
  s.description = %q{This gem supports posting and listing sites on Posterous}
14
14
  s.email = %q{hernan43@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ray Hernandez
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-07 00:00:00 -04:00
17
+ date: 2010-05-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20