lc-api 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lc-api/api.rb CHANGED
@@ -11,9 +11,17 @@ module LcApi
11
11
  end
12
12
  end
13
13
 
14
+ # error code response classes
14
15
  class ResponseError < StandardError; end
15
- class NotFound < ResponseError; end
16
+ class BadRequest < ResponseError; end
17
+ class Unauthorized < ResponseError; end
16
18
  class Forbidden < ResponseError; end
19
+ class NotFound < ResponseError; end
20
+ class Gone < ResponseError; end
17
21
  class InternalServerError < ResponseError; end
22
+ class BadGateway < ResponseError; end
23
+ class ServiceUnavailable < ResponseError; end
24
+ class GatewayTimeout < ResponseError; end
25
+
18
26
  end
19
27
  end
@@ -0,0 +1,26 @@
1
+ module ErrorCodes
2
+
3
+ def error_code_check(response)
4
+ case response.code.to_i
5
+ when 400
6
+ raise LcApi::API::BadRequest.new(response), "The request was invalid."
7
+ when 401
8
+ raise LcApi::API::Unauthorized.new(response), "Authentication credentials were missing or incorrect."
9
+ when 403
10
+ raise LcApi::API::Forbidden.new(response), "The request is understood, but it has been refused or access is not allowed."
11
+ when 404
12
+ raise LcApi::API::NotFound.new(response), "The URI requested is invalid or the resource requested does not exist."
13
+ when 410
14
+ raise LcApi::API::Gone.new(response), "This resource is gone. This indicates that an API endpoint has been turned off."
15
+ when 500
16
+ raise LcApi::API::InternalServerError.new(response), "Something is broken. Please let the API Team know so that we can investigate."
17
+ when 502
18
+ raise LcApi::API::BadGateway.new(response), "The LifeChurch.tv API is down or is being upgraded."
19
+ when 503
20
+ raise LcApi::API::ServiceUnavailable.new(response), "The LifeChurch.tv API servers are up, but overloaded with requests. Try again later."
21
+ when 504
22
+ raise LcApi::API::GatewayTimeout.new(response), "The LifeChurch.tv API servers are up, but the request couldn't be serviced due to some failure within the stack. Try again later."
23
+ end
24
+ end
25
+
26
+ end
@@ -1,6 +1,6 @@
1
1
  module LcApi
2
2
  class Message < Resource
3
- ATTRIBUTES = %w[id title part length series_id speaker_id resource_url youversionlive_id date_released]
3
+ ATTRIBUTES = %w[id title part length series_id speaker_id resource_url youversionlive_id date_released formats]
4
4
  define_attribute_methods(ATTRIBUTES)
5
5
  end
6
6
  end
@@ -4,11 +4,11 @@ require 'active_support/inflector'
4
4
  module LcApi
5
5
  class Resource
6
6
  class << self
7
+ include ErrorCodes
7
8
 
8
9
  def find(id, options={})
9
10
  uri = member_name # ie 'message'
10
11
  uri += "/#{id}" if id
11
- puts "uri is: #{uri}"
12
12
  parse_response(API.get(uri, options))
13
13
  end
14
14
 
@@ -18,7 +18,7 @@ module LcApi
18
18
  end
19
19
 
20
20
  def parse_response(response, multiple=false)
21
- error_code_check(response)
21
+ error_code_check(response) # from ErrorCodes mixin
22
22
 
23
23
  # build a single record and return if there is only one resource (via ".find" method)
24
24
  return build_record(response.parsed_response) unless multiple
@@ -29,17 +29,6 @@ module LcApi
29
29
  return resources
30
30
  end
31
31
 
32
- def error_code_check(response)
33
- case response.code.to_i
34
- when 404
35
- raise LcApi::API::NotFound.new(response), "Resource was not found"
36
- when 403
37
- raise LcApi::API::Forbidden.new(response), "Forbidden"
38
- when 500
39
- raise LcApi::API::InternalServerError.new(response), "500 Internal Server error"
40
- end
41
- end
42
-
43
32
  def build_record(response)
44
33
  attributes = {}
45
34
  response.each_pair { |k,v| attributes[k] = v if @attributes.include? k }
data/lib/lc-api.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'lc-api/api'
2
2
  require 'lc-api/resource'
3
+ require 'lc-api/error_codes'
3
4
  require 'lc-api/resource/message'
4
5
  require 'lc-api/resource/series'
5
6
  require 'lc-api/resource/speaker'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lc-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-30 00:00:00.000000000 Z
13
+ date: 2013-05-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -53,6 +53,7 @@ files:
53
53
  - lib/lc-api.rb
54
54
  - lib/lc-api/api.rb
55
55
  - lib/lc-api/resource.rb
56
+ - lib/lc-api/error_codes.rb
56
57
  - lib/lc-api/resource/category.rb
57
58
  - lib/lc-api/resource/location.rb
58
59
  - lib/lc-api/resource/message.rb