psn 0.0.1 → 0.0.2

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.
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p327@psn"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.17.0 (master)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
@@ -1,10 +1,12 @@
1
1
  require 'active_support/all'
2
+ require 'cgi'
2
3
  require 'retriable/no_kernel'
3
4
  require 'open-uri'
4
5
  require 'net/http'
5
6
  require 'nokogiri'
6
7
  module PSN
7
8
  class API
9
+ RETRIES = 3
8
10
  BASE_URL="http://www.psnapi.com.ar/ps3/api/psn.asmx"
9
11
  attr_reader :client
10
12
 
@@ -19,20 +21,28 @@ module PSN
19
21
 
20
22
  private
21
23
  def fetch(url, options)
22
- response = Retriable.retriable on: OpenURI::HTTPError, tries: 3, interval: 1 do
23
- open("#{BASE_URL}/#{url}?#{normalize_params options}").read
24
+ url = "#{BASE_URL}/#{url}?#{normalize_params options}"
25
+ response = Retriable.retriable on: OpenURI::HTTPError, tries: RETRIES, interval: 1 do
26
+ open(url).read
24
27
  end
25
28
  parse_and_extract_response response
29
+ rescue OpenURI::HTTPError => e
30
+ raise Error, url
26
31
  end
27
32
 
28
33
  def normalize_params(params)
29
34
  query = ""
30
- params.each {|k, v| query += "#{k}=#{v}&"}
35
+ params.each {|k, v| query += "#{k}=#{CGI.escape v}&"}
31
36
  query
32
37
  end
33
38
 
34
39
  def parse_and_extract_response(response)
35
40
  Nokogiri::Slop response
36
41
  end
42
+ class Error < RuntimeError
43
+ def initialize(url)
44
+ super("#{url} is not working after #{RETRIES} retries. Please check.")
45
+ end
46
+ end
37
47
  end
38
48
  end
@@ -1,3 +1,3 @@
1
1
  module PSN
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -13,5 +13,10 @@ module PSN
13
13
  it "fetches games for an user", :vcr do
14
14
  api.games_for(user).should be_a_kind_of Nokogiri::XML::NodeSet
15
15
  end
16
+
17
+ it "raises PSN::API::Error for errors in API", :vcr do
18
+ username = 'Kevin100Brasil'
19
+ expect{api.games_for(User.new(username))}.to raise_error(PSN::API::Error)
20
+ end
16
21
  end
17
22
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: psn
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pedro Nascimento
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -153,6 +153,7 @@ extensions: []
153
153
  extra_rdoc_files: []
154
154
  files:
155
155
  - .gitignore
156
+ - .rvmrc
156
157
  - Gemfile
157
158
  - LICENSE.txt
158
159
  - README.md
@@ -190,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
191
  version: '0'
191
192
  segments:
192
193
  - 0
193
- hash: 2485592278397945638
194
+ hash: 224315629052507505
194
195
  none: false
195
196
  required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  requirements:
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  version: '0'
200
201
  segments:
201
202
  - 0
202
- hash: 2485592278397945638
203
+ hash: 224315629052507505
203
204
  none: false
204
205
  requirements: []
205
206
  rubyforge_project: