From 46baa812ba022e46e68eed3bc3c8327a6e570504 Mon Sep 17 00:00:00 2001 From: danijoo Date: Sun, 15 Dec 2013 01:57:17 +0100 Subject: [PATCH] documentation --- .DS_Store | Bin 0 -> 6148 bytes .../modules/sightstone_base_module.rb | 36 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .DS_Store create mode 100644 lib/sightstone/modules/sightstone_base_module.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..90479bf993ef7311be05c8c8ff875876469c93cd GIT binary patch literal 6148 zcmeHKy-ve05VqR_i7G*m7+~|p(xFgL*@!}!SdfBXpr|CIqLHc?wJ9A+rHuT(2ZDju zVc=o7v)ziSurMH0-AU)~e7>{gFOkn?jB&3QZ7}9A#w<|8oDI!4g5#)Dk~1Dej&pRc z!nO>d_Yq!AMU&${GJxMM&mtz-McDuP{n~LiEtlVUE?=0NU$AVuXcrfkif4XH_Wd+S zdtEQ+oMP`VNL!(?kECpm?I1jkoBf8fvL}-?h?8bVCC5<{Lh2`R63ML|NQ=+Orjn!Kn%9?y literal 0 HcmV?d00001 diff --git a/lib/sightstone/modules/sightstone_base_module.rb b/lib/sightstone/modules/sightstone_base_module.rb new file mode 100644 index 0000000..030180b --- /dev/null +++ b/lib/sightstone/modules/sightstone_base_module.rb @@ -0,0 +1,36 @@ +require 'open-uri' + +# Base class of the api modules +# @abstract +class SightstoneBaseModule + + protected + def _get_api_response(uri, header={}) + params = {'api_key' => @sightstone.api_key}.merge header + RestClient.get(uri, headers={:params => params}) {|response, request, result| response } + rescue SocketError => e + nil + + end + + def _parse_response(response, &block) + response_code = if response.nil? + 500 + else + response.code + end + + if response_code == 200 + block.call(response.body) + elsif response_code == 404 + raise Sightstone::SummonerNotFoundException + elsif response_code == 500 + raise Sightstone::SightstoneConnectionException + elsif response_code == 429 + raise Sightstone::RateLimitExceededException + else + raise Sightstone::SightstoneApiException 'Unknown error occured' + end + end + +end \ No newline at end of file