jdpace-weatherman 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,19 +2,20 @@ require 'net/http'
2
2
  require 'xmlsimple'
3
3
  require 'weather_man_response'
4
4
 
5
- # Raised if partner_id and license_key are not provided
6
- class WeatherManNotConfiguredError < StandardError
7
- end
8
-
9
- # Raised when the API returns an error
10
- class WeatherManApiError < StandardError
11
- end
12
-
13
- # Raised when a location is not found by id
14
- class WeatherManLocationNotFoundError < StandardError
15
- end
16
-
17
5
  class WeatherMan
6
+
7
+ # Raised if partner_id and license_key are not provided
8
+ class NotConfiguredError < StandardError
9
+ end
10
+
11
+ # Raised when the API returns an error
12
+ class ApiError < StandardError
13
+ end
14
+
15
+ # Raised when there is no response from the server
16
+ class NoResponseError < StandardError
17
+ end
18
+
18
19
  VALID_UNITS = ['s', 'm']
19
20
  DEFAULT_UNIT = 's' #standard
20
21
 
@@ -94,16 +95,16 @@ class WeatherMan
94
95
  response = XmlSimple.xml_in(xml_data)
95
96
 
96
97
  # Check if a response was returned at all
97
- raise(WeatherManNoResponseError, "WeatherMan Error: No Response.") unless response
98
+ raise(WeatherMan::NoResponseError, "WeatherMan Error: No Response.") unless response
98
99
 
99
100
  # Check if API call threw an error
100
- raise(WeatherManApiError, "WeatherMan Error #{response['err'][0]['type']}: #{response['err'][0]['content']}") if response['err']
101
+ raise(WeatherMan::ApiError, "WeatherMan Error #{response['err'][0]['type']}: #{response['err'][0]['content']}") if response['err']
101
102
 
102
103
  response
103
104
  end
104
105
 
105
106
  def self.check_authentication
106
- raise(WeatherManNotConfiguredError, 'A partner id and a license key must be provided before acessing the API') unless @@partner_id && @@license_key
107
+ raise(WeatherMan::NotConfiguredError, 'A partner id and a license key must be provided before acessing the API') unless @@partner_id && @@license_key
107
108
  end
108
109
 
109
110
  # API url for searching for locations
@@ -5,13 +5,13 @@ describe WeatherMan, 'trying to access the api before being configured' do
5
5
  it 'should throw an error when searching' do
6
6
  lambda {
7
7
  WeatherMan.search('test')
8
- }.should raise_error(WeatherManNotConfiguredError)
8
+ }.should raise_error(WeatherMan::NotConfiguredError)
9
9
  end
10
10
 
11
11
  it 'should throw an error when initializing' do
12
12
  lambda {
13
13
  WeatherMan.new('28115')
14
- }.should raise_error(WeatherManNotConfiguredError)
14
+ }.should raise_error(WeatherMan::NotConfiguredError)
15
15
  end
16
16
  end
17
17
 
@@ -45,7 +45,7 @@ describe WeatherMan, 'using a bad partner id / license key' do
45
45
  it 'should raise an error when fetching the weather' do
46
46
  lambda {
47
47
  @weatherman.fetch
48
- }.should raise_error(WeatherManApiError)
48
+ }.should raise_error(WeatherMan::ApiError)
49
49
  end
50
50
  end
51
51
 
@@ -58,7 +58,7 @@ describe WeatherMan, 'trying to use a bad location id' do
58
58
  it 'should raise an error when fetching the weather' do
59
59
  lambda {
60
60
  @weatherman.fetch
61
- }.should raise_error(WeatherManApiError)
61
+ }.should raise_error(WeatherMan::ApiError)
62
62
  end
63
63
  end
64
64
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdpace-weatherman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Pace