nitroapi 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.md +67 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/examples/award_challenge.rb +13 -0
- data/examples/log_and_check_status.rb +13 -0
- data/keys.json.example +4 -0
- data/lib/nitro_api.rb +148 -0
- data/lib/nitro_api/challenge.rb +5 -0
- data/nitroapi.gemspec +69 -0
- data/spec/nitro_api_spec.rb +171 -0
- data/spec/spec_helper.rb +13 -0
- metadata +134 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
# Please keep me alphabetized!
|
4
|
+
gem 'activesupport'
|
5
|
+
gem 'json'
|
6
|
+
|
7
|
+
# Please keep me alphabetized!
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.3.0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.6.4"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
17
|
+
|
18
|
+
group :test do
|
19
|
+
gem "webmock"
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.9)
|
5
|
+
addressable (2.2.6)
|
6
|
+
crack (0.1.8)
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
git (1.2.5)
|
9
|
+
jeweler (1.6.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
json (1.5.3)
|
14
|
+
rake (0.8.7)
|
15
|
+
rcov (0.9.9)
|
16
|
+
rspec (2.3.0)
|
17
|
+
rspec-core (~> 2.3.0)
|
18
|
+
rspec-expectations (~> 2.3.0)
|
19
|
+
rspec-mocks (~> 2.3.0)
|
20
|
+
rspec-core (2.3.1)
|
21
|
+
rspec-expectations (2.3.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.3.0)
|
24
|
+
webmock (1.6.4)
|
25
|
+
addressable (~> 2.2, > 2.2.5)
|
26
|
+
crack (>= 0.1.7)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
activesupport
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
jeweler (~> 1.6.4)
|
35
|
+
json
|
36
|
+
rcov
|
37
|
+
rspec (~> 2.3.0)
|
38
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Keas Inc
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
Nitro API
|
2
|
+
============
|
3
|
+
|
4
|
+
Client for Bunchball's Nitro API http://www.bunchball.com/nitro/
|
5
|
+
(not complete)
|
6
|
+
|
7
|
+
Usage
|
8
|
+
--------
|
9
|
+
First, checkout the examples folder. TL;DR:
|
10
|
+
|
11
|
+
* create connection object with your api_key, and secret.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'nitro_api'
|
15
|
+
nitro = NitroApi::NitroApi.new user, settings['key'], settings['secret']
|
16
|
+
```
|
17
|
+
|
18
|
+
* login
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
nitro.login
|
22
|
+
```
|
23
|
+
|
24
|
+
* log actions
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
nitro.log_action "Video_Watch"
|
28
|
+
```
|
29
|
+
|
30
|
+
* check status
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
nitro.action_history "Video_Watch"
|
34
|
+
nitro.challenge_progress "Watch 10 Videos"
|
35
|
+
```
|
36
|
+
|
37
|
+
Installing
|
38
|
+
----------
|
39
|
+
add to your Gemfile
|
40
|
+
```
|
41
|
+
gem 'nitroapi', :git => 'git://github.com/KeasInc/nitroapi.git'
|
42
|
+
```
|
43
|
+
|
44
|
+
License
|
45
|
+
-------
|
46
|
+
|
47
|
+
Copyright (c) Keas Inc.
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
"Software"), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
63
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
64
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
65
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
66
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
67
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
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 = "nitroapi"
|
18
|
+
gem.homepage = "http://github.com/Keasinc/nitroapi"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Api client for Bunchball's Nitro"
|
21
|
+
gem.description = "Api client for Bunchball's Nitro. http://www.bunchball.com/nitro/"
|
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
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "nitroapi #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nitro_api'
|
4
|
+
|
5
|
+
settings = JSON.parse(File.read('keys.json'))
|
6
|
+
|
7
|
+
nitro = NitroApi::NitroApi.new 1, settings['key'], settings['secret']
|
8
|
+
|
9
|
+
nitro.login
|
10
|
+
nitro.award_challenge "Watch 5 Hours of Video"
|
11
|
+
|
12
|
+
progress = nitro.challenge_progress "Watch 5 Hours of Video"
|
13
|
+
puts "#{progress['name']} completed count:#{progress['completionCount']}"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nitro_api'
|
4
|
+
|
5
|
+
settings = JSON.parse(File.read('keys.json'))
|
6
|
+
|
7
|
+
nitro = NitroApi::NitroApi.new 1, settings['key'], settings['secret']
|
8
|
+
|
9
|
+
nitro.login
|
10
|
+
nitro.log_action "Video_Watch"
|
11
|
+
nitro.challenge_progress
|
12
|
+
|
13
|
+
puts nitro.action_history "Video_Watch"
|
data/keys.json.example
ADDED
data/lib/nitro_api.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'net/http'
|
4
|
+
require 'nitro_api/challenge'
|
5
|
+
|
6
|
+
module NitroApi
|
7
|
+
HOST = "http://sandbox.bunchball.net/nitro/"
|
8
|
+
ACCEPT = "json?"
|
9
|
+
|
10
|
+
class NitroError < StandardError
|
11
|
+
attr_accessor :code
|
12
|
+
|
13
|
+
def initialize (err_code=nil)
|
14
|
+
@code = err_code
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class NitroApi
|
19
|
+
attr_accessor :session
|
20
|
+
|
21
|
+
def initialize (user_id, api_key, secret)
|
22
|
+
# Required Parameters
|
23
|
+
@secret = secret
|
24
|
+
@api_key = api_key
|
25
|
+
@user = user_id
|
26
|
+
end
|
27
|
+
|
28
|
+
# Method for constructing a signature
|
29
|
+
def sign
|
30
|
+
time = Time.now.utc.to_i.to_s
|
31
|
+
unencrypted_signature = @api_key + @secret + time + @user.to_s
|
32
|
+
to_digest = unencrypted_signature + unencrypted_signature.length.to_s
|
33
|
+
return Digest::MD5.hexdigest(to_digest)
|
34
|
+
end
|
35
|
+
|
36
|
+
def login
|
37
|
+
params = {
|
38
|
+
:sig => sign,
|
39
|
+
:ts => Time.now.utc.to_i.to_s,
|
40
|
+
:apiKey => @api_key,
|
41
|
+
:userId => @user,
|
42
|
+
:method => 'user.login'
|
43
|
+
}
|
44
|
+
response = make_call(params)
|
45
|
+
@session = response["Login"]["sessionKey"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def log_action(actions, opts={})
|
49
|
+
value = opts.delete(:value)
|
50
|
+
user_id = opts.delete(:other_user)
|
51
|
+
params = {
|
52
|
+
:tags => actions.is_a?(Array) ? actions.join(",") : actions,
|
53
|
+
:sessionKey => @session,
|
54
|
+
:method => 'user.logAction'
|
55
|
+
}
|
56
|
+
params[:value] = value.to_s if value && !value.to_s.empty?
|
57
|
+
params[:userId] = user_id if user_id && !user_id.to_s.empty
|
58
|
+
make_call(params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def challenge_progress(opts={})
|
62
|
+
params = {
|
63
|
+
:sessionKey => @session,
|
64
|
+
:method => 'user.getChallengeProgress'
|
65
|
+
}
|
66
|
+
challenge = opts[:challenge]
|
67
|
+
params['challengeName'] = challenge if challenge and !challenge.to_s.empty?
|
68
|
+
params['showOnlyTrophies'] = opts.delete(:trophies_only) || false
|
69
|
+
params['folder'] = opts.delete(:folder) if opts.has_key?(:folder)
|
70
|
+
|
71
|
+
response = make_call(params)
|
72
|
+
|
73
|
+
if response['challenges']
|
74
|
+
response['challenges']['Challenge'].inject({}) do |challenges, item|
|
75
|
+
challenge = Challenge.new
|
76
|
+
challenge.name = item["name"]
|
77
|
+
challenge.description = item["description"]
|
78
|
+
challenge.full_url = item["fullUrl"]
|
79
|
+
challenge.thumb_url = item["thumbUrl"]
|
80
|
+
challenge.completed = item["completionCount"].to_i
|
81
|
+
|
82
|
+
challenges[challenge.name] = challenge
|
83
|
+
challenges
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def award_challenge(challenge)
|
89
|
+
params = {
|
90
|
+
:sessionKey => @session,
|
91
|
+
:userId => @user,
|
92
|
+
:method => 'user.awardChallenge',
|
93
|
+
:challenge => challenge
|
94
|
+
}
|
95
|
+
make_call(params)
|
96
|
+
end
|
97
|
+
|
98
|
+
def action_history actions=[]
|
99
|
+
params = {
|
100
|
+
:sessionKey => @session,
|
101
|
+
:method => 'user.getActionHistory'
|
102
|
+
}
|
103
|
+
if actions && !actions.empty?
|
104
|
+
params[:tags] = actions.is_a?(Array) ? actions.join(",") : actions
|
105
|
+
end
|
106
|
+
response = make_call(params)
|
107
|
+
if response['ActionHistoryRecord']
|
108
|
+
response['ActionHistoryRecord']['ActionHistoryItem'].inject([]) do
|
109
|
+
|history, item|
|
110
|
+
history<< {:tags => item['tags'],
|
111
|
+
:ts => Time.at(item['ts'].to_i),
|
112
|
+
:value => item['value'].to_i
|
113
|
+
}
|
114
|
+
end
|
115
|
+
else
|
116
|
+
[]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def join_group group
|
121
|
+
params = {
|
122
|
+
:sessionKey => @session,
|
123
|
+
:method => 'user.joinGroup',
|
124
|
+
:groupName => group
|
125
|
+
}
|
126
|
+
make_call(params)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def make_call(params)
|
132
|
+
request = HOST + ACCEPT + to_query(params)
|
133
|
+
data = Net::HTTP.get(URI.parse(request))
|
134
|
+
json = JSON.parse(data)
|
135
|
+
response = json["Nitro"]
|
136
|
+
error = response["Error"]
|
137
|
+
if error
|
138
|
+
raise NitroError.new(error["Code"]), error["Message"]
|
139
|
+
else
|
140
|
+
response
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def to_query params
|
145
|
+
URI.escape(params.map { |k,v| "#{k.to_s}=#{v.to_s}" }.join("&"))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/nitroapi.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{nitroapi}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Gilad Buchman"]
|
12
|
+
s.date = %q{2011-08-09}
|
13
|
+
s.description = %q{Api client for Bunchball's Nitro. http://www.bunchball.com/nitro/}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"examples/award_challenge.rb",
|
28
|
+
"examples/log_and_check_status.rb",
|
29
|
+
"keys.json.example",
|
30
|
+
"lib/nitro_api.rb",
|
31
|
+
"lib/nitro_api/challenge.rb",
|
32
|
+
"nitroapi.gemspec",
|
33
|
+
"spec/nitro_api_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/Keasinc/nitroapi}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.6.2}
|
40
|
+
s.summary = %q{Api client for Bunchball's Nitro}
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
47
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
54
|
+
s.add_dependency(%q<json>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
62
|
+
s.add_dependency(%q<json>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe NitroApi do
|
4
|
+
before do
|
5
|
+
@user = "user"
|
6
|
+
@api_key = "key"
|
7
|
+
@secret = "secret"
|
8
|
+
@nitro = NitroApi::NitroApi.new @user, @api_key, @secret
|
9
|
+
@success = {"Nitro" => {"res" => "ok"}}.to_json
|
10
|
+
@session = "1"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#sign" do
|
14
|
+
it "takes MD5 like in http://wiki.bunchball.com/w/page/12748060/user_login" do
|
15
|
+
to_digest = @api_key + @secret + Time.now.utc.to_i.to_s + @user.to_s
|
16
|
+
to_digest += to_digest.length.to_s
|
17
|
+
@nitro.sign.should == Digest::MD5.hexdigest(to_digest)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#login" do
|
22
|
+
it "should set session id for a successful call" do
|
23
|
+
mock_json = {"Nitro" => {"Login" => {"sessionKey" => @session}}}
|
24
|
+
url = NitroApi::HOST + "?.*method=user.login.*"
|
25
|
+
stub_http_request(:get, Regexp.new(url)).
|
26
|
+
to_return(:body => mock_json.to_json)
|
27
|
+
|
28
|
+
@nitro.login
|
29
|
+
@nitro.session.should == @session
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when authenticated" do
|
34
|
+
before do
|
35
|
+
@nitro.session = @session
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#log_action" do
|
39
|
+
it "sends one action with session on query string" do
|
40
|
+
action_name = "action"
|
41
|
+
params = {"tags" => action_name,
|
42
|
+
"sessionKey" => @session,
|
43
|
+
"method" => "user.logAction"
|
44
|
+
}
|
45
|
+
url = NitroApi::HOST + "?.*method=user.logAction.*"
|
46
|
+
stub_http_request(:get, Regexp.new(url)).
|
47
|
+
with(:query => params).
|
48
|
+
to_return(:body => @success)
|
49
|
+
|
50
|
+
@nitro.log_action action_name
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sends comma seperated action list with session on query string" do
|
54
|
+
actions = ["action1", "action2"]
|
55
|
+
params = {"tags" => actions.join(","),
|
56
|
+
"sessionKey" => @session,
|
57
|
+
"method" => "user.logAction"
|
58
|
+
}
|
59
|
+
url = NitroApi::HOST + "?.*method=user.logAction.*"
|
60
|
+
stub_http_request(:get, Regexp.new(url)).
|
61
|
+
with(:query => params).
|
62
|
+
to_return(:body => @success)
|
63
|
+
|
64
|
+
@nitro.log_action actions
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#challenge_progress" do
|
69
|
+
it "returns the challenge part of the response" do
|
70
|
+
params = {
|
71
|
+
"showOnlyTrophies" => "false",
|
72
|
+
"sessionKey" => @session,
|
73
|
+
"method" => "user.getChallengeProgress"
|
74
|
+
}
|
75
|
+
url = NitroApi::HOST + "?.*method=user.getChallengeProgress.*"
|
76
|
+
mock_data = [{"completionCount"=>"1",
|
77
|
+
"description" => "some description",
|
78
|
+
"name" => "Watch 10 Videos"}]
|
79
|
+
|
80
|
+
mock_json = {"Nitro" => {"challenges" => {"Challenge" => mock_data}}}
|
81
|
+
stub_http_request(:get, Regexp.new(url)).
|
82
|
+
with(:query => params).
|
83
|
+
to_return(:body => mock_json.to_json)
|
84
|
+
|
85
|
+
progress = @nitro.challenge_progress
|
86
|
+
progress.should_not be_empty
|
87
|
+
challenge = progress["Watch 10 Videos"]
|
88
|
+
challenge.should_not be_nil
|
89
|
+
challenge.description.should == "some description"
|
90
|
+
challenge.completed.should == 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#award challenge" do
|
95
|
+
it "returns the challenge part of the response" do
|
96
|
+
params = {
|
97
|
+
"userId" => @user,
|
98
|
+
"sessionKey" => @session,
|
99
|
+
"challenge" => "TestChallenge",
|
100
|
+
"method" => "user.awardChallenge"
|
101
|
+
}
|
102
|
+
url = NitroApi::HOST + "?.*method=user.awardChallenge.*"
|
103
|
+
stub_http_request(:get, Regexp.new(url)).
|
104
|
+
with(:query => params).
|
105
|
+
to_return(:body => @success)
|
106
|
+
|
107
|
+
@nitro.award_challenge "TestChallenge"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#action_history" do
|
112
|
+
before do
|
113
|
+
@now = Time.now
|
114
|
+
@mock_history =
|
115
|
+
[
|
116
|
+
{'ts' => @now.to_i, 'tags' => 'action0', 'value' => '0'},
|
117
|
+
{'ts' => @now.to_i, 'tage' => 'action1', 'value' => '1'}
|
118
|
+
]
|
119
|
+
@mock_json = {"Nitro" =>
|
120
|
+
{"ActionHistoryRecord" =>
|
121
|
+
{"ActionHistoryItem" => @mock_history}}}.to_json
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns an array of log entries with date & value for all actions" do
|
125
|
+
params = {
|
126
|
+
"sessionKey" => @session,
|
127
|
+
"method" => "user.getActionHistory"
|
128
|
+
}
|
129
|
+
url = NitroApi::HOST + "?.*method=user.getActionHistory.*"
|
130
|
+
stub_http_request(:get, Regexp.new(url)).
|
131
|
+
with(:query => params).
|
132
|
+
to_return(:body => @mock_json)
|
133
|
+
|
134
|
+
history = @nitro.action_history
|
135
|
+
history.count.should == 2
|
136
|
+
history[0][:tags].should == 'action0'
|
137
|
+
history[0][:ts].to_i.should == @now.to_i
|
138
|
+
history[1][:value].should == 1
|
139
|
+
end
|
140
|
+
|
141
|
+
it "can ask for history for a specific action list" do
|
142
|
+
params = {
|
143
|
+
"sessionKey" => @session,
|
144
|
+
"method" => "user.getActionHistory",
|
145
|
+
"tags" => "action1"
|
146
|
+
}
|
147
|
+
url = NitroApi::HOST + "?.*method=user.getActionHistory.*"
|
148
|
+
stub_http_request(:get, Regexp.new(url)).
|
149
|
+
with(:query => params).
|
150
|
+
to_return(:body => @mock_json)
|
151
|
+
|
152
|
+
@nitro.action_history 'action1'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#join_group name_of_group" do
|
157
|
+
it "sends that user joined a group" do
|
158
|
+
params = {"groupName" => "group",
|
159
|
+
"sessionKey" => @session,
|
160
|
+
"method" => "user.joinGroup"
|
161
|
+
}
|
162
|
+
url = NitroApi::HOST + "?.*method=user.joinGroup.*"
|
163
|
+
stub_http_request(:get, Regexp.new(url)).
|
164
|
+
with(:query => params).
|
165
|
+
to_return(:body => @success)
|
166
|
+
|
167
|
+
@nitro.join_group "group"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'nitro_api'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nitroapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gilad Buchman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-09 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &2151919720 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2151919720
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: json
|
28
|
+
requirement: &2151918760 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2151918760
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &2151917460 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.3.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2151917460
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &2151916000 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2151916000
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &2151914100 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.6.4
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2151914100
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &2151913060 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2151913060
|
81
|
+
description: Api client for Bunchball's Nitro. http://www.bunchball.com/nitro/
|
82
|
+
email:
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
files:
|
89
|
+
- .document
|
90
|
+
- .rspec
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- examples/award_challenge.rb
|
98
|
+
- examples/log_and_check_status.rb
|
99
|
+
- keys.json.example
|
100
|
+
- lib/nitro_api.rb
|
101
|
+
- lib/nitro_api/challenge.rb
|
102
|
+
- nitroapi.gemspec
|
103
|
+
- spec/nitro_api_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
has_rdoc: true
|
106
|
+
homepage: http://github.com/Keasinc/nitroapi
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: -3986991512343110220
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.6.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Api client for Bunchball's Nitro
|
134
|
+
test_files: []
|