badgeville 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +53 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +47 -0
- data/Gemfile +2 -18
- data/Gemfile.lock +24 -24
- data/README.md +15 -3
- data/Rakefile +5 -42
- data/badgeville.gemspec +20 -63
- data/examples/log_and_check_status.rb +18 -11
- data/lib/badgeville.rb +63 -23
- data/lib/badgeville/helpers.rb +8 -0
- data/lib/badgeville/reward.rb +3 -5
- data/lib/badgeville/version.rb +3 -0
- data/spec/badgeville_spec.rb +68 -1
- data/spec/reward_spec.rb +32 -14
- metadata +31 -33
- data/CHANGELOG +0 -31
- data/VERSION +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
examples/my*
|
2
|
+
# rcov generated
|
3
|
+
coverage
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
keys.json
|
19
|
+
|
20
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
21
|
+
#
|
22
|
+
# * Create a file at ~/.gitignore
|
23
|
+
# * Include files you want ignored
|
24
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
25
|
+
#
|
26
|
+
# After doing this, these files will be ignored in all your git projects,
|
27
|
+
# saving you from having to 'pollute' every project you touch with them
|
28
|
+
#
|
29
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
30
|
+
#
|
31
|
+
# For MacOS:
|
32
|
+
#
|
33
|
+
#.DS_Store
|
34
|
+
|
35
|
+
# For TextMate
|
36
|
+
#*.tmproj
|
37
|
+
#tmtags
|
38
|
+
|
39
|
+
# For emacs:
|
40
|
+
#*~
|
41
|
+
#\#*
|
42
|
+
#.\#*
|
43
|
+
|
44
|
+
# For vim:
|
45
|
+
#*.swp
|
46
|
+
|
47
|
+
# For redcar:
|
48
|
+
#.redcar
|
49
|
+
|
50
|
+
# For rubinius:
|
51
|
+
#*.rbc
|
52
|
+
keys.json.dev
|
53
|
+
keys.json.pro
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
0.1.0 (May 5, 2012)
|
2
|
+
===================
|
3
|
+
|
4
|
+
* Fixed support for new response format in tags
|
5
|
+
* Added support for protocol relative image urls
|
6
|
+
* Tests are now run by TravisCI against 1.9.2 / 1.9.3
|
7
|
+
* Dropping support for 1.8.x if there every was one
|
8
|
+
* add debug flag
|
9
|
+
* create a user / player
|
10
|
+
|
11
|
+
0.0.8 (November 30, 2011)
|
12
|
+
=========================
|
13
|
+
|
14
|
+
* support pagination and get all pages for rewards and rewards definitions
|
15
|
+
* misc bug fixes
|
16
|
+
|
17
|
+
0.0.7 (November 30, 2011)
|
18
|
+
=========================
|
19
|
+
|
20
|
+
* HAS MAJOR BUG DO NOT USE
|
21
|
+
|
22
|
+
0.0.6 (November 15, 2011)
|
23
|
+
=========================
|
24
|
+
|
25
|
+
* change set player to use new players/info end point
|
26
|
+
* add delete method for earned rewards
|
27
|
+
* add definition_id to reward
|
28
|
+
|
29
|
+
0.0.5 (October 10, 2011)
|
30
|
+
========================
|
31
|
+
|
32
|
+
* set default timeout to 3s
|
33
|
+
* add timeout parameter
|
34
|
+
|
35
|
+
0.0.4 (September 18, 2011)
|
36
|
+
==========================
|
37
|
+
|
38
|
+
* count activities
|
39
|
+
* better error handling
|
40
|
+
* add tags to rewards
|
41
|
+
|
42
|
+
0.0.3 (September 12, 2011)
|
43
|
+
==========================
|
44
|
+
|
45
|
+
* Activity.rewards includes reward objects not reward definitions
|
46
|
+
* Reward has verb and threshold data for achievments type rewards
|
47
|
+
* Raise non json errors
|
data/Gemfile
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source :rubygems
|
2
2
|
|
3
|
-
|
4
|
-
gem 'json'
|
5
|
-
gem 'rest-client'
|
6
|
-
# Please keep me alphabetized!
|
7
|
-
|
8
|
-
# Add dependencies to develop your gem here.
|
9
|
-
# Include everything needed to run rake, tests, features, etc.
|
10
|
-
group :development do
|
11
|
-
gem "rspec"
|
12
|
-
gem "bundler"
|
13
|
-
gem "jeweler"
|
14
|
-
gem "rcov", ">= 0"
|
15
|
-
end
|
16
|
-
|
17
|
-
group :test do
|
18
|
-
gem "webmock"
|
19
|
-
end
|
3
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
badgeville (0.0.8)
|
5
|
+
json
|
6
|
+
rest-client
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: http://rubygems.org/
|
3
10
|
specs:
|
4
|
-
addressable (2.2.
|
11
|
+
addressable (2.2.8)
|
5
12
|
crack (0.3.1)
|
6
13
|
diff-lcs (1.1.3)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rake
|
12
|
-
json (1.6.1)
|
13
|
-
mime-types (1.17.2)
|
14
|
-
rake (0.9.2.2)
|
15
|
-
rcov (0.9.11)
|
14
|
+
json (1.7.0)
|
15
|
+
mime-types (1.18)
|
16
|
+
rdoc (3.12)
|
17
|
+
json (~> 1.4)
|
16
18
|
rest-client (1.6.7)
|
17
19
|
mime-types (>= 1.16)
|
18
|
-
rspec (2.
|
19
|
-
rspec-core (~> 2.
|
20
|
-
rspec-expectations (~> 2.
|
21
|
-
rspec-mocks (~> 2.
|
22
|
-
rspec-core (2.
|
23
|
-
rspec-expectations (2.
|
24
|
-
diff-lcs (~> 1.1.
|
25
|
-
rspec-mocks (2.
|
26
|
-
webmock (1.
|
27
|
-
addressable (
|
20
|
+
rspec (2.10.0)
|
21
|
+
rspec-core (~> 2.10.0)
|
22
|
+
rspec-expectations (~> 2.10.0)
|
23
|
+
rspec-mocks (~> 2.10.0)
|
24
|
+
rspec-core (2.10.0)
|
25
|
+
rspec-expectations (2.10.0)
|
26
|
+
diff-lcs (~> 1.1.3)
|
27
|
+
rspec-mocks (2.10.1)
|
28
|
+
webmock (1.8.6)
|
29
|
+
addressable (>= 2.2.7)
|
28
30
|
crack (>= 0.1.7)
|
29
31
|
|
30
32
|
PLATFORMS
|
31
33
|
ruby
|
32
34
|
|
33
35
|
DEPENDENCIES
|
36
|
+
badgeville!
|
34
37
|
bundler
|
35
|
-
|
36
|
-
json
|
37
|
-
rcov
|
38
|
-
rest-client
|
38
|
+
rdoc
|
39
39
|
rspec
|
40
40
|
webmock
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/rmehner/badgeville.png)](http://travis-ci.org/rmehner/badgeville)
|
2
|
+
|
1
3
|
Badgeville API
|
2
|
-
|
4
|
+
==============
|
3
5
|
|
4
6
|
Client for Badgeville API http://rules.badgeville.com/
|
5
7
|
|
6
|
-
(not complete)
|
7
|
-
|
8
8
|
Usage
|
9
9
|
--------
|
10
10
|
First, checkout the examples folder. TL;DR:
|
@@ -17,6 +17,18 @@ settings = JSON.parse(File.read('keys.json.example'))
|
|
17
17
|
badgeville = Badgeville::Client.new(email, settings)
|
18
18
|
```
|
19
19
|
|
20
|
+
* register user and player on site
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
badgeville.create_player
|
24
|
+
```
|
25
|
+
|
26
|
+
* get player id
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
badgeville.player_info
|
30
|
+
```
|
31
|
+
|
20
32
|
* log actions
|
21
33
|
|
22
34
|
```ruby
|
data/Rakefile
CHANGED
@@ -1,48 +1,11 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rdoc/task'
|
2
4
|
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "badgeville"
|
18
|
-
gem.homepage = "http://github.com/Keasinc/badgeville"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = "Client for Badgeville's Core API"
|
21
|
-
gem.description = "Client for Badgeville's Core API v2. http://rules.badgeville.com"
|
22
|
-
gem.authors = ["Gilad Buchman"]
|
23
|
-
# dependencies defined in Gemfile
|
24
|
-
end
|
25
|
-
Jeweler::RubygemsDotOrgTasks.new
|
26
|
-
|
27
|
-
require 'rspec/core'
|
28
|
-
require 'rspec/core/rake_task'
|
29
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
31
|
-
end
|
32
|
-
|
33
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
34
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
35
|
-
spec.rcov = true
|
36
|
-
end
|
37
|
-
|
38
|
-
task :default => :spec
|
39
|
-
|
40
|
-
require 'rake/rdoctask'
|
41
5
|
Rake::RDocTask.new do |rdoc|
|
42
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
-
|
44
6
|
rdoc.rdoc_dir = 'rdoc'
|
45
|
-
rdoc.title
|
7
|
+
rdoc.title = "badgeville"
|
8
|
+
|
46
9
|
rdoc.rdoc_files.include('README*')
|
47
10
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
11
|
end
|
data/badgeville.gemspec
CHANGED
@@ -1,69 +1,26 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/badgeville/version', __FILE__)
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "badgeville"
|
6
|
+
gem.description = "Badgeville API client"
|
7
|
+
gem.summary = "Client for Badgeville's Core API v2. http://rules.badgeville.com"
|
8
|
+
gem.version = Badgeville::VERSION
|
9
|
+
gem.authors = ["Gilad Buchman", "Robin Mehner"]
|
10
|
+
gem.homepage = "http://github.com/rmehner/badgeville"
|
11
|
+
gem.date = Time.now.utc.strftime("%Y-%m-%d")
|
12
|
+
gem.licenses = ["MIT"]
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.md"
|
16
|
-
]
|
17
|
-
s.files = [
|
18
|
-
".document",
|
19
|
-
"CHANGELOG",
|
20
|
-
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
|
-
"README.md",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"badgeville.gemspec",
|
26
|
-
"examples/log_and_check_status.rb",
|
27
|
-
"keys.json.example",
|
28
|
-
"lib/badgeville.rb",
|
29
|
-
"lib/badgeville/activity.rb",
|
30
|
-
"lib/badgeville/helpers.rb",
|
31
|
-
"lib/badgeville/reward.rb",
|
32
|
-
"spec/badgeville_spec.rb",
|
33
|
-
"spec/reward_spec.rb",
|
34
|
-
"spec/spec_helper.rb"
|
35
|
-
]
|
36
|
-
s.homepage = %q{http://github.com/Keasinc/badgeville}
|
37
|
-
s.licenses = ["MIT"]
|
38
|
-
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.6.2}
|
40
|
-
s.summary = %q{Client for Badgeville's Core API}
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.rubygems_version = %q{1.6.2}
|
41
18
|
|
42
|
-
|
43
|
-
|
19
|
+
gem.add_dependency 'rest-client'
|
20
|
+
gem.add_dependency 'json'
|
44
21
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
s.add_development_dependency(%q<bundler>, [">= 0"])
|
50
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
51
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
-
else
|
53
|
-
s.add_dependency(%q<json>, [">= 0"])
|
54
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
55
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
57
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
58
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
-
end
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<json>, [">= 0"])
|
62
|
-
s.add_dependency(%q<rest-client>, [">= 0"])
|
63
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
64
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
65
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
-
end
|
22
|
+
gem.add_development_dependency 'bundler'
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
gem.add_development_dependency 'rdoc'
|
25
|
+
gem.add_development_dependency 'webmock'
|
68
26
|
end
|
69
|
-
|
@@ -4,22 +4,29 @@ require 'badgeville'
|
|
4
4
|
require 'pp'
|
5
5
|
|
6
6
|
settings = JSON.parse(File.read('keys.json'))
|
7
|
-
badgeville = Badgeville::Client.new('
|
7
|
+
badgeville = Badgeville::Client.new('test_8@example.com', settings)
|
8
8
|
|
9
|
-
|
9
|
+
#turn on debugging
|
10
|
+
badgeville.debug = true
|
10
11
|
|
11
|
-
|
12
|
+
#create player on site
|
13
|
+
pp badgeville.create_player
|
14
|
+
pp badgeville.player_info
|
12
15
|
|
13
|
-
pp badgeville.
|
16
|
+
#pp badgeville.reward_definitions #all defined definitions for site
|
17
|
+
|
18
|
+
#pp badgeville.log_activity "commented"
|
19
|
+
|
20
|
+
#pp badgeville.log_activity "join_team", :team => "myteam"
|
14
21
|
|
15
22
|
#check histoy for user
|
16
|
-
pp badgeville.get_activities
|
17
|
-
pp badgeville.count_activities
|
18
|
-
pp badgeville.count_activities :verb => "commented"
|
19
|
-
pp badgeville.count_activities :verb => "junk"
|
23
|
+
#pp badgeville.get_activities
|
24
|
+
#pp badgeville.count_activities
|
25
|
+
#pp badgeville.count_activities :verb => "commented"
|
26
|
+
#pp badgeville.count_activities :verb => "junk"
|
20
27
|
|
21
|
-
pp badgeville.get_rewards #earned for user
|
28
|
+
#pp badgeville.get_rewards #earned for user
|
22
29
|
|
23
30
|
#award and delete rewards
|
24
|
-
reward = badgeville.award "The First Step"
|
25
|
-
badgeville.delete reward
|
31
|
+
#reward = badgeville.award "The First Step"
|
32
|
+
#badgeville.delete reward
|
data/lib/badgeville.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rest_client'
|
|
3
3
|
require 'badgeville/helpers'
|
4
4
|
require 'badgeville/activity'
|
5
5
|
require 'badgeville/reward'
|
6
|
+
require 'badgeville/version'
|
6
7
|
|
7
8
|
module Badgeville
|
8
9
|
TIMEOUT_SECS = 3
|
@@ -24,7 +25,8 @@ module Badgeville
|
|
24
25
|
end
|
25
26
|
|
26
27
|
class Client
|
27
|
-
|
28
|
+
include Helpers
|
29
|
+
attr_accessor :user, :site, :player_id, :site_id, :timeout, :debug
|
28
30
|
|
29
31
|
def initialize (email, opts={})
|
30
32
|
# Required Parameters
|
@@ -38,15 +40,38 @@ module Badgeville
|
|
38
40
|
@per_page = opts['per_page']
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def create_player(opts={})
|
44
|
+
#try to see if player already exists
|
45
|
+
begin
|
46
|
+
return player_info
|
47
|
+
rescue
|
48
|
+
end
|
49
|
+
|
50
|
+
#try to create user
|
51
|
+
begin
|
52
|
+
params = property_params(:user, {email: @user}.merge(opts))
|
53
|
+
response = make_call(:post, :users, params)
|
54
|
+
rescue BadgevilleError => e
|
55
|
+
if e.code != 422
|
56
|
+
if ensure_array(e.data["email"]).none? {|erorr_msg|
|
57
|
+
error_msg =~ "is already taken"
|
58
|
+
}
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
end
|
49
62
|
end
|
63
|
+
|
64
|
+
#create player
|
65
|
+
params = {email: @user, site: @site}.merge(
|
66
|
+
property_params(:player, {email: @user}.merge(
|
67
|
+
opts)))
|
68
|
+
json = make_call(:post, :players, params)
|
69
|
+
@site_id = json["site_id"]
|
70
|
+
@player_id = json["id"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def log_activity(activity, opts={})
|
74
|
+
params = property_params(:activity, {verb: activity}.merge(opts))
|
50
75
|
response = make_call(:post, :activities, params)
|
51
76
|
Activity.new(response)
|
52
77
|
end
|
@@ -110,20 +135,26 @@ module Badgeville
|
|
110
135
|
end
|
111
136
|
end
|
112
137
|
|
113
|
-
def
|
138
|
+
def debug=(flag)
|
139
|
+
log_file = flag ? "stdout" : nil
|
140
|
+
RestClient.log = log_file
|
141
|
+
@debug = flag
|
142
|
+
end
|
143
|
+
|
144
|
+
def player_info
|
114
145
|
end_point = "/players/info.json"
|
115
146
|
begin
|
116
|
-
|
117
|
-
|
147
|
+
params = {:email => @user, :site => @site}
|
148
|
+
response = session[end_point].get(:params => params)
|
118
149
|
data = response.body
|
119
150
|
json = JSON.parse(data)
|
120
151
|
json = json["data"]
|
121
|
-
@player_id = json["id"]
|
122
152
|
@site_id = json["site_id"]
|
153
|
+
@player_id = json["id"]
|
123
154
|
rescue => e
|
124
|
-
if e.respond_to? :response
|
155
|
+
if e.respond_to? :response && e.response
|
125
156
|
data = JSON.parse(e.response)
|
126
|
-
raise BadgevilleError.new(e.http_code, data["error"])
|
157
|
+
raise BadgevilleError.new(e.http_code, data["errors"]["error"])
|
127
158
|
else
|
128
159
|
raise e
|
129
160
|
end
|
@@ -132,14 +163,14 @@ module Badgeville
|
|
132
163
|
|
133
164
|
def site_id
|
134
165
|
unless @site_id
|
135
|
-
|
166
|
+
player_info
|
136
167
|
end
|
137
168
|
@site_id
|
138
169
|
end
|
139
170
|
|
140
171
|
def player_id
|
141
172
|
unless @player_id
|
142
|
-
|
173
|
+
player_info
|
143
174
|
end
|
144
175
|
@player_id
|
145
176
|
end
|
@@ -161,15 +192,11 @@ module Badgeville
|
|
161
192
|
|
162
193
|
def make_call(method, action, params={})
|
163
194
|
end_point = "#{action.to_s}.json"
|
164
|
-
|
165
|
-
|
166
|
-
end
|
195
|
+
params = add_default_params(method, action, params)
|
196
|
+
|
167
197
|
begin
|
168
198
|
case method
|
169
199
|
when :get
|
170
|
-
unless @per_page.nil? || params.has_key?(:per_page)
|
171
|
-
params[:per_page] = @per_page
|
172
|
-
end
|
173
200
|
response = session[end_point].send(method, :params => params)
|
174
201
|
when :post, :put, :delete
|
175
202
|
response = session[end_point].send(method, to_query(params))
|
@@ -177,6 +204,7 @@ module Badgeville
|
|
177
204
|
data = response.body
|
178
205
|
json = JSON.parse(data)
|
179
206
|
rescue => e
|
207
|
+
puts e if debug
|
180
208
|
if e.respond_to? :response
|
181
209
|
begin
|
182
210
|
data = JSON.parse(e.response)
|
@@ -198,6 +226,18 @@ module Badgeville
|
|
198
226
|
URI.escape(params.map { |k,v| "#{k.to_s}=#{v.to_s}" }.join("&"))
|
199
227
|
end
|
200
228
|
|
229
|
+
def add_default_params(method, action, params)
|
230
|
+
should_not_add = params.keys.none? { |k| k =~ /player_id/ }
|
231
|
+
should_not_add &= [:users, :players].include? action
|
232
|
+
unless should_not_add
|
233
|
+
params.merge!(:user => @user, :site => @site)
|
234
|
+
end
|
235
|
+
if method == :get && @per_page && !params.has_key?(:per_page)
|
236
|
+
params[:per_page] = @per_page
|
237
|
+
end
|
238
|
+
params
|
239
|
+
end
|
240
|
+
|
201
241
|
def rewards_from_response(response)
|
202
242
|
response["data"].map do |reward_json|
|
203
243
|
Reward.new(reward_json)
|
data/lib/badgeville/helpers.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module Badgeville
|
2
2
|
module Helpers
|
3
|
+
def property_params(object_name, params)
|
4
|
+
params.inject({}) do |new_params, entry|
|
5
|
+
k, v = entry
|
6
|
+
new_params["#{object_name.to_s}[#{k.to_s}]"] = v
|
7
|
+
new_params
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
def ensure_array(items)
|
4
12
|
items.is_a?(Array) ? items : [items]
|
5
13
|
end
|
data/lib/badgeville/reward.rb
CHANGED
@@ -46,7 +46,7 @@ module Badgeville
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def image_url(format = :original)
|
49
|
-
@image_url.sub('original', format.to_s)
|
49
|
+
@image_url.sub('original', format.to_s).sub(/^https?:/, '')
|
50
50
|
end
|
51
51
|
|
52
52
|
# <b>DEPRECATED:</b> Please use <tt>image_url('grayscale')</tt> instead.
|
@@ -68,10 +68,8 @@ module Badgeville
|
|
68
68
|
@verb = json["data"]["verb"]
|
69
69
|
@threshold = json["data"]["threshold"].to_i
|
70
70
|
end
|
71
|
-
|
72
|
-
|
73
|
-
@tags = json["tags"].split(',').map(&:strip)
|
74
|
-
end
|
71
|
+
|
72
|
+
@tags = json['tags'] || []
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
data/spec/badgeville_spec.rb
CHANGED
@@ -174,7 +174,7 @@ describe Badgeville do
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
describe "#
|
177
|
+
describe "#player_info" do
|
178
178
|
before do
|
179
179
|
@url = /http:\/\/#{Badgeville::HOST}.*\/players\/info\.json.*email=#{@user}.*/
|
180
180
|
stub_http_request(:get, @url).to_return(:body => {"data" => {"id" => "1", "site_id" => "site"}}.to_json)
|
@@ -194,4 +194,71 @@ describe Badgeville do
|
|
194
194
|
it {new_badgeville.timeout.should == 10}
|
195
195
|
end
|
196
196
|
|
197
|
+
describe "#create_player" do
|
198
|
+
before do
|
199
|
+
url = /http:\/\/#{Badgeville::HOST}.*\/players\/info\.json.*email=#{@user}.*/
|
200
|
+
stub_http_request(:get, url).to_return(:status => 404,
|
201
|
+
:body => {"errors" => {"error" => "invalid player"}}.to_json)
|
202
|
+
|
203
|
+
players_url = /http:\/\/#{Badgeville::HOST}.*\/players\.json/
|
204
|
+
body = "email=#{@user}&site=example.com&player[email]=#{@user}"
|
205
|
+
result = {"_id" => "1","id" => "1", "site_id" => "site_id"}
|
206
|
+
stub_http_request(:post, players_url).with(body: body).
|
207
|
+
to_return(:body => result.to_json)
|
208
|
+
|
209
|
+
@users_url = /http:\/\/#{Badgeville::HOST}.*\/users\.json/
|
210
|
+
@users_body = "user[email]=#{@user}"
|
211
|
+
end
|
212
|
+
|
213
|
+
context "with new user" do
|
214
|
+
before do
|
215
|
+
result = {"_id" => "1","email" => @user}
|
216
|
+
stub_http_request(:post, @users_url).with(body: @users_body).
|
217
|
+
to_return(:body => result.to_json)
|
218
|
+
@response = @badgeville.create_player
|
219
|
+
end
|
220
|
+
|
221
|
+
it "returns the created player id" do
|
222
|
+
@response.should == "1"
|
223
|
+
end
|
224
|
+
|
225
|
+
it "sets player id" do
|
226
|
+
@badgeville.player_id.should == "1"
|
227
|
+
end
|
228
|
+
|
229
|
+
context "with existing user on new site" do
|
230
|
+
before do
|
231
|
+
result = {"errors" => {"email" => ["user email is already taken"]}}
|
232
|
+
stub_http_request(:post, @users_url).with(body: @users_body).
|
233
|
+
to_return(:status => 422, :body => result.to_json)
|
234
|
+
@response = @badgeville.create_player
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
it "returns the created player id" do
|
239
|
+
@response.should == "1"
|
240
|
+
end
|
241
|
+
|
242
|
+
it "sets player id" do
|
243
|
+
@badgeville.player_id.should == "1"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context "when player already exists" do
|
248
|
+
before do
|
249
|
+
url = /http:\/\/#{Badgeville::HOST}.*\/players\/info\.json.*email=#{@user}.*/
|
250
|
+
stub_http_request(:get, url).
|
251
|
+
to_return(:body => {"data" => {"id" => "1", "site_id" => "site"}}.to_json)
|
252
|
+
@response = @badgeville.create_player
|
253
|
+
end
|
254
|
+
|
255
|
+
it "returns the created player id" do
|
256
|
+
@response.should == "1"
|
257
|
+
end
|
258
|
+
|
259
|
+
it "sets player id" do
|
260
|
+
@badgeville.player_id.should == "1"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
197
264
|
end
|
data/spec/reward_spec.rb
CHANGED
@@ -40,39 +40,57 @@ describe Badgeville::Reward do
|
|
40
40
|
@reward.name.should == "A Way with Words"
|
41
41
|
@reward.active.should be_true
|
42
42
|
@reward.id.should == "4e4dfab6c47eed727b005c38"
|
43
|
-
@reward.tags.should == []
|
44
43
|
@reward.definition_id.should == '4e4dfab6c47eed727b005c38'
|
45
44
|
@reward.message.should == 'You won the internet!'
|
46
45
|
end
|
47
46
|
|
48
47
|
describe "image_url" do
|
49
48
|
it "returns the original url by default" do
|
50
|
-
@reward.image_url.should == '
|
49
|
+
@reward.image_url.should == '//s3.amazon.com/original.png?1'
|
51
50
|
end
|
52
51
|
|
53
52
|
it "allows to request specific formats" do
|
54
53
|
[:original, :large, :medium, :grayscale, :grayscale_small].each do |format|
|
55
|
-
@reward.image_url(format).should == "
|
54
|
+
@reward.image_url(format).should == "//s3.amazon.com/#{format}.png?1"
|
56
55
|
end
|
57
56
|
end
|
58
|
-
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
@parsed_json["tags"] = "tag"
|
63
|
-
@reward = Badgeville::Reward.new(@parsed_json)
|
58
|
+
it "returns a protocol relative url for a http original image url" do
|
59
|
+
@reward.image_url.should == '//s3.amazon.com/original.png?1'
|
64
60
|
end
|
65
61
|
|
66
|
-
it
|
62
|
+
it "returns a protocol relative url for a https original image url" do
|
63
|
+
@parsed_json['image_url'] = 'https://s3.amazon.com/original.png?1'
|
64
|
+
reward = Badgeville::Reward.new(@parsed_json)
|
65
|
+
|
66
|
+
@reward.image_url.should == '//s3.amazon.com/original.png?1'
|
67
|
+
end
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
@
|
72
|
-
|
70
|
+
describe "tags" do
|
71
|
+
it "returns an empty array if no tag key is in the parsed json" do
|
72
|
+
@reward = Badgeville::Reward.new({})
|
73
|
+
|
74
|
+
@reward.tags.should == []
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns an empty array if no tags are defined" do
|
78
|
+
@reward = Badgeville::Reward.new('tags' => nil)
|
79
|
+
|
80
|
+
@reward.tags.should == []
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns the defined tag" do
|
84
|
+
@reward = Badgeville::Reward.new('tags' => ['tag'])
|
85
|
+
|
86
|
+
@reward.tags.should == ["tag"]
|
73
87
|
end
|
74
88
|
|
75
|
-
it
|
89
|
+
it "returns all defined tags" do
|
90
|
+
@reward = Badgeville::Reward.new('tags' =>['tag1', 'tag2'])
|
91
|
+
|
92
|
+
@reward.tags.should == ['tag1', 'tag2']
|
93
|
+
end
|
76
94
|
end
|
77
95
|
end
|
78
96
|
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: badgeville
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gilad Buchman
|
9
|
+
- Robin Mehner
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
13
|
+
date: 2012-05-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: rest-client
|
17
|
+
requirement: &70255487231240 !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: *70255487231240
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: json
|
28
|
+
requirement: &70255487230420 !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: *70255487230420
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
38
|
+
name: bundler
|
39
|
+
requirement: &70255487230000 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70255487230000
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
50
|
-
requirement: &
|
49
|
+
name: rspec
|
50
|
+
requirement: &70255487229540 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70255487229540
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
-
requirement: &
|
60
|
+
name: rdoc
|
61
|
+
requirement: &70255487228800 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70255487228800
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
72
|
-
requirement: &
|
71
|
+
name: webmock
|
72
|
+
requirement: &70255487228100 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,21 +77,21 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
description:
|
80
|
+
version_requirements: *70255487228100
|
81
|
+
description: Badgeville API client
|
82
82
|
email:
|
83
83
|
executables: []
|
84
84
|
extensions: []
|
85
|
-
extra_rdoc_files:
|
86
|
-
- README.md
|
85
|
+
extra_rdoc_files: []
|
87
86
|
files:
|
88
87
|
- .document
|
89
|
-
-
|
88
|
+
- .gitignore
|
89
|
+
- .travis.yml
|
90
|
+
- CHANGELOG.md
|
90
91
|
- Gemfile
|
91
92
|
- Gemfile.lock
|
92
93
|
- README.md
|
93
94
|
- Rakefile
|
94
|
-
- VERSION
|
95
95
|
- badgeville.gemspec
|
96
96
|
- examples/log_and_check_status.rb
|
97
97
|
- keys.json.example
|
@@ -99,11 +99,11 @@ files:
|
|
99
99
|
- lib/badgeville/activity.rb
|
100
100
|
- lib/badgeville/helpers.rb
|
101
101
|
- lib/badgeville/reward.rb
|
102
|
+
- lib/badgeville/version.rb
|
102
103
|
- spec/badgeville_spec.rb
|
103
104
|
- spec/reward_spec.rb
|
104
105
|
- spec/spec_helper.rb
|
105
|
-
|
106
|
-
homepage: http://github.com/Keasinc/badgeville
|
106
|
+
homepage: http://github.com/rmehner/badgeville
|
107
107
|
licenses:
|
108
108
|
- MIT
|
109
109
|
post_install_message:
|
@@ -116,9 +116,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- - ! '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
|
-
segments:
|
120
|
-
- 0
|
121
|
-
hash: 3687302667246409787
|
122
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
120
|
none: false
|
124
121
|
requirements:
|
@@ -127,8 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
124
|
version: '0'
|
128
125
|
requirements: []
|
129
126
|
rubyforge_project:
|
130
|
-
rubygems_version: 1.
|
127
|
+
rubygems_version: 1.8.11
|
131
128
|
signing_key:
|
132
129
|
specification_version: 3
|
133
|
-
summary: Client for Badgeville's Core API
|
130
|
+
summary: Client for Badgeville's Core API v2. http://rules.badgeville.com
|
134
131
|
test_files: []
|
132
|
+
has_rdoc:
|
data/CHANGELOG
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
* 0.0.8
|
2
|
-
|
3
|
-
* support pagination and get all pages for rewards and rewards definitions
|
4
|
-
* misc bug fixes
|
5
|
-
* 0.0.7
|
6
|
-
|
7
|
-
* HAS MAJOR BUG DO NOT USE
|
8
|
-
|
9
|
-
* 0.0.6
|
10
|
-
|
11
|
-
* change set player to use new players/info end point
|
12
|
-
* add delete method for earned rewards
|
13
|
-
* add definition_id to reward
|
14
|
-
|
15
|
-
* 0.0.5
|
16
|
-
|
17
|
-
* set default timeout to 3s
|
18
|
-
* add timeout paramater
|
19
|
-
|
20
|
-
* 0.0.4
|
21
|
-
|
22
|
-
* count activities
|
23
|
-
* better error handling
|
24
|
-
* add tags to rewards
|
25
|
-
|
26
|
-
|
27
|
-
* 0.0.3
|
28
|
-
|
29
|
-
* Activity.rewards includes reward objects not reward definitions
|
30
|
-
* Reward has verb and threshold data for achievments type rewards
|
31
|
-
* Raise non json errors
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.8
|