gamygame_gem 0.4.1

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.
@@ -0,0 +1,3 @@
1
+ .ruby-gemset
2
+ .ruby-version
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nuvado.gemspec
4
+ gemspec
5
+ gem 'sinatra'
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gamygame (0.0.1)
5
+ httparty (~> 0.10.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.4)
11
+ crack (0.3.2)
12
+ httparty (0.10.2)
13
+ multi_json (~> 1.0)
14
+ multi_xml (>= 0.5.2)
15
+ metaclass (0.0.1)
16
+ minitest (4.7.4)
17
+ mocha (0.14.0)
18
+ metaclass (~> 0.0.1)
19
+ multi_json (1.7.3)
20
+ multi_xml (0.5.3)
21
+ rack (1.5.2)
22
+ rack-protection (1.5.0)
23
+ rack
24
+ rake (10.0.4)
25
+ sinatra (1.4.2)
26
+ rack (~> 1.5, >= 1.5.2)
27
+ rack-protection (~> 1.4)
28
+ tilt (~> 1.3, >= 1.3.4)
29
+ tilt (1.4.1)
30
+ webmock (1.11.0)
31
+ addressable (>= 2.2.7)
32
+ crack (>= 0.3.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ gamygame!
39
+ minitest (~> 4.2)
40
+ mocha
41
+ rake
42
+ sinatra
43
+ webmock
@@ -0,0 +1,93 @@
1
+ # GamyGame Ruby Client
2
+
3
+ Is a ruby client for the GamyGame API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gamygame', github: 'ArtmobileTechnologies/gamygame-server'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ ### Authentication
18
+ #### Step 1 - Redirect to the authorization url
19
+ In order to build the authorization url you need to provide your client id and a callback url to which GamyGame will redirect after your users authorize your application.
20
+
21
+ ```ruby
22
+ authenticator = GamyGame::Authenticator.new
23
+ authenticator.authorization_url(CALLBACK_URL, YOUR_CLIENT_ID)
24
+ ```
25
+ #### Step 2 - Trade player code for player token
26
+ Before redirecting to your callback url, GamyGame will add a code param to the url's query string. You'll need to trade that code for a player token.
27
+
28
+ ```ruby
29
+ player_token = authenticator.get_player_token(CODE)
30
+ ```
31
+ #### Step 3 - Access the API
32
+ Using your application's GamyGame API key and the player's token. You can initialize a GamyGame client to interact with the API.
33
+
34
+ ```ruby
35
+ client = GamyGame::Client.new(API_KEY, PLAYER_TOKEN)
36
+ ```
37
+ ### Api Usage - Brand
38
+ You can check the brand stats by using the following method:
39
+
40
+ ```ruby
41
+ client.brand.stats
42
+ => [{"title"=>"Pages", "logo"=>{"logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "name"=>"Pages", "id"=>"20"}]
43
+ ```
44
+
45
+ And the brand badges by using the following method:
46
+
47
+ ```ruby
48
+ client.brand.badges
49
+ => [{"title"=>"Read First Book", "name"=>"One of Us! One of Us!", "logo"=>{"badge_logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "id"=>"95"}, {"title"=>"Read a Science Fiction Book", "name"=>"Beam me up, Scotty", "logo"=>{"badge_logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "id"=>"96"},...]
50
+ ```
51
+ ### Api Usage - Player
52
+ #### Stats
53
+ You can get the player stats with:
54
+
55
+ ```ruby
56
+ client.player.stats
57
+ => [{"id"=>40670, "count"=>940, "stat"=>{"title"=>"Pages", "logo"=>{"logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "name"=>"Pages", "id"=>"20"}}]
58
+ ```
59
+
60
+ or a single player stat with:
61
+
62
+ ```ruby
63
+ client.player.stat(40670)
64
+ => {"id"=>40670, "count"=>940, "stat"=>{"title"=>"Pages", "logo"=>{"logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "name"=>"Pages", "id"=>"20"}}
65
+ ```
66
+
67
+ You can also increase a single stat with:
68
+
69
+ ```ruby
70
+ client.player.increment_stat("Pages") # will increase by one
71
+ client.player.increment_stat("Pages", :quantity => ANY_AMOUNT) # will increase by any amount
72
+ ```
73
+ #### Achievements
74
+ You can get a list of all the badges achieved by the player with:
75
+
76
+ ```ruby
77
+ client.player.achievements
78
+ => [{"count"=>1, "id"=>13, "badge"=>{"title"=>"Read First Book", "name"=>"One of Us! One of Us!", "logo"=>{"badge_logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "id"=>"95"}}, ...]
79
+ ```
80
+
81
+ or a single achieved badge with:
82
+
83
+ ```ruby
84
+ client.player.achievement(13)
85
+ => {"count"=>1, "id"=>13, "badge"=>{"title"=>"Read First Book", "name"=>"One of Us! One of Us!", "logo"=>{"badge_logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "id"=>"95"}}
86
+ ```
87
+
88
+ You can also grant new badges to players with:
89
+
90
+ ```ruby
91
+ client.player.grant_achievement("Beam me up, Scotty")
92
+ => {"count"=>1, "id"=>14, "badge"=>{"title"=>"Read a Science Fiction Book", "name"=>"Beam me up, Scotty", "logo"=>{"badge_logo"=>{"url"=>"http://placehold.it/28x28", "thumb"=>{"url"=>"http://placehold.it/28x28"}}}, "id"=>"96"}}
93
+ ```
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :console do
7
+ puts "Loading development console..."
8
+ system("irb -r gamygame")
9
+ end
10
+
11
+ task :test do
12
+ Dir.chdir('test')
13
+ end
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << '../lib'
17
+ t.libs << '../test'
18
+ t.test_files = FileList['*_test.rb']
19
+ t.verbose = false
20
+ end
21
+
22
+ task :default => :test
@@ -0,0 +1,21 @@
1
+ require 'sinatra'
2
+ require 'gamygame'
3
+
4
+ enable :sessions
5
+
6
+ helpers do
7
+ def get_token(client_id, code)
8
+ authenticator = GamyGame::Authenticator.new
9
+ redirect authenticator.authorization_url(request.url, client_id)
10
+ session["token"] = authenticator.get_player_token(code)
11
+ session["token"]
12
+ end
13
+ end
14
+
15
+ get '/' do
16
+ client_id = "YOUR CLIENT ID"
17
+ api_key = "YOUR API KEY"
18
+ token = session["token"] || get_token(client_id, params[:code])
19
+ client = GamyGame::Client.new(api_key, token)
20
+ %Q{Hola #{client.me["nickname"]}}
21
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gamygame/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gamygame_gem"
8
+ spec.version = GamyGame::VERSION
9
+ spec.authors = ["GamyGame.com"]
10
+ spec.email = ""
11
+ spec.description = %q{Official GamyGame Client.}
12
+ spec.summary = %q{Official GamyGame Client.}
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "httparty", "~> 0.10.2"
20
+
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest", "~> 4.2"
23
+ spec.add_development_dependency "mocha"
24
+ spec.add_development_dependency "webmock"
25
+ end
@@ -0,0 +1,6 @@
1
+ require 'gamygame/api_call'
2
+ require 'gamygame/http_client'
3
+ require 'gamygame/authenticator'
4
+ require 'gamygame/player'
5
+ require 'gamygame/brand'
6
+ require 'gamygame/client'
@@ -0,0 +1,42 @@
1
+ module GamyGame
2
+ class ApiCall
3
+
4
+ # Initialize with HttpClient
5
+ # initial scope "/api/v1"
6
+ def initialize(http)
7
+ @http = http
8
+ @scope = ["/api/v1"]
9
+ end
10
+
11
+ # Get base for root, index
12
+ # Alias: index, get
13
+ def get
14
+ @http.get(@scope.join("/"))
15
+ end
16
+ alias :index :get
17
+
18
+ # Http POST with params
19
+ # Alias: create, post
20
+ def post(params = {})
21
+ @http.post(@scope.join("/"), :body => params)
22
+ end
23
+ alias :create :post
24
+
25
+ # HTTP Delete
26
+ def delete(params = {})
27
+ @http.delete(@scope.join("/"), :body => params)
28
+ end
29
+
30
+ # Add id_scope to scope
31
+ def find(id)
32
+ @scope << id
33
+ self
34
+ end
35
+
36
+ # Add Method missing with args and block to scope
37
+ def method_missing(method, *args, &block)
38
+ @scope << method
39
+ self
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module GamyGame
2
+ class Authenticator
3
+
4
+ # Defines an the redirect_uri and client_id for authorization
5
+ # usefull for external authorization
6
+ def authorization_url(redirect_uri, client_id)
7
+ url = URI.join http.class.base_uri, "/dialogs/", "auth"
8
+ url.query = "redirect_uri=#{URI.escape(redirect_uri)}&client_id=#{URI.escape(client_id)}"
9
+ url.to_s
10
+ end
11
+
12
+ # Get the player Token based in his code
13
+ # GamyGame API V1 Compatible
14
+ def get_player_token(player_code)
15
+ http.post("/api/v1/tokens", :body => {:code => player_code})["token"]
16
+ end
17
+
18
+ private
19
+
20
+ def http
21
+ HttpClient.new
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module GamyGame
2
+ class Brand
3
+
4
+ # Initialize with HTTParty client
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ # Get Brand Stats
10
+ def stats
11
+ api.stats.index
12
+ end
13
+
14
+ # Get Brand Badges
15
+ def badges
16
+ api.badges.index
17
+ end
18
+
19
+ # Get Brand Open Info
20
+ def data(id)
21
+ api.data.find(id).get
22
+ end
23
+
24
+ private
25
+ def api
26
+ ApiCall.new(@http).brand
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ module GamyGame
2
+ class Client
3
+
4
+ # Initialize with GamyGame.Brand api_key and GamyGame valid player_token
5
+ def initialize(api_key, player_token)
6
+ http_params = {
7
+ :basic_auth => {:username => api_key, :password => player_token}
8
+ }
9
+ @http = HttpClient.new(http_params)
10
+ end
11
+
12
+ def player
13
+ Player.new(@http)
14
+ end
15
+
16
+ def brand
17
+ Brand.new(@http)
18
+ end
19
+
20
+ def me
21
+ api.me.get
22
+ end
23
+
24
+ def start_session_tracking(params = {})
25
+ api.actions.sessions.create({:ts => Time.now.to_i, :params => params})
26
+ end
27
+
28
+ def end_session_tracking(params = {})
29
+ api.actions.sessions.delete({:ts => Time.now.to_i, :params => params})
30
+ end
31
+
32
+ def track_action(action_name, params = {})
33
+ api.actions.track.create({:ts => Time.now.to_i, :name => action_name, :params => params})
34
+ end
35
+
36
+ def begin_action_tracking(action_name, params = {})
37
+ api.actions.begin_track.create({:ts => Time.now.to_i, :name => action_name, :params => params})
38
+ end
39
+
40
+ def end_action_tracking(action_name, params = {})
41
+ api.actions.end_track.create({:ts => Time.now.to_i, :name => action_name, :params => params})
42
+ end
43
+
44
+ private
45
+ def api
46
+ ApiCall.new(@http)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ require 'httparty'
2
+
3
+ module GamyGame
4
+ class HttpClient
5
+ include HTTParty
6
+ base_uri 'https://platform.gamygame.com'
7
+ format :json
8
+
9
+ attr_reader :http_params
10
+
11
+ def initialize(http_params = {})
12
+ @http_params = http_params
13
+ end
14
+
15
+ def get(path, options = {})
16
+ options.merge!(http_params)
17
+ self.class.get(path, options).parsed_response
18
+ end
19
+
20
+ def post(path, options = {})
21
+ options.merge!(http_params)
22
+ self.class.post(path, options).parsed_response
23
+ end
24
+
25
+ def delete(path, options = {})
26
+ options.merge!(http_params)
27
+ self.class.delete(path, options).parsed_response
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ module GamyGame
2
+ class Player
3
+ def initialize(http)
4
+ @http = http
5
+ end
6
+
7
+ def stats
8
+ api.stats.index
9
+ end
10
+
11
+ def stat(id)
12
+ api.stats.find(id).get
13
+ end
14
+
15
+ def increment_stat(stat_name, params = {})
16
+ api.stats.find(stat_name).increment.post(params)
17
+ end
18
+
19
+ def achievements
20
+ api.achievements.index
21
+ end
22
+
23
+ def achievement(id)
24
+ api.achievements.find(id).get
25
+ end
26
+
27
+ def grant_achievement(badge_name)
28
+ api.achievements.create(:badge_name => badge_name)
29
+ end
30
+
31
+ def advance_to_next_level
32
+ api.level.post
33
+ end
34
+
35
+ private
36
+ def api
37
+ ApiCall.new(@http).player
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module GamyGame
2
+ VERSION = "0.4.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class AuthenticatorTest < MiniTest::Unit::TestCase
4
+ def test_trade_player_code_for_player_token
5
+ stub_request(:post, "http://localhost:3000/api/v1/tokens").
6
+ with(:body => "code=code").
7
+ to_return(:status => 200, :body => "{\"token\":\"token\"}", :headers => {})
8
+
9
+ authenticator = GamyGame::Authenticator.new
10
+ assert_equal "token", authenticator.get_player_token("code")
11
+ end
12
+
13
+ def test_authorization_url
14
+ authenticator = GamyGame::Authenticator.new
15
+ expected_url = "http://localhost:3000/dialogs/auth?redirect_uri=http://localhost:4567/me&client_id=client_id"
16
+ assert_equal expected_url, authenticator.authorization_url("http://localhost:4567/me", "client_id")
17
+ end
18
+ end
@@ -0,0 +1,204 @@
1
+ require 'test_helper'
2
+
3
+ class ClientTest < MiniTest::Unit::TestCase
4
+ def test_index_brand_badges
5
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/brand/badges").
6
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
7
+
8
+ client = GamyGame::Client.new("key", "token")
9
+ assert_equal ["stuff"], client.brand.badges
10
+ end
11
+
12
+ def test_index_brand_stats
13
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/brand/stats").
14
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
15
+
16
+ client = GamyGame::Client.new("key", "token")
17
+ assert_equal ["stuff"], client.brand.stats
18
+ end
19
+
20
+ def test_me
21
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/me").
22
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
23
+
24
+ client = GamyGame::Client.new("key", "token")
25
+ assert_equal ["stuff"], client.me
26
+ end
27
+
28
+ def test_start_session_client_method
29
+ Time.any_instance.stubs(:to_i).returns(1)
30
+
31
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/sessions").
32
+ with(:body => "ts=1").
33
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
34
+
35
+ client = GamyGame::Client.new("key", "token")
36
+ assert_equal ["stuff"], client.start_session_tracking
37
+ end
38
+
39
+ def test_start_session_client_method_with_params
40
+ Time.any_instance.stubs(:to_i).returns(1)
41
+
42
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/sessions").
43
+ with(:body => "ts=1&params[data]=data").
44
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
45
+
46
+ client = GamyGame::Client.new("key", "token")
47
+ assert_equal ["stuff"], client.start_session_tracking({:data => :data})
48
+ end
49
+
50
+ def test_end_session_client_method
51
+ Time.any_instance.stubs(:to_i).returns(1)
52
+
53
+ stub_request(:delete, "http://key:token@localhost:3000/api/v1/actions/sessions").
54
+ with(:body => "ts=1").
55
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
56
+
57
+ client = GamyGame::Client.new("key", "token")
58
+ assert_equal ["stuff"], client.end_session_tracking
59
+ end
60
+
61
+
62
+ def test_end_session_client_method_with_data
63
+ Time.any_instance.stubs(:to_i).returns(1)
64
+
65
+ stub_request(:delete, "http://key:token@localhost:3000/api/v1/actions/sessions").
66
+ with(:body => "ts=1&params[data]=data").
67
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
68
+
69
+ client = GamyGame::Client.new("key", "token")
70
+ assert_equal ["stuff"], client.end_session_tracking({:data => :data})
71
+ end
72
+
73
+ def test_track_action_client_method
74
+ Time.any_instance.stubs(:to_i).returns(1)
75
+
76
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/track").
77
+ with(:body => "ts=1&name=action").
78
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
79
+
80
+ client = GamyGame::Client.new("key", "token")
81
+ assert_equal ["stuff"], client.track_action("action")
82
+ end
83
+
84
+ def test_track_action_client_method_with_action_params
85
+ Time.any_instance.stubs(:to_i).returns(1)
86
+
87
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/track").
88
+ with(:body => "ts=1&name=action&params[data]=data").
89
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
90
+
91
+ client = GamyGame::Client.new("key", "token")
92
+ assert_equal ["stuff"], client.track_action("action", {:data => :data})
93
+ end
94
+
95
+ def test_begin_track_client_method
96
+ Time.any_instance.stubs(:to_i).returns(1)
97
+
98
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/begin_track").
99
+ with(:body => "ts=1&name=action").
100
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
101
+
102
+ client = GamyGame::Client.new("key", "token")
103
+ assert_equal ["stuff"], client.begin_action_tracking("action")
104
+ end
105
+
106
+ def test_begin_track_client_method_with_action_params
107
+ Time.any_instance.stubs(:to_i).returns(1)
108
+
109
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/begin_track").
110
+ with(:body => "ts=1&name=action&params[data]=data").
111
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
112
+
113
+ client = GamyGame::Client.new("key", "token")
114
+ assert_equal ["stuff"], client.begin_action_tracking("action", {:data => :data})
115
+ end
116
+
117
+ def test_end_track_client_method
118
+ Time.any_instance.stubs(:to_i).returns(1)
119
+
120
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/end_track").
121
+ with(:body => "ts=1&name=action").
122
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
123
+
124
+ client = GamyGame::Client.new("key", "token")
125
+ assert_equal ["stuff"], client.end_action_tracking("action")
126
+ end
127
+
128
+ def test_end_track_client_method_with_action_params
129
+ Time.any_instance.stubs(:to_i).returns(1)
130
+
131
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/actions/end_track").
132
+ with(:body => "ts=1&name=action&params[data]=data").
133
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
134
+
135
+ client = GamyGame::Client.new("key", "token")
136
+ assert_equal ["stuff"], client.end_action_tracking("action", {:data => :data})
137
+ end
138
+
139
+ def test_index_player_stats
140
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/player/stats").
141
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
142
+
143
+ client = GamyGame::Client.new("key", "token")
144
+ assert_equal ["stuff"], client.player.stats
145
+ end
146
+
147
+ def test_show_player_stat
148
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/player/stats/1").
149
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
150
+
151
+ client = GamyGame::Client.new("key", "token")
152
+ assert_equal ["stuff"], client.player.stat(1)
153
+ end
154
+
155
+ def test_increment_player_stat
156
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/player/stats/1/increment").
157
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
158
+
159
+ client = GamyGame::Client.new("key", "token")
160
+ assert_equal ["stuff"], client.player.increment_stat(1)
161
+ end
162
+
163
+ def test_increment_player_stat_with_quantity
164
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/player/stats/1/increment").
165
+ with(:body => "quantity=2").
166
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
167
+
168
+ client = GamyGame::Client.new("key", "token")
169
+ assert_equal ["stuff"], client.player.increment_stat(1, :quantity => 2)
170
+ end
171
+
172
+ def test_index_player_achievements
173
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/player/achievements").
174
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
175
+
176
+ client = GamyGame::Client.new("key", "token")
177
+ assert_equal ["stuff"], client.player.achievements
178
+ end
179
+
180
+ def test_show_player_achievement
181
+ stub_request(:get, "http://key:token@localhost:3000/api/v1/player/achievements/1").
182
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
183
+
184
+ client = GamyGame::Client.new("key", "token")
185
+ assert_equal ["stuff"], client.player.achievement(1)
186
+ end
187
+
188
+ def test_create_player_achievement
189
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/player/achievements").
190
+ with(:body => "badge_name=running%20a%20test").
191
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
192
+
193
+ client = GamyGame::Client.new("key", "token")
194
+ assert_equal ["stuff"], client.player.grant_achievement("running a test")
195
+ end
196
+
197
+ def test_player_go_to_next_level
198
+ stub_request(:post, "http://key:token@localhost:3000/api/v1/player/level").
199
+ to_return(:status => 200, :body => "[\"stuff\"]", :headers => {})
200
+
201
+ client = GamyGame::Client.new("key", "token")
202
+ assert_equal ["stuff"], client.player.advance_to_next_level
203
+ end
204
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'gamygame'
3
+ require 'mocha/setup'
4
+ require 'webmock/minitest'
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamygame_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GamyGame.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '4.2'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Official GamyGame Client.
95
+ email: ''
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - .gitignore
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - README.md
104
+ - Rakefile
105
+ - examples/authentication_example.rb
106
+ - gamygame.gemspec
107
+ - lib/gamygame.rb
108
+ - lib/gamygame/api_call.rb
109
+ - lib/gamygame/authenticator.rb
110
+ - lib/gamygame/brand.rb
111
+ - lib/gamygame/client.rb
112
+ - lib/gamygame/http_client.rb
113
+ - lib/gamygame/player.rb
114
+ - lib/gamygame/version.rb
115
+ - test/authenticator_test.rb
116
+ - test/client_test.rb
117
+ - test/test_helper.rb
118
+ homepage:
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.23
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Official GamyGame Client.
142
+ test_files:
143
+ - test/authenticator_test.rb
144
+ - test/client_test.rb
145
+ - test/test_helper.rb