yandex_dictionary_api 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,12 @@ module YandexDictionaryApi
2
2
 
3
3
  class ApiError < StandardError
4
4
 
5
- end
5
+ attr_reader :code
6
6
 
7
+ def initialize(int_code, str_message)
8
+ @code = int_code
9
+ msg = "Response code: #{int_code}. " + str_message
10
+ super(msg)
11
+ end
12
+ end
7
13
  end
@@ -1,3 +1,3 @@
1
1
  module YandexDictionaryApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -8,7 +8,7 @@ module YandexDictionaryApi
8
8
  class ApiInterface
9
9
 
10
10
  def initialize(api_key)
11
- @client = YandexDictionaryApi::ApiClient.new( api_key )
11
+ @client = YandexDictionaryApi::ApiClient.new(api_key)
12
12
  end
13
13
 
14
14
  #Executes getLangs (list of supported languages) request to YandexDictionaryApi api
@@ -32,17 +32,17 @@ module YandexDictionaryApi
32
32
  when 200
33
33
  response
34
34
  when 401
35
- raise ApiError.new("Invalid api key.")
35
+ raise ApiError.new(response.code, "Invalid api key.")
36
36
  when 402
37
- raise ApiError.new("Spicified api key is blocked.")
37
+ raise ApiError.new(response.code, "Spicified api key is blocked.")
38
38
  when 403
39
- raise ApiError.new("The daily limit on the number of requests exceeded.")
39
+ raise ApiError.new(response.code, "The daily limit on the number of requests exceeded.")
40
40
  when 413
41
- raise ApiError.new("Limit on the size of text exceeded.")
41
+ raise ApiError.new(response.code, "Limit on the size of text exceeded.")
42
42
  when 501
43
- raise ApiError.new("Spicified direction of translation is not supported.")
43
+ raise ApiError.new(response.code, "Spicified direction of translation is not supported.")
44
44
  else
45
- raise ApiError.new("Try again later.")
45
+ raise ApiError.new(response.code, "Try again later.")
46
46
  end
47
47
  end
48
48
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe YandexDictionaryApi do
4
4
 
5
5
  before do
6
- $interface = YandexDictionaryApi::ApiInterface.new("dict.1.1.20140904T085142Z.bc794363dea5e8da.bcafbef2c018fc447d8de5c67ff8e2dd7f57481f")
6
+ $interface = YandexDictionaryApi::ApiInterface.new(ENV["KEY"])
7
7
  end
8
8
 
9
9
  it "should return a list of supported languages" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yandex_dictionary_api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - IronSerj