al_papi 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -90,6 +90,14 @@ When making an API request a response object is returned with any errors, http r
90
90
  # 500: Server Error
91
91
  res.code
92
92
 
93
+ # Over Limit:
94
+ # Returns true or false if over hourly limit
95
+ res.over_limit?
96
+
97
+ # Suspended:
98
+ # Returns true or false if your account has been suspended
99
+ res.over_limit?
100
+
93
101
  ### Engines
94
102
 
95
103
  Supported engines are Google, Yahoo and Bing. To get a list of supported engines run the following:
data/lib/al_papi/http.rb CHANGED
@@ -2,10 +2,10 @@ module AlPapi
2
2
 
3
3
  class Http # @private
4
4
 
5
- attr_accessor :errors, :response, :success, :config
5
+ attr_accessor :errors, :response, :success, :config, :over_limit, :suspended
6
6
 
7
7
  def initialize(_config)
8
- @config, @errors, @success = _config, [], false
8
+ @config, @errors, @success, @over_limit, @suspended = _config, [], false, false, false
9
9
  end
10
10
 
11
11
  def get(path, params = {})
@@ -45,6 +45,14 @@ module AlPapi
45
45
  self.errors << RequestError.new('No Content', code, path, params)
46
46
  when 401
47
47
  self.errors << RequestError.new('Invalid Auth Token Provided', code, path, params)
48
+ when 403
49
+ if body.match /Account Suspended/i
50
+ self.suspended = true
51
+ self.errors << RequestError.new('Account Suspended', code, path, params)
52
+ elsif body.match /Request Limit Exceeded/i
53
+ self.over_limit = true
54
+ self.errors << RequestError.new('Request Limit Exceeded', code, path, params)
55
+ end
48
56
  else
49
57
  self.errors << RequestError.new(body, code, path, params)
50
58
  end
@@ -2,10 +2,11 @@ module AlPapi
2
2
 
3
3
  class Response
4
4
 
5
- attr_reader :success, :body, :errors, :code, :path, :params
5
+ attr_reader :success, :body, :errors, :code, :path, :params, :over_limit, :suspeneded
6
6
 
7
7
  def initialize(http, _code, _path, _params) # @private
8
8
  @success, @body, @errors = http.success, http.response, http.errors
9
+ @over_limit, @suspended = http.over_limit, http.suspended
9
10
  @code, @path, @params = _code, _path, _params
10
11
  end
11
12
 
@@ -17,6 +18,22 @@ module AlPapi
17
18
  return @success
18
19
  end
19
20
 
21
+ ##
22
+ #
23
+ # Convenience method to see if you have reached your hourly limit
24
+
25
+ def over_limit?
26
+ return @over_limit
27
+ end
28
+
29
+ ##
30
+ #
31
+ # Convenience method to see if your account is supended
32
+
33
+ def suspended?
34
+ return @suspended
35
+ end
36
+
20
37
  end
21
38
 
22
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: al_papi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-04 00:00:00.000000000 Z
12
+ date: 2012-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &70201333396700 !ruby/object:Gem::Requirement
16
+ requirement: &70208320860320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70201333396700
24
+ version_requirements: *70208320860320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70201333395880 !ruby/object:Gem::Requirement
27
+ requirement: &70208320859520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70201333395880
35
+ version_requirements: *70208320859520
36
36
  description: Wraps AuthorityLabs Partner API calls in a gem.
37
37
  email: ''
38
38
  executables: []