badgeville 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/VERSION +1 -1
- data/badgeville.gemspec +2 -2
- data/lib/badgeville.rb +18 -7
- data/spec/badgeville_spec.rb +13 -2
- metadata +15 -15
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/badgeville.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{badgeville}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gilad Buchman"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-07}
|
13
13
|
s.description = %q{Client for Badgeville's Core API v2. http://rules.badgeville.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.md"
|
data/lib/badgeville.rb
CHANGED
@@ -5,7 +5,7 @@ require 'badgeville/activity'
|
|
5
5
|
require 'badgeville/reward'
|
6
6
|
|
7
7
|
module Badgeville
|
8
|
-
|
8
|
+
TIMEOUT_SECS = 3
|
9
9
|
HOST = "sandbox.v2.badgeville.com"
|
10
10
|
PROTOCOL = "http"
|
11
11
|
|
@@ -14,18 +14,24 @@ module Badgeville
|
|
14
14
|
|
15
15
|
def initialize (err_code=nil, error_msg="")
|
16
16
|
super error_msg
|
17
|
+
@message = error_msg
|
17
18
|
@code = err_code
|
18
19
|
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"ERROR #{@code} : #{@message}"
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
class Client
|
22
|
-
attr_accessor :user, :site, :player_id, :site_id
|
27
|
+
attr_accessor :user, :site, :player_id, :site_id, :timeout
|
23
28
|
|
24
29
|
def initialize (email, opts={})
|
25
30
|
# Required Parameters
|
26
31
|
@site = opts['site']
|
27
32
|
@private_key = opts['private_key']
|
28
33
|
@public_key = opts['public_key']
|
34
|
+
@timeout = opts['timeout'] || TIMEOUT_SECS
|
29
35
|
@host = opts['host'] || HOST
|
30
36
|
@protocol = opts['protocol'] || PROTOCOL
|
31
37
|
@user = email
|
@@ -91,9 +97,10 @@ module Badgeville
|
|
91
97
|
end
|
92
98
|
|
93
99
|
def set_player
|
94
|
-
end_point = "#{@site}/players
|
100
|
+
end_point = "#{@site}/players/info.json"
|
95
101
|
begin
|
96
|
-
response = session[end_point].get
|
102
|
+
response = session[end_point].get(:params =>
|
103
|
+
{:user => @user, :site => @site})
|
97
104
|
data = response.body
|
98
105
|
json = JSON.parse(data)
|
99
106
|
json = json["data"]
|
@@ -109,6 +116,10 @@ module Badgeville
|
|
109
116
|
end
|
110
117
|
end
|
111
118
|
|
119
|
+
def timeout
|
120
|
+
@timeout
|
121
|
+
end
|
122
|
+
|
112
123
|
def site_id
|
113
124
|
unless @site_id
|
114
125
|
set_player
|
@@ -132,7 +143,7 @@ module Badgeville
|
|
132
143
|
def session
|
133
144
|
if @session.nil?
|
134
145
|
base_url = "#{@protocol}://#{@host}/api/berlin/#{@private_key}"
|
135
|
-
@session = RestClient::Resource.new base_url
|
146
|
+
@session = RestClient::Resource.new base_url, :timeout => @timeout
|
136
147
|
end
|
137
148
|
@session
|
138
149
|
end
|
@@ -155,9 +166,9 @@ module Badgeville
|
|
155
166
|
if e.respond_to? :response
|
156
167
|
begin
|
157
168
|
data = JSON.parse(e.response)
|
158
|
-
raise BadgevilleError.new(e.http_code, data["error"])
|
159
|
-
rescue TypeError
|
160
169
|
raise BadgevilleError.new(e.http_code, data)
|
170
|
+
rescue TypeError, JSON::ParserError
|
171
|
+
raise BadgevilleError.new(e.http_code, e.message)
|
161
172
|
end
|
162
173
|
else
|
163
174
|
raise e
|
data/spec/badgeville_spec.rb
CHANGED
@@ -63,7 +63,7 @@ describe Badgeville do
|
|
63
63
|
describe "#get_activities" do
|
64
64
|
before do
|
65
65
|
@url = /http:\/\/#{Badgeville::HOST}.*activities.json.*user=#{@user}.*/
|
66
|
-
mock_activities = {
|
66
|
+
mock_activities = {
|
67
67
|
"data" => [
|
68
68
|
{
|
69
69
|
"verb" => "join_team",
|
@@ -125,11 +125,22 @@ describe Badgeville do
|
|
125
125
|
|
126
126
|
describe "#set_player" do
|
127
127
|
before do
|
128
|
-
@url = /http:\/\/#{Badgeville::HOST}.*example.com\/players
|
128
|
+
@url = /http:\/\/#{Badgeville::HOST}.*example.com\/players\/info\.json.*user=#{@user}.*/
|
129
129
|
stub_http_request(:get, @url).to_return(:body => {"data" => {"id" => "1", "site_id" => "site"}}.to_json)
|
130
130
|
end
|
131
131
|
|
132
132
|
it {@badgeville.player_id.should == "1"}
|
133
133
|
it {@badgeville.site_id.should == "site"}
|
134
134
|
end
|
135
|
+
|
136
|
+
describe "verify default timeout is 3" do
|
137
|
+
it {@badgeville.timeout.should == 3}
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "verify timeout parameter is set" do
|
141
|
+
new_badgeville = Badgeville::Client.new @user, 'private_key' => "api_key",
|
142
|
+
'site' => 'example.com', 'timeout' => 10
|
143
|
+
it {new_badgeville.timeout.should == 10}
|
144
|
+
end
|
145
|
+
|
135
146
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: badgeville
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-10 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
17
|
-
requirement: &
|
17
|
+
requirement: &2160449300 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2160449300
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rest-client
|
28
|
-
requirement: &
|
28
|
+
requirement: &2160448300 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2160448300
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2160447640 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 2.3.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2160447640
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &2160447000 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.0.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2160447000
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &2160446280 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 1.6.4
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2160446280
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rcov
|
72
|
-
requirement: &
|
72
|
+
requirement: &2160445520 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2160445520
|
81
81
|
description: Client for Badgeville's Core API v2. http://rules.badgeville.com
|
82
82
|
email:
|
83
83
|
executables: []
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: 832478503767646954
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|