data-com-api 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTE1ZTQ2N2ZjN2NmZWIwNjEzMDE5YzcyZGMwZWFjOWNjMDZkY2UyMA==
4
+ NWY4NzZiOGVlYjg0MDJkM2ZjNjMyZDIxMzM5Zjg2ZWVlN2RiY2Y0ZA==
5
5
  data.tar.gz: !binary |-
6
- YjVkZGQ2NjEyZmNjOTY5NjI5Nzk0NTIxOWFmYzY1ZmE2OGFkODQxMQ==
6
+ ZGE3NGQ3NGRmNWYwYjFlYjU0ODgwYjkwNDhkODY2NzJlNjgxMjIzZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWIwMTQyZTE5YmFmOTViMDQ2OTBmMTZmOGZlMWUyNjc2OWEwNDQ3MmM0N2Vi
10
- YWRlNmU0NDQyMGZhNTA1NGIzODVjMTAxMmY0ZTYxMzRjNzhiMmE2ODE4YjA2
11
- Y2U5ZGQyZTVjNmE3OTIzYTFjZjhhMjZlMDA1NTliNzEyNjZjZDk=
9
+ OGQ5YmQ0NTgyNDYxN2QwMDhjMTY1ZDE3MDdlNzJlNWIwMmY1YmNlZTMzZGY5
10
+ YmQ3ZDQ5ZThjN2M1NjhjNDBiYzJiMzRiYmE1YjViMDZkNmUyMzkxMDY1MGVj
11
+ ZmIwODAwNGQ1ZDUzMWZhNWEwMmYzMTNmODNiNDU3NjQxNzFkZDU=
12
12
  data.tar.gz: !binary |-
13
- ODIzNzMxNWVhZThlNzgzZTcyNGI4NDdmZjhlMWY2YTI4OWEwM2FkYzQwZGJm
14
- MjgyN2I0NmYxN2NkNTBjODEzNDY3ODgzOGFjZTg5NDQzMjRmMGEwZjM0NTE4
15
- ZDcyOWYyZDhmM2FjNTNiZmZiZmRlMDIxOGNiODNhOTQ2MzEyYTY=
13
+ MzU5NzYxYzAwZDkyMGQ3OGZhNTIxZTVjZmU4ZDAzMWNjZGU4YWIxZGVhYjIy
14
+ MzJkNDU0NzE1NjAxZDhhMTE4MjY2ZjU1NDE0MzIwY2UxNmFmY2NjODRhOGRm
15
+ YzVjMjQyMDcyYTgxZjliZGIzMGU5MzNhZWM0OTY3NjcyZWVjOWI=
@@ -227,7 +227,13 @@ module DataComApi
227
227
  private
228
228
 
229
229
  def json_or_raise(json_str)
230
- json = JSON.parse(json_str)
230
+ json = nil
231
+
232
+ if json_str == DataComApi::Error::API_LIMIT_EXCEEDED_MSG
233
+ raise ApiLimitExceededError, json_str
234
+ else
235
+ json = JSON.parse(json_str)
236
+ end
231
237
 
232
238
  if json.kind_of? Array
233
239
  error = json.first
@@ -4,8 +4,9 @@ module DataComApi
4
4
 
5
5
  class Error < StandardError
6
6
 
7
- API_HTTP_STATUS_CODE = 0
8
- API_ERROR_CODE = 'no error code provided'
7
+ API_HTTP_STATUS_CODE = 0
8
+ API_ERROR_CODE = 'no error code provided'.freeze
9
+ API_LIMIT_EXCEEDED_MSG = 'API plan limit exceeded'.freeze
9
10
 
10
11
  attr_reader :http_status_code
11
12
  attr_reader :api_stack_trace
@@ -93,4 +94,13 @@ module DataComApi
93
94
  API_ERROR_CODE = 'NOT_AVAILABLE'.freeze
94
95
  end
95
96
 
97
+ class ApiLimitExceededError < Error
98
+ # This info are not true, there is no error code nor status code, but
99
+ # I added those to keep consistency.
100
+ # The limit exceeded error is returned as "API plan limit exceeded" plain
101
+ # string
102
+ API_HTTP_STATUS_CODE = 404
103
+ API_ERROR_CODE = 'API_LIMIT_EXCEEDED'.freeze
104
+ end
105
+
96
106
  end
@@ -1,3 +1,3 @@
1
1
  module DataComApi
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -8,6 +8,7 @@ require 'data-com-api/client'
8
8
  require 'data-com-api/company_contact_count/department'
9
9
  require 'data-com-api/company_contact_count/level'
10
10
  require 'data-com-api/contact'
11
+ require 'data-com-api/errors'
11
12
 
12
13
  describe DataComApi::Client do
13
14
 
@@ -15,6 +16,21 @@ describe DataComApi::Client do
15
16
 
16
17
  describe "#search_contact" do
17
18
 
19
+ it "raises ApiLimitExceededError when API limit exceeded text is returned" do
20
+ stub_request(
21
+ :get,
22
+ URI.join(
23
+ DataComApi::Client.base_uri, DataComApi::ApiURI.search_contact
24
+ ).to_s
25
+ ).with(query: hash_including({})).to_return(
26
+ body: DataComApi::Error::API_LIMIT_EXCEEDED_MSG
27
+ )
28
+
29
+ expect{
30
+ client.search_contact.size
31
+ }.to raise_error DataComApi::ApiLimitExceededError
32
+ end
33
+
18
34
  it "has records when searched with no params" do
19
35
  DataComApiStubRequests.stub_search_contact(
20
36
  total_hits: 10
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data-com-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty